swaggerconformance.apitemplates 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 SwaggerParameter interface, which is the type of object that is passed to a ValueFactory to generate values for.

class swaggerconformance.apitemplates.APITemplate(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, OperationTemplate))
template_operations()[source]

All operations of the API across all endpoints.

Return type:iter(OperationTemplate)
class swaggerconformance.apitemplates.OperationTemplate(app, operation)[source]

Bases: object

Template for an operation on an endpoint.

Parameters:
  • app (pyswagger.core.App) – The app representing the API.
  • operation (pyswagger.spec.v2_0.objects.Operation) – The definition of the operation in the API schema.
hypothesize_parameters(value_factory)[source]

Generate hypothesis fixed dictionary mapping of parameters.

Parameters:value_factory (swaggerconformance.valuetemplates.ValueFactory) – Factory to generate strategies for values.
operation

The actual API operation this template represents.

Return type:pyswagger.spec.v2_0.objects.Operation
parameters

Mapping of the names of the parameters to their templates.

Return type:dict(str, ParameterTemplate)
response_codes

List of HTTP response codes this operation might return.

Return type:set(int)
class swaggerconformance.apitemplates.ParameterTemplate(swagger_definition)[source]

Bases: object

Common class for Swagger API operation parameters.

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

The format of this parameter.

Return type:str
hypothesize(value_factory)[source]

Generate a hypothesis strategy representing this parameter.

Parameters:value_factory (swaggerconformance.valuetemplates.ValueFactory) – Factory to generate strategies for values.
items

The children of this parameter if it’s an array - None otherwise.

Return type:ParameterTemplate or None
name

The name of this parameter, if it has one.

Return type:str or None
properties

The children of this parameter if it’s a dict - None otherwise.

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

Whether this parameter is required.

Return type:bool
required_properties

List of required property names of this parameter if it’s an dict.

Return type:list(str) or None
type

The type of this parameter.

Return type:str
class swaggerconformance.apitemplates.SwaggerParameter(swagger_app, swagger_definition)[source]

Bases: object

Wrapper around a parameter to pass to an operation on an endpoint.

This may be a Parameter or a Schema 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, treat that as a parameter 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_app (pyswagger.core.App) – The API the parameter is part of.
  • 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 paramater is a dict that accepts arbitrary entries.

Return type:bool
enum

List of valid values for this paramater.

Return type:list
exclusiveMaximum

Whether the maximum value of this parameter is allowed.

Return type:bool
exclusiveMinimum

Whether the minimum value of this parameter is allowed.

Return type:bool
format

The format of this parameter.

Return type:str
items

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

Return type:SwaggerParameter or None
location

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

Return type:str or None
maxItems

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

Return type:int
maxLength

The maximum length of this parameter.

Return type:int
maxProperties

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

Return type:int
maximum

The maximum value of this parameter.

Return type:float
minItems

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

Return type:int
minLength

The minimum length of this parameter.

Return type:int
minProperties

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

Return type:int
minimum

The minimum value of this parameter.

Return type:float
multipleOf

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

Return type:float or None
name

The name of this parameter, if it has one.

Return type:str or None
pattern

The regex pattern for this parameter.

Return type:string
properties

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

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

Whether this parameter is required.

Return type:bool
required_properties

List of required property names of this Parameter if it’s an object.

Return type:list(str) or None
type

The type of this parameter.

Return type:str
uniqueItems

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

Return type:bool