Added a wrapper for get_oas to throw spec info (#12) (#13)

* Added a wrapper for get_oas to throw spec info (#12)

* Added tests generate_oas

* Moved params to Application

Co-authored-by: Спиненко Иван ispinenko@ussc.ru <ispinenko@ussc.ru>
This commit is contained in:
spinenkoia
2021-04-04 16:22:05 +05:00
committed by GitHub
parent 7492af5acf
commit beb638c0af
9 changed files with 89 additions and 18 deletions

View File

@@ -22,8 +22,12 @@ def test_show_oas_of_app(cmd_line):
args.func(args)
expected = dedent(
"""
{
"""
{
"info": {
"title": "Aiohttp pydantic application",
"version": "1.0.0"
},
"openapi": "3.0.0",
"paths": {
"/route-1/{a}": {
@@ -69,8 +73,12 @@ def test_show_oas_of_sub_app(cmd_line):
args.output = StringIO()
args.func(args)
expected = dedent(
"""
{
"""
{
"info": {
"title": "Aiohttp pydantic application",
"version": "1.0.0"
},
"openapi": "3.0.0",
"paths": {
"/sub-app/route-2/{b}": {
@@ -110,7 +118,7 @@ def test_show_oas_of_a_callable(cmd_line):
"""
{
"info": {
"title": "MyApp",
"title": "Aiohttp pydantic application",
"version": "1.0.0"
},
"openapi": "3.0.0",

View File

@@ -5,10 +5,16 @@ from aiohttp_pydantic.oas.struct import OpenApiSpec3
def test_info_title():
oas = OpenApiSpec3()
assert oas.info.title is None
assert oas.info.title == "Aiohttp pydantic application"
oas.info.title = "Info Title"
assert oas.info.title == "Info Title"
assert oas.spec == {"info": {"title": "Info Title"}, "openapi": "3.0.0"}
assert oas.spec == {
"info": {
"title": "Info Title",
"version": "1.0.0",
},
"openapi": "3.0.0",
}
def test_info_description():
@@ -16,15 +22,22 @@ def test_info_description():
assert oas.info.description is None
oas.info.description = "info description"
assert oas.info.description == "info description"
assert oas.spec == {"info": {"description": "info description"}, "openapi": "3.0.0"}
assert oas.spec == {
"info": {
"description": "info description",
"title": "Aiohttp pydantic application",
"version": "1.0.0",
},
"openapi": "3.0.0",
}
def test_info_version():
oas = OpenApiSpec3()
assert oas.info.version is None
assert oas.info.version == "1.0.0"
oas.info.version = "3.14"
assert oas.info.version == "3.14"
assert oas.spec == {"info": {"version": "3.14"}, "openapi": "3.0.0"}
assert oas.spec == {"info": {"version": "3.14", "title": "Aiohttp pydantic application"}, "openapi": "3.0.0"}
def test_info_terms_of_service():
@@ -33,7 +46,11 @@ def test_info_terms_of_service():
oas.info.terms_of_service = "http://example.com/terms/"
assert oas.info.terms_of_service == "http://example.com/terms/"
assert oas.spec == {
"info": {"termsOfService": "http://example.com/terms/"},
"info": {
"title": "Aiohttp pydantic application",
"version": "1.0.0",
"termsOfService": "http://example.com/terms/",
},
"openapi": "3.0.0",
}

View File

@@ -6,6 +6,7 @@ def test_paths_description():
oas.paths["/users/{id}"].description = "This route ..."
assert oas.spec == {
"openapi": "3.0.0",
"info": {"title": "Aiohttp pydantic application", "version": "1.0.0"},
"paths": {"/users/{id}": {"description": "This route ..."}},
}
@@ -13,7 +14,11 @@ def test_paths_description():
def test_paths_get():
oas = OpenApiSpec3()
oas.paths["/users/{id}"].get
assert oas.spec == {"openapi": "3.0.0", "paths": {"/users/{id}": {"get": {}}}}
assert oas.spec == {
"openapi": "3.0.0",
"info": {"title": "Aiohttp pydantic application", "version": "1.0.0"},
"paths": {"/users/{id}": {"get": {}}},
}
def test_paths_operation_description():
@@ -22,6 +27,7 @@ def test_paths_operation_description():
operation.description = "Long descriptions ..."
assert oas.spec == {
"openapi": "3.0.0",
"info": {"title": "Aiohttp pydantic application", "version": "1.0.0"},
"paths": {"/users/{id}": {"get": {"description": "Long descriptions ..."}}},
}
@@ -32,6 +38,7 @@ def test_paths_operation_summary():
operation.summary = "Updates a pet in the store with form data"
assert oas.spec == {
"openapi": "3.0.0",
"info": {"title": "Aiohttp pydantic application", "version": "1.0.0"},
"paths": {
"/users/{id}": {
"get": {"summary": "Updates a pet in the store with form data"}
@@ -51,6 +58,7 @@ def test_paths_operation_parameters():
assert oas.spec == {
"openapi": "3.0.0",
"info": {"title": "Aiohttp pydantic application", "version": "1.0.0"},
"paths": {
"/users/{petId}": {
"get": {
@@ -86,6 +94,7 @@ def test_paths_operation_requestBody():
request_body.required = True
assert oas.spec == {
"openapi": "3.0.0",
"info": {"title": "Aiohttp pydantic application", "version": "1.0.0"},
"paths": {
"/users/{petId}": {
"get": {

View File

@@ -9,6 +9,7 @@ def test_sever_url():
oas.servers[1].url = "https://development.gigantic-server.com/v2"
assert oas.spec == {
"openapi": "3.0.0",
"info": {"title": "Aiohttp pydantic application", "version": "1.0.0"},
"servers": [
{"url": "https://development.gigantic-server.com/v1"},
{"url": "https://development.gigantic-server.com/v2"},
@@ -22,6 +23,7 @@ def test_sever_description():
oas.servers[0].description = "Development server"
assert oas.spec == {
"openapi": "3.0.0",
"info": {"title": "Aiohttp pydantic application", "version": "1.0.0"},
"servers": [
{
"url": "https://development.gigantic-server.com/v1",

View File

@@ -8,6 +8,7 @@ from pydantic.main import BaseModel
from aiohttp_pydantic import PydanticView, oas
from aiohttp_pydantic.oas.typing import r200, r201, r204, r404
from aiohttp_pydantic.oas.view import generate_oas
class Color(str, Enum):
@@ -316,3 +317,23 @@ async def test_simple_type_route_should_have_get_method(generated_oas):
}
},
}
async def test_generated_view_info_default():
apps = (web.Application(),)
spec = generate_oas(apps)
assert spec == {'info': {'title': 'Aiohttp pydantic application', 'version': '1.0.0'}, 'openapi': '3.0.0'}
async def test_generated_view_info_as_version():
apps = (web.Application(),)
spec = generate_oas(apps, version_spec="test version")
assert spec == {'info': {'title': 'Aiohttp pydantic application', 'version': 'test version'}, 'openapi': '3.0.0'}
async def test_generated_view_info_as_title():
apps = (web.Application(),)
spec = generate_oas(apps, title_spec="test title")
assert spec == {'info': {'title': 'test title', 'version': '1.0.0'}, 'openapi': '3.0.0'}