标签: springfox

SpringFox Swagger - 模型中的可选和必填字段

我使用SpringFox库来获取我的spring boot应用程序的休息文档.当我单击模型时,所有元素都将作为可选项返回.有没有办法将所需元素显示为必需元素?是否需要添加其他配置?

java spring swagger spring-boot springfox

9
推荐指数
1
解决办法
8110
查看次数

如何为swagger 2.8.0做友好的基本网址

我正在尝试更改 API 文档的基本访问 url。网址是“ http://localhost:8080/swagger-ui.html ”。我想得到类似“ http://localhost:8080/myapi/swagger-ui.html ”的东西。

我使用的是 Springfox 2.8.0 Swagger、Java 8、Spring Boot 2.0 的 swagger 配置是:

@Configuration
@EnableSwagger2
public class SwaggerConfiguration {

    @Bean
    public Docket api(ServletContext servletContext) {
        return new Docket(DocumentationType.SWAGGER_2)
                .pathProvider(new RelativePathProvider(servletContext) {
                    @Override
                    public String getApplicationBasePath() {
                        return "/myapi";
                    }
                })
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(Predicates.not(PathSelectors.regex("/error")))
                .build()
                .useDefaultResponseMessages(false);
    }
}
Run Code Online (Sandbox Code Playgroud)

自定义路径提供程序必须提供帮助,但我仍然可以通过使用 url“ http://localhost:8080/swagger-ui.html ”访问 api 文档。如果我使用 url " http://localhost:8080/myapi/swagger-ui.html ",我会收到404 错误。看看下面的截图。

在此处输入图片说明

java rest swagger spring-boot springfox

9
推荐指数
2
解决办法
2万
查看次数

Springfox 类参数已弃用

在 Springfox 3.0 中,springfox.documentation.service.Parameter已弃用。

是否有提供参数及其构建器的更新方法?

以及如何提供其default价值?

swagger springfox

9
推荐指数
2
解决办法
4766
查看次数

Spring Boot REST API:SpringDoc + OpenAPI 3 (springdoc-openapi-ui) 或 Swagger2 v3 (springfox-boot-starter)

有两种方法可以将 OpenAPI 3 添加到 Spring Boot 项目。

\n\n

https://www.dariawan.com/tutorials/spring/documenting-spring-boot-rest-api-springdoc-openapi-3/

\n\n

https://medium.com/@hala3k/setting-up-swagger-3-with-spring-boot-2-a7c1c3151545

\n

还有配置和注释的迁移问题

\n

问题是:对于 Spring Boot 项目,有什么理由在它们之间做出选择吗?

\n

更新:迁移到 OpenAPI 3。不太难:)也许会有帮助:

\n

OpenApiConfig ,\n pom.xml ,\n \xd0\x9e\xd0\xbf\xd0\xb8\xd1\x81\xd0\xb0\xd0\xbd\xd0\xb8\xd0\xb5

\n

swagger spring-boot springfox springdoc-openapi-ui

9
推荐指数
1
解决办法
5123
查看次数

如何为springfox修改swagger-ui.html?

我正在使用springfox的swagger实现.我想修改swagger-ui.html以获取自定义标头值.如何修改此文件?或者告诉spring fox使用备用文件?

springfox

8
推荐指数
1
解决办法
1万
查看次数

如何更改Swagger中成功操作的响应状态代码?

如图所示,它为添加操作显示"响应类(状态200)".但是,添加操作已经实现,它永远不会返回200.成功时返回201.

我的问题是如何将(状态200)更改为(状态201)?该部分的代码如下:

