swagger-2.0

“discriminator” in polymorphism, OpenAPI 2.0 (Swagger 2.0)

戏子无情 提交于 2019-11-28 11:54:25
Referencing OpenAPI 2.0, Schema Object , or Swagger 2.0, Schema Object , and the definition of discriminator field as: Adds support for polymorphism. The discriminator is the schema property name that is used to differentiate between other schema that inherit this schema. The property name used MUST be defined at this schema and it MUST be in the required property list. When used, the value MUST be the name of this schema or any schema that inherits it. My confusions/ questions: It is ambiguous to me, what role exactly it plays in inheritance or polymorphism. Could some one please explain

Can I create a stub swagger model definition from a json file

限于喜欢 提交于 2019-11-28 11:52:02
问题 Is there a tool that lets me generate a Swagger yaml definition model from sample JSON? I would go in and and edit and clean up the yaml, but would be nice if there was something out there that would stub out the structure of a yaml based on a large or complex sample json object. 回答1: You can use Apigee's API Studio that has this feature: http://apistudio.io/ Click on Insert menu and then New Model . Form a JSON example you can create all of the paths and operations you want. 来源: https:/

How to generate JSON examples from OpenAPI/Swagger model definition?

若如初见. 提交于 2019-11-28 11:48:13
I'm building a fuzzer for a REST API that has an OpenAPI (Swagger) definition. I want to test all available path from the OpenAPI definition, generate data to test the servers, analyse responses code and content, and to verify if the responses are conform to the API definition. I'm looking for a way to generate data (JSON object) from model definitions. For example, given this model: ... "Pet": { "type": "object", "required": [ "name", "photoUrls" ], "properties": { "id": { "type": "integer", "format": "int64" }, "category": { "$ref": "#/definitions/Category" }, "name": { "type": "string",

How to organise/build a Swagger UI interface for a directory which contains many Swagger definition .json/.yml files

喜你入骨 提交于 2019-11-28 11:38:40
I am trying to document, via Swagger UI, for internal company consumption, existing API services which are developed in a vendor product (WSO2 ESB). The vendor product does not support swagger. I plan to programmatically inspect/process the source code for my API services (written in the vendor product) and generate a directory/folder/library of swagger definition files in .json or .yml format. That is fine, I can do that. Each of these api defintion files will render nicely in swagger UI, I am looking at using https://www.npmjs.com/package/swagger-ui . My issue is I will end up with around

Swagger: wildcard path parameters

拈花ヽ惹草 提交于 2019-11-28 10:01:34
I have an API which allows any arbitrary path to be passed in, for example all of these: /api/tags /api/tags/foo /api/tags/foo/bar/baz Are valid paths. I tried to describe it as follows: /tags{tag_path}: get: parameters: - name: tag_path in: path required: true type: string default: "/" However, https://generator.swagger.io encodes slashes in the path, so it doesn't work. So is there a way to describe my API in Swagger? So this is not going to be supported soon (it's not even planned for Swagger 3.0), and I have to resort to a workaround. If I have a path /tags{tag_path} and I enter something

Swashbuckle Swagger - How to annotate content types?

社会主义新天地 提交于 2019-11-28 09:50:25
How do I annotate my ASP.NET WebAPI actions so that the swagger metadata includes the content-types that my resources support? Specifically, I want the documentation to show that one of my resources can return the 'original' application/json and application/xml but also now returns a new format, application/vnd.blah+json or +xml . What you need to do is this; Swagger spec: you need to add your response-type to the list of response-types for that operation "produces": [ "application/json", "text/json" ], This can be done with an OperationFilter Pseudo Code incoming!!! public class

Add individual custom headers in different controllers in web api using Swasbuckle

强颜欢笑 提交于 2019-11-28 09:38:21
问题 How can I add individual headers on different controllers. E.g.: Controller Name: Controller1, Custom header: Header1 Controller Name: Controller2, Custom header: Header2 The headers should be displayed for all the apis under the specific controller 回答1: This can be solved by adding an OperationFilter to your swagger configuration. First you have to provide a class that implements IOperationFilter . The Apply method receives an Operation parameter which contains the controller name in the tag

Swagger: take one or more values from enum

时间秒杀一切 提交于 2019-11-28 09:37:47
问题 I am working on a swagger file, where a query parameter can take none, or n values. How can I write this in Swagger Yaml? The url I give: /sort=field1,field2 The parameter declared in swagger file - name: sort in: query schema: type: string enum: [field1,field2,field3] allowEmptyValue: true required: false description: Sort the results by attributes. (See http://jsonapi.org/format/1.1/#fetching-sorting) Have a nice day/night. 回答1: A query parameter containing a comma-separated list of values

Data annotations in Swagger

試著忘記壹切 提交于 2019-11-28 02:34:37
问题 I am using ASP.NET and Swagger that exposes a complex type that accepts a POST. It has a number of string fields that have different restricted lengths. How can I reflect that in the Swagger UI? 回答1: You can annotate the properties with the StringLengthAttribute from System.ComponentModel.DataAnnotations . For instance: [StringLength(10)] public String Name {get;set;} will become: "name": { "minLength": 0, "maxLength": 10, "type": "string" } And this: [StringLength(10, MinimumLength = 5)]

Schema object without a type attribute in Swagger 2.0

爱⌒轻易说出口 提交于 2019-11-28 02:14:59
Does a Schema object in Swagger/OpenAPI 2.0 have to have the type attribute or not? On the one hand, according to the JSON Schema Draft 4 spec, not specifying the type attribute is OK and means that the instance can be of any type (an object, an array or a primitive). On the other hand, I've seen a lot of Swagger schemas which contain Schema objects without the type attribute, but with the properties attribute, which makes it clear that the schema author wants the instance to be a proper object (and doesn't want to accept arrays or primitive as valid values). Are all those schemas incorrect?