swagger

Swagger

非 Y 不嫁゛ 提交于 2020-01-07 15:24:06
1.创建spring boot项目 2.导入jar <!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui --> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.9.2</version> </dependency> <!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 --> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.9.2</version> </dependency> 3.编写一个Hello 工程 4.配置swagger ==>Config @Configuration br/>@EnableSwagger2//开启swagger2 public class SwaggerConfig { } 5.测试运行: http://127.0.0.1:8080/swagger-ui.html

Swagger项目错误解析

不羁的心 提交于 2020-01-07 14:52:08
解决方案 然后启动项目 最合理的解决方案: 其他解决方案,出现的连锁反应; 解决方案一: 连锁出现的问题: 解决连锁出现的问题 方案一: 解决方法一: @ ComponentScan ( { "com.example.demo.config" } ) 上面的问题已解决 但是继续连锁出现问题 该问题待解决,此路暂时不通 方案二: 直接把 @EnableSwagger2 注解加在主启动类就可以了, 上面的问题已解决 但是会出现以下问题方法和类,出现 error 解决访问 swaggerUI 接口文档显示 basic-error-controler 问题 暂时没有找到,此路不通 方案三 虽然解决报错,但是该属性,是规避找不到bean,所以该方案不行 最总分析: 首先,出现连锁最根本的问题在于, @ComponentScan和@MapperScan 注解使用 继续分析 之前用户使用的是3个注解注解他们的 main 类。分别是 @Configuration , @EnableAutoConfiguration , @ComponentScan 。 如果 @SpringBootApplication 和 @ComponentScan 注解共存,那么 @SpringBootApplication 注解的扫描的作用将会失效,也就是说不能够扫描启动类所在包以及子包了。因此,我们必须在

springboot集成swagger

懵懂的女人 提交于 2020-01-07 12:36:39
  Swagger 是一个规范和完整的框架,用于生成、描述、调用和可视化 RESTful 风格的 Web 服务。总体目标是使客户端和文件系统作为服务器以同样的速度来更新。 作用: 接口的文档在线自动生成。 功能测试。 1、配置pom.xml <!-- swagger --> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.9.2</version> </dependency> <!-- swagger-ui --> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.9.2</version> </dependency> <!-- jackson相关依赖 --> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.5.4</version> </dependency> <dependency> <groupId

Swagger/Swashbuckle document POST with JSON

↘锁芯ラ 提交于 2020-01-07 03:08:10
问题 I have a challenge with Swashbuckle or Swagger. I'm not sure if the problem is with Swagger or Swashbuckle. I have web api call, implemented both with the parameter as URI params, and with reading the content from the body of the request. One is implemented like this: [Route("application/uri")] [HttpPost] public async Task<string> Post([ModelBinder] Application application) { return await RegisterApplication(application); } The other is implemented like this: [Route("loanapplication/json")]

Spring Cloud微服务接口这么多怎么调试?

帅比萌擦擦* 提交于 2020-01-06 18:38:20
前言 今天和大家聊一下Spring Cloud微服务下服务接口调试及管理的话题!我们知道在微服务架构下,软件系统会被拆分成很多个独立运行的服务,而这些服务间需要交互通信,就需要定义各种各样的服务接口。具体来说,在基于Spring Cloud的微服务模式中,各个微服务会基于Spring MVC的Controller定义多个该微服务需要向外部发布的接口。 根据各个微服务功能边界定义的不同,有些微服务会提供与具体业务相关的接口,如支付接口、账户接口等;而有些微服务则会提供一些公共性质的服务接口,如短信接口、统一认证接口之类。而这些微服务往往又是由多个不同的团队在开发维护,传统方式下服务接口的定义往往需要服务提供方提供良好的、可阅读性比较高的接口文档才可以比较方便地对接和测试,而事实上,随着时间的推移、人员的迭代更新,很多情况下这些早期的接口文档往往很快就会因为无人维护而过时,即便不过时,微服务模式下这样的方式也会因为服务接口文档太多而让开发人员显得抓狂! 那么有没有一种更便捷地方式,可以让开发接口的同时,自动就能生成与服务接口高度一致的文档来呢?答案是有的,接下来就和大家一起聊聊到底有什么样方式可以让微服务的接口管理变得更加容易些! 接口管理方式介绍 事实上,市面上已经有多种开源项目提供了这样的支持!如:Swagger、ApiDoc、RAP、DOCLever、CrapApi等

Asp.net Core WebApi使用Swagger

余生长醉 提交于 2020-01-06 16:20:33
1、安装: NuGet:搜索Swagger,安装Swashbuckle.AspNetCore 2、配置XML文件:右键项目--生成--XML文档,记录xml文档的位置并修改第3步中xml文档的名称 3、配置swagger中间件 // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); //注册Swagger生成器,定义一个和多个Swagger 文档 services.AddSwaggerGen(c => { c.SwaggerDoc("v1.0", new Info { Title = "My Demo API", Version = "1.0" }); c.IncludeXmlComments(System.IO.Path.Combine(System.AppContext.BaseDirectory, "SwaggerCoreApi.xml")); }); } View Code

Html Example Response with Swagger and Swashbuckle

醉酒当歌 提交于 2020-01-06 11:48:30
问题 I have a .NET Web API 2 app, with a controller method that returns HTML. I want to provide sample HTML in the swagger docs, but I can't get anything to show. This is what I have: [HttpGet] [SwaggerResponse(HttpStatusCode.OK, Type = typeof(string))] [SwaggerResponse(HttpStatusCode.NotFound)] [SwaggerResponseContentType("text/html", Exclusive = true)] [SwaggerResponseExamples(typeof(string), typeof(ExampleProvider))] public async Task<HttpResponseMessage> Get(Guid id) { var example = GetExample

Swagger file with AWS Extensions stored in S3 Bucket for API Creation with Cloudformation

…衆ロ難τιáo~ 提交于 2020-01-06 08:28:12
问题 I'm trying to create an API Gateway using a Cloudformation template like this: Resources: InvoiceApi: Type: AWS::ApiGateway::RestApi Properties: Description: an Api for our Invoicegen App Name: !Ref ApiName ApiKeySourceType: !Ref ApiKeySourceType BinaryMediaTypes: - !Ref binaryMediaType1 - !Ref binaryMediaType2 BodyS3Location: Bucket: Fn::ImportValue: !Sub ${EnvironmentName}-SwaggerApiBucket-Name Key: swaggertest.yaml ETag: !Ref ETag EndpointConfiguration: Types: - REGIONAL FailOnWarnings:

“ERROR Server not found or an error occurred” while Using Swagger Spec Post Method

*爱你&永不变心* 提交于 2020-01-06 05:40:51
问题 I'm creating a simple get/post api, when I use post Method I get "ERROR Server not found or an error occurred", even when I run it from POSTMAN or from chrome (Where I have installed CORS Toggle extension) my server is running on: http://localhost:10010 My Spec : swagger: "2.0" info: version: "0.0.1" title: Todo API # during dev, should point to your local machine host: localhost:10010 # basePath prefixes all resource paths basePath: / # schemes: # tip: remove http to make production-grade -

Display Custom HashMap Key Using Swagger Annotations

Deadly 提交于 2020-01-05 04:20:18
问题 I'm trying to generate Swagger documentation from Java code and one of my nested model properties is a HashMap. The generated example for it is as follows: "additionalProp1": { "customObject": {} }, "additionalProp2": { "customObject": {} }, "additionalProp3": { "customObject": {} } What I need it to look like is: "objectName": { "customObject": {} } In other words, I need to tell them what the additionalProp String should be and preferably not have it repeated three times. Is there any way