bravado-core is a Python library that implements the Swagger 2.0 (OpenAPI Specification v2.0). It provides core functionalities for both client-side and server-side support, including Swagger Schema ingestion and validation, marshalling and unmarshalling of requests and responses, and modeling Swagger definitions as Python classes or dictionaries. The current version is 6.1.1, and it maintains an active, though not rapid, release cadence with new versions typically addressing bugs or minor features rather than frequent major changes.
pip install bravado-coreVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to load a Swagger/OpenAPI specification using `Spec.from_dict`, access defined models as Python types, and validate data against those models. It highlights basic model instantiation and the core validation feature of `bravado-core`.
Use the `is_equal` methods provided by `bravado-core` for comparing `Spec` objects if equality checking is required.
Review the changelog and migration guides for `bravado-core` 5.0.0. Update calls to `flattened_spec` with the new signature and replace usage of removed model-related public methods with their new equivalents or recommended patterns.
Ensure that your `jsonschema` dependency is pinned to a version compatible with your `bravado-core` installation, typically `jsonschema>=2.5.1,<4.0.0` as specified by `bravado-core`'s `install_requires`. If using a system that requires `jsonschema>=4.0.0`, consider upgrading `bravado-core` to a version that officially supports it, if available, or finding a workaround.
Always provide a correct `origin_url` when using `Spec.from_dict()` for local files. For example, use `Path.cwd().as_uri()` or a suitable file URI for the `origin_url` parameter.
Define custom formats using `bravado_core.formatter.SwaggerFormat` and pass them in the `config` dictionary when creating the `Spec` object (e.g., `config={'formats': [my_custom_format]}`).Upgrade to Python 3.7 or newer. The current recommended Python version is >=3.7.
Upgrade `bravado-core` to version 5.0.2 or newer, which contains the fix for this regression. Alternatively, if upgrading is not an immediate option, disable the `internally_dereference_refs` configuration option.
Upgrade `bravado-core` to a version where this regression was fixed (e.g., 4.7.2 or later). The `marshal` and `unmarshal` methods should be called on instances of the model, not the model class itself, but this specific error pointed to a deeper issue with the model generation in affected versions.
Ensure that the data being passed or received strictly adheres to the schema defined in your Swagger/OpenAPI specification. For the example given, provide an integer value instead of a string where an integer is expected.
Register a custom formatter for the specified format using `bravado_core.formatter.register_format`. For example, to register a simple pass-through for 'JSON' format, you would define a `SwaggerFormat` and pass it in the `formats` config to `Spec.from_dict` or `SwaggerClient.from_url`.
If the parameter is expected to be an array, define its `type` as 'array' and specify the `collectionFormat` (e.g., 'multi' for `param=1¶m=2`) in your Swagger specification. If it should always be a single value, ensure that clients send only a single value for that parameter.