@Test public void existingTypeIsUsedWhenTypeIsAlreadyGenerated() throws URISyntaxException { JType previouslyGeneratedType = mock(JType.class); URI schemaUri = getClass().getResource("/schema/address.json").toURI(); SchemaStore schemaStore = new SchemaStore(); Schema schema = schemaStore.create(schemaUri, "#/."); schema.setJavaType(previouslyGeneratedType); final GenerationConfig mockGenerationConfig = mock(GenerationConfig.class); when(mockGenerationConfig.getRefFragmentPathDelimiters()).thenReturn("#/."); when(mockRuleFactory.getSchemaStore()).thenReturn(schemaStore); when(mockRuleFactory.getGenerationConfig()).thenReturn(mockGenerationConfig); ObjectNode schemaNode = new ObjectMapper().createObjectNode(); schemaNode.put("$ref", schemaUri.toString()); JType result = rule.apply(NODE_NAME, schemaNode, null,null, schema); assertThat(result, is(sameInstance(previouslyGeneratedType))); }
@Override public JType apply(String nodeName, JsonNode schemaNode, JsonNode parent, JClassContainer generatableType, Schema schema) { if (schemaNode.has("$ref")) { final String nameFromRef = nameFromRef(schemaNode.get("$ref").asText()); schema = ruleFactory.getSchemaStore().create(schema, schemaNode.get("$ref").asText(), ruleFactory.getGenerationConfig().getRefFragmentPathDelimiters()); schemaNode = schema.getContent(); if (schema.isGenerated()) { return schema.getJavaType(); } return apply(nameFromRef != null ? nameFromRef : nodeName, schemaNode, parent, generatableType, schema); } schema = schema.deriveChildSchema(schemaNode); JType javaType; if (schemaNode.has("enum")) { javaType = ruleFactory.getEnumRule().apply(nodeName, schemaNode, parent, generatableType, schema); } else { javaType = ruleFactory.getTypeRule().apply(nodeName, schemaNode, parent, generatableType.getPackage(), schema); } schema.setJavaTypeIfEmpty(javaType); return javaType; }
SchemaRule implements Rule<JClassContainer, JType> { @Override public JType apply(String nodeName, JsonNode schemaNode, JsonNode parent, JClassContainer generatableType, Schema schema) { if (schemaNode.has("$ref")) { final String nameFromRef = nameFromRef(schemaNode.get("$ref").asText()); schema = ruleFactory.getSchemaStore().create(schema, schemaNode.get("$ref").asText(), ruleFactory.getGenerationConfig().getRefFragmentPathDelimiters()); schemaNode = schema.getContent(); if (schema.isGenerated()) { return schema.getJavaType(); } return apply(nameFromRef != null ? nameFromRef : nodeName, schemaNode, parent, generatableType, schema); } schema = schema.deriveChildSchema(schemaNode); JType javaType; if (schemaNode.has("enum")) { javaType = ruleFactory.getEnumRule().apply(nodeName, schemaNode, parent, generatableType, schema); } else { javaType = ruleFactory.getTypeRule().apply(nodeName, schemaNode, parent, generatableType.getPackage(), schema); } schema.setJavaTypeIfEmpty(javaType); return javaType; } }
SchemaRule implements Rule<JClassContainer, JType> { @Override public JType apply(String nodeName, JsonNode schemaNode, JsonNode parent, JClassContainer generatableType, Schema schema) { if (schemaNode.has("$ref")) { final String nameFromRef = nameFromRef(schemaNode.get("$ref").asText()); schema = ruleFactory.getSchemaStore().create(schema, schemaNode.get("$ref").asText(), ruleFactory.getGenerationConfig().getRefFragmentPathDelimiters()); schemaNode = schema.getContent(); if (schema.isGenerated()) { return schema.getJavaType(); } return apply(nameFromRef != null ? nameFromRef : nodeName, schemaNode, parent, generatableType, schema); } schema = schema.deriveChildSchema(schemaNode); JType javaType; if (schemaNode.has("enum")) { javaType = ruleFactory.getEnumRule().apply(nodeName, schemaNode, parent, generatableType, schema); } else { javaType = ruleFactory.getTypeRule().apply(nodeName, schemaNode, parent, generatableType.getPackage(), schema); } schema.setJavaTypeIfEmpty(javaType); return javaType; } protected  SchemaRule(RuleFactory ruleFactory); }
SchemaRule implements Rule<JClassContainer, JType> { @Override public JType apply(String nodeName, JsonNode schemaNode, JsonNode parent, JClassContainer generatableType, Schema schema) { if (schemaNode.has("$ref")) { final String nameFromRef = nameFromRef(schemaNode.get("$ref").asText()); schema = ruleFactory.getSchemaStore().create(schema, schemaNode.get("$ref").asText(), ruleFactory.getGenerationConfig().getRefFragmentPathDelimiters()); schemaNode = schema.getContent(); if (schema.isGenerated()) { return schema.getJavaType(); } return apply(nameFromRef != null ? nameFromRef : nodeName, schemaNode, parent, generatableType, schema); } schema = schema.deriveChildSchema(schemaNode); JType javaType; if (schemaNode.has("enum")) { javaType = ruleFactory.getEnumRule().apply(nodeName, schemaNode, parent, generatableType, schema); } else { javaType = ruleFactory.getTypeRule().apply(nodeName, schemaNode, parent, generatableType.getPackage(), schema); } schema.setJavaTypeIfEmpty(javaType); return javaType; } protected  SchemaRule(RuleFactory ruleFactory); @Override JType apply(String nodeName, JsonNode schemaNode, JsonNode parent, JClassContainer generatableType, Schema schema); }
SchemaRule implements Rule<JClassContainer, JType> { @Override public JType apply(String nodeName, JsonNode schemaNode, JsonNode parent, JClassContainer generatableType, Schema schema) { if (schemaNode.has("$ref")) { final String nameFromRef = nameFromRef(schemaNode.get("$ref").asText()); schema = ruleFactory.getSchemaStore().create(schema, schemaNode.get("$ref").asText(), ruleFactory.getGenerationConfig().getRefFragmentPathDelimiters()); schemaNode = schema.getContent(); if (schema.isGenerated()) { return schema.getJavaType(); } return apply(nameFromRef != null ? nameFromRef : nodeName, schemaNode, parent, generatableType, schema); } schema = schema.deriveChildSchema(schemaNode); JType javaType; if (schemaNode.has("enum")) { javaType = ruleFactory.getEnumRule().apply(nodeName, schemaNode, parent, generatableType, schema); } else { javaType = ruleFactory.getTypeRule().apply(nodeName, schemaNode, parent, generatableType.getPackage(), schema); } schema.setJavaTypeIfEmpty(javaType); return javaType; } protected  SchemaRule(RuleFactory ruleFactory); @Override JType apply(String nodeName, JsonNode schemaNode, JsonNode parent, JClassContainer generatableType, Schema schema);  }