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

Fails with explicit mapping keys #128

Open
NathanHazout opened this issue May 8, 2019 · 2 comments
Open

Fails with explicit mapping keys #128

NathanHazout opened this issue May 8, 2019 · 2 comments

Comments

@NathanHazout
Copy link

I tried to use "prettier.io" on my api-doc.yml.

Here is a simplified snippet of my original yml which works:

swagger: '2.0'
host: localhost:4000
basePath: /
info:
  title: Sample
  version: '3.0.0'
securityDefinitions:
  Bearer:
    type: apiKey
    name: Authorization
    in: header
definitions:
  Error:
    additionalProperties: true
paths:
  /participant-organizations/{participantOrganizationId}/policies/validation/{recordType}: 
    parameters:
      - name: participantOrganizationId
        in: path
        type: string
        required: true
        description: OrganizationId
      - name: recordType
        in: path
        type: string
        required: true
        description: specified type of record
    put:
      tags:
        - Validation Policy
      description: Update validation policy for the record type
      operationId: updateValidationPolicy
      security:
        - Bearer: []
      parameters:
        - name: validation policy
          in: body
          schema:
            $ref: "#/definitions/ValidationPolicy"
      responses:
        201:
          description: validation policy was updated

After running the formatter, the yml looks like:

swagger: "2.0"
host: localhost:4000
basePath: /
info:
  title: Sample
  version: "3.0.0"
securityDefinitions:
  Bearer:
    type: apiKey
    name: Authorization
    in: header
definitions:
  Error:
    additionalProperties: true
paths:
  ? /participant-organizations/{participantOrganizationId}/policies/validation/{recordType}
  : parameters:
      - name: participantOrganizationId
        in: path
        type: string
        required: true
        description: OrganizationId
      - name: recordType
        in: path
        type: string
        required: true
        description: specified type of record
    put:
      tags:
        - Validation Policy
      description: Update validation policy for the record type
      operationId: updateValidationPolicy
      security:
        - Bearer: []
      parameters:
        - name: validation policy
          in: body
          schema:
            $ref: "#/definitions/ValidationPolicy"
      responses:
        201:
          description: validation policy was updated

Notice the syntax ? /participant-organizations/{participantOrganizationId}/policies/validation/{recordType}?

According to this thread, this is valid syntax: prettier/prettier#5599 (comment)

However, after these changes my server does not start:

/Users/nathanh/Git/my-project/services/core/node_modules/yamljs/lib/Parser.js:270
        throw new ParseException('Unable to parse.', this.getRealCurrentLineNb() + 1, this.currentLine);
        ^
Error: Unable to parse.
npm ERR! code ELIFECYCLE
@NathanHazout NathanHazout changed the title Fails with question mark Fails with explicit mapping keys May 8, 2019
@kaylakantola
Copy link

Hey, I just ran into this issue as well. For me it was a prettier/prettier-atom config issue. To solve it, I added an .eslintignore file to my project root, and included this to have prettier ignore yaml files :

**/*.yaml

I had to also ensure that in prettier-atom, I had set "respectEslintignore" to true in prettier-atom/config-schema.json. It defaults to true, but that's a place to look if the above solution doesn't work right away.

@jeremyfa
Copy link
Owner

This is indeed valid syntax, but yaml.js is not handling all the spec, and there is no plan to change this.
You could use https://github.com/nodeca/js-yaml instead, which is more feature complete, if you do need this syntax to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants