singer_sdk.schema.source.OpenAPISchema

class singer_sdk.schema.source.OpenAPISchema[source]

Schema source for OpenAPI specifications.

Supports loading schemas from a local or remote OpenAPI 2.0 or 3.x specification in JSON or YAML format.

Example

openapi_schema = OpenAPISchema(”https://api.example.com/openapi.json”) stream_schema = openapi_schema(“ProjectListItem”)

__init__(source, *args, preprocessor=None, **kwargs)[source]

Initialize the OpenAPI schema source.

Parameters:
  • source (str | Path | Traversable) – URL, file path, or Traversable object pointing to an OpenAPI spec in JSON or YAML format.

  • preprocessor (OpenAPISchemaNormalizer | None) – Optional schema normalizer. If not provided, an OpenAPISchemaNormalizer instance will be created automatically to normalize OpenAPI schemas to standard JSON Schema.

  • *args (t.Any) – Additional arguments to pass to the superclass constructor.

  • **kwargs (t.Any) – Additional keyword arguments to pass to the superclass constructor.

Return type:

None

fetch_schema(key)[source]

Retrieve a schema from the OpenAPI specification.

Parameters:

key (_TKey) – The schema component name to retrieve. The format of the key depends on the implementation of build_base_schema.

Returns:

A JSON schema dictionary.

Return type:

dict[str, Any]

get_unresolved_schema(key)[source]

Build the base schema for the given key.

By default, this method treats the key as a component name and builds a reference to it. It can be overridden to support other key types, such as endpoint paths.

Parameters:

key (_TKey) – The key to build the schema for.

Returns:

A JSON schema dictionary.

Return type:

dict[str, Any]

resolve_schema(key)[source]

Resolve the schema references.

Parameters:

key (_TKey) – The schema component name to resolve.

Returns:

A JSON schema dictionary.

Return type:

dict[str, Any]

property spec: dict[str, Any][source]

Get the loaded OpenAPI specification.

Returns:

The full OpenAPI specification as a dictionary.

property spec_version: Literal['v2', 'v3'][source]

Get the OpenAPI specification version.

Returns:

The OpenAPI specification version.

Raises:

UnsupportedOpenAPISpec – If the OpenAPI specification format is unknown.