Skip to content

Feature request: Add compression for swagger ui #3935

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

Closed
2 tasks done
xquek opened this issue Mar 12, 2024 · 5 comments · Fixed by #3946
Closed
2 tasks done

Feature request: Add compression for swagger ui #3935

xquek opened this issue Mar 12, 2024 · 5 comments · Fixed by #3946

Comments

@xquek
Copy link
Contributor

xquek commented Mar 12, 2024

Use case

Hi when serving swagger over ALB, there is a 1 MB limit.

We are able to get pass it by using swagger_base_url and servce the js file from it.
But i was wondering if ti will be possible to add a compress flag and return a compress response when setting enable_swagger

Solution/User Experience

# usage 
app.enable_swagger(..., compress=True)

and then in line

def enable_swagger(...):
   ...
   return Response(
        compress = compress 
   )

or at
https://github.com/aws-powertools/powertools-lambda-python/blob/fa235c0d7335265342f3f13d189d7e10af0ed0b6/aws_lambda_powertools/event_handler/api_gateway.py#L1662C8-L1662C74

       @self.get(path, middlewares=middlewares, include_in_schema=False, compress = compress)
        def swagger_handler():

I have tested this on my local development stack, it went from over 1mb which results in 502, to ~ 330kb in response size.

We can set the default as false so it is backwards compatible

Alternative solutions

No response

Acknowledgment

Copy link

boring-cyborg bot commented Mar 12, 2024

Thanks for opening your first issue here! We'll come back to you as soon as we can.
In the meantime, check out the #python channel on our Powertools for AWS Lambda Discord: Invite link

@leandrodamascena
Copy link
Contributor

Hi @xquek! Thanks for opening this issue with this important feature request. I completely agree with you that we should provide a way to allow customers to choose whether they want the HTTP Response to be compressed or not when serving the swagger file. This can be a challenge for anyone using a browser request that doesn't add the "Accept-Encoding" header, for example, but it's something we add in our documentation so the customer is aware.

I like the implementation of adding a parameter compress in enable_swagger function and setting False as default to keep backwards compatibility.

Do you want to send a PR to add this feature? We can work together to get it merged before our next release.

Thanks

@leandrodamascena leandrodamascena self-assigned this Mar 12, 2024
@leandrodamascena leandrodamascena added event_handlers openapi-schema and removed triage Pending triage from maintainers labels Mar 12, 2024
@leandrodamascena leandrodamascena moved this from Triage to Working on it in Powertools for AWS Lambda (Python) Mar 12, 2024
@xquek
Copy link
Contributor Author

xquek commented Mar 13, 2024

Hi @leandrodamascena! thanks for the feedback! ill be very happy to send in a PR! Thanks!!

@xquek
Copy link
Contributor Author

xquek commented Mar 13, 2024

Hi there , i created - #3946 let me know if there is any question! thanks!

Copy link
Contributor

⚠️COMMENT VISIBILITY WARNING⚠️

This issue is now closed. Please be mindful that future comments are hard for our team to see.

If you need more assistance, please either tag a team member or open a new issue that references this one.

If you wish to keep having a conversation with other community members under this issue feel free to do so.

@leandrodamascena leandrodamascena moved this from Coming soon to Shipped in Powertools for AWS Lambda (Python) Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Shipped
Development

Successfully merging a pull request may close this issue.

2 participants