Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

YYYYMMDD Date format on yaml definition

I have a requirement where the request pass date in YYYYMMDD format. Based on swagger documentation, date filed defined under string type. However, it follows RFC 3339, section 5.6, documentation (ex.2018-03-20 as format)

below code doesn't work with yaml.

dateOfBirth:
          type: string
          minLength: 8
          maxLength: 8
          format: date
          example: 19000101
          description: Birth date of the  member in YYYYMMDD format.

How to define YAML definition for the date format of YYYYMMDD.

like image 415
user3540722 Avatar asked Jan 22 '26 20:01

user3540722


1 Answers

According to documentation for type string you can add regex pattern to define the date format YYYYMMDD :

pattern: '^\d{4}(0[1-9]|1[012])(0[1-9]|[12][0-9]|3[01])$'

Also let me suggest you to update your example date format with a date like 20190317 to easily understand the expected date format.

definitions:
  Pet:
    type: object
    required:
      - id
      - name
    properties:
      id:
        type: integer
        format: int64
      name:
        type: string
      tag:
        type: string
      dateOfBirth:
        type: string
        minLength: 8
        maxLength: 8
        format: date
        pattern: '^\d{4}(0[1-9]|1[012])(0[1-9]|[12][0-9]|3[01])$'
        example: 20190816
        description: Birth date of the  member in YYYYMMDD format.
like image 100
bdzzaid Avatar answered Jan 25 '26 16:01

bdzzaid



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!