prance

Prance implements parsers for Swagger/OpenAPI 2.0 API specs.

See https://openapis.org/ for details on the specification.

Included is a BaseParser that reads and validates swagger specs, and a ResolvingParser that additionally resolves any $ref references.

Exceptions

exception prance.SwaggerValidationError[source]

Bases: exceptions.Exception

Classes

class prance.BaseParser(url=None, spec_string=None, lazy=False, **kwargs)[source]

Bases: prance.mixins.YAMLMixin, prance.mixins.JSONMixin, object

The BaseParser loads, parses and validates Swagger/OpenAPI 2.0 specs.

Uses YAMLMixin and JSONMixin for additional functionality.

json()

Return a JSON representation of the specifications.

Returns:JSON representation.
Return type:dict
parse()[source]

When the BaseParser was lazily created, load and parse now.

You can use this function to re-use an existing parser for parsing multiple files by setting its url property and then invoking this function.

specs_updated()

Test if self.specficiation changed.

Returns:Whether the specs changed.
Return type:bool
yaml()

Return a YAML representation of the specifications.

Returns:YAML representation.
Return type:dict
BACKENDS = {'flex': '_validate_flex', 'swagger-spec-validator': '_validate_swagger_spec_validator'}
class prance.ResolvingParser(url=None, spec_string=None, lazy=False, **kwargs)[source]

Bases: prance.BaseParser

The ResolvingParser extends BaseParser with resolving references.

json()

Return a JSON representation of the specifications.

Returns:JSON representation.
Return type:dict
parse()

When the BaseParser was lazily created, load and parse now.

You can use this function to re-use an existing parser for parsing multiple files by setting its url property and then invoking this function.

specs_updated()

Test if self.specficiation changed.

Returns:Whether the specs changed.
Return type:bool
yaml()

Return a YAML representation of the specifications.

Returns:YAML representation.
Return type:dict
BACKENDS = {'flex': '_validate_flex', 'swagger-spec-validator': '_validate_swagger_spec_validator'}