我想在OpenAPI规范的函数的查询字符串参数中定义一个枚举值。
以下是我如何在我的OpenAPI规范(yaml)中指定参数的示例:
openapi: 3.0.0
info:
description: Vends sodas
version: 1.0.0
title: VendingMachineService
paths:
/soda/{bill}:
get:
summary: Provides a soda for a provided amount of money
description: Provides a soda for a provided amount of money
operationId: getSoda
parameters:
- name: bill
in: path
description: Money (e.g. one, two, five)
required: true
schema:
$ref: "#/components/schemas/Bill"
responses:
"200":
description: Success
content:
application/json:
schema:
$ref: "#/components/schemas/Result"
"404":
description: Templates for Source not found
servers:
- url: http://localhost:8080/
components:
schemas:
Bill:
type: string
enum:
- one
- two
- five
Result:
type: string
OpenAPI规范的关键部分是我在底部的架构对象中定义枚举,键入字符串,然后在函数的参数部分中引用它,还将其定义为路径/ {bill的一部分}
然后我使用openapi-generator生成spring服务器:
openapi-generator generate -i ~/vending-machine.yaml -g spring -o ~/output
然后,我启动服务器(将项目导入Intellij并以spring-boot配置运行)并转到localhost:8080 /打开Swagger UI。我尝试锻炼api并收到以下错误:
{“ timestamp”:“ 2019-03-29T15:43:14.737Z”,“ status”:400,
“错误”:“错误的请求”,“消息”:“无法转换类型的值 'java.lang.String'为必需的类型'org.openapitools.model.Bill'; 嵌套异常为 org.springframework.core.convert.ConversionFailedException:失败 从类型[java.lang.String]转换为类型 [@ javax.validation.constraints.NotNull @ io.swagger.annotations.ApiParam @ javax.validation.Valid @ org.springframework.web.bind.annotation.RequestParam org.openapitools.model.Bill]值“ null”;嵌套异常为 java.lang.IllegalArgumentException:没有枚举常量 org.openapitools.model.Bill.null“,”路径“:” / soda /%7Bbill%7D“}
(预计未实现501)
在OpenAPI规范中定义查询参数和枚举以使用枚举值的正确方法是什么?