Open
Conversation
When adding operation `path` to the base_url, the use of the `+` operator can lead to doubling of `/` characters if the base_url ends with a `/`. Using urljoin should fix this. This is also a cleaner way to work with url paths. Signed-off-by: Ondrej Lichtner <olichtne@redhat.com>
Dorthu
requested changes
Oct 14, 2022
Owner
Dorthu
left a comment
There was a problem hiding this comment.
This behaves unexpectedly when the servers listed include a path fragment. For example:
openapi: 3.0.2
info:
title: LNST Dashboard
version: ''
description: API to the interact with the dashboard db directly - upload or get
and process data as you wish
servers:
- url: https://api.example.com/v2
paths:
/artifacts/:
get:
operationId: listArtifacts
...A request to the listArtifacts operation here would result in a request to https://api.example.com/artifacts/ instead of https://api.example.com/v2/artifacts/; this appears to be the behavior of urljoin:
>>> from urllib.parse import urljoin
>>> urljoin("https://api.example.com/v2", "/artifacts/")
'https://api.example.com/artifacts/'
>>> urljoin("https://api.example.com/v2/", "/artifacts/")
'https://api.example.com/artifacts/'Maybe stripping the extra / if it's present in both the server name and the path would be a simpler solution?
Author
|
hmmm, good point
i feel like there should be a better way to do this, doing string editing operations on path fragments for a simple join operation feels weird to me. i'll think about this next week when i have some time for this. thanks for looking at the PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When adding operation
pathto the base_url, the use of the+operator can lead to doubling of/characters if the base_url ends with a/.Using urljoin should fix this. This is also a cleaner way to work with url paths.
This causes some minor issues for us when interacting with our rest api server where the doubled
/character is not matched correctly and results in 404 errors.Even though the doubled
/characters are defined in RFCs as something that should be simply skipped and don't effectively change the path, some http servers can be configured either way.An example of a reproducer is to use a schema that looks as follows:
vs.
Note that the difference is the final
/in the server url.For the first schema with the current code of openapi3 the request
api.call_listArtifacts()would call:Whereas with the fix the same request would call: