gpt4 book ai didi

swagger - OpenAPI 规范 : default value of query param is ignored

转载 作者:行者123 更新时间:2023-12-05 02:28:56 24 4
gpt4 key购买 nike

我将 OpenAPI 3 规范中的参数描述为

review_requests:
get:
tags:
- dashboard
operationId: reviewRequests
parameters:
- name: page
in: query
default: 0
description: Page number
schema:
type: integer
responses:
200:
description: OK

编译后我发现 Java 代码中缺少默认值,参数实际上描述如下:

@Valid @RequestParam(value = "page", required = false) Integer page

如果 GET 请求中未提供参数,我将收到 null 而不是 0。据我了解应该是

@Valid @RequestParam(value = "page", required = false, defaultValue = "0") Integer page

这是错误还是我做错了什么?

最佳答案

最后我找到了解决方案:在 OpenAPI 3.x 中,必须在参数的 schema 中指定默认值。换句话说,而不是

    parameters:
- name: page
in: query
default: 0
description: Page number
schema:
type: integer

应该是

    parameters:
- name: page
in: query
description: Page number
schema:
type: integer
default: 0

关于swagger - OpenAPI 规范 : default value of query param is ignored,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72433670/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com