我已经创建了我的补丁端点( RFC 6902中指定的Json路径)。在由springfox生成的UI中,显示了我的端点,但没有显示模型示例(唯一的补丁)。
为了在我的Spring-boot2项目中使用Json补丁,我使用了对pom.xml的依赖。
<dependencies>
<dependency>
<groupId>com.github.java-json-tools</groupId>
<artifactId>json-patch</artifactId>
<version>1.12</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.11.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<scope>compile</scope>
</dependency>
</dependencies>在我的端点,我的代码是:
@RestController
@RequestMapping(value = "/operation", produces = "application/json")
public class IntentController {
@RequestMapping(value = "/{id}",
method = RequestMethod.PATCH,
consumes = "application/json-patch+json")
public void updateValue(@PathVariable Long id, @RequestBody JsonPatch patch){ {
// ... do magic
}
@RequestMapping(value = "/{id}",
method = RequestMethod.GET)
public MyDto getValue(@PathVariable Long id){ {
MyDto dto = service.findById(id);
return dto;
}
@RequestMapping(method = RequestMethod.POST)
public void updateValue(@RequestBody MyDto dto){ {
service.insert(dto);
}
}我的GET和POST端点在UI中使用它们的示例模型生成得很好。
唯一的补丁不能很好的工作。他们的示例模型没有生成。
发布于 2020-10-16 03:02:11
问题出在JsonPatch对象上,这个对象没有任何getter方法,所以Springfox库无法生成请求的模型。
一种可能的解决方案可能是这样的:使用getter和setter创建一个自定义的MyJsonPatch POJO,并使用MyJsonPatch的数据创建一个JsonPatch。
发布于 2020-10-17 04:03:10
我找不到问题的解决方案,所以我决定使用来自Swagger的@ApiParam来描述这个字段是一个RFC6902实现。
https://stackoverflow.com/questions/64372379
复制相似问题