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

Spectral fails to validate parameter example with a schema correctly #321

Closed
brianmrock opened this issue Jul 6, 2019 · 1 comment
Closed
Labels
t/bug Something isn't working

Comments

@brianmrock
Copy link

brianmrock commented Jul 6, 2019

Context

OAS3 uses two types of examples (example property, not examples property!):

  1. JSON Schema "example"
  2. OpenAPI "example"

Test cases (OAS3)

TEST 1

Given oas3 with

parameters:
        - name: petId
          in: path
          required: true
          description: The id of the pet to retrieve
          schema:
            type: string
          example: "1234567890"

when

spec linted

expect

no errors (example matches the nested schema)

TEST 2

Given oas3 with

parameters:
        - name: petId
          in: path
          required: true
          description: The id of the pet to retrieve
          schema:
            type: string
          example: 123

when

spec linted

expect

error (example is an integer, schema requires string)

TEST 3

Given oas3 with

parameters:
        - name: petId
          in: path
          required: true
          description: The id of the pet to retrieve
          schema:
            type: string
            example: "123"

when

spec linted

expect

be OK

TEST 4

Given oas3 with

parameters:
        - name: petId
          in: path
          required: true
          description: The id of the pet to retrieve
          schema:
            type: string
            example: 123
          example: "abc"

when

spec linted

expect

be OK (nested example is canceled by parent example!!)

TEST 5

Given oas3 with

parameters:
        - name: petId
          in: path
          required: true
          description: The id of the pet to retrieve
          example: "abc"

when

spec linted

expect

be OK (no schema to use)

Test cases (OAS2)

only "in body" OAS2 params can have example... (see the spec to double check)

Figure out the tests :)

In scope

  • create a rule that can validate examples nested in "property" objects.

Out of scope

We do not want to support validating the examples yet.

@brianmrock brianmrock added the t/bug Something isn't working label Jul 6, 2019
@philsturgeon
Copy link
Contributor

Dupe of #223

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants