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

Validation fails when default is set as object property #2781

Open
luzeno opened this issue Feb 20, 2025 · 0 comments
Open

Validation fails when default is set as object property #2781

luzeno opened this issue Feb 20, 2025 · 0 comments

Comments

@luzeno
Copy link

luzeno commented Feb 20, 2025

Describe the bug
The oas validation fails when the default property is set as an object property, but it doesn't cover all the required values:

38:15 error oas3-valid-schema-example "default" property must have required property "count" components.schemas.Foo.default.

To Reproduce

  1. Given this OpenAPI document and Spectral configuration

api.yaml

openapi: 3.0.3
info:
  title: Sample API
  version: 0.1.0

paths:
  /test:
    post:
      requestBody:
        description: Optional description in *Markdown*
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Foo'
      responses:
        "200": # status code
          description: Sample response
          content:
            application/json:
              schema:
                type: array
                items:
                  type: string

components:
  schemas:
    Foo:
      type: object
      properties:
        name:
          type: string
        count:
          type: integer
      required:
        - name
        - count
      default: # <--- Failing because 'default' doesn't contain the 'count' property that is required
        name: foo

.spectral.yaml

extends: ["spectral:oas"]
  1. Run this command: spectral lint api.yaml
  2. Validation fails with the following error:

38:15 error oas3-valid-schema-example "default" property must have required property "count" components.schemas.Foo.default

Expected behavior
The validation should pass since it is compliant with the json schema validation and the oas specification.

Environment:

  • Library version: 6.14.2

Additional context
The validation works fine for the given OpenAPI document using the swagger editor online.

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

1 participant