gravitee-io / gravitee-docs

Gravitee - Documentation
Apache License 2.0
29 stars 66 forks source link

[swagger] Cannot validate JSON body schema of API policy update request #167

Open fmigneault opened 4 years ago

fmigneault commented 4 years ago

Schema validation provided below fails although it shouldn't.

Giving following body to the PUT {GRAVITEE_APIM_URI}/management/apis/:id request, I get a successful update response (200). The API is also correctly updated when I go look at the policy definition within Gravitee APIM UI.

{
    "name": "test-api",
    "version": "3",
    "description": "test",
    "visibility": "public",
    "tags": [],
    "labels": [],
    "proxy": {
        "context_path": "/test-api",
        "strip_context_path": false,
        "groups": [
            {
                "name": "test-api",
                "endpoints": [
                    {
                        "name": "default",
                        "target": "http://api:5000",
                        "weight": 1,
                        "backup": false,
                        "type": "HTTP",
                        "inherit": true
                    }
                ],
                "load_balancing": {
                    "type": "ROUND_ROBIN"
                },
                "services": {
                    "discovery": {
                        "enabled": false
                    }
                },
                "proxy": {
                    "enabled": false,
                    "host": "null",
                    "port": 0,
                    "type": "HTTP"
                },
                "http": {
                    "connectTimeout": 5000,
                    "idleTimeout": 60000,
                    "keepAlive": true,
                    "readTimeout": 10000,
                    "pipelining": false,
                    "maxConcurrentConnections": 100,
                    "useCompression": true,
                    "followRedirects": false
                },
                "ssl": {
                    "trustAll": false,
                    "hostnameVerifier": false
                }
            }
        ]
    },
    "paths": {
        "/status": [
            {
                "methods": [
                    "DELETE",
                    "POST",
                    "PUT"
                ],
                "custom-policy": {
                    "field": "value"
                },
                "description": "Description of the Custom Gravitee Policy",
                "enabled": true
            },
       ],
   }
}

But using JSON schema validation between the Gravitee OpenAPI specification and the above body raises a validation error. Specifically, it doesn't like the following part of the definition:

"Path": {
    "type": "object",
    "properties": {
        "path": {
            "type": "string"
        },
        "rules": {
            "type": "array",
            "items": {
                "$ref": "#/definitions/Rule"
            }
        }
    }
},

The OpenAPI specification is invalid because the content under each path (ie: the policy definitions with its arguments) are indeed not formatted (nor expected by the API) with path and rules fields.

relates to #162

fmigneault commented 4 years ago

Under UpdateApiEntity, the "paths" section:

"paths": {
    "type": "object",
    "additionalProperties": {
        "$ref": "#/definitions/Path"
    }
},

Should be replaced by something as follows :

"paths": {
    "type": "object",
    "additionalProperties": {
        "type": "array", 
                "items": { "$ref": "#/definitions/Rule" }
    }
},