swaggerconformance.schema package

Module contents

This package provides templates which can be generated from a Swagger schema to represent parts of that schema which can later be filled in by generated values.

It also exposes the Primitive interface, which is the type of object that is passed to a StrategyFactory to generate values for.

class swaggerconformance.schema.Api(client)[source]

Bases: object

Template for an entire Swagger API.

endpoints

Mapping of the endpoints of this API to their operations.

Return type:dict(str, dict(str, schema.Operation))
operation(operation_id)[source]

Access a single operation by its unique operation ID.

Return type:schema.Operation
operations()[source]

All operations of the API across all endpoints.

Return type:Generator(schema.Operation)
class swaggerconformance.schema.Operation(operation)[source]

Bases: object

Template for an operation on an endpoint.

Parameters:operation (pyswagger.spec.v2_0.objects.Operation) – The definition of the operation in the API schema.
id

The Swagger operationId of this operation.

Return type:str
method

The method of this operation.

Return type:str
parameters

Mapping of the names of the parameters to their templates.

Return type:dict(str, Parameter)
parameters_strategy(value_factory)[source]

Generate hypothesis fixed dictionary mapping of parameters.

Parameters:value_factory (strategies.StrategyFactory) – Factory to generate strategies for values.
path

The path of this operation.

Return type:str
response_codes

List of HTTP response codes this operation might return.

Return type:set(int)
class swaggerconformance.schema.Parameter(swagger_definition)[source]

Bases: object

A Swagger API operation parameter.

Parameters:swagger_definition (schema.Primitive) – The swagger spec portion defining the parameter.
format

The format of this parameter.

Return type:str or None
name

The name of this parameter, if it has one.

Return type:str or None
required

Whether this parameter is required.

Return type:bool
strategy(value_factory)[source]

Generate a hypothesis strategy representing this parameter.

Parameters:value_factory (strategies.StrategyFactory) – Factory to generate strategies for values.
type

The type of this parameter.

Return type:str
class swaggerconformance.schema.Primitive(swagger_definition)[source]

Bases: object

Wrapper around a primitive in a swagger schema.

This may be a Parameter or a Schema Swagger object, either passed directly as a parameter to an operation as a child of one.

Since a Swagger Items object may be a child of a Parameter or schema, treat that the same as well since it’s sufficiently similar we don’t care about the distinction. Items don’t have names though, so be careful of that.

Parameters:swagger_definition (pyswagger.spec.v2_0.objects.Parameter or pyswagger.spec.v2_0.objects.Items or pyswagger.spec.v2_0.objects.Schema) – The swagger spec definition of this parameter.
additionalProperties

Whether this Primitive is a dict that accepts arbitrary entries.

Return type:bool or None
enum

List of valid values for this Primitive.

Return type:list or None
exclusiveMaximum

Whether the maximum value of this Primitive is allowed.

Return type:bool
exclusiveMinimum

Whether the minimum value of this Primitive is allowed.

Return type:bool
format

The format of this Primitive.

Return type:str or None
items

The Parameter elements of this Primitive if it’s an array.

Return type:Primitive or None
location

The location of this Primitive - e.g. ‘header’ or ‘body’, or None if not a top-level primitive.

Return type:str or None
maxItems

The maximum number of items in this Primitive if it’s an array.

Return type:int or None
maxLength

The maximum length of this Primitive.

Return type:int or None
maxProperties

The maximum number of properties in this Primitive if it’s a dict.

Return type:int or None
maximum

The maximum value of this Primitive.

Return type:float or None
minItems

The minimum number of items in this Primitive if it’s an array.

Return type:int or None
minLength

The minimum length of this Primitive.

Return type:int or None
minProperties

The minimum number of properties in this Primitive if it’s a dict.

Return type:int or None
minimum

The minimum value of this Primitive.

Return type:float or None
multipleOf

The value of this Primitive must be a multiple of this value.

Return type:float or None
name

The name of this Primitive, if it has one.

Return type:str or None
pattern

The regex pattern for this Primitive.

Return type:string or None
properties

The dict of Primitive elements of this Primitive if it’s an object.

Return type:dict(str, Primitive) or None
required

Whether this Primitive is required.

Return type:bool
required_properties

Set of required property names of this Primitive if it’s an object.

Return type:set(str) or None
type

The type of this Primitive.

Return type:str
uniqueItems

Whether the items in this Primitive are unique if it’s an array.

Return type:bool