Skip to content

Commit

Permalink
✨ Enhanced OpenAPI docstrings (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
perdy authored and migduroli committed Sep 3, 2024
1 parent 96229a1 commit d944180
Show file tree
Hide file tree
Showing 4 changed files with 729 additions and 518 deletions.
26 changes: 13 additions & 13 deletions flama/schemas/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,22 +364,22 @@ def _build_endpoint_parameters(
def _build_endpoint_body(
self, endpoint: EndpointInfo, metadata: t.Dict[str, t.Any]
) -> t.Optional[openapi.RequestBody]:
if not endpoint.body_parameter:
return None
content = {k: v for k, v in metadata.get("requestBody", {}).get("content", {}).items()}

if endpoint.body_parameter:
if endpoint.body_parameter.schema.schema not in self.schemas:
self.schemas.register(schema=endpoint.body_parameter.schema.schema)

content["application/json"] = openapi.MediaType(
schema=self.schemas.get_openapi_ref(endpoint.body_parameter.schema.schema, multiple=False),
)

if endpoint.body_parameter.schema.schema not in self.schemas:
self.schemas.register(schema=endpoint.body_parameter.schema.schema)
if not content:
return None

return openapi.RequestBody(
content={
"application/json": openapi.MediaType(
schema=self.schemas.get_openapi_ref(endpoint.body_parameter.schema.schema, multiple=False),
)
},
**{
x: metadata.get("requestBody", {}).get("content", {}).get("application/json", {}).get(x)
for x in ("description", "required")
},
content=content,
**{x: metadata.get("requestBody", {}).get(x) for x in ("description", "required")},
)

def _build_endpoint_default_response(self, metadata: t.Dict[str, t.Any]) -> openapi.Response:
Expand Down
Loading

0 comments on commit d944180

Please sign in to comment.