From 2ef3e5124835be4ee31bf8f184cd2fcb3e93c9e0 Mon Sep 17 00:00:00 2001 From: reda-alaoui Date: Thu, 12 Feb 2015 14:21:57 +0100 Subject: [PATCH] Add a readonly property --- .../jackson/module/jsonSchema/JsonSchema.java | 16 ++++++++++++++++ .../jsonSchema/TestGenerateJsonSchema.java | 5 +++++ 2 files changed, 21 insertions(+) diff --git a/src/main/java/com/fasterxml/jackson/module/jsonSchema/JsonSchema.java b/src/main/java/com/fasterxml/jackson/module/jsonSchema/JsonSchema.java index e67122fa..11ccd996 100644 --- a/src/main/java/com/fasterxml/jackson/module/jsonSchema/JsonSchema.java +++ b/src/main/java/com/fasterxml/jackson/module/jsonSchema/JsonSchema.java @@ -148,6 +148,13 @@ public abstract class JsonSchema @JsonProperty private Boolean required = null; + /** + * This attribute indicates if the instance is not modifiable. + * This is false by defaul, making the instance modifiable. + */ + @JsonProperty + private Boolean readonly = null; + /** * This attribute is a string that provides a full description of the of * purpose the instance property. @@ -271,6 +278,7 @@ public boolean equals(Object obj) { JsonSchema that = ((JsonSchema)obj); return equals(getType(), getType()) && equals(getRequired(), that.getRequired()) && + equals(getReadonly(), that.getReadonly()) && equals(get$ref(), that.get$ref()) && equals(get$schema(), that.get$schema()) && equals(getDisallow(), that.getDisallow()) && @@ -301,6 +309,10 @@ public Boolean getRequired() { return required; } + public Boolean getReadonly() { + return readonly; + } + public String getDescription() { return description; } @@ -453,6 +465,10 @@ public void setRequired(Boolean required) { this.required = required; } + public void setReadonly(Boolean readonly){ + this.readonly = readonly; + } + public void setDescription(String description) { this.description = description; } diff --git a/src/test/java/com/fasterxml/jackson/module/jsonSchema/TestGenerateJsonSchema.java b/src/test/java/com/fasterxml/jackson/module/jsonSchema/TestGenerateJsonSchema.java index 8be9d1d1..9c71336f 100644 --- a/src/test/java/com/fasterxml/jackson/module/jsonSchema/TestGenerateJsonSchema.java +++ b/src/test/java/com/fasterxml/jackson/module/jsonSchema/TestGenerateJsonSchema.java @@ -141,16 +141,19 @@ public void testGeneratingJsonSchema() throws Exception { assertNotNull(prop1); assertTrue(prop1.isIntegerSchema()); assertNull(prop1.getRequired()); + assertNull(prop1.getReadonly()); JsonSchema prop2 = properties.get("property2"); assertNotNull(prop2); assertTrue(prop2.isStringSchema()); assertNull(prop2.getRequired()); + assertNull(prop2.getReadonly()); JsonSchema prop3 = properties.get("property3"); assertNotNull(prop3); assertTrue(prop3.isArraySchema()); assertNull(prop3.getRequired()); + assertNull(prop3.getReadonly()); Items items = prop3.asArraySchema().getItems(); assertTrue(items.isSingleItems()); JsonSchema itemType = items.asSingleItems().getSchema(); @@ -161,6 +164,7 @@ public void testGeneratingJsonSchema() throws Exception { assertNotNull(prop4); assertTrue(prop4.isArraySchema()); assertNull(prop4.getRequired()); + assertNull(prop4.getReadonly()); items = prop4.asArraySchema().getItems(); assertTrue(items.isSingleItems()); itemType = items.asSingleItems().getSchema(); @@ -170,6 +174,7 @@ public void testGeneratingJsonSchema() throws Exception { JsonSchema prop5 = properties.get("property5"); assertNotNull(prop5); assertTrue(prop5.getRequired()); + assertNull(prop5.getReadonly()); }