Loading src/main/java/com/kjetland/jackson/jsonSchema/annotations/JsonSchemaUniqueItemsByRequiredProperties.java 0 → 100755 +12 −0 Original line number Diff line number Diff line package com.kjetland.jackson.jsonSchema.annotations; import java.lang.annotation.Retention; import java.lang.annotation.Target; import static java.lang.annotation.ElementType.*; import static java.lang.annotation.RetentionPolicy.RUNTIME; @Target({ METHOD, FIELD, PARAMETER, TYPE }) @Retention(RUNTIME) public @interface JsonSchemaUniqueItemsByRequiredProperties { } src/main/scala/com/kjetland/jackson/jsonSchema/JsonSchemaGenerator.scala +15 −2 Original line number Diff line number Diff line Loading @@ -364,6 +364,9 @@ class JsonSchemaGenerator setType(node, currentProperty, "array") //node.put("type", "array") if (propertyIsUniqueItemsByRequiredProperties(currentProperty)) node.put("uniqueItemsByRequiredProperties", true) config.defaultArrayFormat.foreach { format => setFormat(node, format) } Loading Loading @@ -701,7 +704,7 @@ class JsonSchemaGenerator val objectBuilder: ObjectNode => Option[JsonObjectFormatVisitor] = { thisObjectNode: ObjectNode => thisObjectNode.put("type", "object") //thisObjectNode.put("additionalProperties", false) // If class is annotated with JsonSchemaFormat, we should add it Loading Loading @@ -765,6 +768,9 @@ class JsonSchemaGenerator def myPropertyHandler(propertyName: String, propertyType: JavaType, prop: Option[BeanProperty], jsonPropertyRequired: Boolean): Unit = { if (propertyIsNotIgnored(prop)) { setType(thisObjectNode, prop, "object"); l(s"JsonObjectFormatVisitor - ${propertyName}: ${propertyType}") if (propertiesNode.get(propertyName) != null) { if (!config.disableWarnings) { Loading Loading @@ -966,7 +972,7 @@ class JsonSchemaGenerator def setType(node: ObjectNode, prop: Option[BeanProperty], typePrimary: String) = { if (propertyIsNullable(prop)) { if (prop == null || propertyIsNullable(prop)) { val types = JsonNodeFactory.instance.arrayNode() types.add(typePrimary) types.add("null") Loading @@ -989,6 +995,13 @@ class JsonSchemaGenerator { (prop.isEmpty || prop.get.getAnnotation(classOf[JsonSchemaIgnore]) == null) } // Comprueba si se debe añadir la propiedad uniqueItemsByRequiredProperties def propertyIsUniqueItemsByRequiredProperties(prop: Option[BeanProperty]) = { (prop != null && !prop.isEmpty && prop.get.getAnnotation(classOf[JsonSchemaUniqueItemsByRequiredProperties]) != null) } } def generateTitleFromPropertyName(propertyName:String):String = { Loading Loading
src/main/java/com/kjetland/jackson/jsonSchema/annotations/JsonSchemaUniqueItemsByRequiredProperties.java 0 → 100755 +12 −0 Original line number Diff line number Diff line package com.kjetland.jackson.jsonSchema.annotations; import java.lang.annotation.Retention; import java.lang.annotation.Target; import static java.lang.annotation.ElementType.*; import static java.lang.annotation.RetentionPolicy.RUNTIME; @Target({ METHOD, FIELD, PARAMETER, TYPE }) @Retention(RUNTIME) public @interface JsonSchemaUniqueItemsByRequiredProperties { }
src/main/scala/com/kjetland/jackson/jsonSchema/JsonSchemaGenerator.scala +15 −2 Original line number Diff line number Diff line Loading @@ -364,6 +364,9 @@ class JsonSchemaGenerator setType(node, currentProperty, "array") //node.put("type", "array") if (propertyIsUniqueItemsByRequiredProperties(currentProperty)) node.put("uniqueItemsByRequiredProperties", true) config.defaultArrayFormat.foreach { format => setFormat(node, format) } Loading Loading @@ -701,7 +704,7 @@ class JsonSchemaGenerator val objectBuilder: ObjectNode => Option[JsonObjectFormatVisitor] = { thisObjectNode: ObjectNode => thisObjectNode.put("type", "object") //thisObjectNode.put("additionalProperties", false) // If class is annotated with JsonSchemaFormat, we should add it Loading Loading @@ -765,6 +768,9 @@ class JsonSchemaGenerator def myPropertyHandler(propertyName: String, propertyType: JavaType, prop: Option[BeanProperty], jsonPropertyRequired: Boolean): Unit = { if (propertyIsNotIgnored(prop)) { setType(thisObjectNode, prop, "object"); l(s"JsonObjectFormatVisitor - ${propertyName}: ${propertyType}") if (propertiesNode.get(propertyName) != null) { if (!config.disableWarnings) { Loading Loading @@ -966,7 +972,7 @@ class JsonSchemaGenerator def setType(node: ObjectNode, prop: Option[BeanProperty], typePrimary: String) = { if (propertyIsNullable(prop)) { if (prop == null || propertyIsNullable(prop)) { val types = JsonNodeFactory.instance.arrayNode() types.add(typePrimary) types.add("null") Loading @@ -989,6 +995,13 @@ class JsonSchemaGenerator { (prop.isEmpty || prop.get.getAnnotation(classOf[JsonSchemaIgnore]) == null) } // Comprueba si se debe añadir la propiedad uniqueItemsByRequiredProperties def propertyIsUniqueItemsByRequiredProperties(prop: Option[BeanProperty]) = { (prop != null && !prop.isEmpty && prop.get.getAnnotation(classOf[JsonSchemaUniqueItemsByRequiredProperties]) != null) } } def generateTitleFromPropertyName(propertyName:String):String = { Loading