for (Parameter parameter : this.methodDoc.parameters()) {
if (!shouldIncludeParameter(this.httpMethod, excludeParams, parameter)) {
continue;
}
Type paramType = parameter.type();
String paramCategory = ParserHelper.paramTypeOf(consumesMultipart, parameter, this.options);
String paramName = parameter.name();
// see if its a special composite type e.g. @BeanParam
if ("composite".equals(paramCategory)) {
ApiModelParser modelParser = new ApiModelParser(this.options, this.translator, paramType, consumesMultipart);
Set<Model> models = modelParser.parse();
String rootModelId = modelParser.getRootModelId();
for (Model model : models) {
if (model.getId().equals(rootModelId)) {
Map<String, Property> modelProps = model.getProperties();
for (Map.Entry<String, Property> entry : modelProps.entrySet()) {
Property property = entry.getValue();
String renderedParamName = entry.getKey();
String fawFieldName = property.getRawFieldName();
Boolean allowMultiple = getAllowMultiple(paramCategory, fawFieldName, csvParams);
Boolean required = getRequired(paramCategory, fawFieldName, property.getType(), optionalParams, requiredParams);
String itemsRef = property.getItems() == null ? null : property.getItems().getRef();
String itemsType = property.getItems() == null ? null : property.getItems().getType();
ApiParameter param = new ApiParameter(property.getParamCategory(), renderedParamName, required, allowMultiple, property.getType(),
property.getFormat(), property.getDescription(), itemsRef, itemsType, property.getUniqueItems(),
property.getAllowableValues(), property.getMinimum(), property.getMaximum(), property.getDefaultValue());
parameters.add(param);
}
break;
}
}
continue;
}
// look for a custom input type for body params
if ("body".equals(paramCategory)) {
String customParamType = ParserHelper.getTagValue(this.methodDoc, this.options.getInputTypeTags());
paramType = readCustomParamType(customParamType, paramType);
}
OptionalName paramTypeFormat = this.translator.parameterTypeName(consumesMultipart, parameter, paramType);
String typeName = paramTypeFormat.value();
String format = paramTypeFormat.getFormat();
Boolean allowMultiple = null;
List<String> allowableValues = null;
String itemsRef = null;
String itemsType = null;
Boolean uniqueItems = null;
String minimum = null;
String maximum = null;
String defaultVal = null;
// set to form param type if data type is File
if ("File".equals(typeName)) {
paramCategory = "form";
} else {
if (this.options.isParseModels()) {
this.models.addAll(new ApiModelParser(this.options, this.translator, paramType).parse());
}
// set enum values
ClassDoc typeClassDoc = parameter.type().asClassDoc();
allowableValues = ParserHelper.getAllowableValues(typeClassDoc);
if (allowableValues != null) {
typeName = "string";
}
// set whether its a csv param
allowMultiple = getAllowMultiple(paramCategory, paramName, csvParams);
// get min and max param values
minimum = paramMinVals.get(paramName);
maximum = paramMaxVals.get(paramName);
String validationContext = " for the method: " + this.methodDoc.name() + " parameter: " + paramName;
// verify min max are numbers
ParserHelper.verifyNumericValue(validationContext + " min value.", typeName, format, minimum);
ParserHelper.verifyNumericValue(validationContext + " max value.", typeName, format, maximum);
// get a default value, prioritize the jaxrs annotation
// otherwise look for the javadoc tag
defaultVal = ParserHelper.getDefaultValue(parameter);
if (defaultVal == null) {
defaultVal = paramDefaultVals.get(paramName);
}
// verify default vs min, max and by itself
if (defaultVal != null) {
if (minimum == null && maximum == null) {
// just validate the default
ParserHelper.verifyValue(validationContext + " default value.", typeName, format, defaultVal);
}
// if min/max then default is validated as part of comparison
if (minimum != null) {
int comparison = ParserHelper.compareNumericValues(validationContext + " min value.", typeName, format, defaultVal, minimum);
if (comparison < 0) {
throw new IllegalStateException("Invalid value for the default value of the method: " + this.methodDoc.name() + " parameter: "
+ paramName + " it should be >= the minimum: " + minimum);
}
}
if (maximum != null) {
int comparison = ParserHelper.compareNumericValues(validationContext + " max value.", typeName, format, defaultVal, maximum);
if (comparison > 0) {
throw new IllegalStateException("Invalid value for the default value of the method: " + this.methodDoc.name() + " parameter: "
+ paramName + " it should be <= the maximum: " + maximum);
}
}
}
// if enum and default value check it matches the enum values
if (allowableValues != null && defaultVal != null && !allowableValues.contains(defaultVal)) {
throw new IllegalStateException("Invalid value for the default value of the method: " + this.methodDoc.name() + " parameter: " + paramName
+ " it should be one of: " + allowableValues);
}
// set collection related fields
// TODO: consider supporting parameterized collections as api parameters...
Type containerOf = null;
containerOf = ParserHelper.getContainerType(paramType, null);
String containerTypeOf = containerOf == null ? null : this.translator.typeName(containerOf).value();
if (containerOf != null) {
if (ParserHelper.isPrimitive(containerOf, this.options)) {
itemsType = containerTypeOf;