private static ObjectNode createSchemaFromModel(final ObjectNode json, final String name, final Model schema) { if (schema instanceof ArrayModel) { final Property items = ((ArrayModel) schema).getItems(); final ObjectNode itemSchema = createSchemaFromProperty(json, name, items); itemSchema.remove(Arrays.asList("$schema", "title")); final ObjectNode jsonSchema = JsonNodeFactory.instance.objectNode(); jsonSchema.put("type", "array"); jsonSchema.set("items", itemSchema); return jsonSchema; } else if (schema instanceof ModelImpl) { return createSchemaFromModelImpl(name, schema); } final String title = determineTitleOf(name, schema); return JsonSchemaHelper.resolveSchemaForReference(json, title, schema.getReference()); }
private static ObjectNode createSchemaFromProperty(final ObjectNode json, final String name, final Property schema) { if (schema instanceof MapProperty || schema instanceof ObjectProperty) { try { final String schemaString = Json.writer().writeValueAsString(schema); return JsonSchemaHelper.parseJsonSchema(schemaString); } catch (final JsonProcessingException e) { throw new IllegalStateException("Unable to serialize/read given JSON specification in response schema: " + schema, e); } } else if (schema instanceof StringProperty) { final ObjectNode jsonSchema = JsonNodeFactory.instance.objectNode(); final String format = schema.getFormat(); if (format != null) { jsonSchema.put("format", format); } final String type = schema.getType(); if (type != null) { jsonSchema.put("type", type); } return jsonSchema; } final String reference = JsonSchemaHelper.determineSchemaReference(schema); final String title = determineTitleOf(name, schema); return JsonSchemaHelper.resolveSchemaForReference(json, title, reference); }