Loading src/main/scala/com/kjetland/jackson/jsonSchema/JsonSchemaGenerator.scala +13 −3 Original line number Diff line number Diff line Loading @@ -28,7 +28,8 @@ object JsonSchemaConfig { autoGenerateTitleForProperties = false, defaultArrayFormat = None, useOneOfForOption = false, usePropertyOrdering = false usePropertyOrdering = false, hidePolymorphismTypeProperty = false ) /** Loading @@ -44,7 +45,8 @@ object JsonSchemaConfig { autoGenerateTitleForProperties = true, defaultArrayFormat = Some("table"), useOneOfForOption = true, usePropertyOrdering = true usePropertyOrdering = true, hidePolymorphismTypeProperty = true ) } Loading @@ -54,7 +56,8 @@ case class JsonSchemaConfig autoGenerateTitleForProperties:Boolean, defaultArrayFormat:Option[String], useOneOfForOption:Boolean, usePropertyOrdering:Boolean usePropertyOrdering:Boolean, hidePolymorphismTypeProperty:Boolean ) Loading Loading @@ -437,6 +440,13 @@ class JsonSchemaGenerator enumObjectNode.set("enum", enumValuesNode) enumObjectNode.put("default", pi.subTypeName) if (config.hidePolymorphismTypeProperty) { // Make sure the editor hides this polymorphism-specific property val optionsNode = JsonNodeFactory.instance.objectNode() enumObjectNode.set("options", optionsNode) optionsNode.put("hidden", true) } propertiesNode.set(pi.typePropertyName, enumObjectNode) getRequiredArrayNode(thisObjectNode).add(pi.typePropertyName) Loading src/test/scala/com/kjetland/jackson/jsonSchema/JsonSchemaGeneratorTest.scala +22 −5 Original line number Diff line number Diff line Loading @@ -95,7 +95,7 @@ class JsonSchemaGeneratorTest extends FunSuite with Matchers { schema } def assertJsonSubTypesInfo(node:JsonNode, typeParamName:String, typeName:String): Unit ={ def assertJsonSubTypesInfo(node:JsonNode, typeParamName:String, typeName:String, html5Checks:Boolean = false): Unit ={ /* "properties" : { "type" : { Loading @@ -113,6 +113,10 @@ class JsonSchemaGeneratorTest extends FunSuite with Matchers { assert( node.at(s"/title").asText() == typeName) assert( getRequiredList(node).contains(typeParamName)) if (html5Checks) { assert( node.at(s"/properties/$typeParamName/options/hidden").asBoolean() == true ) } } def getArrayNodeAsListOfStrings(node:JsonNode):List[String] = { Loading Loading @@ -202,6 +206,19 @@ class JsonSchemaGeneratorTest extends FunSuite with Matchers { } // Java - html5 { val jsonNode = assertToFromJson(jsonSchemaGeneratorHTML5, testData.pojoWithParent) val schema = generateAndValidateSchema(jsonSchemaGeneratorHTML5, testData.pojoWithParent.getClass, Some(jsonNode)) assert(false == schema.at("/additionalProperties").asBoolean()) assert(schema.at("/properties/pojoValue/type").asText() == "boolean") assertChild1(schema, "/properties/child/oneOf", html5Checks = true) assertChild2(schema, "/properties/child/oneOf", html5Checks = true) } // Scala { val jsonNode = assertToFromJson(jsonSchemaGeneratorScala, testData.pojoWithParentScala) Loading @@ -217,9 +234,9 @@ class JsonSchemaGeneratorTest extends FunSuite with Matchers { } def assertChild1(node:JsonNode, path:String, defName:String = "Child1"): Unit ={ def assertChild1(node:JsonNode, path:String, defName:String = "Child1", html5Checks:Boolean = false): Unit ={ val child1 = getNodeViaArrayOfRefs(node, path, defName) assertJsonSubTypesInfo(child1, "type", "child1") assertJsonSubTypesInfo(child1, "type", "child1", html5Checks) assert( child1.at("/properties/parentString/type").asText() == "string" ) assert( child1.at("/properties/child1String/type").asText() == "string" ) assert( child1.at("/properties/_child1String2/type").asText() == "string" ) Loading @@ -227,9 +244,9 @@ class JsonSchemaGeneratorTest extends FunSuite with Matchers { assert(getRequiredList(child1).contains("_child1String3")) } def assertChild2(node:JsonNode, path:String, defName:String = "Child2"): Unit ={ def assertChild2(node:JsonNode, path:String, defName:String = "Child2", html5Checks:Boolean = false): Unit ={ val child2 = getNodeViaArrayOfRefs(node, path, defName) assertJsonSubTypesInfo(child2, "type", "child2") assertJsonSubTypesInfo(child2, "type", "child2", html5Checks) assert( child2.at("/properties/parentString/type").asText() == "string" ) assert( child2.at("/properties/child2int/type").asText() == "integer" ) } Loading Loading
src/main/scala/com/kjetland/jackson/jsonSchema/JsonSchemaGenerator.scala +13 −3 Original line number Diff line number Diff line Loading @@ -28,7 +28,8 @@ object JsonSchemaConfig { autoGenerateTitleForProperties = false, defaultArrayFormat = None, useOneOfForOption = false, usePropertyOrdering = false usePropertyOrdering = false, hidePolymorphismTypeProperty = false ) /** Loading @@ -44,7 +45,8 @@ object JsonSchemaConfig { autoGenerateTitleForProperties = true, defaultArrayFormat = Some("table"), useOneOfForOption = true, usePropertyOrdering = true usePropertyOrdering = true, hidePolymorphismTypeProperty = true ) } Loading @@ -54,7 +56,8 @@ case class JsonSchemaConfig autoGenerateTitleForProperties:Boolean, defaultArrayFormat:Option[String], useOneOfForOption:Boolean, usePropertyOrdering:Boolean usePropertyOrdering:Boolean, hidePolymorphismTypeProperty:Boolean ) Loading Loading @@ -437,6 +440,13 @@ class JsonSchemaGenerator enumObjectNode.set("enum", enumValuesNode) enumObjectNode.put("default", pi.subTypeName) if (config.hidePolymorphismTypeProperty) { // Make sure the editor hides this polymorphism-specific property val optionsNode = JsonNodeFactory.instance.objectNode() enumObjectNode.set("options", optionsNode) optionsNode.put("hidden", true) } propertiesNode.set(pi.typePropertyName, enumObjectNode) getRequiredArrayNode(thisObjectNode).add(pi.typePropertyName) Loading
src/test/scala/com/kjetland/jackson/jsonSchema/JsonSchemaGeneratorTest.scala +22 −5 Original line number Diff line number Diff line Loading @@ -95,7 +95,7 @@ class JsonSchemaGeneratorTest extends FunSuite with Matchers { schema } def assertJsonSubTypesInfo(node:JsonNode, typeParamName:String, typeName:String): Unit ={ def assertJsonSubTypesInfo(node:JsonNode, typeParamName:String, typeName:String, html5Checks:Boolean = false): Unit ={ /* "properties" : { "type" : { Loading @@ -113,6 +113,10 @@ class JsonSchemaGeneratorTest extends FunSuite with Matchers { assert( node.at(s"/title").asText() == typeName) assert( getRequiredList(node).contains(typeParamName)) if (html5Checks) { assert( node.at(s"/properties/$typeParamName/options/hidden").asBoolean() == true ) } } def getArrayNodeAsListOfStrings(node:JsonNode):List[String] = { Loading Loading @@ -202,6 +206,19 @@ class JsonSchemaGeneratorTest extends FunSuite with Matchers { } // Java - html5 { val jsonNode = assertToFromJson(jsonSchemaGeneratorHTML5, testData.pojoWithParent) val schema = generateAndValidateSchema(jsonSchemaGeneratorHTML5, testData.pojoWithParent.getClass, Some(jsonNode)) assert(false == schema.at("/additionalProperties").asBoolean()) assert(schema.at("/properties/pojoValue/type").asText() == "boolean") assertChild1(schema, "/properties/child/oneOf", html5Checks = true) assertChild2(schema, "/properties/child/oneOf", html5Checks = true) } // Scala { val jsonNode = assertToFromJson(jsonSchemaGeneratorScala, testData.pojoWithParentScala) Loading @@ -217,9 +234,9 @@ class JsonSchemaGeneratorTest extends FunSuite with Matchers { } def assertChild1(node:JsonNode, path:String, defName:String = "Child1"): Unit ={ def assertChild1(node:JsonNode, path:String, defName:String = "Child1", html5Checks:Boolean = false): Unit ={ val child1 = getNodeViaArrayOfRefs(node, path, defName) assertJsonSubTypesInfo(child1, "type", "child1") assertJsonSubTypesInfo(child1, "type", "child1", html5Checks) assert( child1.at("/properties/parentString/type").asText() == "string" ) assert( child1.at("/properties/child1String/type").asText() == "string" ) assert( child1.at("/properties/_child1String2/type").asText() == "string" ) Loading @@ -227,9 +244,9 @@ class JsonSchemaGeneratorTest extends FunSuite with Matchers { assert(getRequiredList(child1).contains("_child1String3")) } def assertChild2(node:JsonNode, path:String, defName:String = "Child2"): Unit ={ def assertChild2(node:JsonNode, path:String, defName:String = "Child2", html5Checks:Boolean = false): Unit ={ val child2 = getNodeViaArrayOfRefs(node, path, defName) assertJsonSubTypesInfo(child2, "type", "child2") assertJsonSubTypesInfo(child2, "type", "child2", html5Checks) assert( child2.at("/properties/parentString/type").asText() == "string" ) assert( child2.at("/properties/child2int/type").asText() == "integer" ) } Loading