0

I have a swagger .yaml file which generates java class as below:

AlleleExportRequest:
      type: object
      properties:
         speciesId:
          type: integer
          format: int64
          example: 17
          required: true
          minimum: 1
        assemblyId:
          type: integer
          format: int64
          example: 65
          required: true
          minimum: 1
        varIds:
          type: array
          example: [ 1,2 ]
          items:
            type: integer
            format: int64

Above swagger config generates AlleleExportPost.java class as follows:

@Validated
@javax.annotation.Generated
public class AlleleExportRequest {

  @JsonProperty("speciesId")
  private Long speciesId = null;

  @JsonProperty("assemblyId")
  private Long assemblyId = null;

  @JsonProperty("varIds")
  @Valid
  private List<Long> varIds = null;
}

When I send request to my controller from swagger UI, it is returning 400 error without any specific error message. varIds should contain only integers as shown in config file, but If I send list of varIds which contains some String values, it is giving 400 error. How can I validate varIds and return proper error message in case it contains string values? Can I remove @Valid annotation from auto-generated java class or add some custom validation? Any help is appreciated. I tried @Valid annotation from controller but did not help.

MyController.java

@Override
public ResponseEntity<JobStatus> alleleMatrixExportPost(@Valid @RequestBody AlleleExportRequest body) {
    alleleMatrixService.setDefaultAggregationFilters(body);
        validateAlleleExportRequest(body);
        JobStatus response = alleleMatrixService.triggerAlleleExport(body);
        return ResponseEntity.ok(response);
    }

Example request with wrong varIds 'S1234'

{
  "speciesId": 20,
  "assemblyId": 113,
  "varIds": ["12696767", "12696776","S1234"]
}
Abdusoli
  • 661
  • 1
  • 8
  • 24

0 Answers0