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 request bodies #937

Merged
merged 15 commits into from
Sep 4, 2024
Merged

Conversation

VishnuSanal
Copy link
Contributor

@VishnuSanal VishnuSanal commented Aug 22, 2024

Description

This PR fixes #935

Summary

This PR does add request bodies to openapi implementation.

PR Checklist

Please ensure that:

  • The PR contains a descriptive title
  • The PR contains a descriptive summary of the changes
  • You build and test your changes before submitting a PR.
  • You have added relevant documentation
  • You have added relevant tests. We prefer integration tests wherever possible

Pre-Commit Instructions:

Copy link

vercel bot commented Aug 22, 2024

@VishnuSanal is attempting to deploy a commit to the sparckles Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

codspeed-hq bot commented Aug 22, 2024

CodSpeed Performance Report

Merging #937 will not alter performance

Comparing VishnuSanal:request-bodies (d8d9ee2) with main (12d8c0b)

Summary

✅ 114 untouched benchmarks

🆕 1 new benchmarks

Benchmarks breakdown

Benchmark main VishnuSanal:request-bodies Change
🆕 test_openapi_request_body N/A 6 ms N/A

Copy link
Member

@sansyrox sansyrox left a comment

Choose a reason for hiding this comment

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

Not super happy with the interface here. @VishnuSanal , we need to allow either a class or a typeddict like in query params

@VishnuSanal VishnuSanal requested a review from sansyrox August 26, 2024 05:18
Copy link
Member

@sansyrox sansyrox left a comment

Choose a reason for hiding this comment

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

Hey @VishnuSanal ,

needs fixing.

@sansyrox
Copy link
Member

The body should resemble the style of query params

@sansyrox
Copy link
Member

@VishnuSanal , this should be the interface

class CustomBody(TypedDict):
    file: bytes
    file_name: str

@app.post("/sync/multipart-file")
def sync_multipart_file(request: Request, body: CustomBody):
    files = request.files
    file_names = files.keys()
    return {"file_names": list(file_names)}

@VishnuSanal VishnuSanal marked this pull request as draft August 27, 2024 09:55
@VishnuSanal VishnuSanal marked this pull request as ready for review August 27, 2024 14:06
@VishnuSanal VishnuSanal requested a review from sansyrox August 27, 2024 14:06
@VishnuSanal
Copy link
Contributor Author

https://github.com/sparckles/Robyn/actions/runs/10579769894/job/29313024961 please try rerunning. Issue is with websocket tests.

@sansyrox
Copy link
Member

@VishnuSanal , is this PR up for review?

@sansyrox
Copy link
Member

@VishnuSanal , could you please show the example of the openapi page generated?

Attach a screenshot?

@VishnuSanal
Copy link
Contributor Author

VishnuSanal commented Aug 28, 2024

@VishnuSanal , is this PR up for review?

Yep @sansyrox

@VishnuSanal
Copy link
Contributor Author

image

class CreateItemBody(TypedDict):
    name: Optional[str]
    description: str
    price: float
    tax: float


@app.post("/upload/file")
def create_item(request: Request, body=CreateItemBody):
    return request.body

Copy link

vercel bot commented Aug 28, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
robyn ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 4, 2024 1:19pm

@sansyrox
Copy link
Member

Amazing! ✨
Next update should be to make them look like the following

class CreateItemBody(TypedDict):
    name: Optional[str]
    description: str
    price: float
    tax: float


@app.post("/upload/file")
def create_item(request: Request, body: CreateItemBody):
    return request.body

But we can address that in the next PR when we add support for response schemas! GG @VishnuSanal . Need to give a final review

@VishnuSanal VishnuSanal requested a review from sansyrox September 2, 2024 09:36
@VishnuSanal
Copy link
Contributor Author

image

@sansyrox example ☝🏿

@sansyrox
Copy link
Member

sansyrox commented Sep 3, 2024

Love this @VishnuSanal

Doing a final review before merging

Copy link
Member

@sansyrox sansyrox left a comment

Choose a reason for hiding this comment

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

Looks good to me 😄

Good job!

@sansyrox sansyrox merged commit d158bb7 into sparckles:main Sep 4, 2024
60 checks passed
@VishnuSanal VishnuSanal deleted the request-bodies branch September 4, 2024 14:26
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.

expose the operator object params to the user in openapi spec
2 participants