feat: Resolver tests for valid and invalid recursive models

This commit is contained in:
Benjamin Nolan (TwoWholeWorms)
2023-01-05 14:07:39 +01:00
committed by Dave Shanley
parent 5f92de63a4
commit e8a954d5ae
5 changed files with 270 additions and 25 deletions

View File

@@ -14,6 +14,8 @@ components:
properties:
things:
"$ref": "#/components/schemas/Two"
required:
- things
Two:
description: "test two"
properties:
@@ -21,6 +23,9 @@ components:
"$ref": "#/components/schemas/One"
anyOf:
- "$ref": "#/components/schemas/Four"
required:
- testThing
- anyOf
Three:
description: "test three"
properties:
@@ -30,30 +35,40 @@ components:
"$ref": "#/components/schemas/Seven"
yester:
"$ref": "#/components/schemas/Seven"
required:
- tester
- bester
- yester
Four:
description: "test four"
properties:
lemons:
"$ref": "#/components/schemas/Nine"
required:
- lemons
Five:
properties:
rice:
"$ref": "#/components/schemas/Six"
required:
- rice
Six:
properties:
mints:
"$ref": "#/components/schemas/Nine"
required:
- mints
Seven:
properties:
wow:
"$ref": "#/components/schemas/Three"
required:
- wow
Nine:
description: done.
Ten:
properties:
yeah:
"$ref": "#/components/schemas/Ten"
required:
- yeah

View File

@@ -12,11 +12,15 @@ definitions:
properties:
things:
"$ref": "#/definitions/Two"
required:
- things
Two:
description: "test two"
properties:
testThing:
"$ref": "#/definitions/One"
required:
- testThing
Three:
description: "test three"
properties:
@@ -26,26 +30,40 @@ definitions:
"$ref": "#/definitions/Seven"
yester:
"$ref": "#/definitions/Seven"
required:
- tester
- bester
- yester
Four:
description: "test four"
properties:
lemons:
"$ref": "#/definitions/Nine"
required:
- lemons
Five:
properties:
rice:
"$ref": "#/definitions/Six"
required:
- rice
Six:
properties:
mints:
"$ref": "#/definitions/Nine"
required:
- mints
Seven:
properties:
wow:
"$ref": "#/definitions/Three"
required:
- wow
Nine:
description: done.
Ten:
properties:
yeah:
"$ref": "#/definitions/Ten"
"$ref": "#/definitions/Ten"
required:
- yeah

View File

@@ -0,0 +1,99 @@
schemes:
- https
securityDefinitions:
api_token:
type: apiKey
in: header
name: Swagger-Token
definitions:
BaseModel:
description: BaseModel is the top-level definition in this example
type: object
properties:
directChildren:
description: A nested array of direct recursive models.
type: array
items:
$ref: '#/definitions/DirectRecursiveModel'
indirectChildren:
description: A nested array of indirect recursive models.
type: array
items:
$ref: '#/definitions/IndirectRecursiveModelOne'
additionalProperties: false
required:
- directChildren
- indirectChildren
DirectRecursiveModel:
description: DirectRecursiveModel is a nested model which can optionally contain itself.
type: object
properties:
children:
description: A nested array of direct recursive models.
type: array
items:
$ref: '#/definitions/DirectRecursiveModel'
additionalProperties: false
required:
- children
IndirectRecursiveModelOne:
description: IndirectRecursiveModelOne is a nested model which can optionally contain IndirectRecursiveModelTwo.
type: object
properties:
children:
description: A nested array of indirect recursive models.
type: array
items:
$ref: '#/definitions/IndirectRecursiveModelTwo'
additionalProperties: false
required:
- children
IndirectRecursiveModelTwo:
description: IndirectRecursiveModelTwo is a nested model which can optionally contain IndirectRecursiveModelOne.
type: object
properties:
children:
description: A nested array of indirect recursive models.
type: array
items:
$ref: '#/definitions/IndirectRecursiveModelOne'
additionalProperties: false
required:
- children
security:
- api_token: []
produces:
- application/json
paths:
/baseModels:
post:
parameters:
- in: body
name: BaseModel
description: ''
required: true
schema:
$ref: '#/definitions/BaseModel'
responses:
'201':
schema:
$ref: '#/definitions/BaseModel'
description: Resource
'400':
description: Schema mismatch
'404':
description: Resource does not exist
'422':
description: Unprocessable
operationId: createBaseModel
description: Create BaseModel allows you to create a new BaseModel
summary: Create BaseModel
consumes:
- application/json
host: api.app.example.com
info:
title: Invalid Recursive Definition Example
version: '1.0'
description: This example contains recursive model definitions which are invalid because their "children", "directChildren", and "indirectChildren" properties are all marked as required.
swagger: '2.0'
basePath: /

View File

@@ -0,0 +1,93 @@
schemes:
- https
securityDefinitions:
api_token:
type: apiKey
in: header
name: Swagger-Token
definitions:
BaseModel:
description: BaseModel is the top-level definition in this example
type: object
properties:
directChildren:
description: A nested array of direct recursive models.
type: array
items:
$ref: '#/definitions/DirectRecursiveModel'
indirectChildren:
description: A nested array of indirect recursive models.
type: array
items:
$ref: '#/definitions/IndirectRecursiveModelOne'
additionalProperties: false
required:
- directChildren
- indirectChildren
DirectRecursiveModel:
description: DirectRecursiveModel is a nested model which can optionally contain itself.
type: object
properties:
children:
description: A nested array of direct recursive models.
type: array
items:
$ref: '#/definitions/DirectRecursiveModel'
additionalProperties: false
IndirectRecursiveModelOne:
description: IndirectRecursiveModelOne is a nested model which can optionally contain IndirectRecursiveModelTwo.
type: object
properties:
children:
description: A nested array of indirect recursive models.
type: array
items:
$ref: '#/definitions/IndirectRecursiveModelTwo'
additionalProperties: false
IndirectRecursiveModelTwo:
description: IndirectRecursiveModelTwo is a nested model which can optionally contain IndirectRecursiveModelOne.
type: object
properties:
children:
description: A nested array of indirect recursive models.
type: array
items:
$ref: '#/definitions/IndirectRecursiveModelOne'
additionalProperties: false
security:
- api_token: []
produces:
- application/json
paths:
/baseModels:
post:
parameters:
- in: body
name: BaseModel
description: ''
required: true
schema:
$ref: '#/definitions/BaseModel'
responses:
'201':
schema:
$ref: '#/definitions/BaseModel'
description: Resource
'400':
description: Schema mismatch
'404':
description: Resource does not exist
'422':
description: Unprocessable
operationId: createBaseModel
description: Create BaseModel allows you to create a new BaseModel
summary: Create BaseModel
consumes:
- application/json
host: api.app.example.com
info:
title: Valid Recursive Definition Example
version: '1.0'
description: This example contains a recursive model definition which is valid because DirectRecursiveModel's "children" property is optional.
swagger: '2.0'
basePath: /