API reference¶
cornice_apispec
¶
includeme(config)
¶
Wire cornice-apispec into a Pyramid app.
Includes pyramid_apispec.views, registers the pcm_* view predicates, and adds
the /{version}/openapi.json route with its /{version}/api-explorer explorer.
The spec view imports {root_package}.views.api.{version}.apispecview and returns
its api_spec(request). A missing module responds with 404.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Configurator
|
The Pyramid configurator, passed by |
required |
get_spec(request, title, version, description=None, security_scheme=None)
¶
Build the OpenAPI 3.0.2 document for the API version in the request URL.
Only views whose pcm_show equals the {version} path segment are included.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
Request
|
The current request. Its |
required |
title
|
str
|
The |
required |
version
|
str
|
The |
required |
description
|
str | None
|
Optional |
None
|
security_scheme
|
dict[str, dict[str, Any]] | None
|
Optional mapping of scheme name to OpenAPI security scheme,
added to |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The OpenAPI document as a dict, ready to render as JSON. |
cornice_apispec.generator
¶
AutoDoc
¶
Build the OpenAPI operation for one view from its pcm_* metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
str
|
The HTTP method of the view, such as |
required |
introspectable_view
|
dict[str, Any]
|
The Pyramid introspectable of the view. |
required |
cornice_service
|
Service
|
The Cornice service that owns the view's route. |
required |
to_dict()
¶
Return the operation keyed by lowercase method, for APISpec.path.
get_schema_name(schema)
¶
Return the OpenAPI component name for a Marshmallow schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
type[Schema] | Schema
|
A schema class or instance. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The class name for a schema class. For an instance, the |
str
|
value when set, otherwise the class name, with a 5-character MD5 suffix when the |
str
|
instance sets |
cornice_apispec.marshmallow
¶
MarshmallowPlugin
¶
Bases: MarshmallowPlugin
apispec Marshmallow plugin that uses OneofOpenAPIConverter.
Pass it to APISpec(plugins=[MarshmallowPlugin()]) in place of apispec's own
MarshmallowPlugin.
OneofOpenAPIConverter
¶
Bases: OpenAPIConverter
OpenAPI converter that renders OneOfSchema as oneOf with a discriminator.
Each member schema is registered as a component. When a member's component name is
already taken, the name is qualified from the member's module path: V{N} for a
vN segment, otherwise the capitalized parent package, otherwise Alt.
is_oneof(schema)
¶
Return whether schema is a OneOfSchema class or instance.