swagger

swagger小使用

懵懂的女人 提交于 2020-01-12 04:04:21
swagger默认访问地址 一般为:项目地址+项目端口+/swagger-ui.html sawgger在springboot中如何使用 引入maven依赖 < dependency > < groupId > io . springfox < / groupId > < artifactId > springfox - swagger2 < / artifactId > < / dependency > < dependency > < groupId > io . springfox < / groupId > < artifactId > springfox - swagger - ui < / artifactId > < / dependency > 创建一个SwaggerConfig类 @Configuration @EnableSwagger2 @ComponentScan ( "org.demo.energy.sys.controller" ) public class SwaggerConfig { @Bean public Docket createRestApi ( ) { return new Docket ( DocumentationType . SWAGGER_2 ) . apiInfo ( apiInfo ( ) ) . select ( ) .

Swagger not detecting Spring Data Rest APIs with Spring Boot

独自空忆成欢 提交于 2020-01-12 01:37:07
问题 I setup a Spring Boot project including Spring Data Rest and Swagger: <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-rest</artifactId> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.4.0</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.4.0</version> </dependency> This is my Swagger configuration:

How to specify multiple 404 causes in OpenAPI (Swagger)?

回眸只為那壹抹淺笑 提交于 2020-01-11 08:57:09
问题 I'm defining a path for a nested resource (content belonging to a delivery). If the client gets a 404 it could either because the delivery ID was not found, or the delivery did not contain any content of the specified type. How do I model that using OpenAPI (YAML)? I've got this right now... paths: '/deliveries/{id}/content/articles': get: summary: Retrieves articles from a delivery description: Retrieves all articles from a single delivery [...] responses: '200': description: articles found

Adding JAR with ObjectMapper makes my ObjectMapper non-discoverable

狂风中的少年 提交于 2020-01-11 05:33:27
问题 How can I make my object mapper work in situation when there is another object mapper defined in jar from dependencies ? I'm trying to use Swagger with Jersey 2 which is being run under Jetty. The problem is that as soon as I add Swagger JAX-RX jar into classpath my object mapper is not discovered therefore I lose custom serialization of my objects. Here is how my object mapper defined @Provider public class ObjectMapperProvider implements ContextResolver<ObjectMapper> { } I've posted issue

SpringBoot 整合 swagger2 实现快速测试和快速生成 API 文档

眉间皱痕 提交于 2020-01-10 18:45:06
现在很多项目都是前后端分离模式,所以在开发团队中经常需要写 API 文档,便于前后端开发对接。 若手写 API 文档,则有以下几个痛点: 文档需要更新的时候,需要再次发送一份给前端,也就是文档更新交流不及时。 文档编写需要单独占用时间,占用人力 接口文档太多,不好管理 不能直接在线测试接口,通常需要使用工具,比如 postman SpringBoot 项目整合 swagger2 插件,可以快速生成接口文档,便于测试接口。当然 swagger2 也有缺点,最明显的就是代码移入性比较强。下面简单介绍下如何在项目中使用 swagger2。 一、在 pom.xml 里面添加 jar 依赖 < 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 > 二

SpringBoot快速上手《三》:SpringBoot Restful 风格Api+swagger

我只是一个虾纸丫 提交于 2020-01-10 18:01:08
SpringBoot Restful 风格Api开发+SpringBoot 集成Swagger github源码: https://github.com/xivinChen/SpringBoot 一.Restful 风格API restful API 命名禁止出现动词,即用请求方式区分动作。如下: get 查询接口 post 新增接口 put 更新接口 delete 删除接口 1.maven-archetype-quickstart方式创建模块springboot-restful-api 2.把springboot-ssm模块的代码和配置复制过来,不需要额外引入依赖。 3.修改UserController代码,改成Restful接口 @RestController @RequestMapping("/user") public class UserController { @Resource private UserMapper userMapper; //@RequestMapping("/listByUser") @GetMapping("/") public List<User> listByUser() { return userMapper.list(); } //@RequestMapping("/getOneUser") @GetMapping("/{id}")

springCloud+mybatis搭建项目

℡╲_俬逩灬. 提交于 2020-01-10 12:57:05
一、新建项目 1: 点击next 2、 3、下一步选择插件(可不选) web下我选择spring web 项目新建完成 此时我的项目如下图 二、相关项目配置 1:打开swagger web服务 我们需要在Application启动程序上添加 @EnableSwagger2 注解同时添加swagger依赖,否则打开页面会显示 a、添加依赖1 <dependency> <groupId>io.github.wilson-he</groupId> <artifactId>swagger2-spring-boot-starter</artifactId> <version>LATEST</version> </dependency> 并且在yml文件中添加下面配置 swagger: print-init: true enabled: true security-configuration: client-id: client-1 client-secret: secretA scope-separator: \, use-basic-authentication-with-access-code-grant: true dockets: docket-api: base-package: cn.yufeng.transport.controller group-name: api api

How to avoid CORS errors (“Failed to fetch” or “Server not found or an error occurred”) when making requests from Swagger Editor?

放肆的年华 提交于 2020-01-10 05:29:09
问题 I have the following OpenAPI definition: swagger: "2.0" info: version: 1.0.0 title: Simple API description: A simple API to learn how to write OpenAPI Specification schemes: - https host: now.httpbin.org paths: /: get: summary: Get date in rfc2822 format responses: 200: schema: type: object items: properties: now: type: object rfc2822: type: string I would like to retrieve rfc2822 from the response: {"now": {"epoch": 1531932335.0632613, "slang_date": "today", "slang_time": "now", "iso8601":

WebApi接口文档

巧了我就是萌 提交于 2020-01-10 04:14:03
使用Swagger 1.引用swagger nuget包 Swashbuckle和Swagger.Net.UI两个包 2.卸载重复包Swagger.Net   引用Swagger.Net.UI时会引用Swagger.Net这个包,但是Swagger.Net的功能和Swashbuckle重复了,采取了卸载 Swagger.Net。 3.删除多余的SwaggerUI文件夹 4. 删除多余的配置类SwaggerNe 5. 项目属性->勾选生成xml文档文件 6. 修改SwaggerConfig文件,设置接口描述XML路径地址 c.IncludeXmlComments(string.Format("{0}/bin/SwaggerDemo.XML", System.AppDomain.CurrentDomain.BaseDirectory));2.汉化及控制器注释 1.在SwaggerConfig配置文件中有这么一段代码 .EnableSwaggerUi(c =>{ //c.InjectJavaScript(thisAssembly, "Swashbuckle.Dummy.SwaggerExtensions.testScript1.js")//这个地址是放的js文件汉化 }); 2. JS文件属性 操作改为嵌入的资源 3.js文件内容 汉化 /// <summary> /// 中文转换 //

IIS site within virtual directory Swagger UI end point

梦想的初衷 提交于 2020-01-10 04:08:06
问题 Swagger UI end point is not same as dev in staging ( excluding domain names) IIS Configuration public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) app.UseSwagger(c=> { //Change the path of the end point , should also update UI middle ware for this change c.RouteTemplate = "api-docs/{documentName}/swagger.json"; }); app.UseSwaggerUI(c => { //Include virtual directory if site is configured so c.SwaggerEndpoint(Configuration["Appsettings