eemeli / yaml

YAML parser and stringifier for JavaScript
https://eemeli.org/yaml
ISC License
1.32k stars 116 forks source link

`parseDocument(str, options = {}): Document` does not parse elements under `]` character occurrence in new line. #543

Closed Krzysztof-Kolodziejczyk closed 6 months ago

Krzysztof-Kolodziejczyk commented 6 months ago

Example file:

definitions:
  Response:
      errors:
        type: array
        items:
          $ref: '#/definitions/Error'
        example: [{
          "category": "BAD_REQUEST" 
        }]
  Error:
    type: object
    properties:
      category:
        type: string

For this case Error element won't be in result object due to [ character under "category": "BAD_REQUEST".

definitions:
  Response:
      errors:
        type: array
        items:
          $ref: '#/definitions/Error'
        example: [{
          "category": "BAD_REQUEST"  }]
  Error:
    type: object
    properties:
      category:
        type: string

For above scenario text is parsed correctly.

eemeli commented 6 months ago

The example is invalid YAML, because the last line of

        example: [{
          "category": "BAD_REQUEST" 
        }]

is insufficiently indented.

This library makes a specific affordance for cases when the last line contains exactly one flow-collection terminator which has its start on the same line as the mapping key, as in:

        example: [
          { "category": "BAD_REQUEST" }
        ]

I am not comfortable with expanding this affordance and deviation from the spec further to cover your case.