Add missing 'range' support for @ApiParam's allowableValues
Range is documented as follows:
* <li>To set a range of values, start the value with "range", and surrounding by square
* brackets include the minimum and maximum values. For example: {@code range[1, 5]}.</li>
* <li>To set a minimum/maximum value, use the same format for range but use "infinity"
* or "-infinity" as the second value. For example, {@code range[1, infinity]} means the
* minimum allowable value of this parameter is 1.</li>
The range[10, -infinity] definition looks to be confusing. I would suggest to allow "-infinity" as a first agrument.
The code contains a test mock for range definition:
@ApiParam(value = "sample param data", required = true, allowableValues = "range[0,10]")
@DefaultValue("5")
@PathParam("id") String id
Internal class for string parameters defines holders for minimum and maximum length. Do we have to convert range values into length constraints?
That may be a mistake in the documentation. What I'd suggest you do is try to check out one of the older tags, (1.3.0 for example, or even earlier) and check in the tests and samples if there's any usage of -infinity and how it is used. We don't want to change the behavior, so we need to see how it used to work in the past. There may be an example of it in the current samples/tests that you can check. If you find the documentation is wrong, you can fix that as well.
The range will not affect the length validation of a string, but the value. That specific test may not make sense. Try to check the range in the samples and how it is applied there.
The parameter object has minimum and maximum fields (from the spec: https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#parameterObject) It seems doesn't support in current implementation. Example from the PathParameter class:
@JsonPropertyOrder({ "name", "in", "description", "required", "type", "items", "collectionFormat", "default"})
public class PathParameter extends AbstractParameter implements SerializableParameter {;
protected String type;
protected String format;
protected String collectionFormat;
protected Property items;
protected List<String> _enum;
@JsonProperty("default")
protected String defaultValue;
And if a parameter type is "array" then parameter object has "items" with minimum and maximum fields (from the spec: https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#itemsObject)
So, if a parameter type is a scalar, then we use minimum/maximum fields in parameter object. And if a parameter type is an array, then we use minimum/maximum fields in "items" field. Is it correct?
Looks right, though you may want to take into account the other validation constraints that can be applied to parameters as well (exclusiveMinimum/Maximum, min/maxLength and so on). If you look at the Property objects, you'll see that they have some sort of structure that supports it. You may want to look into a fuller solution.
Fixed in develop_2.0.