How should a basePath "/" be interpreted by tooling in OAS2? #2636
Replies: 2 comments 1 reply
-
This is why writing specifications is hard. 😉 This seems more like an edge case that was almost thought through, but wasn't. I'd say it is safe to assume that if the Unfortunately, clarifying it in the specification itself is not an option, since we can't really make any changes to it. 2.0 was not structured in a way we can publish patch releases. However, this discussion will hopefully be able to help additional people in the future. Of course, if people migrate to newer versions, that would not be an issue at all. And they should. Really. 😄 |
Beta Was this translation helpful? Give feedback.
-
Seems like this was answered as much as it could be, given the 2.0 limitations (and it's not a problem in 3.x). Closing. |
Beta Was this translation helpful? Give feedback.
-
When constructing a URL from a document with a basePath
/
it's unclear what the expected outcome is.In the Swagger 2 spec it says that
This suggests the following structure (ignoring scheme for now):
<host><basePath><path>
Without a basePath:
results in
host.com/user
With a basePath:
results in
host.com/api/user
Finally, following the same logic:
results in
host.com//user
Now, I realise that this isn't the offical spec, but it seems that the expectation isn't 100% clear. swagger.io documentation suggests something else:
https://swagger.io/docs/specification/2-0/api-host-and-base-path/
See
This is considering
/
to be the same as not providing the value which isn't in the original spec.A number of other tools such as Stoplight are also interpreting
/
to be the root rather than an explicit basePath, which I think is wrong, and resulting in a lot of bad swaggers in the wild. It's not too bad when you're reading the swagger as documentation and interpreting it yourself, but if you're writing a tool, you need to follow the spec as correctly as possible. In this case it could end up with not calling the correct API, or not showing the correct path as was indended.The question I have:
This should probably be clarified so it's not up to interpretation.
Beta Was this translation helpful? Give feedback.
All reactions