use of org.jsonschema2pojo.util.NameHelper in project jsonschema2pojo by joelittlejohn.
the class ObjectRule method getConstructorProperties.
/**
* Retrieve the list of properties to go in the constructor from node. This
* is all properties listed in node["properties"] if ! onlyRequired, and
* only required properties if onlyRequired.
*
* @param node
* @return
*/
private LinkedHashSet<String> getConstructorProperties(JsonNode node, boolean onlyRequired) {
if (!node.has("properties")) {
return new LinkedHashSet<String>();
}
LinkedHashSet<String> rtn = new LinkedHashSet<String>();
Set<String> draft4RequiredProperties = new HashSet<String>();
// setup the set of required properties for draft4 style "required"
if (onlyRequired && node.has("required")) {
JsonNode requiredArray = node.get("required");
if (requiredArray.isArray()) {
for (JsonNode requiredEntry : requiredArray) {
if (requiredEntry.isTextual()) {
draft4RequiredProperties.add(requiredEntry.asText());
}
}
}
}
NameHelper nameHelper = ruleFactory.getNameHelper();
for (Iterator<Map.Entry<String, JsonNode>> properties = node.get("properties").fields(); properties.hasNext(); ) {
Map.Entry<String, JsonNode> property = properties.next();
JsonNode propertyObj = property.getValue();
if (onlyRequired) {
// draft3 style
if (propertyObj.has("required") && propertyObj.get("required").asBoolean()) {
rtn.add(nameHelper.getPropertyName(property.getKey(), property.getValue()));
}
// draft4 style
if (draft4RequiredProperties.contains(property.getKey())) {
rtn.add(nameHelper.getPropertyName(property.getKey(), property.getValue()));
}
} else {
rtn.add(nameHelper.getPropertyName(property.getKey(), property.getValue()));
}
}
return rtn;
}
use of org.jsonschema2pojo.util.NameHelper in project jsonschema2pojo by joelittlejohn.
the class RuleFactory method setGenerationConfig.
/**
* The generation config options for type generation. These config options
* will influence the java code generated by rules created by this factory.
*
* @param generationConfig
* Generation config
*/
public void setGenerationConfig(final GenerationConfig generationConfig) {
this.generationConfig = generationConfig;
this.nameHelper = new NameHelper(generationConfig);
}
Aggregations