|
| 1 | +from typing import Dict, Optional, Union |
| 2 | + |
| 3 | +from pydantic import BaseModel, Extra |
| 4 | + |
| 5 | +from .callback import Callback |
| 6 | +from .example import Example |
| 7 | +from .header import Header |
| 8 | +from .link import Link |
| 9 | +from .parameter import Parameter |
| 10 | +from .path_item import PathItem |
| 11 | +from .reference import Reference |
| 12 | +from .request_body import RequestBody |
| 13 | +from .response import Response |
| 14 | +from .schema import Schema |
| 15 | +from .security_scheme import SecurityScheme |
| 16 | + |
| 17 | + |
| 18 | +class Components(BaseModel): |
| 19 | + """ |
| 20 | + Holds a set of reusable objects for different aspects of the OAS. |
| 21 | + All objects defined within the components object will have no effect on the API |
| 22 | + unless they are explicitly referenced from properties outside the components object. |
| 23 | + """ |
| 24 | + |
| 25 | + schemas: Optional[Dict[str, Schema]] = None |
| 26 | + """An object to hold reusable [Schema Objects](#schemaObject).""" |
| 27 | + |
| 28 | + responses: Optional[Dict[str, Union[Response, Reference]]] = None |
| 29 | + """An object to hold reusable [Response Objects](#responseObject).""" |
| 30 | + |
| 31 | + parameters: Optional[Dict[str, Union[Parameter, Reference]]] = None |
| 32 | + """An object to hold reusable [Parameter Objects](#parameterObject).""" |
| 33 | + |
| 34 | + examples: Optional[Dict[str, Union[Example, Reference]]] = None |
| 35 | + """An object to hold reusable [Example Objects](#exampleObject).""" |
| 36 | + |
| 37 | + requestBodies: Optional[Dict[str, Union[RequestBody, Reference]]] = None |
| 38 | + """An object to hold reusable [Request Body Objects](#requestBodyObject).""" |
| 39 | + |
| 40 | + headers: Optional[Dict[str, Union[Header, Reference]]] = None |
| 41 | + """An object to hold reusable [Header Objects](#headerObject).""" |
| 42 | + |
| 43 | + securitySchemes: Optional[Dict[str, Union[SecurityScheme, Reference]]] = None |
| 44 | + """An object to hold reusable [Security Scheme Objects](#securitySchemeObject).""" |
| 45 | + |
| 46 | + links: Optional[Dict[str, Union[Link, Reference]]] = None |
| 47 | + """An object to hold reusable [Link Objects](#linkObject).""" |
| 48 | + |
| 49 | + callbacks: Optional[Dict[str, Union[Callback, Reference]]] = None |
| 50 | + """An object to hold reusable [Callback Objects](#callbackObject).""" |
| 51 | + |
| 52 | + pathItems: Optional[Dict[str, Union[PathItem, Reference]]] = None |
| 53 | + """An object to hold reusable [Path Item Object](#pathItemObject).""" |
| 54 | + |
| 55 | + class Config: |
| 56 | + extra = Extra.forbid |
| 57 | + schema_extra = { |
| 58 | + "examples": [ |
| 59 | + { |
| 60 | + "schemas": { |
| 61 | + "GeneralError": { |
| 62 | + "type": "object", |
| 63 | + "properties": { |
| 64 | + "code": {"type": "integer", "format": "int32"}, |
| 65 | + "message": {"type": "string"}, |
| 66 | + }, |
| 67 | + }, |
| 68 | + "Category": { |
| 69 | + "type": "object", |
| 70 | + "properties": {"id": {"type": "integer", "format": "int64"}, "name": {"type": "string"}}, |
| 71 | + }, |
| 72 | + "Tag": { |
| 73 | + "type": "object", |
| 74 | + "properties": {"id": {"type": "integer", "format": "int64"}, "name": {"type": "string"}}, |
| 75 | + }, |
| 76 | + }, |
| 77 | + "parameters": { |
| 78 | + "skipParam": { |
| 79 | + "name": "skip", |
| 80 | + "in": "query", |
| 81 | + "description": "number of items to skip", |
| 82 | + "required": True, |
| 83 | + "schema": {"type": "integer", "format": "int32"}, |
| 84 | + }, |
| 85 | + "limitParam": { |
| 86 | + "name": "limit", |
| 87 | + "in": "query", |
| 88 | + "description": "max records to return", |
| 89 | + "required": True, |
| 90 | + "schema": {"type": "integer", "format": "int32"}, |
| 91 | + }, |
| 92 | + }, |
| 93 | + "responses": { |
| 94 | + "NotFound": {"description": "Entity not found."}, |
| 95 | + "IllegalInput": {"description": "Illegal input for operation."}, |
| 96 | + "GeneralError": { |
| 97 | + "description": "General Error", |
| 98 | + "content": {"application/json": {"schema": {"$ref": "#/components/schemas/GeneralError"}}}, |
| 99 | + }, |
| 100 | + }, |
| 101 | + "securitySchemes": { |
| 102 | + "api_key": {"type": "apiKey", "name": "api_key", "in": "header"}, |
| 103 | + "petstore_auth": { |
| 104 | + "type": "oauth2", |
| 105 | + "flows": { |
| 106 | + "implicit": { |
| 107 | + "authorizationUrl": "http://example.org/api/oauth/dialog", |
| 108 | + "scopes": { |
| 109 | + "write:pets": "modify pets in your account", |
| 110 | + "read:pets": "read your pets", |
| 111 | + }, |
| 112 | + } |
| 113 | + }, |
| 114 | + }, |
| 115 | + }, |
| 116 | + } |
| 117 | + ] |
| 118 | + } |
0 commit comments