pyramid_jsonapi.metadata.OpenAPI package

Module contents

Generate OpenAPI documentation from Models, Schema and Endpoint info.

This module provides 2 metadata views:

  • OpenAPI - the Swagger UI.

  • OpenAPI/specification - the project OpenAPI specification (JSON).

Configuration

The config option openapi_file can be used to provide a JSON or YAML file which will be used to update the dynamically generated documentation.

Metadata for the OpenAPI documentation will be extracted from the PKG-INFO data provided with the pyramid package that is using pyramid_jsonapi, using the pkginfo module. This requires that the pyramid package can be located in the python path (i.e it can be imported).

Documentation is dynamically generated from several sources:

  • Endpoint data -> endpoints, parameters, request and response content.

  • Model docstrings -> endpoint descriptions.

  • sqlalchemy columns -> schemas (via JSONSchema module).

class pyramid_jsonapi.metadata.OpenAPI.OpenAPI(api)[source]

Bases: object

Auto-generate OpenAPI documentation.

static build_content(schema, description='', mediatype='application/vnd.api+json')[source]

Construct a content dictionary for a given schema.

build_parameters(opts)[source]

Build paramaters schema.

build_request(name, method)[source]

Build requestBody part of schema.

build_responses(name, ep_type, method)[source]

Build responses part of schema.

generate_openapi(request=None)[source]

Generate openapi documentation.

generate_pkg_metadata()[source]

Get metadatsa for ‘parent’ pyramid package.

openapi_spec(request=None)[source]

Return the OpenAPI specification dict (as a pyramid view).

Parameters

request (optional) – Pyramid Request object.

Returns

OpenAPI template document.

recurse_remove_keys(dictionary, name)[source]

Recursively build a new version of dictionary with named keys removed.

recurse_replace_in_value(obj, old, new)[source]

Recursively replace() strings in values.

replace_in_value_inner(val, old, new)[source]

Inner part of recurse_replace_in_value.

static swagger_ui(request)[source]

Dynamically generate the swagger-ui index.html

Parameters

request (optional) – Pyramid Request object.

Returns

dict containing variables for template substitution.