【问题标题】:Swagger:Issue with Path parameterSwagger:路径参数问题
【发布时间】:2015-01-25 03:45:39
【问题描述】:

我正在尝试使用以下路径创建一个 swagger 文件: 路径: /v1/customers/{id}/summary :

但是我马上就收到以下错误:

API 需要路径参数但未定义:id 在路径▹ /v1/customers/{id}/summary

它似乎不喜欢'id'参数。谁能告诉我如何纠正这个问题?

如果我对此进行深入研究,我会看到以下内容:

Details
 Object
 swaggerError: Object
 errors: Array [1]
 0: Object
code:  "MISSING_API_PATH_PARAMETER"
message:  "API requires path parameter but it is not defined: id"
data:  "/v1/customers/{id}/summary"
 path: Array [2]
 warnings: Array [0]

【问题讨论】:

  • 您使用哪个 Swagger 版本?您如何创建规范?
  • 我使用的是 Swagger 2.0。我正在从 Apigee_127 的命令行创建规范并填充在编辑器中创建的 YAML 文件。希望能回答这个问题。
  • 如果我深入了解错误,我会得到以下信息:

标签: apigee swagger


【解决方案1】:

基本上,您通过使用路径模板来声明其中包含路径参数的路径。在这种情况下,{id} 声明了一个名为 id 的路径参数。

当您声明这样的路径时,这意味着您必须将该路径参数声明为操作的一部分。

看看这个 YAML 示例:

  /pets/{id}:
    get:
      description: Returns a user based on a single ID, if the user does not have access to the pet
      operationId: findPetById
      produces:
        - application/json
        - application/xml
        - text/xml
        - text/html
      parameters:
        - name: id
          in: path
          description: ID of pet to fetch
          required: true
          type: integer
          format: int64
      responses:
        '200':
          description: pet response
          schema:
            $ref: '#/definitions/pet'
        default:
          description: unexpected error
          schema:
            $ref: '#/definitions/errorModel'

可以看到路径中有{id},以及对应的id参数定义。没有它,规范将无效。

【讨论】:

  • 另请注意,required 是必需的,并且需要设置为 true
  • @Ron Hi Ron,请你看看这个问题 - stackoverflow.com/questions/42348630/…,让我知道你对此的想法
  • 我看到您收到了 Dilip 的回复 - 他是 Springfox 的作者,也是您将获得的最佳回复。
猜你喜欢
  • 1970-01-01
  • 2019-06-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多