javanile / yamlinc

Compose multiple YAML files into one with $include tag. Split Swagger/OpenAPI into multiple YAML files.
MIT License
114 stars 22 forks source link

yamlinc changes example dates when merging #24

Open StephenNay opened 4 years ago

StephenNay commented 4 years ago

Here's a piece of a request definition in one of my source files:

      - name: date
        description: The date
        in: path
        required: true
        schema:
          type: string
          format: date
        example: 2019-12-25

And here's the same section after merging with yamlinc:

        - name: date
          description: The date
          in: path
          required: true
          schema:
            type: string
            format: date
          example: '2019-12-25T00:00:00.000Z'

Note how the example date in the last line has been changed from just the date to a full date and time format, which is not what I want in this case. Is there a way to prevent this from happening?

francescobianco commented 4 years ago

@StephenNay parsing dates is a known problem of YAML, take a look at this https://github.com/nodeca/js-yaml/issues/161

to prevent this, my best choice is quoting as a string the date, but if you will work with the custom schema you can do using --schema argument https://github.com/javanile/yamlinc#use-an-external-schema

See more:

darzang commented 3 years ago

I'm also experiencing this issue but with strings that are not in a specific format: In my base file:

phone:
  type: string
  example: 0102030405

The swagger.inc.yml:

phone:
  type: string
  example: 17314053

What's weird is that I have a postal_code declared the same way:

postal_code:
  type: string
  example: 33130

And in the swagger.inc.yml file the postal_code has the correct value