IBM/openapi-validator

Unexpected inline_response_schema warning when the schema $ref points to another file

brendansafr opened this issue ยท 3 comments

  • Using: ibm-openapi-validator@0.51.3
  • Related to: #125

Hello ๐Ÿ˜„

When using a ref to a response that exists in another file, I get the following warning:

[Warning: inline_response_schema] paths./.get.responses.200.content.application/json.schema (36)
 Response schemas should be defined with a named ref.

Thing is, I think I am using a named ref, it just points to another file...

Excerpt from my index.yml

paths:
  /:
    get:
      ...
      responses:
        "200":
          $ref: "./models/visits.yml#/components/responses/visitItemListResponse"

Excerpt from my models/visits.yml

components:
  ...
  responses:
    visitItemListResponse:
      description: "Visitor Visit List"
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/visitItemList"

In addition, I get the same error using a schema ref, and skipping the response ref:

index.yml

paths:
  /:
    get:
      ...
      responses:
        "200":
          description: "Visitor Visit List"
          content:
            application/json:
              schema:
                $ref: "./models/visits.yml#/components/schemas/visitItemList"

Everything else is validating OK.

Is this expected? Is it bad to re-use responses or schemas that are already declared in another file?

I am not attempting to generate an SDK, but I'm guessing the SDK generator wants the responses to be defined in the same file...

Not an urgent issue ๐Ÿ˜ƒ

Hi @brendansafr - sorry for the delay in response. It is not bad to re-use schemas declared in another file. The tool is supposed to be able to handle API definitions defined across multiple files - this may be occurring due to a bug in the parsing logic. Have you tried this with any later versions?

Good call! No rush :) I'll give it a go on the latest version :D

I created a StackBlitz and can confirm, the warning I received goes away using ibm-openapi-validator@0.81.0. I'll upgrade to the latest version ๐Ÿ˜„ Thank you!