MCPcopy
hub / github.com/encode/starlette / parse_docstring

Method parse_docstring

starlette/schemas.py:98–120  ·  view source on GitHub ↗

Given a function, parse the docstring as YAML and return a dictionary of info.

(self, func_or_method: Callable[..., Any])

Source from the content-addressed store, hash-verified

96 return _remove_converter_pattern.sub("}", path)
97
98 def parse_docstring(self, func_or_method: Callable[..., Any]) -> dict[str, Any]:
99 """
100 Given a function, parse the docstring as YAML and return a dictionary of info.
101 """
102 docstring = func_or_method.__doc__
103 if not docstring:
104 return {}
105
106 assert yaml is not None, "`pyyaml` must be installed to use parse_docstring."
107
108 # We support having regular docstrings before the schema
109 # definition. Here we return just the schema part from
110 # the docstring.
111 docstring = docstring.split("---")[-1]
112
113 parsed = yaml.safe_load(docstring)
114
115 if not isinstance(parsed, dict):
116 # A regular docstring (not yaml formatted) can return
117 # a simple string here, which wouldn't follow the schema.
118 return {}
119
120 return parsed
121
122 def OpenAPIResponse(self, request: Request) -> Response:
123 routes = request.app.routes

Callers 1

get_schemaMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected