Gi60s / openapi-enforcer

Apache License 2.0
94 stars 22 forks source link

Using a $ref which refers to '#/components/responses' which re-refers to '#/components/schemas' issues error #127

Closed phillim1 closed 2 years ago

phillim1 commented 2 years ago

Using the 1.15.4 version of openapi-enforcer with the attached API I get the following warnings/errors:

WARNED - API schema warnings found by openapi-enforcer for openapi.json
[ EnforcerException: One or more warnings exist in the OpenApi definition
at: paths > /order-response > post > responses > 400 > content > application/json > schema
Schemas with an indeterminable type cannot serialize- deserialize- or validate values. [WSCH005] ]

FAILED - API schema errors found by openapi-enforcer for openapi.json
[ EnforcerException: One or more errors exist in the OpenApi definition
 at: paths
 at: /order-response > post > responses > 400 > content > application/json > schema
Property not allowed: content ]

Attached API - openapi.json.txt

It looks as if the error is issued because of the 400 response defined with $ref: '#/components/responses/BadRequest' - this refers to responses/BadRequest which in turn refers to $ref: '#/components/schemas/Error'.

Gi60s commented 2 years ago

Hello @phillim1.

I believe that both of the errors you're seeing above stem from the same problem. Taking your provided OpenAPI document, if I manually dereferencing just the #components/responses/BadRequest we get this:

...
"paths": {
  "/order-response": {
    "post": {
      ...
      "responses": {
        ...
        "400": {
          "description": "Bad Request",
          "content": {
            "application/json": {
              "schema": {
                "description": "Bad Request",
                "content": {
                  "application/json; charset=utf-8": {
                    "schema": {
                      "$ref": "#/components/schemas/Error"
                    }
                  }
                }
              },
              ...
            }
          }
        }
      }
    }
  },
  ...

Notice that you have 400 > content > application/json > schema > content which is not valid.

I hope that helps. Have a great day.

phillim1 commented 2 years ago

Thanks for the info.