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: Crashes when parsing diff for very large specs #388

Merged
merged 2 commits into from
Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions cli/src/main/java/org/openapitools/openapidiff/cli/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,8 @@ public static void main(String... args) {
}
if (line.hasOption("json")) {
JsonRender jsonRender = new JsonRender();
String output = jsonRender.render(result);
String outputFile = line.getOptionValue("json");
writeOutput(output, outputFile);
jsonRender.renderToFile(result, outputFile);
}
if (line.hasOption("state")) {
System.out.println(result.isChanged().getValue());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.openapitools.openapidiff.core.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.v3.oas.models.OpenAPI;
import java.util.List;
import java.util.Objects;
Expand All @@ -8,8 +9,8 @@
import org.openapitools.openapidiff.core.utils.EndpointUtils;

public class ChangedOpenApi implements ComposedChanged {
private OpenAPI oldSpecOpenApi;
private OpenAPI newSpecOpenApi;
@JsonIgnore private OpenAPI oldSpecOpenApi;
@JsonIgnore private OpenAPI newSpecOpenApi;
Comment on lines +12 to +13
Copy link
Contributor

Choose a reason for hiding this comment

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

This would change the output of the JSON renderer and remove the copy of the old and new OpenAPI specifications from the document.

Was this intentional?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm fine with removing/ignoring these fields since none of the other output renderers is using them, but I want to make sure this was intentional on your end. 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes it was. IMO that information is redundant as they are the inputs to the tool. Plus in the case of large files it makes the output unnecessarily large.

private List<Endpoint> newEndpoints;
private List<Endpoint> missingEndpoints;
private List<ChangedOperation> changedOperations;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.nio.file.Paths;
import org.openapitools.openapidiff.core.model.ChangedOpenApi;

public class JsonRender implements Render {
Expand All @@ -17,4 +19,14 @@ public String render(ChangedOpenApi diff) {
throw new RuntimeException("Could not serialize diff as JSON", e);
}
}

public void renderToFile(ChangedOpenApi diff, String file) {
try {
objectMapper.writeValue(Paths.get(file).toFile(), diff);
} catch (JsonProcessingException e) {
throw new RuntimeException("Could not serialize diff as JSON", e);
} catch (IOException e) {
throw new RuntimeException("Could not write to JSON file", e);
}
}
}