Xj0 ddlmZddlZddlZddlmZddlmZmZddl m Z ddl m Z ddl mZmZmZmZ ddlZGdd e ZGd d eZej,d ZGd dZGddeZy#e$rdZYGwxYw)) annotationsN)Callable)Any NamedTuple)Request)Response) BaseRouteHostMountRouteceZdZdZddZy)OpenAPIResponsezapplication/vnd.oai.openapictJdt|tsJdtj|dj dS)Nz2`pyyaml` must be installed to use OpenAPIResponse.z|j |j }dD]Y}t+|j |st-|j |}|j't||j)|[|Scc}w)a  Given the routes, yields the following information: - path eg: /users/ - http_method one of 'get', 'post', 'put', 'patch', 'delete', 'options' - func method ready to extract the docstring )r%r&r(GETHEAD)getpostputpatchdeleteoptions)rr r r/_remove_converterr% get_endpointsr#joinr&r(extendr include_in_schemainspect isfunctionendpointismethodmethodsappendlowerhasattrgetattr) rr/endpoints_inforouter% sub_endpoint sub_endpointsmethodr(s rr<z!BaseSchemaGenerator.get_endpoints(s.0 TE%.+eU+11%**=DD)-(:(:6(B ! % !WWdL,=,=%>?$0$<$<)..! !%%m4u-U5L5L##ENN3w7G7G7W--ejj9#mm6w^F' ")),tV\\^U^^*\]^ --ejj9RTF"5>>6: "5>>6:D")),tV\\^T*RS T9 TD7!s1AHc.tjd|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. })_remove_converter_patternsub)rr%s rr;z%BaseSchemaGenerator._remove_converterYs),,S$77rc|j}|siStJd|jdd}tj|}t |t siS|S)z` Given a function, parse the docstring as YAML and return a dictionary of info. z2`pyyaml` must be installed to use parse_docstring.z---)__doc__rsplit safe_loadrr)rfunc_or_method docstringparseds rparse_docstringz#BaseSchemaGenerator.parse_docstringbsb#** IU!UU OOE*2.  *&$'I rch|jj}|j|}t|S)N)r/)appr/r0r)rrequestr/schemas rrz#BaseSchemaGenerator.OpenAPIResponsezs,##/v&&rNr/list[BaseRoute]rdict[str, Any])r/r`rzlist[EndpointInfo])r%r$rr$)rWr'rra)r]rrr)rrrr0r<r;rZrr!rrr+r+$s$/b80'rr+ceZdZddZddZy)SchemaGeneratorc||_yr-) base_schema)rres r__init__zSchemaGenerator.__init__s &rcDt|j}|jdi|j|}|D]b}|j |j }|s!|j |dvri|d|j <||d|j |j<d|S)Npaths)rre setdefaultr<rZr(r%r&)rr/r^rIrBrYs rr0zSchemaGenerator.get_schemasd&&''2&++F3& JH))(--8F}}F7O313w .CIF7OHMM *8+?+? @ J rN)rerarNoner_)rrrrfr0r!rrrcrcs 'rrc) __future__rr@recollections.abcrtypingrrstarlette.requestsrstarlette.responsesrstarlette.routingr r r r rModuleNotFoundErrorrr#compilerPr+rcr!rrrts" $"&(;; LhL: 'BJJx0Y'Y'x)e DsA88BB