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

Unwrap the API RequestObject for the function validation if it's a nested pydantic class #68

Merged
merged 11 commits into from
Mar 4, 2024

Conversation

majdyz
Copy link
Contributor

@majdyz majdyz commented Mar 3, 2024

It's tested using api_test.py

@majdyz majdyz requested review from ntindle and Swiftyos March 3, 2024 14:32
Temporarily remove `| JsonResponse` type hint.
@@ -38,14 +38,21 @@ async def develop_application(ids: Identifiers, spec: Specification) -> Complete
compiled_routes = []
if spec.ApiRouteSpecs:
for api_route in spec.ApiRouteSpecs:
if not api_route.RequestObject:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a better course of action here would be for me to separate route and query/body params and insert them separately. Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we are fine for now?

@@ -1,5 +1,5 @@
from prisma.models import Specification
from prisma.types import SpecificationCreateInput
from prisma.models import ObjectField, ObjectType, Specification
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Swiftyos I guess this change is not needed depending on what's our plan on collecting the DataType

@majdyz majdyz marked this pull request as draft March 4, 2024 09:22
@Swiftyos Swiftyos marked this pull request as ready for review March 4, 2024 11:54
@@ -312,7 +305,8 @@ def create_server_route_code(complied_route: CompiledRoute) -> str:
is_file_response = True
else:
if return_type.Type is not None:
response_model = f"{return_type.Type.name} | JSONResponse"
# TODO(SwiftyOS): consider revert, `| JSONResponse` was removed from here.
response_model = return_type.Type.name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I needed to have 2 response models, 1 if the | json as the function return type and 1 for the route annotation.

I'll push an update for this.

route_fucntion_def += ")"

# TODO(SwiftyOS): consider replacing the prefix with a proper import and func call.
route_function_def = f"def api_{http_verb.lower()}_{main_function.functionName}("
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, I had this previously and forgot to add it during the rewrite.

The only additional thing I had was I was also storing a set of the route function names, if it turned up more than once I added a random string to the end.

Though that is a hack, we should add this as a validation step on the route definition creation

@Swiftyos Swiftyos merged commit 76e69d2 into main Mar 4, 2024
1 check passed
@Swiftyos Swiftyos deleted the zamilmajdy/unwrap-nested-request-api branch March 4, 2024 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants