Skip to content

JSR-303: Size annotation on Path Param generates maximum/minimum, but on Model generates maxLength/minLength #2415

@retinaburn

Description

@retinaburn

Version: 2.8.0
Latest Version: 2.9.0

What kind of issue is this?

Bug Report - JSR-303 Size not generated correctly when specified on a String path parameter

When a String ApiParam is specified with a Size, the json is generated with minimum and maximum instead of rhe expected minLength and maxLength.

However is Size is specified on a string field in a request object, maxLength and minLength are generated correctly.

I might be barking up the wrong tree here, but this is what I have and what I am seeing.

MyApplication.java has the following annotations:

@SpringBootApplication
@EnableSwagger2
@PropertySource({ "classpath:swagger/swagger.properties" })
@Import({ springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration.class })

My Controller has:

public ResponseEntity<OtherRDO> getIncomingTransfer(
@Pattern(regexp="^[A-Za-z0-9]{8,16}$") 
@Size(min=8,max=16)
@ApiParam(value = "Transfer Id",required=true ) 
@PathVariable("transferId") String transferId) {
        return new ResponseEntity<OtherRDO>(requestHandler.getTransfer(transferId), HttpStatus.OK);
    }

Which generates the following json:

      parameters:
        - name: transferId
          in: path
          description: 'Transfer Id'
          required: true
          type: string
          maximum: 16
          minimum: 8
          pattern: '^[A-Za-z0-9]{8,16}$'

I would expect maxLength and minLength so swagger validates it correctly.
Interestingly, if you remove the Size annotation minLength/maxLength are generated correctly.

My Model has:

public class MyRDO {

	private String transferId = null;

	public MyRDO transferId(String transferId) {
		this.transferId= transferId;
		return this;
	}

	@JsonProperty("transferId")
	@ApiModelProperty(required = true, value = "<p>Transfer Id</p>")    @NotNull@Pattern(regexp="^[A-Za-z0-9]{8,16}$") @Size(min=8,max=16)
	public String getTransferId() {
		return transferId;
	}

	public void setTransferId(String transferId) {
		this.transferId = transferId;
	}
}

Which generates:

      transferId:
        type: string
        description: <p>Transfer Id</p>
        allowEmptyValue: false
        minLength: 8
        maxLength: 16
        pattern: '^[A-Za-z0-9]{8,16}$'

Sample Repo Created - https://github.com/retinaburn/sizetest/tree/master/src/main/java/io/springfox/custom

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions