@Test void generateSchema() { final Schema schema = factory .newSchemaBuilder(Schema.Type.RECORD) .withEntry(factory.newEntryBuilder().withType(Schema.Type.STRING).withName("name").build()) .withEntry(factory.newEntryBuilder().withType(Schema.Type.INT).withName("id").build()) .withEntry(factory .newEntryBuilder() .withType(Schema.Type.RECORD) .withName("nested") .withElementSchema(factory .newSchemaBuilder(Schema.Type.RECORD) .withEntry(factory .newEntryBuilder() .withType(Schema.Type.LONG) .withName("counter") .build()) .build()) .build()) .build(); final JsonObject object = new JsonSchemaGenerator(schema.getEntries(), Json.createBuilderFactory(emptyMap())).get(); assertEquals( "{\"type\":[\"null\",\"object\"],\"additionalProperties\":false,\"properties\":{\"name\":{\"type\":[\"string\"]},\"id\":{\"type\":[\"integer\"]},\"nested\":{\"type\":[\"null\",\"object\"],\"additionalProperties\":false,\"properties\":{\"counter\":{\"type\":[\"integer\"]}}}}}", object.toString()); }
@Override public JsonObject get() { final JsonObjectBuilder json = jsonBuilderFactory.createObjectBuilder(); json.add("type", jsonBuilderFactory.createArrayBuilder().add("null").add("object").build()); json.add("additionalProperties", false); json.add("properties", properties.stream().map(this::toJson).collect(toJsonObject())); return json.build(); }
JsonSchemaGenerator implements Supplier<JsonObject> { @Override public JsonObject get() { final JsonObjectBuilder json = jsonBuilderFactory.createObjectBuilder(); json.add("type", jsonBuilderFactory.createArrayBuilder().add("null").add("object").build()); json.add("additionalProperties", false); json.add("properties", properties.stream().map(this::toJson).collect(toJsonObject())); return json.build(); } }
JsonSchemaGenerator implements Supplier<JsonObject> { @Override public JsonObject get() { final JsonObjectBuilder json = jsonBuilderFactory.createObjectBuilder(); json.add("type", jsonBuilderFactory.createArrayBuilder().add("null").add("object").build()); json.add("additionalProperties", false); json.add("properties", properties.stream().map(this::toJson).collect(toJsonObject())); return json.build(); }  }
JsonSchemaGenerator implements Supplier<JsonObject> { @Override public JsonObject get() { final JsonObjectBuilder json = jsonBuilderFactory.createObjectBuilder(); json.add("type", jsonBuilderFactory.createArrayBuilder().add("null").add("object").build()); json.add("additionalProperties", false); json.add("properties", properties.stream().map(this::toJson).collect(toJsonObject())); return json.build(); }  @Override JsonObject get(); }
JsonSchemaGenerator implements Supplier<JsonObject> { @Override public JsonObject get() { final JsonObjectBuilder json = jsonBuilderFactory.createObjectBuilder(); json.add("type", jsonBuilderFactory.createArrayBuilder().add("null").add("object").build()); json.add("additionalProperties", false); json.add("properties", properties.stream().map(this::toJson).collect(toJsonObject())); return json.build(); }  @Override JsonObject get();  }