Skip to content

[Bug]: Response content schema path is unresolvable #858

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

Closed
litteratum opened this issue Jun 20, 2024 · 3 comments
Closed

[Bug]: Response content schema path is unresolvable #858

litteratum opened this issue Jun 20, 2024 · 3 comments
Labels
kind/bug Indicates an issue

Comments

@litteratum
Copy link

Actual Behavior

I have the following paths:

openapi: 3.1.0
info:
  title: My API
  description: My API
  version: 1.0.0

paths:
  /customer:
    post:
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: response.json

The "response.json" schema exists on the same level as the "api.yaml".

Then I use OpenAPI.from_file_path("apis/api.yaml"). And it fails with:

referencing.exceptions.Unresolvable: response.json

So for some reason, response schema resolution always fails...

Expected Behavior

I expect response schemas to be looked up relative to the API specification file. The same they are looked up for requests (and which works for me).

Steps to Reproduce

  1. Create the following "api.yaml":
openapi: 3.1.0
info:
  title: My API
  description: My API
  version: 1.0.0

paths:
  /customer:
    post:
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: response.json
  1. Create a "response.json" file with {} content.
  2. Run the following code:
from openapi_core import OpenAPI

OpenAPI.from_file_path("api.yaml")

OpenAPI Core Version

0.19.2

OpenAPI Core Integration

flask

Affected Area(s)

dependencies, schema

References

No response

Anything else we need to know?

No response

Would you like to implement a fix?

None

@litteratum litteratum added the kind/bug Indicates an issue label Jun 20, 2024
@litteratum
Copy link
Author

Update: referencing paths also does not work:

paths:
  /customer:
    $ref: customer.yaml

I see "ValueError: unknown url type: 'customer.yaml'" from the tracelog.

Should it work or do I miss something?

@p1c2u
Copy link
Collaborator

p1c2u commented Jun 20, 2024

You are missing spec_base_uri configuration to make referencing to work. It needs to be explicitly defined (version 0.19.3 will fix the problem).

import os

from openapi_core import Config, OpenAPI

SPEC_PATH = os.path.join(os.path.dirname(__file__), "api.yaml")

config = Config(spec_base_uri=f"file://{SPEC_PATH}")

OpenAPI.from_file_path(SPEC_PATH, config=config)

@litteratum
Copy link
Author

@p1c2u, thank you for your support. It indeed solved my issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Indicates an issue
Projects
None yet
Development

No branches or pull requests

2 participants