enums - 是否可以在 yaml 中使用枚举作为路径参数?
问题描述
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
推荐阅读
- react-native - 如何使用 React Native Animate 为不同的 Svg 属性设置动画
- java - YamlConfiguration 写入空文件
- javascript - Convert async/await style to traditional .then style
- php - 在表中插入记录后如何在mysql触发器中调用URL?
- windows - Powershell允许用户根据列表离线集群资源
- asp.net - 如何将所有 ASP 配置文件属性重置为其默认值?
- c# - 在 Swashbuckle 中,如何根据状态代码过滤模型
- javascript - Summernote 非引导版本的滚动问题
- sql - 在 SQL 中使用连接克隆的 ID
- r - ggline stat_compare_means function messing up y axis scale