swaggerpy.swagger_model module
Code for handling the base Swagger API model.
- class swaggerpy.swagger_model.Loader(http_client, processors=None)[source]
Bases:
object
Abstraction for loading Swagger API’s.
- Parameters
http_client (swaggerpy.http_client.HttpClient) – HTTP client interface.
processors (list of swaggerpy.processors.SwaggerProcessor) – List of processors to apply to the API.
- load_api_declaration(base_url, api_dict)[source]
Load an API declaration file.
- api_dict is modified with the results of the load:
[‘url’] = URL api declaration was loaded from
[‘api_declaration’] = Parsed results of the load
- Parameters
base_url – Base URL to load from
api_dict – api object from resource listing.
- load_resource_listing(resources_url, base_url=None)[source]
Load a resource listing, loading referenced API declarations.
- The following fields are added to the resource listing object model.
[‘url’] = URL resource listing was loaded from
The [‘apis’] array is modified according to load_api_declaration()
The Loader’s processors are applied to the fully loaded resource listing.
- Parameters
resources_url – File name for resources.json
base_url – Optional URL to be the base URL for finding API declarations. If not specified, ‘basePath’ from the resource listing is used.
- class swaggerpy.swagger_model.ValidationProcessor[source]
Bases:
SwaggerProcessor
A processor that validates the Swagger model.
- process_api_declaration(resources, resource, context)[source]
Post process a resource object.
This is parsed from a .json file reference by a resource listing’s ‘api’ array.
- Parameters
resources – Resource listing object
resource – resource object.
context (ParsingContext) – Current context in the API.
- process_error_response(resources, resource, api, operation, error_response, context)[source]
Post process an errorResponse on an operation.
- Parameters
resources – Resource listing object
resource – resource object.
api – API object
operation – Operation object.
error_response – Response object.
context (ParsingContext) – Current context in the API.
- process_model(resources, resource, model, context)[source]
Post process a model from a resources model dictionary.
- Parameters
resources – Resource listing object
resource – resource object.
model – Model object.
context (ParsingContext) – Current context in the API.
- process_operation(resources, resource, api, operation, context)[source]
Post process an operation on an api.
- Parameters
resources – Resource listing object
resource – resource object.
api – API object
operation – Operation object.
context (ParsingContext) – Current context in the API.
- process_parameter(resources, resource, api, operation, parameter, context)[source]
Post process a parameter on an operation.
- Parameters
resources – Resource listing object
resource – resource object.
api – API object
operation – Operation object.
parameter – Parameter object.
context (ParsingContext) – Current context in the API.
- process_property(resources, resource, model, prop, context)[source]
Post process a property from a model.
- Parameters
resources – Resource listing object
resource – resource object.
model – Model object.
prop – Property object.
context (ParsingContext) – Current context in the API.
- process_resource_api(resources, resource, api, context)[source]
Post process entries in a resource’s api array
- Parameters
resources – Resource listing object
resource – resource object.
api – API object
context (ParsingContext) – Current context in the API.
- process_resource_listing(resources, context)[source]
Post process a resources.json object.
- Parameters
resources – ResourceApi object.
context (ParsingContext) – Current context in the API.
- process_resource_listing_api(resources, listing_api, context)[source]
Post process entries in a resource.json’s api array.
- Parameters
resources – Resource listing object
listing_api – ResourceApi object.
context (ParsingContext) – Current context in the API.
- swaggerpy.swagger_model.json_load_url(http_client, url)[source]
Download and parse JSON from a URL.
- Parameters
http_client (http_client.HttpClient) – HTTP client interface.
url – URL for JSON to parse
- Returns
Parsed JSON dict
- swaggerpy.swagger_model.load_file(resource_listing_file, http_client=None, processors=None)[source]
Loads a resource listing file, applying the given processors.
- Parameters
http_client – HTTP client interface.
resource_listing_file – File name for a resource listing.
processors – List of SwaggerProcessors to apply to the resulting resource.
- Returns
Processed object model from
- Raise
IOError: On error reading api-docs.
- swaggerpy.swagger_model.load_json(resource_listing, http_client=None, processors=None)[source]
Process a resource listing that has already been parsed.
- Parameters
resource_listing (dict) – Parsed resource listing.
http_client –
processors –
- Returns
Processed resource listing.
- swaggerpy.swagger_model.load_url(resource_listing_url, http_client=None, processors=None, base_url=None)[source]
Loads a resource listing, applying the given processors.
- Parameters
resource_listing_url – URL for a resource listing.
http_client – HTTP client interface.
processors – List of SwaggerProcessors to apply to the resulting resource.
base_url – Optional URL to be the base URL for finding API declarations. If not specified, ‘basePath’ from the resource listing is used.
- Returns
Processed object model from
- Raise
IOError, URLError: On error reading api-docs.
- swaggerpy.swagger_model.validate_required_fields(json, required_fields, context)[source]
Checks a JSON object for a set of required fields.
If any required field is missing, a SwaggerError is raised.
- Parameters
json – JSON object to check.
required_fields – List of required fields.
context – Current context in the API.