-
Notifications
You must be signed in to change notification settings - Fork 421
Bug: Swagger UI doesn't work correctly when using custom domain name with mapping key #4915
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
Comments
The first issue with wrong OpenAPI schema link can be solved here replacing:
with:
(to get absolute URL) or:
(to get relative URL) |
Hi @tlinhart! Thanks for bringing ideas to solve this issue and help with the project! Indeed, using relative URL helps in this case because in this line we update the URL to enable JSON download and it will consider the right path. But we still have the issue when you try to invoke the API using SwaggerUI interface, because we set a default object Server as "/", if not informed, and SwaggerUI take it in consideration to invoke the APIs. from aws_lambda_powertools.event_handler.openapi.models import Server
server = Server(url="/api")
app = APIGatewayRestResolver()
app.enable_swagger(path="/swagger",servers=[server]) Do you want to submit a PR to fix this problem? I'm still making some other tests, but I think this is the right direction to go. Leandro |
Hi @leandrodamascena, I can prepare a PR to fix the JSON download URL. When it comes to the other issues, i.e. invoking the API via Swagger UI, what are you suggesting? After reading the OpenAPI spec and thinking about it thoroughly, I'm more and more convinced that it's up to the developer to supply the correct |
Thanks @tlinhart! We can make a patch release to fix this.
Since this isn't really a bug, it's more about explaining to people how to use Swagger with a different path/custom domain, I think it's worth improving the messaging here:https://docs.powertools.aws.dev/lambda/python/latest/core/event_handler/api_gateway/#enabling-swaggerui. While you work to send the PR to fix the JavaScript part, let me think a way to improve this documentation. |
@leandrodamascena here's the PR – #4930. Please note that:
|
|
Expected Behaviour
I have an API Gateway HTTP API with route
/foo
. I create a custom domain name for the APImy.domain.com
and create a mapping with a mapping keyapi
. Thus I access my foo operation withhttps://my.domain.com/api/foo
. In my Lambda function, I create a resolver app and enable swagger on/swagger
path:I define my operation foo with:
I can then access the Swagger UI on
https://my.domain.com/api/swagger
. I also expect:https://my.domain.com/api/swagger?format=json
.GET /api/foo
.https://my.domain.com/api/foo
.Current Behaviour
At the moment, it works like this:
https://my.domain.com/swagger?format=json
, i.e. without the mapping keyapi
.GET /foo
, i.e. it lacks the mapping keyapi
.https://my.domain.com/foo
, i.e. without the mapping keyapi
.Code snippet
Possible Solution
The last problem with Try it out can be worked around by defining a server with
url="/api"
. The rest of the issues stays.Steps to Reproduce
It's described above.
Powertools for AWS Lambda (Python) version
latest
AWS Lambda function runtime
3.11
Packaging format used
PyPi
Debugging logs
No response
The text was updated successfully, but these errors were encountered: