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

Register ObjectMapper modules #419

Merged
merged 1 commit into from
Oct 24, 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
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@
import org.openapitools.openapidiff.core.model.ChangedOpenApi;

public class JsonRender implements Render {
private final ObjectMapper objectMapper =
new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL);
private final ObjectMapper objectMapper;

public JsonRender() {
objectMapper = new ObjectMapper();
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
objectMapper.findAndRegisterModules();
}

@Override
public String render(ChangedOpenApi diff) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,12 @@ public void renderDoesNotFailWhenPropertyHasBeenRemoved() {
OpenApiCompare.fromLocations("missing_property_1.yaml", "missing_property_2.yaml");
assertThat(render.render(diff)).isNotBlank();
}

@Test
public void renderDoesNotFailForJsr310Types() {
JsonRender render = new JsonRender();
ChangedOpenApi diff =
OpenApiCompare.fromLocations("jsr310_property_1.yaml", "jsr310_property_2.yaml");
assertThat(render.render(diff)).isNotBlank();
}
}
23 changes: 23 additions & 0 deletions core/src/test/resources/jsr310_property_1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
openapi: 3.0.1
info:
title: Title
version: 1.0.0
description: Description
paths:
/:
get:
summary: Simple GET
operationId: simpleGet
responses:
default:
description: Default response
content:
application/json:
schema:
properties:
someDateTime:
description: Date time
example: 2021-11-03T13:50:47Z
type: string
format: date-time
description: Simple GET
22 changes: 22 additions & 0 deletions core/src/test/resources/jsr310_property_2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
openapi: 3.0.1
info:
title: Title
version: 1.0.0
description: Description
paths:
/:
get:
summary: Simple GET
operationId: simpleGet
responses:
default:
description: Default response
content:
application/json:
schema:
properties:
someDateTime:
description: Date time
example: 2021-11-03T13:50:47Z
type: string
description: Simple GET