a cX@sddlZddlZddlZddlmZddlmZddlmZm Z m Z z ddl Z Wne yfdZ Yn0GdddeZ GdddejZGd d d ZGd d d eZdS) N)Request)Response) BaseRouteMountRoutec@s"eZdZdZejedddZdS)OpenAPIResponsezapplication/vnd.oai.openapi)contentreturncCs6tdusJdt|ts"Jdtj|dddS)Nz2`pyyaml` must be installed to use OpenAPIResponse.z7s z5BaseSchemaGenerator.get_endpoints..GETHEAD)getpostputpatchdeleteoptions)r r_remove_converterrr# get_endpointsextendrZinclude_in_schemainspect isfunctionendpointismethodmethodsappendrlowerhasattrgetattr)rr#endpoints_infoZrouteZ sub_endpointsmethodrrr*rr5$s4          z!BaseSchemaGenerator.get_endpoints)rr cCstdd|S)z Remove the converter from the path. For example, a route like this: Route("/users/{id:int}", endpoint=get_user, methods=["GET"]) Should be represented as `/users/{id}` in the OpenAPI schema. z:\w+}})resub)rrrrrr4Vsz%BaseSchemaGenerator._remove_converter)func_or_methodr cCsH|j}|siStdusJd|dd}t|}t|tsDiS|S)z` Given a function, parse the docstring as YAML and return a dictionary of info. Nz2`pyyaml` must be installed to use parse_docstring.z---)__doc__r splitZ safe_loadr r )rrE docstringparsedrrrparse_docstring_s  z#BaseSchemaGenerator.parse_docstring)requestr cCs|jj}|j|d}t|S)N)r#)Zappr#r&r)rrLr#schemarrrrws z#BaseSchemaGenerator.OpenAPIResponseN)rrrrListrr r&rr5rr4r rKrrrrrrrr! s 2 r!c@s2eZdZeddddZejeedddZdS)SchemaGeneratorN) base_schemar cCs ||_dSr$)rP)rrPrrr__init__~szSchemaGenerator.__init__r"cCspt|j}|di||}|D]F}||j}|s:q$|j|dvrVi|d|j<||d|j|j<q$|S)Npaths)r rP setdefaultr5rKrrr)rr#rMr@r9rJrrrr&s    zSchemaGenerator.get_schema) rrrr rQrrNrr&rrrrrO}srO)r7rCrZstarlette.requestsrZstarlette.responsesrZstarlette.routingrrrr ImportErrorr NamedTuplerr!rOrrrrs      ]