MCPcopy Index your code
hub / github.com/pathwaycom/pathway / generate_docs

Method generate_docs

python/pathway/io/http/_server.py:169–212  ·  view source on GitHub ↗
(self, format, method, schema)

Source from the content-addressed store, hash-verified

167 self.examples = examples
168
169 def generate_docs(self, format, method, schema) -> dict:
170 if not self._is_method_exposed(method):
171 return {}
172 if method.upper() == "GET":
173 # Get requests receive parameters from CGI, so their schema description
174 # is a bit different from the POST / PUT / PATCH
175 endpoint_description = {
176 "parameters": self._construct_openapi_get_request_schema(schema),
177 # disable yaml optimization to avoid
178 # "instance type (string) does not match any allowed primitive type"
179 # error from openapi validator
180 "responses": copy.deepcopy(self.DEFAULT_RESPONSES_DESCRIPTION),
181 }
182 else:
183 if format == "raw":
184 content_header = "text/plain"
185 openapi_schema = self._construct_openapi_plaintext_schema(schema)
186 elif format == "custom":
187 content_header = "application/json"
188 openapi_schema = self._construct_openapi_json_schema(schema)
189 else:
190 raise ValueError(f"Unknown endpoint input format: {format}")
191 schema_and_examples = {"schema": openapi_schema}
192 if self.examples:
193 schema_and_examples["examples"] = self.examples._openapi_description()
194 content_description = {content_header: schema_and_examples}
195 endpoint_description = {
196 "requestBody": {
197 "content": content_description,
198 },
199 # disable yaml optimization to avoid
200 # "instance type (string) does not match any allowed primitive type"
201 # error from openapi validator
202 "responses": copy.deepcopy(self.DEFAULT_RESPONSES_DESCRIPTION),
203 }
204
205 if self.tags is not None:
206 endpoint_description["tags"] = list(self.tags)
207 if self.description is not None:
208 endpoint_description["description"] = self.description
209 if self.summary is not None:
210 endpoint_description["summary"] = self.summary
211
212 return {method.lower(): endpoint_description}
213
214 def _is_method_exposed(self, method):
215 return self.method_types is None or method.upper() in self.method_types

Callers 1

_register_endpointMethod · 0.80

Calls 7

_is_method_exposedMethod · 0.95
upperMethod · 0.80
_openapi_descriptionMethod · 0.80
lowerMethod · 0.80

Tested by

no test coverage detected