Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
retinaburn opened this issue May 11, 2018 · 1 comment
Labels
Milestone

Comments

@retinaburn
Copy link

retinaburn commented May 11, 2018

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

@dilipkrish
Copy link
Member

Thank you for your detailed issue! It is super helpful in reproducing the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants