prance¶
Prance implements parsers for Swagger/OpenAPI 2.0 and 3.0.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¶
Classes¶
- class prance.BaseParser(url=None, spec_string=None, lazy=False, **kwargs)[source]¶
-
The BaseParser loads, parses and validates OpenAPI 2.0 and 3.0.0 specs.
Uses
YAMLMixin
andJSONMixin
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': ((2,), '_validate_flex'), 'openapi-spec-validator': ((2, 3), '_validate_openapi_spec_validator'), 'swagger-spec-validator': ((2,), '_validate_swagger_spec_validator')}¶
- SPEC_VERSION_2_PREFIX = 'Swagger/OpenAPI'¶
- SPEC_VERSION_3_PREFIX = 'OpenAPI'¶
- class prance.ResolvingParser(url=None, spec_string=None, lazy=False, **kwargs)[source]¶
Bases:
BaseParser
The ResolvingParser extends BaseParser with resolving references by inlining.
- 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': ((2,), '_validate_flex'), 'openapi-spec-validator': ((2, 3), '_validate_openapi_spec_validator'), 'swagger-spec-validator': ((2,), '_validate_swagger_spec_validator')}¶
- SPEC_VERSION_2_PREFIX = 'Swagger/OpenAPI'¶
- SPEC_VERSION_3_PREFIX = 'OpenAPI'¶