private void objectExample(StringBuilder sb, int maxlength, String indent, JsonSchema schema, Map<String, JsonSchema> refs, Set<String> followed, Set<String> referenced, String id) { sb.append("{"); if (referenced.contains(id)) { shortId(sb, schema); } ObjectSchema os = schema.asObjectSchema(); if (os.getProperties().isEmpty()) { AdditionalProperties additionalProperties = os.getAdditionalProperties(); if (additionalProperties instanceof SchemaAdditionalProperties) { sb.append("\n").append(indent).append(" ").append("abc").append(": "); example(sb, maxlength, indent + " ", ((SchemaAdditionalProperties) additionalProperties).getJsonSchema(), refs, followed, referenced); sb.append(", ..."); } } Map<String, JsonSchema> props = new TreeMap<>(os.getProperties()); for (Entry<String, JsonSchema> entry : props.entrySet()) { sb.append("\n").append(indent).append(" ").append(entry.getKey()).append(": "); example(sb, maxlength, indent + " ", entry.getValue(), refs, followed, referenced); sb.append(","); } sb.append("\n").append(indent).append("}"); }
@Override public ObjectSchema.AdditionalProperties deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { if (p.hasCurrentToken()) { switch (p.getCurrentTokenId()) { case JsonTokenId.ID_TRUE: return null; // "additionalProperties":true is the default case JsonTokenId.ID_FALSE: return ObjectSchema.NoAdditionalProperties.instance; case JsonTokenId.ID_START_OBJECT: case JsonTokenId.ID_FIELD_NAME: case JsonTokenId.ID_END_OBJECT: // 29-Dec-2015, tatu: may need/want to use property value reader in future but for now: JsonSchema innerSchema = ctxt.readValue(p, JsonSchema.class); return new ObjectSchema.SchemaAdditionalProperties(innerSchema); } } return ctxt.reportInputMismatch(this, "additionalProperties nodes can only be of type boolean or object, got token of type: %s", p.getCurrentToken()); } }
@Override public ObjectSchema.AdditionalProperties deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { if (p.hasCurrentToken()) { switch (p.getCurrentTokenId()) { case JsonTokenId.ID_TRUE: return null; // "additionalProperties":true is the default case JsonTokenId.ID_FALSE: return ObjectSchema.NoAdditionalProperties.instance; case JsonTokenId.ID_START_OBJECT: case JsonTokenId.ID_FIELD_NAME: case JsonTokenId.ID_END_OBJECT: // 29-Dec-2015, tatu: may need/want to use property value reader in future but for now: JsonSchema innerSchema = ctxt.readValue(p, JsonSchema.class); return new ObjectSchema.SchemaAdditionalProperties(innerSchema); } } return ctxt.reportInputMismatch(this, "additionalProperties nodes can only be of type boolean or object, got token of type: %s", p.getCurrentToken()); } }
@Override public boolean equals(Object obj) { return (obj instanceof SchemaAdditionalProperties) && JsonSchema.equals(getJsonSchema(), ((SchemaAdditionalProperties)obj).getJsonSchema()); }
@Override public boolean equals(Object obj) { return (obj instanceof SchemaAdditionalProperties) && JsonSchema.equals(getJsonSchema(), ((SchemaAdditionalProperties)obj).getJsonSchema()); }
@Override public void valueFormat(JsonFormatVisitable handler, JavaType valueType) throws JsonMappingException { // ISSUE #24: https://github.com/FasterXML/jackson-module-jsonSchema/issues/24 JsonSchema valueSchema = propertySchema(handler, valueType); ObjectSchema.AdditionalProperties ap = new ObjectSchema.SchemaAdditionalProperties(valueSchema.asSimpleTypeSchema()); this.schema.setAdditionalProperties(ap); }
@Override public void valueFormat(JsonFormatVisitable handler, JavaType valueType) throws JsonMappingException { // ISSUE #24: https://github.com/FasterXML/jackson-module-jsonSchema/issues/24 JsonSchema valueSchema = propertySchema(handler, valueType); ObjectSchema.AdditionalProperties ap = new ObjectSchema.SchemaAdditionalProperties(valueSchema.asSimpleTypeSchema()); this.schema.setAdditionalProperties(ap); }