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

Misleading error for invalid header object #1715

Open
MarcusAckermann opened this issue Jul 6, 2021 · 2 comments
Open

Misleading error for invalid header object #1715

MarcusAckermann opened this issue Jul 6, 2021 · 2 comments
Labels
OpenAPI Issues related to the OpenAPI ruleset t/bug Something isn't working triaged

Comments

@MarcusAckermann
Copy link

To Reproduce

  1. Given the attached OpenAPI/AsyncAPI document
  2. Run this CLI command 'spectral lint openapi.json'
  3. I get ' 38:18 error oas3-schema Property schema is not expected to be here. components.headers.Cache-Control.schema'

Expected behavior
According to https://swagger.io/specification/#header-object the property 'schema' is allowed in a header declaration. There should be no error regarding rule oas3-schema.

openapi.zip

@P0lip P0lip added OpenAPI Issues related to the OpenAPI ruleset t/bug Something isn't working labels Oct 24, 2021
@P0lip P0lip changed the title False positive error with oas3-schema rule Misleading error for invalid header object Oct 24, 2021
@P0lip
Copy link
Contributor

P0lip commented Oct 24, 2021

Hey, first of all, my apologies for a delayed response.
In our case, the way you reference that header object is invalid.
One should do

     "headers": {
         "Cache-Control"  : {
                "$ref": "#/components/headers/Cache-Control"
          }
    }

I do agree however that the error could be more meaningful.

@jstockdi-marstone
Copy link

jstockdi-marstone commented Nov 2, 2021

I came across this error and it stumped me for a bit. For anyone else who has the same issue:

Change:

            "headers": {
              "Cache-Control" :{
                "schema": {
                  "$ref": "#/components/headers/Cache-Control"
                }
              }
            }

To:

            "headers": {
              "Cache-Control" :{
                "$ref": "#/components/headers/Cache-Control"
              }
            }

It's easy to mix up, as schema often has an attribute $ref in other use cases. If the component has schema in it, then the object referencing it should not refer to it from a schema attribute. I think... if anyone posts additional info here, that'd help me out.

NOTE: only happens for version 3.0.1, it works fine in 3.1.0.

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

No branches or pull requests

4 participants