-
Notifications
You must be signed in to change notification settings - Fork 534
swagger-parser-v3 fails to generate spec on relative server urls on Windows #1553
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
Could this be the ultimate cause of OpenAPITools/openapi-generator#8266 mayhaps? My scenario in that bug would make sense if |
@Klaboe I discovered this issue when I attempted the same upgrade to openapi-generator 5.0.0 as @UnleashSpirit describes, so yes, this is the underlying issue. |
I would love to see this fixed so we can start using openapi generator 5.1.0 which has some fixes we were waiting for. Is someone able to PR this? |
I will be able to make a pull request, but not immediately :-) |
@willemsendennis I've submitted a pull request. It looks like I misclassified the core issue - it was resolution of Windows path names |
#1553 fails to generate spec on relative server urls on Windows
Thanks @jhannes! |
+1 |
After a change in OpenAPIDeserializer, swagger-parser-v3 fails to generate any model for a spec with a relative server url when running on Windows.
The message recorded in result is "begin 0, end -1, length 3", quite unhelpfully, while the result of
new OpenAPIParser().readLocation(inputSpec, authorizationValues, options)
is just result.openAPI andresult.messages
both being nullAccording to the OpenAPI spec relative base paths are supported by the OpenAPI standard. Relative URLs are of course very useful when developing a backend-for-frontend API. At any rate, if swagger-parser was to not support it, users deserve a better error message.
Here is a minimum OpenAPI spec to reproduce the problem:
As of now, I'm executing the parser through openapi-generator, so I don't have a targeted test case or pull request, but can work on this if you want.
Cause:
Trying to substitute server variable values when there are no variables causes a
StringIndexOutOfBoundsException
. This line should've checked onvalue.indexOf("{")
before doingsubstring
. Additionally, the code does not support multiple template variables as required by the spec. Please not that the code here uses tabs and spaces inconsistently and looks bad on github.The substitution only happens on URIParseException, which is caused by Windows-style paths with "" instead of "/".
The exception is caught in OpenAPIDeserializer.deserialize, with
result.setMessages(Arrays.asList(e.getMessage()));
. I suggest replacing this withresult.setMessages(Arrays.asList(e.toString()));
, which would have given the slightly more helpfuljava.lang.StringIndexOutOfBoundsException: begin 0, end -1, length 4
in this case. Or perhaps the exception should be allowed to propagate further?In my case, the code returns to OpenAPIParser which continues with the next extension (first was OpenAPI, second is Swagger). This means that as
OpenAPIParser.readLocation
returns even the meager message "begin 0, end -1, length 4" is lost.Suggested fix
io.swagger.v3.parser.util.OpenAPIDeserializer#getServer
io.swagger.v3.parser.util.OpenAPIDeserializer#deserialize
, letting fatal bugs messages propagate to the user instead of causing silent errors. Alternatively, usee.toString()
instead ofe.getMessage()
to get less cryptic errorsoutput.getMessages() != null
so that errors during processing of OpenAPI aren't overwritten by the Swagger parserThe text was updated successfully, but these errors were encountered: