From df5619c4886f65c3cbf3d6b5eda779e9aa92809a Mon Sep 17 00:00:00 2001 From: Reuven Date: Wed, 3 Nov 2021 10:44:50 +0200 Subject: [PATCH] test openapi spec 3.1 --- data/openapi31-test1.yaml | 34 ++++++++++++++++++++++++++++++++++ data/openapi31-test2.yaml | 35 +++++++++++++++++++++++++++++++++++ diff/diff_test.go | 18 ++++++++++++++++++ 3 files changed, 87 insertions(+) create mode 100644 data/openapi31-test1.yaml create mode 100644 data/openapi31-test2.yaml diff --git a/data/openapi31-test1.yaml b/data/openapi31-test1.yaml new file mode 100644 index 00000000..3a4783ae --- /dev/null +++ b/data/openapi31-test1.yaml @@ -0,0 +1,34 @@ +openapi: 3.1.0 +info: + title: Webhook Example + version: 1.0.0 +# Since OAS 3.1.0 the paths element isn't necessary. Now a valid OpenAPI Document can describe only paths, webhooks, or even only reusable components +webhooks: + # Each webhook needs a name + newPet: + # This is a Path Item Object, the only difference is that the request is initiated by the API provider + post: + requestBody: + description: Information about a new pet in the system + content: + application/json: + schema: + $ref: "#/components/schemas/Pet" + responses: + "200": + description: Return a 200 status to indicate that the data was received successfully + +components: + schemas: + Pet: + required: + - id + - name + properties: + id: + type: integer + format: int64 + name: + type: string + tag: + type: string \ No newline at end of file diff --git a/data/openapi31-test2.yaml b/data/openapi31-test2.yaml new file mode 100644 index 00000000..4ce465d0 --- /dev/null +++ b/data/openapi31-test2.yaml @@ -0,0 +1,35 @@ +openapi: 3.1.0 +info: + title: Webhook Example + version: 1.0.0 +# Since OAS 3.1.0 the paths element isn't necessary. Now a valid OpenAPI Document can describe only paths, webhooks, or even only reusable components +webhooks: + # Each webhook needs a name + newPet: + # This is a Path Item Object, the only difference is that the request is initiated by the API provider + post: + requestBody: + description: Information about a new pet in the system + content: + application/json: + schema: + $ref: "#/components/schemas/Pet" + responses: + "200": + description: Return a 200 status to indicate that the data was received successfully + +components: + schemas: + Pet: + required: + - id + - name + - nickname + properties: + id: + type: integer + format: int64 + name: + type: string + tag: + type: string \ No newline at end of file diff --git a/diff/diff_test.go b/diff/diff_test.go index fbd6a3c9..4400c323 100644 --- a/diff/diff_test.go +++ b/diff/diff_test.go @@ -536,3 +536,21 @@ func TestModifiedSecurityRequirement(t *testing.T) { securityScopesDiff["OAuth"].Deleted, "write:pets") } + +func TestOAS31(t *testing.T) { + loader := openapi3.NewLoader() + + s1, err := loader.LoadFromFile("../data/openapi31-test1.yaml") + require.NoError(t, err) + + s2, err := loader.LoadFromFile("../data/openapi31-test2.yaml") + require.NoError(t, err) + + d, err := diff.Get(diff.NewConfig(), s1, s2) + require.NoError(t, err) + + // while specific 3.1 features, such as webhooks, are not yet supported by kin-openapi, the diff still works + require.Contains(t, + d.ComponentsDiff.SchemasDiff.Modified["Pet"].RequiredDiff.Added, + "nickname") +}