Openapi date format validation

Viewed 810

I have a POST rest service that receive dates, one in queryParameter and the other one in requestBody. Here are parts of the yaml definition.

paths:
...
parameters:
        - in: query
          name: queryDate
          schema:
            type: string
            format: date
schemas:
...
TestObject:
      type: object
      properties:
        bodyDate:
          type: string
          format: date

The format is date, not date-time, so I expect to get a date like

  • "2021-08-23" and not like
  • "2021-08-23T05:39:12Z"

QueryDate is OK This behaviour works well for queryDate, the query parameter.

  • If I put "2021-08-23", I get a HTTP 200, which is correct.
  • If I put "2021-08-23T05:39:12Z" I get a 400 error Bad request, which is correct.

bodyDate is NOK This behaviour is different for bodyDate, contained in the requestBody.

  • If I put "2021-08-23", I get a HTTP 200 which is correct.
  • If I put "2021-08-23T05:39:12Z", I get a HTTP 200, which is NOT CORRECT -> I should get a HTTP 400 error for bad request.

I tried to add a pattern to bodyDate but it adds an @Pattern annotation on the generated TestObject.queryDate field which is already a LocalDate so it does not work.

Is there a way to force the validation of bodyDate to respect the format yyyy-mm-dd without removing "format: date"? Thanks

0 Answers
Related