diff --git a/springwolf-add-ons/springwolf-json-schema/src/main/java/io/github/stavshamir/springwolf/addons/json_schema/JsonSchemaGenerator.java b/springwolf-add-ons/springwolf-json-schema/src/main/java/io/github/stavshamir/springwolf/addons/json_schema/JsonSchemaGenerator.java index e23c163aa..575323005 100644 --- a/springwolf-add-ons/springwolf-json-schema/src/main/java/io/github/stavshamir/springwolf/addons/json_schema/JsonSchemaGenerator.java +++ b/springwolf-add-ons/springwolf-json-schema/src/main/java/io/github/stavshamir/springwolf/addons/json_schema/JsonSchemaGenerator.java @@ -21,7 +21,8 @@ public class JsonSchemaGenerator { public Object fromSchema(Schema schema, Map 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 definitions, Set visited) { diff --git a/springwolf-add-ons/springwolf-json-schema/src/test/java/io/github/stavshamir/springwolf/addons/json_schema/JsonSchemaGeneratorTest.java b/springwolf-add-ons/springwolf-json-schema/src/test/java/io/github/stavshamir/springwolf/addons/json_schema/JsonSchemaGeneratorTest.java index 7b04decdf..64527cb56 100644 --- a/springwolf-add-ons/springwolf-json-schema/src/test/java/io/github/stavshamir/springwolf/addons/json_schema/JsonSchemaGeneratorTest.java +++ b/springwolf-add-ons/springwolf-json-schema/src/test/java/io/github/stavshamir/springwolf/addons/json_schema/JsonSchemaGeneratorTest.java @@ -55,25 +55,24 @@ public void validateJsonSchemaTest(String expectedJsonSchema, Supplier 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 validateJsonSchemaTest() {