Skip to content

Commit

Permalink
fix test error with pydantic
Browse files Browse the repository at this point in the history
  • Loading branch information
waketzheng committed Dec 15, 2024
1 parent 3779706 commit 2ee43b6
Showing 1 changed file with 210 additions and 14 deletions.
224 changes: 210 additions & 14 deletions tests/test_openapi_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -1049,9 +1049,68 @@ def home() -> PydPaginatedSetOfCat: ...
yaml = serializer.to_yaml(docs.generate_documentation(app))

if sys.version_info >= (3, 9):
assert (
yaml.strip()
== """
if PYDANTIC_VERSION == 1:
assert (
yaml.strip()
== """
openapi: 3.0.3
info:
title: Example
version: 0.0.1
paths:
/:
get:
responses:
'200':
description: Success response
content:
application/json:
schema:
$ref: '#/components/schemas/PydPaginatedSetOfCat'
operationId: home
components:
schemas:
PydCat:
type: object
required:
- id
- name
- childs
properties:
id:
type: integer
format: int64
nullable: false
name:
type: string
nullable: false
childs:
type: array
nullable: false
items:
nullable: false
PydPaginatedSetOfCat:
type: object
required:
- items
- total
properties:
items:
type: array
nullable: false
items:
$ref: '#/components/schemas/PydCat'
total:
type: integer
format: int64
nullable: false
tags: []
""".strip()
)
else:
assert (
yaml.strip()
== """
openapi: 3.0.3
info:
title: Example
Expand Down Expand Up @@ -1107,7 +1166,7 @@ def home() -> PydPaginatedSetOfCat: ...
nullable: false
tags: []
""".strip()
)
)
else:
assert (
yaml.strip()
Expand Down Expand Up @@ -1177,9 +1236,89 @@ def home() -> PydTypeWithChildModels: ...
yaml = serializer.to_yaml(docs.generate_documentation(app))

if sys.version_info >= (3, 9):
assert (
yaml.strip()
== """
if PYDANTIC_VERSION == 1:
assert (
yaml.strip()
== """
openapi: 3.0.3
info:
title: Example
version: 0.0.1
paths:
/:
get:
responses:
'200':
description: Success response
content:
application/json:
schema:
$ref: '#/components/schemas/PydTypeWithChildModels'
operationId: home
components:
schemas:
PydCat:
type: object
required:
- id
- name
- childs
properties:
id:
type: integer
format: int64
nullable: false
name:
type: string
nullable: false
childs:
type: array
nullable: false
items:
nullable: false
PydPaginatedSetOfCat:
type: object
required:
- items
- total
properties:
items:
type: array
nullable: false
items:
$ref: '#/components/schemas/PydCat'
total:
type: integer
format: int64
nullable: false
PydExampleWithSpecificTypes:
type: object
required:
- url
properties:
url:
type: string
format: uri
maxLength: 2083
minLength: 1
nullable: false
PydTypeWithChildModels:
type: object
required:
- child
- friend
properties:
child:
$ref: '#/components/schemas/PydPaginatedSetOfCat'
friend:
$ref: '#/components/schemas/PydExampleWithSpecificTypes'
tags: []
""".strip()
)
else:
assert (
yaml.strip()
== """
openapi: 3.0.3
info:
title: Example
Expand Down Expand Up @@ -1256,7 +1395,7 @@ def home() -> PydTypeWithChildModels: ...
$ref: '#/components/schemas/PydExampleWithSpecificTypes'
tags: []
""".strip()
)
)
else:
assert (
yaml.strip()
Expand Down Expand Up @@ -1347,9 +1486,68 @@ def home() -> PaginatedSet[PydCat]: ...
yaml = serializer.to_yaml(docs.generate_documentation(app))

if sys.version_info >= (3, 9):
assert (
yaml.strip()
== """
if PYDANTIC_VERSION == 1:
assert (
yaml.strip()
== """
openapi: 3.0.3
info:
title: Example
version: 0.0.1
paths:
/:
get:
responses:
'200':
description: Success response
content:
application/json:
schema:
$ref: '#/components/schemas/PaginatedSetOfPydCat'
operationId: home
components:
schemas:
PydCat:
type: object
required:
- id
- name
- childs
properties:
id:
type: integer
format: int64
nullable: false
name:
type: string
nullable: false
childs:
type: array
nullable: false
items:
nullable: false
PaginatedSetOfPydCat:
type: object
required:
- items
- total
properties:
items:
type: array
nullable: false
items:
$ref: '#/components/schemas/PydCat'
total:
type: integer
format: int64
nullable: false
tags: []
""".strip()
)
else:
assert (
yaml.strip()
== """
openapi: 3.0.3
info:
title: Example
Expand Down Expand Up @@ -1405,7 +1603,7 @@ def home() -> PaginatedSet[PydCat]: ...
nullable: false
tags: []
""".strip()
)
)
else:
assert (
yaml.strip()
Expand Down Expand Up @@ -1939,8 +2137,6 @@ def home() -> PydResponse[PydCat]: ...
type: array
nullable: false
items:
type: string
format: uuid
nullable: false
Error:
type: object
Expand Down

0 comments on commit 2ee43b6

Please sign in to comment.