-
Notifications
You must be signed in to change notification settings - Fork 526
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
Delegate resolving of relative URLs to Java framework #751
Closed
Conversation
This file contains 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
Hi! thanks for this PR, can you please add a unit test with some cases before I merge. |
gracekarina
suggested changes
Sep 4, 2018
|
||
return StringUtils.join(outputParts, "/"); | ||
public static String buildUrl(String rootPath, String relativePath) throws URISyntaxException { | ||
return new URI(rootPath).resolve(new URI(relativePath)).toString(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi can you please add some tests? thanks!
…ving that in custom code. ## Repro ```Java String rootPath = "https://raw.githubusercontent.com/Azure/azure-rest-api-specs/master/specification/storage/resource-manager/Microsoft.Storage/stable/2018-02-01/storage.json"; String relativePath = "../../../../../common-types/resource-management/v1/types.json"; String expected="https://raw.githubusercontent.com/Azure/azure-rest-api-specs/master/specification/common-types/resource-management/v1/types.json"; System.out.println(io.swagger.parser.util.RefUtils.buildUrl(rootPath, relativePath)); ``` results in an `ArrayIndexOutOfBoundsException`: ```txt Exception in thread "main" java.lang.RuntimeException: Unable to load RELATIVE ref: ../../../../../common-types/resource-management/v1/types.json path:https://raw.githubusercontent.com/Azure/azure-rest-api-specs/master/specification/storage/resource-manager/Microsoft.Storage/stable/2018-02-01/storage.json at io.swagger.parser.util.RefUtils.readExternalUrlRef(RefUtils.java:68) at io.swagger.parser.ResolverCache.loadRef(ResolverCache.java:116) at io.swagger.parser.processors.ParameterProcessor.processParameters(ParameterProcessor.java:37) at io.swagger.parser.processors.OperationProcessor.processOperation(OperationProcessor.java:26) at io.swagger.parser.processors.PathsProcessor.processPaths(PathsProcessor.java:101) at io.swagger.parser.SwaggerResolver.resolve(SwaggerResolver.java:50) at io.swagger.parser.SwaggerParser.read(SwaggerParser.java:71) at io.swagger.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:431) at io.swagger.codegen.cmd.Generate.run(Generate.java:283) at io.swagger.codegen.SwaggerCodegen.main(SwaggerCodegen.java:35) Caused by: java.lang.ArrayIndexOutOfBoundsException at java.lang.System.arraycopy(Native Method) at io.swagger.parser.util.RefUtils.buildUrl(RefUtils.java:108) at io.swagger.parser.util.RefUtils.readExternalUrlRef(RefUtils.java:63) ``` I experienced that when using the codegen CLI: ```bash java -jar swagger-codegen-cli.jar generate \ -l elixir \ -i "https://raw.githubusercontent.com/Azure/azure-rest-api-specs/master/specification/storage/resource-manager/Microsoft.Storage/stable/2018-02-01/storage.json" ```
replaced by 2082 |
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.
Delegate resolving of relative URLs to Java framework, instead of solving that in custom code.
Fix #750
Repro
results in an
ArrayIndexOutOfBoundsException
:I experienced that when using the codegen CLI:
java -jar swagger-codegen-cli.jar generate \ -l elixir \ -i "https://raw.githubusercontent.com/Azure/azure-rest-api-specs/master/specification/storage/resource-manager/Microsoft.Storage/stable/2018-02-01/storage.json"