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 XX.client.cpp
XX.client.cpp: In static member function ‘static void
XX::SendSetProtocolReqRequest(std::string, const
XX::model::SetProtocolReq_Request*,
HTTPRequestEventContext::Ptr, uint64_t, HTTPClient*, FSM*, Statistics*,
std::string, bool)’:
XX_Management.client.cpp:1822:33: error: no matching function for call to
‘Json::ToValue(XX::model::XXEnumProtocolType*,
framework::json::Value*)’
Json::ToValue(¶m, &value);
^
我对 XX.client.cpp 了解不多。 yaml文件编译后自动生成的文件。
最佳答案
对于 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
关于enums - 是否可以在 yaml 中使用枚举作为路径参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56699051/