stoplightio / spectral

A flexible JSON/YAML linter for creating automated style guides, with baked in support for OpenAPI v3.1, v3.0, and v2.0 as well as AsyncAPI v2.x.
https://stoplight.io/spectral
Apache License 2.0
2.35k stars 226 forks source link

fails to parse yaml values with double quote `"` inside #2631

Open pomali opened 1 month ago

pomali commented 1 month ago

Describe the bug when linting yaml file, value containing double quote " does not get recognized as string

To Reproduce

  1. Given this OpenAPI document a.yaml
openapi: 3.0.3
info:
  title: A
  version: 0.1.0
  description: "A"
paths:
  /api/device/apns/:
    get:
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PaginatedAPNSDeviceList'
          description: ''
components:
  schemas:
    PaginatedAPNSDeviceList:
      type: object
      required:
      - results
      properties:
        next:
          type: string
          nullable: true
          format: uri
          example: http://api.example.org/accounts/?cursor=cD00ODY%3D"

and .spectral.yaml

extends: ["spectral:oas"]
  1. Run this CLI command spectral lint a.yaml
  2. See error
    ...
    27:20    error  oas3-valid-schema-example    "example" property must match format "uri"                     components.schemas.PaginatedAPNSDeviceList.properties.next.example

this is caused by " in example. (same arror can happen with oas3-valid-media-example)

Expected behavior other yaml libraries (eg. pyyaml) recognize not-leading double quote and treat the value like a string, so it should not fail the validation (since format: uri gets downgraded to type: string, which should match, and if format: uri is recognized it should be valid anyway)

daniel-white commented 3 weeks ago

is the quote intended to be part of the URL string value or part of the yaml syntax?

pomali commented 3 weeks ago

Pyyaml recognizes it as part of URL string value