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

Fix to SwaggerCompatConverter so it can load inputSpec from classpath. #580

Merged

Conversation

Dema
Copy link
Contributor

@Dema Dema commented Nov 13, 2017

Swagger20Parser already can load input spec from classpath, but codegen project loads extensions one them is SwaggerCompatConverter and it fails loading from classpath

This fixes swagger-api/swagger-codegen#2666

@webron
Copy link
Contributor

webron commented Nov 13, 2017

Thanks for the PR. Can you add a test to it?

@@ -186,7 +191,22 @@ public ResourceListing readResourceListing(String input, MessageBuilder messages
String json = RemoteUrl.urlToString(input, auths);
jsonNode = Json.mapper().readTree(json);
} else {
jsonNode = Json.mapper().readTree(new File(input));
final String fileScheme = "file:";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its final string. Should be constant.

jsonNode = Json.mapper().readTree(new File(input));
final String fileScheme = "file:";
java.nio.file.Path path;
if (input.toLowerCase().startsWith(fileScheme)) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid NPE, to compare with fileSchema, as it is constant

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it can't throw NPE on line 196, it'll throw it in the previous if(input.startsWith("http")) statement.

}
String json;
if (Files.exists(path)) {
json= FileUtils.readFileToString(path.toFile(), "UTF-8");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StandardCharsets already has "UTF-8" constant

@@ -489,7 +509,21 @@ public ApiDeclaration readDeclaration(String input, MessageBuilder messages, Lis
String json = RemoteUrl.urlToString(input, auths);
jsonNode = Json.mapper().readTree(json);
} else {
jsonNode = Json.mapper().readTree(new java.io.File(input));
final String fileScheme = "file:";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for duplicate code ? Can't we refactor this code into function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gracekarina
Copy link
Contributor

@Dema thanks, sorry for the delay on this.

@gracekarina gracekarina merged commit a7402b4 into swagger-api:master Jan 16, 2018
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.

swagger codegen maven plugin support for json file as dependency
4 participants