Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: openapi response schema #960

Merged
merged 6 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: handle robyn.Response
  • Loading branch information
VishnuSanal committed Sep 14, 2024
commit 86fbaec60cf83f5545ebe085a81c6c4d7ffd17d9
7 changes: 5 additions & 2 deletions robyn/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from inspect import Signature
from typing import Callable, Dict, List, Optional, TypedDict, Any

from robyn import Response
from robyn.responses import FileResponse, html


Expand Down Expand Up @@ -291,11 +292,13 @@ def get_path_obj(
openapi_path_object["requestBody"] = request_body_object

response_schema = {}
response_type = "text/plain"

if return_annotation:
if return_annotation and return_annotation is not Response:
response_type = "application/json"
response_schema = self.get_schema_object("response object", return_annotation)

openapi_path_object["responses"] = {"200": {"description": "Successful Response", "content": {"application/json": {"schema": response_schema}}}}
openapi_path_object["responses"] = {"200": {"description": "Successful Response", "content": {response_type: {"schema": response_schema}}}}

return endpoint_with_path_params_wrapped_in_braces, openapi_path_object

Expand Down
5 changes: 5 additions & 0 deletions robyn/types.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import typing
from dataclasses import dataclass
from typing import Optional
VishnuSanal marked this conversation as resolved.
Show resolved Hide resolved

Expand All @@ -16,3 +17,7 @@ def as_list(self):
self.show_files_listing,
self.index_file,
]


class JSONResponse(typing.TypedDict):
pass
Loading