Skip to content
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
wants to merge 1 commit into from

Conversation

chgeuer
Copy link

@chgeuer chgeuer commented Jul 5, 2018

Delegate resolving of relative URLs to Java framework, instead of solving that in custom code.

Fix #750

Repro

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:

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:

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"

@gracekarina
Copy link
Contributor

Hi! thanks for this PR, can you please add a unit test with some cases before I merge.

@gracekarina gracekarina self-requested a review July 31, 2018 19:04

return StringUtils.join(outputParts, "/");
public static String buildUrl(String rootPath, String relativePath) throws URISyntaxException {
return new URI(rootPath).resolve(new URI(relativePath)).toString();
}
Copy link
Contributor

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!

@frantuma frantuma changed the base branch from master to v1 October 10, 2018 13:45
…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"
```
@frantuma
Copy link
Member

frantuma commented May 1, 2024

replaced by 2082

@frantuma frantuma closed this May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants