Beispiel #1
0
def bar_post(request):
    """ Return something.

    ---
    post:
      tags:
      - "Other API"
      summary: "Send a list of bar's"
      description: ""
      operationId: "bar_post"
      consumes:
      - "application/json"
      produces:
      - "application/json"
      parameters:
      - in: "body"
        name: "body"
        description: "Bar body description"
        required: true
        schema:
          $ref: "#/definitions/BarBodySchema"
      responses:
          200:
              description: response for 200 code
              schema:
                $ref: "#/definitions/BarBodySchema"
    """
    schema = validation.BarBodySchema(many=True)
    struct = schema.loads(request.body or "{}")
    return struct.data
Beispiel #2
0
def api_spec(request):
    """
    Serve the spec to explorer
    """
    spec = APISpec(
        title="Some API",
        version="1.0.0",
        openapi_version="2.0",
        plugins=[MarshmallowPlugin()],
    )
    # using marshmallow plugin here
    spec.components.schema("FooBodySchema", schema=validation.FooBodySchema)
    spec.components.schema("BarBodySchema", schema=validation.BarBodySchema(many=True))

    # register API security scheme
    api_auth_scheme = {"type": "apiKey", "in": "header", "name": "Authorization"}
    spec.components.security_scheme("APIKeyHeader", api_auth_scheme)

    # inspect the `foo_route` and generate operations from docstring
    add_pyramid_paths(spec, "users", request=request)

    # inspection supports filtering via pyramid add_view predicate arguments
    add_pyramid_paths(spec, "bar_route", request=request)
    my_spec = spec.to_dict()
    # you can further mutate the spec dict to include things like security definitions
    return my_spec
Beispiel #3
0
def api_spec(request):
    """
    Serve the spec to explorer
    """
    spec = APISpec(title="Some API",
                   version="1.0.0",
                   plugins=["apispec.ext.marshmallow"])
    # using marshmallow plugin here
    spec.definition("FooBodySchema", schema=validation.FooBodySchema)
    spec.definition("BarBodySchema",
                    schema=validation.BarBodySchema(many=True))

    # inspect the `foo_route` and generate operations from docstring
    add_pyramid_paths(spec, "users", request=request)

    # inspection supports filtering via pyramid add_view predicate arguments
    add_pyramid_paths(spec, "bar_route", request=request)
    my_spec = spec.to_dict()
    # you can further mutate the spec dict to include things like security definitions
    return my_spec