swagger

What's the best way to convey required/optional DTO properties in ServiceStack?

心不动则不痛 提交于 2019-12-10 04:29:37
问题 I'm having an issue with my ServiceStack w/ Swagger implementation regarding documenting required/optional properties. Developers implementing clients that consume my services love the Swagger documentation, however they don't know which properties are required vs. optional--aside from getting a 400 response on each attempt to get a valid request through. Take the following example: public class UserProfile { public string FirstName { get; set; } public string LastName { get; set; } public

How to generate Options(CORS) with Swagger

别说谁变了你拦得住时间么 提交于 2019-12-10 04:22:55
问题 For a project we are working on we are generating an Swagger File automatically. However at this moment we are struggling with the CORS part. We are using the Amazon API gateway import api functionality. To use this in combination with Swagger and CORS, we have to create an additional action (operation) in our source code which allows CORS(options) for each api method (operation)! eg: [HttpOptions] [Route("{id}")] [ProducesResponseType((int)HttpStatusCode.OK)] public IActionResult UserOptions

使用Spring MVC开发RESTful API(续)

陌路散爱 提交于 2019-12-10 04:06:06
使用多线程提高REST服务性能 异步处理REST服务,提高服务器吞吐量 使用Runnable异步处理Rest服务 AsyncController.java @RestController @GetMapping("/async") public class AsyncController { private Logger logger = LoggerFactory.getLogger(getClass()); @RequestMapping("/order") public Callable<String> order() throws Exception { logger.info("主线程开始"); Callable<String> result = new Callable<String>() { @Override public String call() throws Exception { logger.info("副线程开始"); Thread.sleep(2000); // 模拟处理下单消耗的时间 logger.info("副线程结束"); return "success"; } }; logger.info("主线程结束"); return result; } } 使用DeferredResult异步处理Rest服务 应用1/线程1:接收下单请求,放到消息队列

How to define header parameters in OpenAPI 3.0?

删除回忆录丶 提交于 2019-12-10 03:39:41
问题 In OpenAPI (Swagger) 2.0, we could define header parameters like so: paths: /post: post: parameters: - in: header name: X-username But in OpenAPI 3.0.0, parameters are replaced by request bodies, and I cannot find a way to define header parameters, which would further be used for authentication. What is the correct way to define request headers in OpenAPI 3.0.0? 回答1: In OpenAPI 3.0, header parameters are defined in the same way as in OpenAPI 2.0, except the type has been replaced with schema

Remove a route with IOperationFilter in SwashBuckle

☆樱花仙子☆ 提交于 2019-12-10 02:36:57
问题 I am looking for a way to show/hide WebAPI routes in the Swagger documentation using SwashBuckle in a configurable way. Adding [ApiExplorerSettings(IgnoreApi = true)] will indeed hide the routes but I'd need to recompile every time I want that to change. I have looked into creating an IOperationFilter to work with a custom Attribute that I defined. That way I can decorate the routes with a [SwaggerTag("MobileOnly")] and check the web.config or something to see if the route should be shown.

Make parameters in swashbuckle optional(not required)

家住魔仙堡 提交于 2019-12-10 02:36:35
问题 I want to make param in my controller as optional but swagger shows it as required. my controller looks like: [HttpGet("{name}")] [SwaggerResponse((int)HttpStatusCode.OK)] [SwaggerResponse((int)HttpStatusCode.BadRequest)] public async Task<IActionResult> GetPolicy(string name) { if (string.IsNullOrEmpty(name)) { return BadRequest("Name is empty"); } try { CRUDPolicyResponse crudPolicyResponse = await _managementOperations.CRUDPolicy(CRUDType.Read, name, null); if (!crudPolicyResponse

Is there a way change the Controller's name in the swagger-ui page?

帅比萌擦擦* 提交于 2019-12-10 01:00:44
问题 I'm using Swashbuckle to enable the use of swagger and swagger-ui in my WebApi project. In the following image you can see two of my controllers shown in the swagger-ui page. These are named as they are in the C# code, however I was wondering if there was a way to change what is shown here? This is mainly because as you can see ManagementDashboardWidget is not a user friendly name, so I want to change it to be user friendly. 回答1: You can use tags for that. By default Swashbuckle adds a tag

SpringBoot整合Swagger测试api构建

社会主义新天地 提交于 2019-12-09 17:12:10
什么是Swagger? Swagger是什么:THE WORLD’S MOST POPULAR API TOOLING 根据官网的介绍: Swagger Inspector:测试API和生成OpenAPI的开发工具。Swagger Inspector的建立是为了解决开发者的三个主要目标。 执行简单的API测试 生成OpenAPI文档 探索新的API功能 如果想学习Java工程化、高性能及分布式、深入浅出。微服务、Spring,MyBatis,Netty源码分析的朋友可以加我的Java高级交流:854630135,群里有阿里大牛直播讲解技术,以及Java大型互联网技术的视频免费分享给大家。 我的理解Swagger是一个规范和完整的框架,用于生成、描述、调用和可视化RESTful风格的Web服务。简单来说,Swagger是一个功能强大的接口管理工具,并且提供了多种编程语言的前后端分离解决方案。根据我的使用,当然我只是最简单的使用,我感觉Swagger有以下几个优点: Swagger可以整合到代码中,在开发时通过注解,编写注释,自动生成API文档。 将前端后台分开,不会有过分的依赖。 界面清晰,无论是editor的实时展示还是ui的展示都十分人性化,如果自己仅仅用markdown来编写,又要纠结该如何展现,十分痛苦。 构建项目 step1.导入依赖 <!-

.NET Core 2 and SwashBuckle Swagger UI is not Displaying

限于喜欢 提交于 2019-12-09 16:35:42
问题 I have followed a few tutorials and have gotten this to work at work but for some reason I am not able to get the UI to display but the Swagger Json is created. Last tutorial I looked at is here. My setup is like so: Nuget Package: Swashbuckle.AspNetCore(1.0.0) ConfigureServices Method: services.AddSwaggerGen(options => { options.SwaggerDoc("v1", new Info { Title = "MediatR Example", Version = "v1", Description = "Trying out the MediatR library to simplify Request and Response logic.",

How to define a map in swagger?

夙愿已清 提交于 2019-12-09 15:46:26
问题 I'm working on an API which also generates swagger documentation. The issue is that for some reasons the request model/schema is not displayed in swagger UI but I don't get any error either. I need to represent map to an array of strings . e.g. map[string][]string. Definition object definition is below. { "definitions": { "versions": { "type": "string", "additionalProperties": { "type": "array", "items": { "type": "string" } } } } } 回答1: The support for maps is still not available in the UI -