API Reference¶
- class defspec.spec.OpenAPI(*, openapi: str = '3.1.0', info: ~defspec.spec.OpenAPIInfo = <factory>, paths: dict[str, dict[str, ~defspec.spec.OpenAPIRoute]] = <factory>, defs: dict[str, dict] = <factory>)[source]¶
OpenAPI specification.
- Usage:
openapi = OpenAPI() # init with customized info openapi = OpenAPI(info=OpenAPIInfo(title=”My API”, version=”1.2.3”))
- register_route(path, method, summary=None, request_type=None, request_content_type=None, response_type=None, response_content_type=None, query_type=None, header_type=None, cookie_type=None, deprecated=False, schema_hook=None)[source]¶
Register a route to OpenAPI specification.
- Parameters:
path (
str
) – path of the routemethod (
Literal
['get'
,'post'
,'put'
,'delete'
,'head'
,'options'
,'connect'
,'trace'
,'patch'
]) – HTTP method of the routerequest_content_type (
Optional
[str
]) – Content-Type of the request bodyresponse_content_type (
Optional
[str
]) – Content-Type of the response bodyheader_type (
Optional
[Type
]) – type of the header parameterscookie_type (
Optional
[Type
]) – type of the cookie parametersdeprecated (
bool
) – whether the route is deprecatedschema_hook (
Optional
[Callable
[[type
],dict
[str
,Any
]]]) – a callable that takes a type and returns a dict for custom schema generation