Controller有以下方法:
@ApiResponses(value = {@ApiResponse(responseCode = "200")})
@GetMapping(value = API_URI_PREFIX + PRODUCTS_URI, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public Flux<Product> getProducts(@Valid @NotNull PagingAndSorting pagingAndSorting) {
}
我需要找到一种方式来显示Swagger
的例子PagingAndSorting
object.
我在用springdoc-api
v1.4.3.
您可以使用@ExampleObject注释。
请注意,如果您想引用示例现有对象,您还可以在示例中使用 ref @ExampleObject(ref="...")。或者理想情况下,从外部配置文件中获取示例并使用 OpenApiCustomiser 添加它们,就像此测试中所做的那样:
- https://github.com/springdoc/springdoc-openapi/blob/master/springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app90/SpringDocTestApp.java https://github.com/springdoc/springdoc-openapi/blob/master/springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app90/SpringDocTestApp.java
以下是使用 @ExampleObject 的示例代码:
@PostMapping("/test/{id}")
public void testme(@PathVariable("id") String id, @RequestBody(content = @Content(examples = {
@ExampleObject(
name = "Person sample",
summary = "person example",
value =
"{\"email\": [email protected] /cdn-cgi/l/email-protection,"
+ "\"firstName\": \"josh\","
+ "\"lastName\": \"spring...\""
+ "}")
})) PersonDTO personDTO) { }
如果您正在使用@RequestBody
控制器中的 Spring 注释需要区分两者,例如使用@io.swagger.v3.oas.annotations.parameters.RequestBody
用于 Swagger 注释。这可以防止下面评论中提到的空参数问题。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)