1

我制定了我的第一个 swagger api 规范,dredd 给出了错误:

error: Compilation error in file '../../docs/swagger.json': Required URI parameter 'id_person' has no example or default value. (person > /person/{id_person} > Updates a already existing person ID with form data)

所以我给参数一个默认值,现在从dredd收到警告:

Required URI parameter 'id_person' has a default value. Default value for a required parameter doesn't make sense from API description perspective. Use example value instead.

我想在规范中提供示例 ID,但在 Swagger 规范中找不到如何使用。

我的大摇大摆的片段:

"post": {
                "tags": ["person"],
                "summary": "Updates a already existing person ID with form data",
                "operationId": "createNewPerson",
                "consumes": ["application/x-www-form-urlencoded"],
                "produces": ["application/json", "application/xml"],
                "parameters": [
                    {
                        "name": "id_person",
                        "in": "path",
                        "description": "ID of person to update",
                        "required": true,
                        "type": "integer",
                        "format": "int64",
                        "default": 1
                    },
4

1 回答 1

4

根据 https://dredd.readthedocs.io/en/latest/how-to-guides/#example-values-for-request-parameters Dredd 支持x-example扩展属性来指定参数示例:

                "parameters": [
                    {
                        "name": "id_person",
                        "in": "path",
                        "description": "ID of person to update",
                        "required": true,
                        "type": "integer",
                        "format": "int64",
                        "x-example": 1
                    },
于 2017-05-02T15:49:11.717 回答