swagger-2.0

Swagger 2.0: what schema to accept any (complex) JSON value

大城市里の小女人 提交于 2019-11-26 23:16:41
The API for which I'm writing a Swagger 2.0 specification is basically a store for any JSON value. I want a path to read value and a path to store any JSON values (null, number, integer, string, object, array) of non-predefined depth. Unfortunately, it seems that Swagger 2.0 is quite strict on schemas for input and output and does not allow the whole set of schemas allowed by JSON Schema. The Swagger editor doesn't allow for example mixed values (for example a property that can be either a boolean or an integer) or loosely defined arrays (the type of items must be strictly defined) and objects

How to configure Spring Security to allow Swagger URL to be accessed without authentication

佐手、 提交于 2019-11-26 22:31:15
问题 My project has Spring Security. Main issue: Not able to access swagger URL at http://localhost:8080/api/v2/api-docs. It says Missing or invalid Authorization header. Screenshot of the browser window My pom.xml has the following entries <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>

How to create different element types within Swagger 2.0 editor

安稳与你 提交于 2019-11-26 22:26:40
问题 I trying to map below JSON to Swagger YAML in swagger editor 2.0 and I am not sure how to set mixed array types into my schema { "obj1": [ "string data", 1 ] } Now, my swagger definition has, schema: object1: type: array items: type: string 回答1: The answer depends on which version of the OpenAPI Specification you use. OpenAPI 2.0 OpenAPI 2.0 (Swagger 2.0) does not really support mixed-type array and parameters. The most you can do is to use a typeless schema {} for items , which means the

Swagger complex response model with dynamic key value hash maps

↘锁芯ラ 提交于 2019-11-26 20:25:00
问题 I'm struggling with the syntax of swagger to describe a response type. What I'm trying to model is a hash map with dynamic keys and values. This is needed to allow a localization. The languages may vary, but english should always be provided. The response would look like this in JSON: { id: "1234", name: { en: "english text", de: "Deutscher Text" } } My first try was looking like that, but I have no idea how to write the part for the name. AdditionalProperties seems to be a key, but I can't

Swagger mock server

≡放荡痞女 提交于 2019-11-26 19:55:13
I have an API reference in Swagger file. I want to create a very simple mock server, so that when I call eg.: mymockurl.com/users it will return a predefined json (no need to connect to a database). What's the easiest way to do this? I'm not a backend guy. Helen SwaggerHub provides a mock server for OpenAPI 2.0 and 3.0 specs. Mocking is supported on both free and paid plans. To use the mock server, import your spec into SwaggerHub and enable "API Auto Mocking". Mock responses can be JSON, YAML and XML, and are generated based on your response schemas and the example , default and enum values

Remove Basic Error Controller In SpringFox SwaggerUI

霸气de小男生 提交于 2019-11-26 16:58:52
问题 Is there a way i can remove the "basic-error-controller" from springfox swagger-ui? Picture: 回答1: You can restrict the request handler selector to scan only the package of your project: return new Docket( DocumentationType.SWAGGER_2) .select() .apis( RequestHandlerSelectors.basePackage( "your package" ) ) ... 回答2: I think, the most elegant solution is to include only @RestController controllers into swagger, only thing to bear in mind, is to annotate all the REST controllers with that

Swagger/OpenAPI - use $ref to pass a reusable defined parameter

╄→尐↘猪︶ㄣ 提交于 2019-11-26 15:36:45
问题 Let's say I've got a parameter like limit . This one gets used all over the place and it's a pain to have to change it everywhere if I need to update it: parameters: - name: limit in: query description: Limits the number of returned results required: false type: number format: int32 Can I use $ref to define this elsewhere and make it reusable? I came across this ticket which suggests that someone wants to change or improve feature, but I can't tell if it already exists today or not? 回答1: This

Swagger mock server

江枫思渺然 提交于 2019-11-26 12:17:19
问题 I have an API reference in Swagger file. I want to create a very simple mock server, so that when I call eg.: mymockurl.com/users it will return a predefined json (no need to connect to a database). What\'s the easiest way to do this? I\'m not a backend guy. 回答1: SwaggerHub provides a mock server for OpenAPI 2.0 and 3.0 specs. Mocking is supported on both free and paid plans. To use the mock server, import your spec into SwaggerHub and enable "API Auto Mocking". Mock responses can be JSON,

How can I represent &#39;Authorization: Bearer <token>&#39; in a Swagger Spec (swagger.json)

▼魔方 西西 提交于 2019-11-26 09:16:57
问题 I am trying to convey that the authentication/security scheme requires setting a header as follows: Authorization: Bearer <token> This is what I have based on the swagger documentation: securityDefinitions: APIKey: type: apiKey name: Authorization in: header security: - APIKey: [] 回答1: Maybe this can help: swagger: '2.0' info: version: 1.0.0 title: Based on "Basic Auth Example" description: > An example for how to use Auth with Swagger. host: basic-auth-server.herokuapp.com schemes: - http -

OpenAPI: what schema to accept any (complex) JSON value

梦想与她 提交于 2019-11-26 08:37:25
问题 The API for which I\'m writing a Swagger 2.0 specification is basically a store for any JSON value. I want a path to read value and a path to store any JSON values (null, number, integer, string, object, array) of non-predefined depth. Unfortunately, it seems that Swagger 2.0 is quite strict on schemas for input and output and does not allow the whole set of schemas allowed by JSON Schema. The Swagger editor doesn\'t allow for example mixed values (for example a property that can be either a