Skip to content

Swagger output is missing method specific input filters #2

@weierophinney

Description

@weierophinney

The Swagger output only contains the default input filter from the config, but not the method specific ones. My api in this example is called OrdersApi, and below are excerpts from /apigility/documentation/OrdersApi-v1 that whows the difference:

Accept: application/json

{
    "name": "OrdersApi",
    "version": "1",
    "services": [
        {
            "name": "OrderListener",
            "route": "/api/order/listener[/:id]",
            "fields": {
                "input_filter": {
                    "worker": {
                        "description": "The worker name",
                        "required": true,
                        "type": "",
                        "example": null
                    },
                    "revision": {
                        "description": "Current revision number",
                        "required": true,
                        "type": "",
                        "example": null
                    }
                },
                "POST": {
                    "worker": {
                        "description": "The worker name",
                        "required": true,
                        "type": "",
                        "example": null
                    }
                }
            }
        }
    ]
}

Accept: application/vnd.swagger+json

{
    "swagger": "2.0",
    "info": {
        "title": "OrdersApi",
        "version": "1"
    },
    "tags": [
        {
            "name": "OrderListener"
        }
    ],
    "paths": {
        "/api/order/listener": {
            "post": {
                "tags": [
                    "OrderListener"
                ],
                "parameters": [
                    {
                        "in": "body",
                        "name": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/OrderListener"
                        }
                    }
                ]
            }
        },
        "/api/order/listener/{id}": {
            "put": {
                "tags": [
                    "OrderListener"
                ],
                "parameters": [
                    {
                        "in": "path",
                        "name": "id",
                        "description": "URL parameter id",
                        "type": "string",
                        "required": true,
                        "minimum": 0,
                        "maximum": 1
                    },
                    {
                        "in": "body",
                        "name": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/OrderListener"
                        }
                    }
                ]
            }
        }
    },
    "definitions": {
        "OrderListener": {
            "type": "object",
            "properties": {
                "worker": {
                    "type": "string",
                    "description": "The worker name"
                },
                "revision": {
                    "type": "string",
                    "description": "Current revision number"
                }
            },
            "required": [
                "worker",
                "revision"
            ]
        }
    }
}

Config

'zf-content-validation' => [
    'OrdersApi\\V1\\Rest\\Order\\Listener\\Controller' => [
        'input_filter' => 'OrdersApi\\V1\\Rest\\Order\\Listener\\Validator',
        'POST' => 'OrdersApi\\V1\\Rest\\Order\\Listener\\ValidatorCreate',
    ],
],
'input_filter_specs' => [
    'OrdersApi\\V1\\Rest\\Order\\Listener\\Validator' => [
        [
            'required' => true,
            'validators' => [
                [
                    'name' => \Zend\Validator\NotEmpty::class,
                    'options' => [],
                ],
                [
                    'name' => \Zend\Validator\StringLength::class,
                    'options' => [],
                ],
            ],
            'filters' => [],
            'name' => 'worker',
            'description' => 'The worker name',
        ],
        [
            'required' => true,
            'validators' => [
                [
                    'name' => \Zend\Validator\NotEmpty::class,
                    'options' => [],
                ],
                [
                    'name' => \Zend\Validator\Digits::class,
                    'options' => [],
                ],
            ],
            'filters' => [],
            'name' => 'revision',
            'description' => 'Current revision number',
        ],
    ],
    'OrdersApi\\V1\\Rest\\Order\\Listener\\ValidatorCreate' => [
        [
            'required' => true,
            'validators' => [
                [
                    'name' => \Zend\Validator\NotEmpty::class,
                    'options' => [],
                ],
                [
                    'name' => \Zend\Validator\StringLength::class,
                    'options' => [],
                ],
            ],
            'filters' => [],
            'name' => 'worker',
            'description' => 'The worker name',
        ],
    ],
],

Originally posted by @Jakovitz at zfcampus/zf-apigility-documentation-swagger#40

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions