@Test public void arrayDefaultsToNonUnique() { JCodeModel codeModel = new JCodeModel(); JPackage jpackage = codeModel._package(getClass().getPackage().getName()); ObjectMapper mapper = new ObjectMapper(); ObjectNode itemsNode = mapper.createObjectNode(); itemsNode.put("type", "boolean"); ObjectNode propertyNode = mapper.createObjectNode(); propertyNode.set("uniqueItems", BooleanNode.FALSE); propertyNode.set("items", itemsNode); Schema schema = mock(Schema.class); when(schema.getId()).thenReturn(URI.create("http: when(schema.deriveChildSchema(any())).thenReturn(schema); JClass propertyType = rule.apply("fooBars", propertyNode, null, jpackage, schema); assertThat(propertyType.erasure(), is(codeModel.ref(List.class))); }
@Override public JClass apply(String nodeName, JsonNode node, JsonNode parent, JPackage jpackage, Schema schema) { boolean uniqueItems = node.has("uniqueItems") && node.get("uniqueItems").asBoolean(); boolean rootSchemaIsArray = !schema.isGenerated(); JType itemType; if (node.has("items")) { itemType = ruleFactory.getSchemaRule().apply(makeSingular(nodeName), node.get("items"), node, jpackage, schema); } else { itemType = jpackage.owner().ref(Object.class); } JClass arrayType; if (uniqueItems) { arrayType = jpackage.owner().ref(Set.class).narrow(itemType); } else { arrayType = jpackage.owner().ref(List.class).narrow(itemType); } if (rootSchemaIsArray) { schema.setJavaType(arrayType); } return arrayType; }
ArrayRule implements Rule<JPackage, JClass> { @Override public JClass apply(String nodeName, JsonNode node, JsonNode parent, JPackage jpackage, Schema schema) { boolean uniqueItems = node.has("uniqueItems") && node.get("uniqueItems").asBoolean(); boolean rootSchemaIsArray = !schema.isGenerated(); JType itemType; if (node.has("items")) { itemType = ruleFactory.getSchemaRule().apply(makeSingular(nodeName), node.get("items"), node, jpackage, schema); } else { itemType = jpackage.owner().ref(Object.class); } JClass arrayType; if (uniqueItems) { arrayType = jpackage.owner().ref(Set.class).narrow(itemType); } else { arrayType = jpackage.owner().ref(List.class).narrow(itemType); } if (rootSchemaIsArray) { schema.setJavaType(arrayType); } return arrayType; } }
ArrayRule implements Rule<JPackage, JClass> { @Override public JClass apply(String nodeName, JsonNode node, JsonNode parent, JPackage jpackage, Schema schema) { boolean uniqueItems = node.has("uniqueItems") && node.get("uniqueItems").asBoolean(); boolean rootSchemaIsArray = !schema.isGenerated(); JType itemType; if (node.has("items")) { itemType = ruleFactory.getSchemaRule().apply(makeSingular(nodeName), node.get("items"), node, jpackage, schema); } else { itemType = jpackage.owner().ref(Object.class); } JClass arrayType; if (uniqueItems) { arrayType = jpackage.owner().ref(Set.class).narrow(itemType); } else { arrayType = jpackage.owner().ref(List.class).narrow(itemType); } if (rootSchemaIsArray) { schema.setJavaType(arrayType); } return arrayType; } protected  ArrayRule(RuleFactory ruleFactory); }
ArrayRule implements Rule<JPackage, JClass> { @Override public JClass apply(String nodeName, JsonNode node, JsonNode parent, JPackage jpackage, Schema schema) { boolean uniqueItems = node.has("uniqueItems") && node.get("uniqueItems").asBoolean(); boolean rootSchemaIsArray = !schema.isGenerated(); JType itemType; if (node.has("items")) { itemType = ruleFactory.getSchemaRule().apply(makeSingular(nodeName), node.get("items"), node, jpackage, schema); } else { itemType = jpackage.owner().ref(Object.class); } JClass arrayType; if (uniqueItems) { arrayType = jpackage.owner().ref(Set.class).narrow(itemType); } else { arrayType = jpackage.owner().ref(List.class).narrow(itemType); } if (rootSchemaIsArray) { schema.setJavaType(arrayType); } return arrayType; } protected  ArrayRule(RuleFactory ruleFactory); @Override JClass apply(String nodeName, JsonNode node, JsonNode parent, JPackage jpackage, Schema schema); }
ArrayRule implements Rule<JPackage, JClass> { @Override public JClass apply(String nodeName, JsonNode node, JsonNode parent, JPackage jpackage, Schema schema) { boolean uniqueItems = node.has("uniqueItems") && node.get("uniqueItems").asBoolean(); boolean rootSchemaIsArray = !schema.isGenerated(); JType itemType; if (node.has("items")) { itemType = ruleFactory.getSchemaRule().apply(makeSingular(nodeName), node.get("items"), node, jpackage, schema); } else { itemType = jpackage.owner().ref(Object.class); } JClass arrayType; if (uniqueItems) { arrayType = jpackage.owner().ref(Set.class).narrow(itemType); } else { arrayType = jpackage.owner().ref(List.class).narrow(itemType); } if (rootSchemaIsArray) { schema.setJavaType(arrayType); } return arrayType; } protected  ArrayRule(RuleFactory ruleFactory); @Override JClass apply(String nodeName, JsonNode node, JsonNode parent, JPackage jpackage, Schema schema);  }