Skip to content

Commit

Permalink
feat(json-schema): cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
timonback committed Nov 11, 2023
1 parent 9ad5a20 commit e1a145d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public class JsonSchemaGenerator {
public Object fromSchema(Schema<?> schema, Map<String, Schema> definitions) throws JsonProcessingException {
ObjectNode node = fromSchemaInternal(schema, definitions, new HashSet<>());
node.put("$schema", "https://json-schema.org/draft-04/schema#");
return node;

return objectMapper.readValue(node.toString(), Object.class);
}

private ObjectNode fromSchemaInternal(Schema<?> schema, Map<String, Schema> definitions, Set<Schema> visited) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,25 +55,24 @@ public void validateJsonSchemaTest(String expectedJsonSchema, Supplier<Schema<?>
pongSchema.setProperties(Map.of("pongField", pongFieldSchema));

// when
String jsonSchema = jsonSchemaGenerator
.fromSchema(
asyncApiSchema.get(),
Map.of(
"StringRef",
new StringSchema(),
"PingSchema",
pingSchema,
"PingFieldSchema",
pingFieldSchema,
"PongSchema",
pongSchema,
"PongFieldSchema",
pongFieldSchema))
.toString();
Object jsonSchema = jsonSchemaGenerator.fromSchema(
asyncApiSchema.get(),
Map.of(
"StringRef",
new StringSchema(),
"PingSchema",
pingSchema,
"PingFieldSchema",
pingFieldSchema,
"PongSchema",
pongSchema,
"PongFieldSchema",
pongFieldSchema));
String jsonSchemaString = mapper.writeValueAsString(jsonSchema);

// then
verifyValidJsonSchema(jsonSchema);
assertThat(jsonSchema).isEqualToIgnoringWhitespace(expectedJsonSchema);
verifyValidJsonSchema(jsonSchemaString);
assertThat(jsonSchemaString).isEqualToIgnoringWhitespace(expectedJsonSchema);
}

public static Stream<Arguments> validateJsonSchemaTest() {
Expand Down

0 comments on commit e1a145d

Please sign in to comment.