@RequestMapping(method = RequestMethod.PUT, value = "/add")
@ApiOperation(value = "Creates a new person", code = 201)
@ApiResponses(value = {
        @ApiResponse(code = 201, message = "Record created successfully"),
        @ApiResponse(code = 409, message = "ID already taken")
})
public ResponseEntity<String> add(@RequestParam(value = "name", required = true) String name,
        @RequestParam(value = "id", required = true) String id) {
    if (PD.searchByID(id).size() == 0) {
        Person p = new Person(name, id);
        PD.addPerson(p);
        System.out.println("Person added.");
        return new ResponseEntity<String>(HttpStatus.CREATED);
    } else {
        System.out.println("ID already taken.");
        return …
Run Code Online (Sandbox Code Playgroud)

java spring-mvc swagger-ui swagger-2.0 springfox

8
推荐指数
1
解决办法
4007
查看次数

Springfox swagger 继承支持

有没有办法在 springfox swagger (2.7.0) 中公开继承/多态性?我知道 swagger 规范支持 allOf。springfox 支持这个吗?下面是示例域模型。

@ApiModel
public abstract class Animal{
    private String name;
}

@ApiModel(parent=Animal.class)
public class Dog extends Animal{
    ...
}

@ApiModel(parent=Animal.class)
public class Cat extends Animal{
    ...
}
Run Code Online (Sandbox Code Playgroud)

如果控制器返回 Animal,则 swagger 合约不会公开 Cat 或 Dog。它只返回 Animal 及其属性。

java swagger springfox

8
推荐指数
1
解决办法
4109
查看次数

SpringFox - 隐藏 Swagger-ui 中调用端点不需要的某些字段

我想知道是否有任何方法可以使 SpringFox 不显示在调用特定端点时不需要的某个实体的所有字段。

例如:

具有以下实体:

public class Car {
    long id;
    String name;
    int wheels;
    String type;
    boolean canFly;
}
Run Code Online (Sandbox Code Playgroud)

以及以下端点:

@RequestMapping(method = RequestMethod.GET,
                produces = MediaType.APPLICATION_JSON_VALUE)
public Car get(@RequestParam(value = "carId", required = true) long projectId) {
    return carService.get(carId);
}

@RequestMapping(method = RequestMethod.POST,
                consumes = MediaType.APPLICATION_JSON_VALUE,
                produces = MediaType.APPLICATION_JSON_VALUE)
public Car create(@RequestBody Car car) {
    return carService.create(car);
}

@RequestMapping(method = RequestMethod.PUT,
                consumes = MediaType.APPLICATION_JSON_VALUE,
                produces = MediaType.APPLICATION_JSON_VALUE)
public Car update(@RequestBody Car car) {
    return carService.update(car);
}
Run Code Online (Sandbox Code Playgroud)

问题是,在 create Car …

java spring swagger swagger-ui springfox

8
推荐指数
1
解决办法
5990
查看次数

无法在 Spring 项目中配置 Swagger,获取 File not found 异常

我正在尝试为我的 spring 应用程序配置 swagger。下面是配置。但是,得到一个错误

[springfox/documentation/spring/web/SpringfoxWebMvcConfiguration.class] 无法打开,因为它不存在

Spring 版本 - 4.0.4 Springfox 版本 - 2.9.2

它不是 Maven 项目,我将所有必需的 jar 文件添加到类路径中。

弹簧上下文.xml

<bean id="Swagger" class="skt.test.SwaggerConfig" />

<mvc:resources mapping="swagger-ui.html" location="classpath:/META-INF/resources/"/>

    <mvc:resources mapping="/webjars/**" location="classpath:/META-INF/resources/webjars/"/> 
Run Code Online (Sandbox Code Playgroud)

Swagger 配置类

package skt.test;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
@EnableWebMvc
public class SwaggerConfig {                                    
    @Bean
    public Docket api() { 
        return new Docket(DocumentationType.SWAGGER_2)  
          .select()                                  
          .apis(RequestHandlerSelectors.any())              
          .paths(PathSelectors.any())                          
          .build();

    }

}
Run Code Online (Sandbox Code Playgroud)

包含 Jar 文件 https://i.imgur.com/sYaYnrY.png

org.springframework.beans.factory.BeanDefinitionStoreException: …
Run Code Online (Sandbox Code Playgroud)

java rest spring swagger springfox

8
推荐指数
1
解决办法
1万
查看次数

更新到最新版本后替换@EnableSwagger2

我迁移到最新springfox-swagger2版本,2.10.0但看起来@EnableSwagger2已被弃用。

为了在 Spring Boot 项目中启用 Swagger,我应该使用什么注释?@EnableSwagger2WebMvc?

spring swagger swagger-2.0 springfox

8
推荐指数
2
解决办法
1万
查看次数