Fix wrong link in OAS components with nested pydantic.BaseModel
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
from enum import Enum
|
||||
from typing import List, Optional, Union
|
||||
from uuid import UUID
|
||||
|
||||
@@ -9,9 +10,21 @@ from aiohttp_pydantic import PydanticView, oas
|
||||
from aiohttp_pydantic.oas.typing import r200, r201, r204, r404
|
||||
|
||||
|
||||
class Color(str, Enum):
|
||||
RED = "red"
|
||||
GREEN = "green"
|
||||
PINK = "pink"
|
||||
|
||||
|
||||
class Toy(BaseModel):
|
||||
name: str
|
||||
color: Color
|
||||
|
||||
|
||||
class Pet(BaseModel):
|
||||
id: int
|
||||
name: str
|
||||
toys: List[Toy]
|
||||
|
||||
|
||||
class PetCollectionView(PydanticView):
|
||||
@@ -53,6 +66,26 @@ async def generated_oas(aiohttp_client, loop) -> web.Application:
|
||||
return await response.json()
|
||||
|
||||
|
||||
async def test_generated_oas_should_have_components_schemas(generated_oas):
|
||||
assert generated_oas["components"]["schemas"] == {
|
||||
"Color": {
|
||||
"description": "An enumeration.",
|
||||
"enum": ["red", "green", "pink"],
|
||||
"title": "Color",
|
||||
"type": "string",
|
||||
},
|
||||
"Toy": {
|
||||
"properties": {
|
||||
"color": {"$ref": "#/components/schemas/Color"},
|
||||
"name": {"title": "Name", "type": "string"},
|
||||
},
|
||||
"required": ["name", "color"],
|
||||
"title": "Toy",
|
||||
"type": "object",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
async def test_generated_oas_should_have_pets_paths(generated_oas):
|
||||
assert "/pets" in generated_oas["paths"]
|
||||
|
||||
@@ -77,7 +110,7 @@ async def test_pets_route_should_have_get_method(generated_oas):
|
||||
"in": "header",
|
||||
"name": "promo",
|
||||
"required": False,
|
||||
"schema": {"title": "promo", "format": "uuid", "type": "string"},
|
||||
"schema": {"format": "uuid", "title": "promo", "type": "string"},
|
||||
},
|
||||
],
|
||||
"responses": {
|
||||
@@ -86,11 +119,35 @@ async def test_pets_route_should_have_get_method(generated_oas):
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"items": {
|
||||
"definitions": {
|
||||
"Color": {
|
||||
"description": "An enumeration.",
|
||||
"enum": ["red", "green", "pink"],
|
||||
"title": "Color",
|
||||
"type": "string",
|
||||
},
|
||||
"Toy": {
|
||||
"properties": {
|
||||
"color": {
|
||||
"$ref": "#/components/schemas/Color"
|
||||
},
|
||||
"name": {"title": "Name", "type": "string"},
|
||||
},
|
||||
"required": ["name", "color"],
|
||||
"title": "Toy",
|
||||
"type": "object",
|
||||
},
|
||||
},
|
||||
"properties": {
|
||||
"id": {"title": "Id", "type": "integer"},
|
||||
"name": {"title": "Name", "type": "string"},
|
||||
"toys": {
|
||||
"items": {"$ref": "#/components/schemas/Toy"},
|
||||
"title": "Toys",
|
||||
"type": "array",
|
||||
},
|
||||
},
|
||||
"required": ["id", "name"],
|
||||
"required": ["id", "name", "toys"],
|
||||
"title": "Pet",
|
||||
"type": "object",
|
||||
},
|
||||
@@ -110,13 +167,35 @@ async def test_pets_route_should_have_post_method(generated_oas):
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"title": "Pet",
|
||||
"type": "object",
|
||||
"definitions": {
|
||||
"Color": {
|
||||
"description": "An enumeration.",
|
||||
"enum": ["red", "green", "pink"],
|
||||
"title": "Color",
|
||||
"type": "string",
|
||||
},
|
||||
"Toy": {
|
||||
"properties": {
|
||||
"color": {"$ref": "#/components/schemas/Color"},
|
||||
"name": {"title": "Name", "type": "string"},
|
||||
},
|
||||
"required": ["name", "color"],
|
||||
"title": "Toy",
|
||||
"type": "object",
|
||||
},
|
||||
},
|
||||
"properties": {
|
||||
"id": {"title": "Id", "type": "integer"},
|
||||
"name": {"title": "Name", "type": "string"},
|
||||
"toys": {
|
||||
"items": {"$ref": "#/components/schemas/Toy"},
|
||||
"title": "Toys",
|
||||
"type": "array",
|
||||
},
|
||||
},
|
||||
"required": ["id", "name"],
|
||||
"required": ["id", "name", "toys"],
|
||||
"title": "Pet",
|
||||
"type": "object",
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -126,13 +205,35 @@ async def test_pets_route_should_have_post_method(generated_oas):
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"title": "Pet",
|
||||
"type": "object",
|
||||
"definitions": {
|
||||
"Color": {
|
||||
"description": "An enumeration.",
|
||||
"enum": ["red", "green", "pink"],
|
||||
"title": "Color",
|
||||
"type": "string",
|
||||
},
|
||||
"Toy": {
|
||||
"properties": {
|
||||
"color": {"$ref": "#/components/schemas/Color"},
|
||||
"name": {"title": "Name", "type": "string"},
|
||||
},
|
||||
"required": ["name", "color"],
|
||||
"title": "Toy",
|
||||
"type": "object",
|
||||
},
|
||||
},
|
||||
"properties": {
|
||||
"id": {"title": "Id", "type": "integer"},
|
||||
"name": {"title": "Name", "type": "string"},
|
||||
"toys": {
|
||||
"items": {"$ref": "#/components/schemas/Toy"},
|
||||
"title": "Toys",
|
||||
"type": "array",
|
||||
},
|
||||
},
|
||||
"required": ["id", "name"],
|
||||
"required": ["id", "name", "toys"],
|
||||
"title": "Pet",
|
||||
"type": "object",
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -174,11 +275,33 @@ async def test_pets_id_route_should_have_get_method(generated_oas):
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"definitions": {
|
||||
"Color": {
|
||||
"description": "An enumeration.",
|
||||
"enum": ["red", "green", "pink"],
|
||||
"title": "Color",
|
||||
"type": "string",
|
||||
},
|
||||
"Toy": {
|
||||
"properties": {
|
||||
"color": {"$ref": "#/components/schemas/Color"},
|
||||
"name": {"title": "Name", "type": "string"},
|
||||
},
|
||||
"required": ["name", "color"],
|
||||
"title": "Toy",
|
||||
"type": "object",
|
||||
},
|
||||
},
|
||||
"properties": {
|
||||
"id": {"title": "Id", "type": "integer"},
|
||||
"name": {"title": "Name", "type": "string"},
|
||||
"toys": {
|
||||
"items": {"$ref": "#/components/schemas/Toy"},
|
||||
"title": "Toys",
|
||||
"type": "array",
|
||||
},
|
||||
},
|
||||
"required": ["id", "name"],
|
||||
"required": ["id", "name", "toys"],
|
||||
"title": "Pet",
|
||||
"type": "object",
|
||||
}
|
||||
@@ -204,11 +327,33 @@ async def test_pets_id_route_should_have_put_method(generated_oas):
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"definitions": {
|
||||
"Color": {
|
||||
"description": "An enumeration.",
|
||||
"enum": ["red", "green", "pink"],
|
||||
"title": "Color",
|
||||
"type": "string",
|
||||
},
|
||||
"Toy": {
|
||||
"properties": {
|
||||
"color": {"$ref": "#/components/schemas/Color"},
|
||||
"name": {"title": "Name", "type": "string"},
|
||||
},
|
||||
"required": ["name", "color"],
|
||||
"title": "Toy",
|
||||
"type": "object",
|
||||
},
|
||||
},
|
||||
"properties": {
|
||||
"id": {"title": "Id", "type": "integer"},
|
||||
"name": {"title": "Name", "type": "string"},
|
||||
"toys": {
|
||||
"items": {"$ref": "#/components/schemas/Toy"},
|
||||
"title": "Toys",
|
||||
"type": "array",
|
||||
},
|
||||
},
|
||||
"required": ["id", "name"],
|
||||
"required": ["id", "name", "toys"],
|
||||
"title": "Pet",
|
||||
"type": "object",
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user