oasapi

The oasapi packages

oasapi.validate(swagger)[source]

Validate a swagger specification.

The validations checks the following points:

  • validate against re. OAS 2.0 schema
  • no missing reference
  • unicity of operationId
  • no missing securityDefinition
  • consistency of parameters (default value vs type)
Parameters:swagger (Dict) – the swagger spec
Return type:Tuple[Dict, List[ValidationError]]
Returns:a set of errors
oasapi.prune(swagger)[source]

Prune a swagger specification.

The pruning removed from the swagger the following elements:

  • unused global definitions/responses/parameters
  • unused securityDefinition/scopes
  • unused tags
  • empty paths (i.e. endpoints with no verbs)
Parameters:swagger (Dict) – the swagger spec
Return type:Tuple[Dict, List[FilterAction]]
Returns:pruned swagger, a set of actions
oasapi.filter(swagger, mode='keep_only', conditions=None)[source]

Filter endpoints of a swagger specification.

The endpoints can be filtered according to two modes:

  • keep_only: it will keep only the operations matching any of the conditions
  • remove: it will remove only the operations matching any of the conditions (TO BE IMPLEMENTED)

The conditions parameter is a list of FilterCondition objects containing each:

  • tags: the operation is kept only if it has at least one tag in the tags
  • operations: the operation is kept only if its VERB + PATH matches at least one operation in the operations
  • security_scopes: the operation is kept only if it requires no security or if some of its security items only requires the scopes in the security_scopes

Any of these fields can be None to avoid matching on the field criteria.

Parameters:
  • mode
  • conditions (Optional[List[FilterCondition]]) –
  • swagger (Dict) – the swagger spec
Return type:

Tuple[Dict, List[FilterAction]]

Returns:

filtered swagger, a set of actions

class oasapi.events.Event(path, reason, type)[source]

Bases: object

Base class for an event (an error, an action, …).

static format_path(path)[source]

Format a path to a JSON Path alike string

Return type:str
path = None

the path in the dictionary to which the even relates

reason = None

the reason of the event

type = None

the string representation of the type of event

class oasapi.events.Error(path, reason, type)[source]

Bases: oasapi.events.Event

Base class for an error

class oasapi.events.ValidationError(path, reason, type)[source]

Bases: oasapi.events.Error

Base class for a validation error (used in the swagger validation)

class oasapi.events.ParameterDefinitionValidationError(path, reason, parameter_name, type='Parameter definition error')[source]

Bases: oasapi.events.ValidationError

An error on a parameter definition

class oasapi.events.ReferenceNotFoundValidationError(path, reason, type='Reference not found')[source]

Bases: oasapi.events.ValidationError

An error on a reference used but not found

class oasapi.events.SecurityDefinitionNotFoundValidationError(path, reason, type='Security definition not found')[source]

Bases: oasapi.events.ValidationError

An error on a securityDefinition used but not found

class oasapi.events.OAuth2ScopeNotFoundInSecurityDefinitionValidationError(path, reason, type='Security scope not found')[source]

Bases: oasapi.events.ValidationError

An error on an OAuth2 scope used but not found

class oasapi.events.DuplicateOperationIdValidationError(path, reason, operationId, path_already_used, type='Duplicate operationId')[source]

Bases: oasapi.events.ValidationError

An error on two operations using the same operationId

operationId = None

the name of the duplicate operationId

path_already_used = None

the path of the first operation using the operationId

class oasapi.events.JsonSchemaValidationError(path, reason, type='Json schema validator error')[source]

Bases: oasapi.events.ValidationError

An error due to an invalid schema