Skip to content

[Feature]: Auto-detect base_uri when using OpenAPI.from_file_path #801

Closed
@jonathanberthias

Description

@jonathanberthias

Suggested Behavior

When I create an OpenAPI instance with a multi-file schema, I find myself writing:

spec_path = "path/to/spec.yaml"
openapi = openapi_core.OpenAPI.from_file_path(
    spec_path,
    config=openapi_core.Config(spec_base_uri=Path(spec_path).as_uri()),
)

This feels redundant as the implementation for SchemaPath.from_file_path also loads the base_uri, but that information is then lost:
https://github.com/p1c2u/jsonschema-path/blob/f35bd22aa5a0b86fa4c194e47a29aa46908b0d10/jsonschema_path/paths.py#L86

Why is this needed?

Ideally I would write the above as:

spec_path = "path/to/spec.yaml"
openapi = openapi_core.OpenAPI.from_file_path(spec_path)

and the spec_base_uri would be correctly set.

The base_uri is technically available but is private, e.g.:

base_uri = openapi.spec.accessor.resolver._base_uri

References

No response

Would you like to implement a feature?

None

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions