我正在使用java spring boot框架为我的项目创建REST api,我使用"springfox-swagger2和springfox-swagger-ui"来生成swagger文档.我可以使用url http:// localhost:8080/swagger-ui.html查看我的文档.
如何创建或生成swagger.json/spec.json,文档不应该与此应用程序一起使用我们使用单独的应用程序列出api文档
我使用Java中的JAX-RS/Jersey开发了我的REST API.我想为它转换为/生成基于Swagger的UI文档.任何人都可以告诉我精确/步骤简单的方法如何这样做?对不起,但他们网站上的步骤对我来说有点模糊.
我正在使用Springfox库来生成REST服务的文档,并在Swagger UI中显示它.我按照Springfox文档中的说明进行操作.
我有一个控制器,它使用查询字符串中的参数,方法映射如下:
@ApiOperation(value = "")
@RequestMapping(method = GET, value = "/customcollection/{id}/data")
public Iterable<CustomeType> getData(@ApiParam(value = "The identifier of the time series.")
@PathVariable String id,
@ApiParam(name = "startDate", value = "start date", defaultValue = "")
@RequestParam("startDate") String startDate,
@ApiParam(name = "endDate", value = "end date", defaultValue = "")
@RequestParam("endDate") String endDate)
Run Code Online (Sandbox Code Playgroud)
swagger-ui中生成的映射器显示为:
GET /customcollection/{id}/data{?startDate,endDate}
Run Code Online (Sandbox Code Playgroud)
但是当我点击Try it Out时,请求URL会被误认为:
http:// localhost:8080/customcollection/1/data {?startDate,endDate}?startDate = 1&endDate = 2
怎么修好?
如何导出Swagger定义文件(它应该是JSON或YAML文件)?我被要求这样做,而且我对Swagger只有粗略的了解.
我们确实有一个端点http://example.com//swagger/ui/index#!看起来像这样(截图不是我们真正的端点,但我不能发布):
版本是api version: v1.
我看不到"导出"按钮.那么我该如何导出呢?
我正在探索Swagger,我必须承认我很喜欢它.
我知道Swagger主要用于RESTful Web服务,但我想知道我们是否可以使它与SOAP Web服务一起使用.可能是将基于SOAP的Web服务转换为RESTful?或者只是通过Swagger UI调用基于SOAP的服务?一些黑客?有人做过吗?
按照此处的说明操作:
http://www.baeldung.com/swagger-2-documentation-for-spring-rest-api
我将这些依赖项添加到我的项目中:
compile "io.springfox:springfox-swagger2:2.7.0"
compile "io.springfox:springfox-swagger-ui:2.7.0"
Run Code Online (Sandbox Code Playgroud)
并像这样配置 SpringFox Swagger:
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
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)
但是 Swagger UI 似乎没有启用。我试过:
我得到的只是:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Mon Sep 11 09:43:46 BST 2017
There was an …Run Code Online (Sandbox Code Playgroud) 为什么springfox-swagger2 UI告诉我Unable to infer base url. 据我所知,我使用的是典型的Swagger spring-boot配置.
正如您在屏幕截图中看到的那样,支持UI的swagger-fox网址是example.com/api.注意:Whitelabel Error Page 当我导航到https:// localhost:9600/api/v2/api-docs /时, 我得到一个标准的Spring .我怀疑这是问题的根源?我没有看到Spring没有加载的错误,springfox-swagger2所以我不知道为什么这不起作用.
我的配置看起来像这样(我已尝试过此配置的各种变体,从网上搜索建议):
@EnableSwagger2
@EnableWebMvc
@ComponentScan(basePackages = {"com.company.project"})
public class SwaggerConfig
{
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(Predicates.not(RequestHandlerSelectors.basePackage("org.springframework.boot")))
.apis(Predicates.not(RequestHandlerSelectors.basePackage("org.springframework.cloud")))
.apis(Predicates.not(RequestHandlerSelectors.basePackage("org.springframework.data.rest.webmvc")))
.paths(PathSelectors.any())
.build();
}
}
Run Code Online (Sandbox Code Playgroud)
和
<!-- to generate /swagger-ui.html -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.7.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
注意:有趣的是,当我尝试2.6.0版时,我没有获得模态弹出窗口,但我的Swagger UI显示0 api内容.所以,我知道模态必须是相当新的?
如果这里没有足够的信息,请给我留言.
我已将Swagger添加到Spring Boot 2应用程序中:
这是我的Swagger配置:
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket api() {
// @formatter:off
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build();
// @formatter:on
}
}
Run Code Online (Sandbox Code Playgroud)
这是Maven依赖:
<!-- Swagger2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.8.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
当我尝试调用例如http:// localhost:8080/api/actuator/auditevents时, 它失败并出现以下错误:
TypeError: Failed to execute 'fetch' on 'Window': Request with GET/HEAD method cannot have body.
Run Code Online (Sandbox Code Playgroud)
我做错了什么以及如何解决?
什么是swagger-ui以及它的用途是什么?
有没有什么好的资源可以开始使用swagger-ui?任何好的教程,博客或书籍?
我也访问http://swagger.io/,但我需要更多信息.
请指导我.谢谢你
带有 springdoc-openapi-ui (Swagger UI) 的 Spring Boot 2.2 应用程序运行 HTTP 端口。该应用程序部署到 Kubernetes,并通过 Ingress 将 HTTPS 请求从集群外部路由到服务。
在这种情况下,可用的 Swagger UIhttps://example.com/api/swagger-ui.html有错误的“生成的服务器 url”- http://example.com/api。虽然应该如此https://example.com/api。
虽然 Swagger UI 通过 HTTPS 访问,但生成的服务器 URL 仍然使用 HTTP。
swagger-ui ×10
swagger ×8
spring-boot ×4
swagger-2.0 ×4
springfox ×2
java ×1
openapi ×1
rest ×1
restful-url ×1
soap ×1
spring ×1
spring-mvc ×1
web-services ×1