首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring-boot 2和swagger 2 (springfox)不显示型号

Spring-boot 2和swagger 2 (springfox)不显示型号
EN

Stack Overflow用户
提问于 2020-10-15 21:14:28
回答 2查看 282关注 0票数 0

我已经创建了我的补丁端点( RFC 6902中指定的Json路径)。在由springfox生成的UI中,显示了我的端点,但没有显示模型示例(唯一的补丁)。

为了在我的Spring-boot2项目中使用Json补丁,我使用了对pom.xml的依赖。

代码语言:javascript
复制
<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>

在我的端点,我的代码是:

代码语言:javascript
复制
@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中使用它们的示例模型生成得很好。

唯一的补丁不能很好的工作。他们的示例模型没有生成。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-10-16 03:02:11

问题出在JsonPatch对象上,这个对象没有任何getter方法,所以Springfox库无法生成请求的模型。

一种可能的解决方案可能是这样的:使用getter和setter创建一个自定义的MyJsonPatch POJO,并使用MyJsonPatch的数据创建一个JsonPatch

票数 3
EN

Stack Overflow用户

发布于 2020-10-17 04:03:10

我找不到问题的解决方案,所以我决定使用来自Swagger的@ApiParam来描述这个字段是一个RFC6902实现。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64372379

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档