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

Unwanted conversion from string to integer in examples #94

Open
Mcourt opened this issue Sep 9, 2019 · 1 comment
Open

Unwanted conversion from string to integer in examples #94

Mcourt opened this issue Sep 9, 2019 · 1 comment
Labels

Comments

@Mcourt
Copy link

Mcourt commented Sep 9, 2019

Describe the bug
My examples are being converted to integers although they should be strings (ex: phone numbers).
This causes problem when validating my openapi file, as the parameter is set as "string" but has a number as example.

To Reproduce

  1. Given this OpenAPI document
openapi: 3.0.0
info:
  title: My title
  version: 1.0.0
paths:
  /my/route:
    post:
      summary: My route
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                phone:
                  type: string
                  example: "0612345678"
        required: true
      responses:
        '204':
          description: No Content
        '400':
          description: Bad Request
  
  1. I execute the combine command
  2. I get the following document (Notice the number example)
openapi: 3.0.0
info:
  title: My title
  version: 1.0.0
paths:
  /my/route:
    post:
      summary: My route
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                phone:
                  type: string
                  example: 0612345678
        required: true
      responses:
        '204':
          description: No Content
        '400':
          description: Bad Request

Expected behavior
I expected my example to stay as a string.

@fabsrc
Copy link
Contributor

fabsrc commented Jan 12, 2020

This seems to be a bug in the js-yaml package.
See: nodeca/js-yaml#530

Tried it with your example:

node -e "console.log(require('js-yaml').safeDump({example: '0612345678'}))"
//  example: 0612345678

Using only digits below 8 (octal digits) seems to work fine:

node -e "console.log(require('js-yaml').safeDump({example: '0612345677'}))"
//  example: '0612345677'

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