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

Cryptic "reference resolves to more than one schema" errors #2140

Closed
hudlow opened this issue Apr 28, 2022 · 2 comments
Closed

Cryptic "reference resolves to more than one schema" errors #2140

hudlow opened this issue Apr 28, 2022 · 2 comments

Comments

@hudlow
Copy link

hudlow commented Apr 28, 2022

Describe the bug
For certain schema compositions and example values, the oas3-valid-media-example and oas3-valid-schema-example rules emit reference <value from example> resolves to more than one schema.

To Reproduce

  1. Given this OpenAPI document:
openapi: 3.0.3
info:
  title: Foo API
  version: "1.0"
  description: API for foos
  contact:
    email: foowizard@example.com
servers:
- url: 'https://foo.example.com/v1'
tags:
- name: Foos
paths:
  /foo:
    get:
      description: Get a foo
      operationId: get_foo
      summary: Get foo
      tags:
      - Foos
      responses:
        '201':
          description: Got a foo!
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Foo'
              example:
                bars:
                - id: 2922d57a-537c-4ae4-b9d8-2f76c34569cf
components:
  schemas:
    Foo:
      description: It's a foo
      properties:
        bars:
          description: Array of bars!
          items:
            $ref: '#/components/schemas/Bar'
          type: array
          example:
          - id: 5b5bc80e-3692-49ce-81a2-6170764e70de
    Bar:
      oneOf:
      - $ref: '#/components/schemas/RealBar'
      - $ref: '#/components/schemas/NotRealBar'
    RealBar:
      type: object
      description: I'm a real bar!
      required:
      - id
      properties:
        id:
          description: The ID for this real bar
          type: string
      example:
        id: 6d353a0f-aeb1-4ae1-832e-1110d10981bb
    NotRealBar:
      description: I'm not a real bar!
      not:
        $ref: '#/components/schemas/RealBar'
  1. Run spectral lint <document> with the spectral:oas ruleset
  2. See error:
 27:23  error  oas3-valid-media-example   reference "6d353a0f-aeb1-4ae1-832e-1110d10981bb" resolves to more than one schema  paths./foo.get.responses[201].content.application/json.example
 40:19  error  oas3-valid-schema-example  reference "6d353a0f-aeb1-4ae1-832e-1110d10981bb" resolves to more than one schema  components.schemas.Foo.properties.bars.example

Expected behavior
As far as I can tell, these errors are spurious.

Environment (remove any that are not applicable):

  • Library version: 6.2.0
  • OS: macOS 12.3.1
@P0lip
Copy link
Contributor

P0lip commented Apr 29, 2022

Hey!
I believe this might be a duplicate of #2081

@hudlow
Copy link
Author

hudlow commented Apr 29, 2022

It appears so! I will close it, but add a note to the other issue in case this supplemental test case is helpful. Thanks @P0lip!

@hudlow hudlow closed this as completed Apr 29, 2022
padamstx added a commit to padamstx/spectral that referenced this issue Feb 22, 2023
This commit modifies the oasExample function so
that example fields are removed from the schema
to be used for validation.  This is needed because
the presence of an "example" field in a schema
confuses ajv in certain scenarios.
References:
- stoplightio#2081
- stoplightio#2140
- ajv-validator/ajv#1426
padamstx added a commit to padamstx/spectral that referenced this issue Feb 23, 2023
This commit modifies the oasExample function so
that example fields are removed from the schema
to be used for validation.  This is needed because
the presence of an "example" field in a schema
confuses ajv in certain scenarios.
References:
- stoplightio#2081
- stoplightio#2140
- ajv-validator/ajv#1426
padamstx added a commit to padamstx/spectral that referenced this issue Mar 1, 2023
This commit modifies the oasExample function so
that example fields are removed from the schema
to be used for validation.  This is needed because
the presence of an "example" field in a schema
confuses ajv in certain scenarios.
References:
- stoplightio#2081
- stoplightio#2140
- ajv-validator/ajv#1426
padamstx added a commit to padamstx/spectral that referenced this issue Apr 5, 2023
This commit modifies the oasExample function so
that example fields are removed from the schema
to be used for validation.  This is needed because
the presence of an "example" field in a schema
confuses ajv in certain scenarios.
References:
- stoplightio#2081
- stoplightio#2140
- ajv-validator/ajv#1426
P0lip added a commit that referenced this issue Apr 25, 2023
* fix(rulesets): avoid false errors from ajv

This commit modifies the oasExample function so
that example fields are removed from the schema
to be used for validation.  This is needed because
the presence of an "example" field in a schema
confuses ajv in certain scenarios.
References:
- #2081
- #2140
- ajv-validator/ajv#1426

* docs(repo): fix lint warning in README

Signed-off-by: Phil Adams <phil_adams@us.ibm.com>

* chore(rulesets): use traverse

---------

Signed-off-by: Phil Adams <phil_adams@us.ibm.com>
Co-authored-by: Jakub Rożek <jakub@stoplight.io>
P0lip added a commit that referenced this issue Apr 25, 2023
* fix(rulesets): avoid false errors from ajv

This commit modifies the oasExample function so
that example fields are removed from the schema
to be used for validation.  This is needed because
the presence of an "example" field in a schema
confuses ajv in certain scenarios.
References:
- #2081
- #2140
- ajv-validator/ajv#1426

* docs(repo): fix lint warning in README

Signed-off-by: Phil Adams <phil_adams@us.ibm.com>

* chore(rulesets): use traverse

---------

Signed-off-by: Phil Adams <phil_adams@us.ibm.com>
Co-authored-by: Jakub Rożek <jakub@stoplight.io>
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

2 participants