Skip to content

Commit

Permalink
test openapi spec 3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Reuven committed Nov 3, 2021
1 parent 5911b12 commit df5619c
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
34 changes: 34 additions & 0 deletions data/openapi31-test1.yaml
Original file line number Diff line number Diff line change
@@ -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
35 changes: 35 additions & 0 deletions data/openapi31-test2.yaml
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions diff/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

0 comments on commit df5619c

Please sign in to comment.