是否可以在yaml中将枚举用作路径参数?

时间:2019-06-21 07:48:35

标签: enums yaml openapi

Swagger: Reusing an enum definition as query parameter中也有类似的问题。我的问题是我是否可以使用枚举(可重用或不可重用)。每当我尝试这样做时,我都会收到错误消息,但是使用字符串不会给出任何错误消息

/path/{protocol}:
  patch:
    summary:
    operationId:
    tags:
    parameters:
      - name: protocol
        in: path
        description: # some description
        required: true
        schema:
          $ref: "#/components/schemas/ProtocolType"

   ProtocolType:
     type: string
     default: abcd
     enum:
      - abcd
      - aaa
      - bbb

我的问题是上面的示例是否有效,或者应该尝试哪些可能的更改。我正在使用OpenAPI 3.0.0。

错误:

Compilation errors in Ngnb_Management.client.cpp
Ngnb_Management.client.cpp: In static member function ‘static void 
Ngnb_ManagementClient::SendSetProtocolReqRequest(std::string, const 
ngnb_management::model::SetProtocolReq_Request*, 
HTTPRequestEventContext::Ptr, uint64_t, HTTPClient*, FSM*, Statistics*, 
std::string, bool)’:
Ngnb_Management.client.cpp:1822:33: error: no matching function for call to 
‘Json::ToValue(ngnb_management::model::NgnbManagementEnumProtocolType*, 
framework::json::Value*)’
 Json::ToValue(&param, &value);  
                             ^

我对Ngnb_Management.client.cpp不太了解。这是一个自动生成的文件,是在编译yaml文件后生成的。

1 个答案:

答案 0 :(得分:0)

对于SwaggerUI-使用2.0规范,您必须使用内联枚举,例如:

swagger: '2.0'
info:
  title: Report API
  version: v1
paths:
  /report/{reportType}:
    get:
      tags:
      - ReportController
      parameters:
      - in: path
        name: reportType
        required: true
        type: string
        enum: [foo, bar, baz]

在3.0中,您可以使用参考:

---
openapi: 3.0.1
info:
  title: Report API
  version: v1
paths:
  "/report/{reportType}":
    get:
      tags:
      - ReportController
      parameters:
      - name: exportType
        in: path
        description: ''
        required: true
        schema:
          "$ref": "#/components/schemas/ReportType"
components:
  schemas:
    ReportType:
      enum:
      - foo
      - bar
      - baz
      type: string