private void findRefs(JsonSchema schema, Map<String, JsonSchema> refs, Set<String> referenced) { addRef(schema, refs); if (schema instanceof ReferenceSchema) { referenced.add(schema.get$ref()); } else if (schema.isArraySchema()) { ArraySchema as = schema.asArraySchema(); if (as.getItems() != null) { if (as.getItems().isSingleItems()) { findRefs(as.getItems().asSingleItems().getSchema(), refs, referenced); } else if (as.getItems().isArrayItems()) { ArrayItems items = as.getItems().asArrayItems(); for (JsonSchema item : items.getJsonSchemas()) { findRefs(item, refs, referenced); } } else { throw new UnsupportedOperationException(as.getItems().toString()); } } } else if (schema.isObjectSchema()) { ObjectSchema os = schema.asObjectSchema(); for (JsonSchema value : os.getProperties().values()) { findRefs(value, refs, referenced); } } }
private void arrayExample(StringBuilder sb, int maxlength, String indent, JsonSchema schema, Map<String, JsonSchema> refs, Set<String> followed, Set<String> referenced) { sb.append("[\n").append(indent).append(" "); ArraySchema as = schema.asArraySchema(); if (as.getItems() == null) { sb.append(" ... ]"); } else if (as.getItems().isSingleItems()) { example(sb, maxlength, indent + " ", as.getItems().asSingleItems().getSchema(), refs, followed, referenced); sb.append(",\n").append(indent).append(" ...\n").append(indent).append("]"); } else if (as.getItems().isArrayItems()) { ArrayItems items = as.getItems().asArrayItems(); for (JsonSchema item : items.getJsonSchemas()) { sb.append("\n").append(indent); example(sb, maxlength, indent + " ", item, refs, followed, referenced); sb.append(","); } sb.append("]"); } else { throw new UnsupportedOperationException(as.getItems().toString()); } }
@Override public Items deserialize(JsonParser parser, DeserializationContext context) throws IOException { // 07-Oct-2015, tatu: Could further optimize by fetching delegating // deserializer in `createContextual`, but should do for now if (parser.isExpectedStartArrayToken()) { JsonSchema[] schemas = context.readValue(parser, JsonSchema[].class); return new ArrayItems(schemas); } JsonSchema schema = context.readValue(parser, JsonSchema.class); return new SingleItems(schema); } }
@Override public Items deserialize(JsonParser parser, DeserializationContext context) throws IOException { // 07-Oct-2015, tatu: Could further optimize by fetching delegating // deserializer in `createContextual`, but should do for now if (parser.isExpectedStartArrayToken()) { JsonSchema[] schemas = context.readValue(parser, JsonSchema[].class); return new ArrayItems(schemas); } JsonSchema schema = context.readValue(parser, JsonSchema.class); return new SingleItems(schema); } }
@Override public boolean equals(Object obj) { if (obj instanceof Items) { ArrayItems that = (ArrayItems) obj; return JsonSchema.equals(getJsonSchemas(), that.getJsonSchemas()); } else { return false; } }
@Override public boolean equals(Object obj) { if (obj instanceof Items) { ArrayItems that = (ArrayItems) obj; return JsonSchema.equals(getJsonSchemas(), that.getJsonSchemas()); } else { return false; } }