Skip to content

Parameter definition: Value of 'collectionFormat' overwritten when defined before 'type' property. #2586

@thoduerr

Description

@thoduerr

Current implementation of AbstractSerializableParameter overwrites value of collectionFormat when 'collectionFormat' property is defined before 'type' property.

Found using:
swagger-core 1.5.16 - but exists also in earlier versions.
fasterXML/jackson - version 2.9.2

Sample definition (Spec 2.0)

[...]
                "parameters": [
                    {
                        "name": "value",
                        "in": "query",
                        "required": true,
                        "collectionFormat": "ssv",                        
                        "type": "array",
                        "items": {
                            "type": "boolean"
                        }                                                              
                    }
                ],
[...]

When deserializing, the order of properties (as defined via annotation @JsonPropertyOrder) has no effect.
https://github.com/swagger-api/swagger-core/blob/master/modules/swagger-models/src/main/java/io/swagger/models/parameters/AbstractSerializableParameter.java

@JsonPropertyOrder({ "name", "in", "description", "required", "type", "items", "collectionFormat", "default", "maximum",
        "exclusiveMaximum", "minimum", "exclusiveMinimum", "maxLength", "minLength", "pattern", "maxItems", "minItems",
        "uniqueItems", "multipleOf" })

See javadoc comment regarding deserialization (line 25):
https://github.com/FasterXML/jackson-annotations/blob/master/src/main/java/com/fasterxml/jackson/annotation/JsonPropertyOrder.java

Therefore the current implementation is not correct. setType(String type) overwrites the value of collectionFormat even if it is set.

Current implementation of io.swagger.models.parameters.AbstractSerializableParameter.java

[...]	
	@Override
	public void setType(String type) {
	this.type = type;
	setCollectionFormat(ArrayProperty.isType(type) ? getDefaultCollectionFormat() : null);
	}
	
	@Override
	public String getCollectionFormat() {
	return collectionFormat;
	}
[...]

Proposed fix

[...]	
	@Override
	public void setType(String type) {
	this.type = type;
	}
	
	@Override
	public String getCollectionFormat() {
	return (collectionFormat != null && !collectionFormat.isEmpty()) ? this.collectionFormat : ((ArrayProperty.isType(type)) ? getDefaultCollectionFormat() : null);
	}
[...]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions