swaggerpy.processors module

Swagger processors enrich and validate the Swagger data model.

This can be to make templating easier, or ensure values required for a particular use case (such as ensuring that description and summary fields exist)

class swaggerpy.processors.FlatenningProcessor[source]

Bases: SwaggerProcessor

Flattens model and property dictionaries into lists.

Mustache requires a regular schema.

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_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.

class swaggerpy.processors.ParsingContext[source]

Bases: object

Context information for parsing.

This object is immutable. To change contexts (like adding an item to the stack), use the next() and next_stack() functions to build a new one.

is_empty()[source]

Tests whether context is empty.

Returns

True if empty, False otherwise.

pop()[source]

Pops the most recent object out of the context

push(obj_type, json, id_field)[source]

Pushes a new self-identifying object into the context.

Parameters
  • json (dict) – Specifies type of object json represents

  • json – Current Jsonified object.

  • id_field (str) – Field name in json that identifies it.

push_str(obj_type, json, id_string)[source]

Pushes a new object into the context.

Parameters
  • obj_type (str) – Specifies type of object json represents

  • json (dict) – Current Jsonified object.

  • id_string (str) – Identifier of the given json.

exception swaggerpy.processors.SwaggerError(msg, context, cause=None)[source]

Bases: Exception

Raised when an error is encountered mapping the JSON objects into the model.

class swaggerpy.processors.SwaggerProcessor[source]

Bases: object

Post processing interface for Swagger API’s.

This processor can add fields to model objects for additional information to use in the templates.

apply(resources)[source]

Apply this processor to a loaded Swagger definition.

Parameters

resources (dict) – Top level Swagger definition.

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.

class swaggerpy.processors.WebsocketProcessor[source]

Bases: SwaggerProcessor

Process the WebSocket extension for Swagger

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_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.