Skip to content

Commit

Permalink
Fix: Serialize StringSchema without error (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
timonback authored Mar 31, 2023
1 parent b243fc3 commit 7578fd1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private void buildExampleAsString(String k, Schema schema) {

private void deserializeExampleToMap(String k, Schema schema) {
try {
schema.setExample(objectMapper.readValue((String) schema.getExample(), Map.class));
schema.setExample(objectMapper.readValue((String) schema.getExample(), Object.class));
} catch (IOException e) {
log.error("Failed to convert example object of {} to map", schema.getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ public void string() throws IOException, JSONException {
.isEqualTo("String");

assertNotNull(schemasService.getDefinitions().get(modelName));

Schema schema = schemasService.getDefinitions().get(modelName);
String example = objectMapper.writeValueAsString(schema.getExample());
String expectedExample = "\"string\"";

assertThat(example).isEqualTo(expectedExample);
}

@Test
Expand All @@ -49,7 +55,6 @@ public void simpleObject() throws IOException, JSONException {

Schema schema = schemasService.getDefinitions().get(modelName);
String example = objectMapper.writeValueAsString(schema.getExample());

String expectedExample = jsonResource(EXAMPLES_PATH + "/simple-foo.json");

JSONAssert.assertEquals(expectedExample, example, JSONCompareMode.STRICT);
Expand Down

0 comments on commit 7578fd1

Please sign in to comment.