swagger

springboot整合swagger2

北城余情 提交于 2019-12-10 20:59:09
依赖: <!--swagger! start--><dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.6.1</version></dependency><dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.6.1</version></dependency><!--swagger! end-->新建类 @Configuration@EnableSwagger2public class SwaggerConfig { @Value("${swagger.enable}") private Boolean enable;@Beanpublic Docket createRestApi() { return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()) .enable(enable) .select() .apis(RequestHandlerSelectors.basePackage("com")) .paths

Swagger UI - can't enable JSON editor for the request body

强颜欢笑 提交于 2019-12-10 19:44:05
问题 I have some issue to make it work, according to following link below, the JSON editor for the request body (disabled by default). https://github.com/jensoleg/swagger-ui How can I enable it? 回答1: I found the solution. Add the following into index.html in the new SwaggerUi({}) constructor: docExpansion: "none", sorter: "alpha", jsonEditor: true, defaultModelRendering: 'schema', showRequestHeaders: true 来源: https://stackoverflow.com/questions/37441859/swagger-ui-cant-enable-json-editor-for-the

Indicate required properties of complex input parameter object in Swagger UI

两盒软妹~` 提交于 2019-12-10 19:39:03
问题 In this method /// <summary> /// Gets activity logs. /// </summary> /// <param name="locationId">Location id.</param> /// <param name="filter">Activity log filter options.</param> /// <response code="200">OK</response> [ResponseType(typeof(ActivityLogResponse))] public async Task<HttpResponseMessage> FetchActivityLogs(int locationId, ActivityLogFilterOptions filter) { } ActivityLogFilterOptions has some required properties and some are optional. Is there any way to indicate this in Swagger UI

Convert string fields to enum fields in Swashbuckle

两盒软妹~` 提交于 2019-12-10 19:36:37
问题 We are using Swashbuckle to document our WebAPI project (using Owin) and are trying to modify the generated Swagger file of Swashbuckle. With the DescribeAllEnumsAsStrings() and an enum property like below, we get an expected result: class MyResponseClass { public Color color; } enum Color { LightBlue, LightRed, DarkBlue, DarkRed } Swagger generated result: "color": { "enum": [ "LightBlue", "LightRed", "DarkBlue", "DarkRed" ], "type": "string" }, The challenge for us is that we have some

How to generate set array of object in post request in Swagger with Laravel?

左心房为你撑大大i 提交于 2019-12-10 18:38:03
问题 I am trying to generate array of object in Laravel-5.5 Swagger using body request in Laravel Model. How should i achieve desired output ?? [ { "user_name": "string", "education": [ { "degree": [ { "year": "string", "name": "string" }, { "year": "string", "name": "string" } ], "hobby": [ { "type": "string", "description": "string" }, { "type": "string", "description": "string" } ] } ] } ] can anyone please help me ? Thanks. 回答1: In "User" model you just need to put this below code. /** * @SWG

API Routes: Multiple operations with path

别等时光非礼了梦想. 提交于 2019-12-10 18:37:17
问题 I am trying to configure my API routes, and I can't seem to get around this error from Swagger: 500 : {"Message":"An error has occurred.","ExceptionMessage":"Not supported by Swagger 2.0: Multiple operations with path 'api/Doors/{OrganizationSys}' and method 'GET'. I understand why I am getting the error, but I'm not sure how to fix it. Here are the API end points: public IHttpActionResult Get(int organizationSys) { .... } public IHttpActionResult Get(int organizationSys, int id) { .... }

OpenAPI multiple types inside an array

半城伤御伤魂 提交于 2019-12-10 18:14:35
问题 I'm having trouble defining a reusable schema component using OpenAPI 3 which would allow for an array that contains multiple types. Each item type inherits from the same parent class but has specific child properties. This seems to work alright in the model view on SwaggerHub but the example view doesn't show the data correctly. TLDR; Is there a way to define an array containing different object types in OpenAPI 3? Response: allOf: - $ref: '#/components/schemas/BaseResponse' - type: object

How to set request interceptor in SwaggerUIBundle?

家住魔仙堡 提交于 2019-12-10 17:56:54
问题 In our swagger.json we are setting basePath to /api , however, when the application is deployed in docker container, the context path is not /api. This could be different thing and we don't know what it is so we can't hard code it. I am trying to set requestInterceptor as per the following guide, in order to catch the request and modify the url path perhaps: https://swagger.io/docs/swagger-tools/#customization-36 But it seems requestInterceptor is being ignored. Is this possible? If not, how

How to receive a dynamic response in a Swagger spec

我们两清 提交于 2019-12-10 17:34:21
问题 I want to request a table from my database through my API. However, I don't know what number of columns the table will have, or what it will contain. How can I specify this in Swagger? This is what I would like to do: paths: /reports/{id}: get: summary: Detailed results description: filler parameters: - name: id in: path description: filler required: true type: integer format: int64 responses: 200: description: OK schema: type: array items: $ref: '#/definitions/DynamicObject' definitions:

Jackson POJOPropertyBuilder finds multiple setters in POJO

安稳与你 提交于 2019-12-10 17:23:43
问题 We're working on a rather large JSON REST API using Spring Web MVC 3.2.2 and Jackson Databind 2.4.4 (among many other libs...). I'm trying to use swagger-springmvc, but I'm having troubles with some our DTOs. No matter if I use a simple @EnableSwagger or a more complex swagger config, I always get the following exception when starting Tomcat 7: java.lang.IllegalArgumentException: Conflicting setter definitions for property "year": javax.xml.datatype.XMLGregorianCalendar#setYear(1 params) vs