Skip to content

Parser

Public API for parsing and navigating OpenAPI documents.

Parameter = _v30.Parameter | _v31.Parameter module-attribute

An OpenAPI 3.0 or 3.1 operation parameter.

Reference = _v30.Reference | _v31.Reference module-attribute

An OpenAPI 3.0 or 3.1 reference.

RequestBody = _v30.RequestBody | _v31.RequestBody module-attribute

An OpenAPI 3.0 or 3.1 request body.

Response = _v30.Response | _v31.Response module-attribute

An OpenAPI 3.0 or 3.1 response.

Responses = _v30.Responses | _v31.Responses module-attribute

An OpenAPI 3.0 or 3.1 responses mapping.

Endpoint = tuple[str, Method, Operation]

An endpoint represented by its path, HTTP method, and operation.

NamedSchema = tuple[str, Schema | Reference]

A component schema represented by its name and schema or reference.

Method

Bases: StrEnum

HTTP method supported by an OpenAPI operation.

Attributes:

Name Type Description
GET

Retrieve a resource.

POST

Submit data to a resource.

PUT

Replace a resource.

PATCH

Partially update a resource.

DELETE

Delete a resource.

HEAD

Retrieve response headers for a resource.

OPTIONS

Retrieve communication options for a resource.

TRACE

Perform a message loop-back test.

OpenAPIParser

Parser for navigating an OpenAPI document.

Parameters:

Name Type Description Default
openapi OpenAPI

Parsed OpenAPI 3.0 or 3.1 document.

required

Attributes:

Name Type Description
openapi

Parsed OpenAPI document exposed by the parser.

endpoints cached property

Return the endpoints in the OpenAPI document.

Path-level parameters are merged into each operation unless overridden by an operation-level parameter with the same name.

Returns:

Type Description
list[Endpoint]

Tuples containing the path, HTTP method, and operation.

info property

Return metadata from the OpenAPI document.

Returns:

Type Description
Info

The document's Info object.

schemas cached property

Return the component schemas in the OpenAPI document.

Returns:

Type Description
list[NamedSchema]

Tuples containing the schema name and its schema or reference.

from_dict(data) classmethod

Load an OpenAPI document from a dictionary.

Parameters:

Name Type Description Default
data dict[str, Any]

Dictionary containing the OpenAPI document.

required

Returns:

Type Description
Self

A parser containing the validated OpenAPI document.

from_source(source) classmethod

Load an OpenAPI document from a file path or URL.

JSON and YAML documents are supported. String sources beginning with http:// or https:// are treated as URLs; all other sources are treated as local file paths.

Parameters:

Name Type Description Default
source str | Path

Local file path or HTTP(S) URL of the OpenAPI document.

required

Returns:

Type Description
Self

A parser containing the validated OpenAPI document.

get_referenced(item)

Resolve an item when it is a reference.

Parameters:

Name Type Description Default
item Reference | T

Reference to resolve or concrete value to return unchanged.

required

Returns:

Type Description
T

The resolved reference or the original concrete value.

Raises:

Type Description
ValueError

If a reference cannot be resolved.

resolve_reference(ref)

Resolve a component reference.

Parameters:

Name Type Description Default
ref Reference

OpenAPI reference to resolve.

required

Returns:

Type Description
Any

The referenced component.

Raises:

Type Description
ValueError

If the reference format is unsupported or the target component does not exist.