public static ObjectNode resolveSchemaForReference(final ObjectNode json, final String title, final String reference) { final ObjectNode dereferenced = (ObjectNode) json.at(reference.substring(1)); return createJsonSchema(title, dereferenced); }
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); }
public static ObjectNode createJsonSchema(final String title, final ObjectNode schema) { final ObjectNode schemaNode = newJsonObjectSchema(); if (title != null) { schemaNode.put("title", title); } schemaNode.setAll(schema); return schemaNode; }
private static DataShape unifiedJsonSchema(final String name, final String description, final ObjectNode bodySchema, final ObjectNode parametersSchema) { if (bodySchema == null && parametersSchema == null) { return DATA_SHAPE_NONE; } final ObjectNode unifiedSchema = JsonSchemaHelper.newJsonObjectSchema(); unifiedSchema.put("$id", "io:syndesis:wrapped"); final ObjectNode properties = unifiedSchema.putObject("properties"); if (parametersSchema != null) { properties.remove(PROPERTIES_TO_REMOVE_ON_MERGE); properties.set("parameters", parametersSchema.get("properties").get("parameters")); } if (bodySchema != null) { bodySchema.remove(PROPERTIES_TO_REMOVE_ON_MERGE); properties.set("body", bodySchema); } return new DataShape.Builder()// .name(name)// .description(description)// .kind(DataShapeKinds.JSON_SCHEMA)// .specification(JsonSchemaHelper.serializeJson(unifiedSchema))// .build(); }
public static String determineSchemaReference(final Property schema) { if (schema instanceof RefProperty) { return ((RefProperty) schema).get$ref(); } else if (schema instanceof ArrayProperty) { final Property property = ((ArrayProperty) schema).getItems(); return determineSchemaReference(property); } throw new IllegalArgumentException("Only references to schemas are supported"); }
public static String javaTypeFor(final SerializableParameter parameter) { final String type = parameter.getType(); if ("array".equals(type)) { final Property items = parameter.getItems(); final String elementType = items.getType(); final String elementFormat = items.getFormat(); return javaTypeFor(elementType, elementFormat) + "[]"; } final String format = parameter.getFormat(); return javaTypeFor(type, format); }
@Value.Lazy default ObjectNode getResolvedJsonGraph() { try { final ObjectNode json = (ObjectNode) Json.reader().readTree(getResolvedSpecification()); return JsonSchemaHelper.resolvableNodeForSpecification(json); } catch (final IOException e) { throw new IllegalStateException("Unable to parse OpenAPI specification resolved as JSON", e); } }
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 String determineTitleOf(final String name, final Property schema) { final String title = schema.getTitle(); if (title != null) { return title; } final String description = schema.getDescription(); if (description != null) { return description; } final String reference = JsonSchemaHelper.determineSchemaReference(schema); if (reference != null) { return reference.replaceAll("^.*/", ""); } return name; }
propertyBuilder.type(type).javaType(JsonSchemaHelper.javaTypeFor(serializableParameter));
private static ObjectNode createSchemaFromModelImpl(final String name, final Model model) { final ObjectNode schema = Json.convertValue(model, ObjectNode.class); final String title = determineTitleOf(name, model); return JsonSchemaHelper.createJsonSchema(title, schema); }
private static ObjectNode createSchemaFor(final List<AbstractSerializableParameter<?>> serializableParameters) { final ObjectNode schema = JsonSchemaHelper.newJsonObjectSchema(); final ObjectNode properties = schema.putObject("properties");