use of org.jsonschema2pojo.model.EnumValueDefinition in project jsonschema2pojo by joelittlejohn.
the class EnumRule method buildEnumDefinitionWithNoExtensions.
protected EnumDefinition buildEnumDefinitionWithNoExtensions(String nodeName, JsonNode parentNode, JsonNode enums, JType backingType) {
ArrayList<EnumValueDefinition> enumValues = new ArrayList<>();
Collection<String> existingConstantNames = new ArrayList<>();
for (int i = 0; i < enums.size(); i++) {
JsonNode value = enums.path(i);
if (!value.isNull()) {
String constantName = getConstantName(value.asText(), null);
constantName = makeUnique(constantName, existingConstantNames);
existingConstantNames.add(constantName);
enumValues.add(new EnumValueDefinition(constantName, value.asText()));
}
}
return new EnumDefinition(nodeName, parentNode, backingType, enumValues, EnumDefinitionExtensionType.NONE);
}
use of org.jsonschema2pojo.model.EnumValueDefinition in project jsonschema2pojo by joelittlejohn.
the class EnumRule method addEnumConstants.
protected void addEnumConstants(EnumDefinition enumDefinition, JDefinedClass _enum, Schema schema) {
JType type = enumDefinition.getBackingType();
String nodeName = enumDefinition.getNodeName();
JsonNode parentNode = enumDefinition.getEnumNode();
for (EnumValueDefinition enumValueDefinition : enumDefinition.values()) {
JEnumConstant constant = _enum.enumConstant(enumValueDefinition.getName());
String value = enumValueDefinition.getValue();
constant.arg(DefaultRule.getDefaultValue(type, value));
Annotator annotator = ruleFactory.getAnnotator();
annotator.enumConstant(_enum, constant, value);
String enumNodeName = nodeName + "#" + value;
if (enumValueDefinition.hasTitle()) {
JsonNode titleNode = enumValueDefinition.getTitleNode();
ruleFactory.getTitleRule().apply(enumNodeName, titleNode, parentNode, constant, schema);
}
if (enumValueDefinition.hasDescription()) {
JsonNode descriptionNode = enumValueDefinition.getDescriptionNode();
ruleFactory.getDescriptionRule().apply(enumNodeName, descriptionNode, parentNode, constant, schema);
}
}
}
use of org.jsonschema2pojo.model.EnumValueDefinition in project jsonschema2pojo by joelittlejohn.
the class EnumRule method buildEnumDefinitionWithJavaEnumNamesExtension.
protected EnumDefinition buildEnumDefinitionWithJavaEnumNamesExtension(String nodeName, JsonNode parentNode, JsonNode enums, JsonNode javaEnumNames, JType backingType) {
ArrayList<EnumValueDefinition> enumValues = new ArrayList<>();
Collection<String> existingConstantNames = new ArrayList<>();
for (int i = 0; i < enums.size(); i++) {
JsonNode value = enums.path(i);
if (!value.isNull()) {
String constantName = getConstantName(value.asText(), javaEnumNames.path(i).asText());
constantName = makeUnique(constantName, existingConstantNames);
existingConstantNames.add(constantName);
enumValues.add(new EnumValueDefinition(constantName, value.asText(), javaEnumNames));
}
}
return new EnumDefinition(nodeName, parentNode, backingType, enumValues, EnumDefinitionExtensionType.JAVA_ENUM_NAMES);
}
use of org.jsonschema2pojo.model.EnumValueDefinition in project jsonschema2pojo by joelittlejohn.
the class EnumRule method buildEnumDefinitionWithJavaEnumsExtension.
protected EnumDefinition buildEnumDefinitionWithJavaEnumsExtension(String nodeName, JsonNode enumNode, JsonNode enums, JsonNode javaEnums, JType type) {
ArrayList<EnumValueDefinition> enumValues = new ArrayList<>();
Collection<String> existingConstantNames = new ArrayList<>();
for (int i = 0; i < enums.size(); i++) {
JsonNode value = enums.path(i);
if (!value.isNull()) {
JsonNode javaEnumNode = javaEnums.path(i);
if (javaEnumNode.isMissingNode()) {
ruleFactory.getLogger().error("javaEnum entry for " + value.asText() + " was not found.");
}
String constantName = getConstantName(value.asText(), javaEnumNode.path("name").asText());
constantName = makeUnique(constantName, existingConstantNames);
existingConstantNames.add(constantName);
JsonNode titleNode = javaEnumNode.path("title");
JsonNode descriptionNode = javaEnumNode.path("description");
enumValues.add(new EnumValueDefinition(constantName, value.asText(), javaEnumNode, titleNode, descriptionNode));
}
}
return new EnumDefinition(nodeName, enumNode, type, enumValues, EnumDefinitionExtensionType.JAVA_ENUMS);
}
Aggregations