Fix bug query string appear as required in generated Open API specification.
This commit is contained in:
0
tests/test_oas/test_struct/__init__.py
Normal file
0
tests/test_oas/test_struct/__init__.py
Normal file
54
tests/test_oas/test_struct/test_info.py
Normal file
54
tests/test_oas/test_struct/test_info.py
Normal file
@@ -0,0 +1,54 @@
|
||||
import pytest
|
||||
|
||||
from aiohttp_pydantic.oas.struct import OpenApiSpec3
|
||||
|
||||
|
||||
def test_info_title():
|
||||
oas = OpenApiSpec3()
|
||||
assert oas.info.title is None
|
||||
oas.info.title = "Info Title"
|
||||
assert oas.info.title == "Info Title"
|
||||
assert oas.spec == {"info": {"title": "Info Title"}, "openapi": "3.0.0"}
|
||||
|
||||
|
||||
def test_info_description():
|
||||
oas = OpenApiSpec3()
|
||||
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"}
|
||||
|
||||
|
||||
def test_info_version():
|
||||
oas = OpenApiSpec3()
|
||||
assert oas.info.version is None
|
||||
oas.info.version = "3.14"
|
||||
assert oas.info.version == "3.14"
|
||||
assert oas.spec == {"info": {"version": "3.14"}, "openapi": "3.0.0"}
|
||||
|
||||
|
||||
def test_info_terms_of_service():
|
||||
oas = OpenApiSpec3()
|
||||
assert oas.info.terms_of_service is None
|
||||
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/"},
|
||||
"openapi": "3.0.0",
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.skip("Not yet implemented")
|
||||
def test_info_license():
|
||||
oas = OpenApiSpec3()
|
||||
oas.info.license.name = "Apache 2.0"
|
||||
oas.info.license.url = "https://www.apache.org/licenses/LICENSE-2.0.html"
|
||||
assert oas.spec == {
|
||||
"info": {
|
||||
"license": {
|
||||
"name": "Apache 2.0",
|
||||
"url": "https://www.apache.org/licenses/LICENSE-2.0.html",
|
||||
}
|
||||
},
|
||||
"openapi": "3.0.0",
|
||||
}
|
||||
124
tests/test_oas/test_struct/test_paths.py
Normal file
124
tests/test_oas/test_struct/test_paths.py
Normal file
@@ -0,0 +1,124 @@
|
||||
from aiohttp_pydantic.oas.struct import OpenApiSpec3
|
||||
|
||||
|
||||
def test_paths_description():
|
||||
oas = OpenApiSpec3()
|
||||
oas.paths["/users/{id}"].description = "This route ..."
|
||||
assert oas.spec == {
|
||||
"openapi": "3.0.0",
|
||||
"paths": {"/users/{id}": {"description": "This route ..."}},
|
||||
}
|
||||
|
||||
|
||||
def test_paths_get():
|
||||
oas = OpenApiSpec3()
|
||||
oas.paths["/users/{id}"].get
|
||||
assert oas.spec == {"openapi": "3.0.0", "paths": {"/users/{id}": {"get": {}}}}
|
||||
|
||||
|
||||
def test_paths_operation_description():
|
||||
oas = OpenApiSpec3()
|
||||
operation = oas.paths["/users/{id}"].get
|
||||
operation.description = "Long descriptions ..."
|
||||
assert oas.spec == {
|
||||
"openapi": "3.0.0",
|
||||
"paths": {"/users/{id}": {"get": {"description": "Long descriptions ..."}}},
|
||||
}
|
||||
|
||||
|
||||
def test_paths_operation_summary():
|
||||
oas = OpenApiSpec3()
|
||||
operation = oas.paths["/users/{id}"].get
|
||||
operation.summary = "Updates a pet in the store with form data"
|
||||
assert oas.spec == {
|
||||
"openapi": "3.0.0",
|
||||
"paths": {
|
||||
"/users/{id}": {
|
||||
"get": {"summary": "Updates a pet in the store with form data"}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def test_paths_operation_parameters():
|
||||
oas = OpenApiSpec3()
|
||||
operation = oas.paths["/users/{petId}"].get
|
||||
parameter = operation.parameters[0]
|
||||
parameter.name = "petId"
|
||||
parameter.description = "ID of pet that needs to be updated"
|
||||
parameter.in_ = "path"
|
||||
parameter.required = True
|
||||
|
||||
assert oas.spec == {
|
||||
"openapi": "3.0.0",
|
||||
"paths": {
|
||||
"/users/{petId}": {
|
||||
"get": {
|
||||
"parameters": [
|
||||
{
|
||||
"description": "ID of pet that needs to be updated",
|
||||
"in": "path",
|
||||
"name": "petId",
|
||||
"required": True,
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def test_paths_operation_requestBody():
|
||||
oas = OpenApiSpec3()
|
||||
request_body = oas.paths["/users/{petId}"].get.request_body
|
||||
request_body.description = "user to add to the system"
|
||||
request_body.content = {
|
||||
"application/json": {
|
||||
"schema": {"$ref": "#/components/schemas/User"},
|
||||
"examples": {
|
||||
"user": {
|
||||
"summary": "User Example",
|
||||
"externalValue": "http://foo.bar/examples/user-example.json",
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
request_body.required = True
|
||||
assert oas.spec == {
|
||||
"openapi": "3.0.0",
|
||||
"paths": {
|
||||
"/users/{petId}": {
|
||||
"get": {
|
||||
"requestBody": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"examples": {
|
||||
"user": {
|
||||
"externalValue": "http://foo.bar/examples/user-example.json",
|
||||
"summary": "User Example",
|
||||
}
|
||||
},
|
||||
"schema": {"$ref": "#/components/schemas/User"},
|
||||
}
|
||||
},
|
||||
"description": "user to add to the system",
|
||||
"required": True,
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def test_paths_operation_responses():
|
||||
oas = OpenApiSpec3()
|
||||
response = oas.paths["/users/{petId}"].get.responses[200]
|
||||
response.description = "A complex object array response"
|
||||
response.content = {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {"$ref": "#/components/schemas/VeryComplexType"},
|
||||
}
|
||||
}
|
||||
}
|
||||
36
tests/test_oas/test_struct/test_servers.py
Normal file
36
tests/test_oas/test_struct/test_servers.py
Normal file
@@ -0,0 +1,36 @@
|
||||
import pytest
|
||||
|
||||
from aiohttp_pydantic.oas.struct import OpenApiSpec3
|
||||
|
||||
|
||||
def test_sever_url():
|
||||
oas = OpenApiSpec3()
|
||||
oas.servers[0].url = "https://development.gigantic-server.com/v1"
|
||||
oas.servers[1].url = "https://development.gigantic-server.com/v2"
|
||||
assert oas.spec == {
|
||||
"openapi": "3.0.0",
|
||||
"servers": [
|
||||
{"url": "https://development.gigantic-server.com/v1"},
|
||||
{"url": "https://development.gigantic-server.com/v2"},
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
def test_sever_description():
|
||||
oas = OpenApiSpec3()
|
||||
oas.servers[0].url = "https://development.gigantic-server.com/v1"
|
||||
oas.servers[0].description = "Development server"
|
||||
assert oas.spec == {
|
||||
"openapi": "3.0.0",
|
||||
"servers": [
|
||||
{
|
||||
"url": "https://development.gigantic-server.com/v1",
|
||||
"description": "Development server",
|
||||
}
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.skip("Not yet implemented")
|
||||
def test_sever_variables():
|
||||
oas = OpenApiSpec3()
|
||||
Reference in New Issue
Block a user