private void generateParameterValidation(Parameter parameter) {
Name parameterName = parameter.getName();
String argName = javaNames.getJavaMemberStyleName(parameterName);
String tagName = schemaNames.getSchemaTagName(parameterName);
List<MemberInvolvementTree> mandatoryAttributes = parameter.getMandatoryAttributes();
if (parameter.isMandatory() || !mandatoryAttributes.isEmpty()) {
javaBuffer.addLine("if (%1$s == null) {", argName);
javaBuffer.addLine(
"throw new ValidationException(\"Parameter '%1$s' is mandatory but was not provided.\");", tagName);
javaBuffer.addLine("}");
}
for (MemberInvolvementTree attribute : mandatoryAttributes) {
List<MemberInvolvementTree> attributeComponents = stackAttributeComponents(attribute);
String attributePath = getSchemaPath(attributeComponents);
if (attribute.hasAlternative()) {
generateAlternativesValidation(parameterName, attribute, attributeComponents, attributePath);
}
else {
javaBuffer.addLine(
"if (%1$s) {",
getFullAttributeCheck(argName, attributeComponents, Operator.OR, false)
);
String fullAttributePath = convertToModelNotation(argName + "." + attributePath);
javaBuffer.addLine("throw new ValidationException(\"Parameter '%1$s' is mandatory but was not provided.\");", fullAttributePath);
}
javaBuffer.addLine("}");
javaBuffer.addLine();
}
}