1

我使用 swagger 创建了我的 api 定义,并使用 NodeJs 中的 Swagger-tools 生成了服务器代码。SwaggerRouter 正确处理所有路由,除了带有 ID 的路由。例如,像这样的路线

/v1/factoris/self /v1/factoris/create

被定向到正确的控制器,但使用 ID 调用

/v1/factoris/{factoris_id}

作为无效路由返回。

知道我可能会错过什么吗?

这是招摇规格的样本

/factoris/create:
post:
  tags:
  - "Factoris"
  summary: "Create New Factori"
  description: ""
  operationId: "factorisCreatePOST"
  parameters:
  - in: "body"
    name: "FactoriCreate"
    description: "Create a new factory"
    required: true
    schema:
      $ref: "#/definitions/FactoriCreate"
  responses:
    201:
      description: "A single factori object"
      schema:
        $ref: "#/definitions/inline_response_201"
    405:
      description: "Method not allowed"
      schema:
        $ref: "#/definitions/inline_response_405"
  security:
  - oauth2:
    - "admin"
  x-swagger-router-controller: "Factoris"

/factoris/{factori-id}:
get:
  tags:
  - "Factoris"
  summary: "Factori Information"
  description: ""
  operationId: "factorisFactori_idGET"
  parameters:
  - name: "factori-id"
    in: "path"
    description: "The factori identifier string"
    required: true
    type: "string"
  - name: "expand"
    in: "query"
    description: "Provide expanded information on Assemblies or Products or Users"
    required: true
    type: "string"
  responses:
    200:
      description: "A single factori object"
      schema:
        $ref: "#/definitions/inline_response_201"
    404:
      description: "Factori not found"
      schema:
        $ref: "#/definitions/inline_response_404"
  security:
  - oauth2:
    - "codeadmin"
  x-swagger-router-controller: "Factoris"
4

1 回答 1

0

经过反复试验,我发现如果路径参数有“-”(factori-id),则路径参数不起作用,因此将factori-id更改为factori_id修复了它。但它仍然是一个错误,因为路径参数无法处理“-”

这是在 Swagger-codegen https://github.com/swagger-api/swagger-codegen/issues/5763中创建的未解决问题

于 2017-06-02T19:55:36.083 回答