我有一个弹簧(引导)服务器,并想从带有 springdoc 的注释中生成 openapi 规范。
我在请求正文中有一个带有两个参数的请求。我希望第一个是必需的,第二个是可选的
@RequestBody(required = {true|false})
似乎只将正文中的所有参数设置为(不是)必需的。@Parameter
另一方面,Javadoc说要使用io.swagger.v3.oas.annotations.parameters.RequestBody
这是我的代码,我希望生成一个规范,其中第一个参数是必需的,第二个是可选的:
@GetMapping("/fstVector")
public ResponseEntity<Vector> fstV(@RequestBody final Vector v1, @RequestBody(required = false) final Vector v2) {
return new ResponseEntity<>(v1, HttpStatus.OK);
}
@PostMapping("/fstVector")
public ResponseEntity<Vector> fstVPost(@RequestBody(required = true) final Vector v1, @RequestBody(required = false) final Vector v2) {
return new ResponseEntity<>(v1, HttpStatus.OK);
}
然而,生成的规范需要两个参数:
/pond/fstVector:
get:
tags:
- circle-escape-controller
operationId: fstV
parameters:
- name: v1
in: query
required: true
schema:
$ref: '#/components/schemas/Vector'
- name: v2
in: query
required: true
schema:
$ref: '#/components/schemas/Vector'
responses:
"200":
description: OK
content:
'*/*':
schema:
$ref: '#/components/schemas/Vector'
post:
tags:
- circle-escape-controller
operationId: fstVPost
requestBody:
content:
application/json:
schema:
type: object
properties:
v1:
$ref: '#/components/schemas/Vector'
v2:
$ref: '#/components/schemas/Vector'
required: true
responses:
"200":
description: OK
content:
'*/*':
schema:
$ref: '#/components/schemas/Vector'
我怎样才能只要求所有四种请求类型的特定参数?