From 6b64c689bc4dd06e7b061d9d7ab6fc1f4fa28ad8 Mon Sep 17 00:00:00 2001 From: Darrel Date: Fri, 9 Sep 2016 22:23:57 -0400 Subject: [PATCH 1/6] Split sentences into lines for better diffing --- versions/3.0.md | 163 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 114 insertions(+), 49 deletions(-) diff --git a/versions/3.0.md b/versions/3.0.md index 6dc8ec03f4..32a373053a 100644 --- a/versions/3.0.md +++ b/versions/3.0.md @@ -10,7 +10,9 @@ The OpenAPI Specification is licensed under [The Apache License, Version 2.0](ht The OpenAPI Specification is a project used to describe and document RESTful APIs. -The OpenAPI Specification defines a set of files required to describe such an API. These files can then be used by the Swagger-UI project to display the API and Swagger-Codegen to generate clients in various languages. Additional utilities can also take advantage of the resulting files, such as testing tools. +The OpenAPI Specification defines a set of files required to describe such an API. +These files can then be used by the Swagger-UI project to display the API and Swagger-Codegen to generate clients in various languages. +Additional utilities can also take advantage of the resulting files, such as testing tools. ## Revision History @@ -28,7 +30,8 @@ Version | Date | Notes Path templating refers to the usage of curly braces ({}) to mark a section of a URL path as replaceable using path parameters. ##### Media Types -Media type definitions are spread across several resources. The media type definitions should be in compliance with [RFC 6838](http://tools.ietf.org/html/rfc6838). +Media type definitions are spread across several resources. +The media type definitions should be in compliance with [RFC 6838](http://tools.ietf.org/html/rfc6838). Some examples of possible media type definitions: ``` @@ -44,14 +47,15 @@ Some examples of possible media type definitions: application/vnd.github.v3.patch ``` ##### HTTP Status Codes -The HTTP Status Codes are used to indicate the status of the executed operation. The available status codes are described by [RFC 7231](http://tools.ietf.org/html/rfc7231#section-6) and in the [IANA Status Code Registry](http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml). +The HTTP Status Codes are used to indicate the status of the executed operation. +The available status codes are described by [RFC 7231](http://tools.ietf.org/html/rfc7231#section-6) and in the [IANA Status Code Registry](http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml). ## Specification ### Format -The files describing the RESTful API in accordance with the OpenAPI Specification are represented as JSON objects and conform to the JSON standards. YAML, being a superset of JSON, can be used as well to -represent a OAS (OpenAPI Specification) file. +The files describing the RESTful API in accordance with the OpenAPI Specification are represented as JSON objects and conform to the JSON standards. +YAML, being a superset of JSON, can be used as well to represent a OAS (OpenAPI Specification) file. For example, if a field is said to have an array value, the JSON array representation will be used: @@ -65,7 +69,9 @@ While the API is described using JSON it does not impose a JSON input/output to All field names in the specification are **case sensitive**. -The schema exposes two types of fields. Fixed fields, which have a declared name, and Patterned fields, which declare a regex pattern for the field name. Patterned fields can have multiple occurrences as long as each has a unique name. +The schema exposes two types of fields. +Fixed fields, which have a declared name, and Patterned fields, which declare a regex pattern for the field name. +Patterned fields can have multiple occurrences as long as each has a unique name. In order to preserve the ability to round-trip between YAML and JSON formats, YAML version [1.2](http://www.yaml.org/spec/1.2/spec.html) is recommended along with some additional constraints: @@ -74,17 +80,25 @@ In order to preserve the ability to round-trip between YAML and JSON formats, YA ### File Structure -The OAS representation of the API is made of a single file. However, parts of the definitions can be split into separate files, at the discretion of the user. This is applicable for `$ref` fields in the specification as follows from the [JSON Schema](http://json-schema.org) definitions. +The OAS representation of the API is made of a single file. +However, parts of the definitions can be split into separate files, at the discretion of the user. +This is applicable for `$ref` fields in the specification as follows from the [JSON Schema](http://json-schema.org) definitions. By convention, the OpenAPI Specification (OAS) file is named `openapi.json` or `openapi.yaml`. ### Data Types -Primitive data types in the OAS are based on the types supported by the [JSON-Schema Draft 4](http://json-schema.org/latest/json-schema-core.html#anchor8). Models are described using the [Schema Object](#schemaObject) which is a subset of JSON Schema Draft 4. +Primitive data types in the OAS are based on the types supported by the [JSON-Schema Draft 4](http://json-schema.org/latest/json-schema-core.html#anchor8). +Models are described using the [Schema Object](#schemaObject) which is a subset of JSON Schema Draft 4. An additional primitive data type `"file"` is used by the [Parameter Object](#parameterObject) and the [Response Object](#responseObject) to set the parameter type or the response as being a file. -Primitives have an optional modifier property `format`. OAS uses several known formats to more finely define the data type being used. However, the `format` property is an open `string`-valued property, and can have any value to support documentation needs. Formats such as `"email"`, `"uuid"`, etc., can be used even though they are not defined by this specification. Types that are not accompanied by a `format` property follow their definition from the JSON Schema (except for `file` type which is defined above). The formats defined by the OAS are: +Primitives have an optional modifier property `format`. +OAS uses several known formats to more finely define the data type being used. +However, the `format` property is an open `string`-valued property, and can have any value to support documentation needs. +Formats such as `"email"`, `"uuid"`, etc., can be used even though they are not defined by this specification +Types that are not accompanied by a `format` property follow their definition from the JSON Schema (except for `file` type which is defined above). +The formats defined by the OAS are: Common Name | [`type`](#dataTypeType) | [`format`](#dataTypeFormat) | Comments @@ -105,13 +119,14 @@ password | `string` | `password` | Used to hint UIs the input needs to be obscur #### OpenAPI Object -This is the root document object for the API specification. It combines what previously was the Resource Listing and API Declaration (version 1.2 and earlier) together into one document. +This is the root document object for the API specification. +It combines what previously was the Resource Listing and API Declaration (version 1.2 and earlier) together into one document. ##### Fixed Fields Field Name | Type | Description ---|:---:|--- -openapi | `string` | **Required.** Specifies the OpenAPI Specification version being used. It can be used by tooling Specifications and clients to interpret the version. The structure shall be `major`.`minor`.`patch`, where `patch` versions _must_ be compatible with the existing `major`.`minor` tooling. Typically patch versions will be introduced to address errors in the documentation, and tooling should typically be compatible with the corresponding `major`.`minor` (3.0.*). Patch versions will correspond to patches of this document. +openapi | `string` | **Required.** Specifies the OpenAPI Specification version being used. It can be used by tooling Specifications and clients to interpret the version. The structure shall be `major`.`minor`.`patch`, where `patch` versions _must_ be compatible with the existing `major`.`minor` tooling. Typically patch versions will be introduced to address errors in the documentation, and tooling should typically be compatible with the corresponding `major`.`minor` (3.0.*). Patch versions will correspond to patches of this document. info | [Info Object](#infoObject) | **Required.** Provides metadata about the API. The metadata can be used by the clients if needed. hosts | [Hosts Object](#hostsObject) | An array of Host objects which provide `scheme`, `host`, `port`, and `basePath` in an associative manner. consumes | [`string`] | A list of media types the APIs can consume. This is global to all APIs but can be overridden on specific API calls. Value MUST be as described under [Media Types](#mediaTypes). @@ -131,7 +146,8 @@ Field Pattern | Type | Description #### Info Object -The object provides metadata about the API. The metadata can be used by the clients if needed, and can be presented in the Swagger-UI for convenience. +The object provides metadata about the API. +The metadata can be used by the clients if needed, and can be presented in the Swagger-UI for convenience. ##### Fixed Fields @@ -263,7 +279,8 @@ url: http://www.apache.org/licenses/LICENSE-2.0.html #### Components Object -Holds a set of schemas for different aspects of the OAS. The intention is to put reusable components into a single location, allowing reuse from this and other OAS documents. +Holds a set of schemas for different aspects of the OAS. +The intention is to put reusable components into a single location, allowing reuse from this and other OAS documents. ##### Fixed Fields @@ -278,7 +295,8 @@ Field Pattern | Type | Description #### Paths Object -Holds the relative paths to the individual endpoints. The path is appended to the [`basePath`](#oasBasePath) in order to construct the full URL. +Holds the relative paths to the individual endpoints. +The path is appended to the [`basePath`](#oasBasePath) in order to construct the full URL. The Paths may be empty, due to [ACL constraints](#securityFiltering). ##### Patterned Fields @@ -332,7 +350,8 @@ Field Pattern | Type | Description #### Path Item Object Describes the operations available on a single path. -A Path Item may be empty, due to [ACL constraints](#securityFiltering). The path itself is still exposed to the documentation viewer but they will not know which operations and parameters are available. +A Path Item may be empty, due to [ACL constraints](#securityFiltering). +The path itself is still exposed to the documentation viewer but they will not know which operations and parameters are available. ##### Fixed Fields @@ -612,7 +631,8 @@ There are five possible parameter types. * Cookie - Used to pass a specific cookie value to the API. -For complex parameter schemas, a serialization strategy is required. For all types, a serialization strategy must be declared. +For complex parameter schemas, a serialization strategy is required. +For all types, a serialization strategy must be declared. ##### Fixed Fields Field Name | Type | Description @@ -819,7 +839,8 @@ schema: #### Items Object -A limited subset of JSON-Schema's items object. It is used by parameter definitions. +A limited subset of JSON-Schema's items object. +It is used by parameter definitions. ##### Fixed Fields Field Name | Type | Description @@ -887,7 +908,10 @@ items: #### Responses Object -A container for the expected responses of an operation. The container maps a HTTP response code to the expected response. It is not expected from the documentation to necessarily cover all possible HTTP response codes, since they may not be known in advance. However, it is expected from the documentation to cover a successful operation response and any known errors. +A container for the expected responses of an operation. +The container maps a HTTP response code to the expected response. +It is not expected from the documentation to necessarily cover all possible HTTP response codes, since they may not be known in advance. +However, it is expected from the documentation to cover a successful operation response and any known errors. The `default` MAY be used as a default response object for all HTTP codes that are not covered individually by the specification. @@ -896,7 +920,9 @@ The `Responses Object` MUST contain at least one response code, and it SHOULD be ##### Fixed Fields Field Name | Type | Description ---|:---:|--- -default | [Response Object](#responseObject) | [Reference Object](#referenceObject) | The documentation of responses other than the ones declared for specific HTTP response codes. It can be used to cover undeclared responses. [Reference Object](#referenceObject) can be used to link to a response that is defined at the [OpenAPI Object's responses](#oasResponses) section. +default | [Response Object](#responseObject) | [Reference Object](#referenceObject) | The documentation of responses other than the ones declared for specific HTTP response codes. +It can be used to cover undeclared responses. +[Reference Object](#referenceObject) can be used to link to a response that is defined at the [OpenAPI Object's responses](#oasResponses) section. ##### Patterned Fields Field Pattern | Type | Description @@ -1126,7 +1152,8 @@ application/json: ``` #### Links Object -The links object represents a set of possible design-time links for a response. The presence of a link does not guarantee the caller's ability to successfully call invoke it, rather it provides a known relationship and traversal mechanism between responses and other operations. +The links object represents a set of possible design-time links for a response. +The presence of a link does not guarantee the caller's ability to successfully call invoke it, rather it provides a known relationship and traversal mechanism between responses and other operations. As opposed to _dynamic_ links--that is, links provided **in** the response payload, the OAS linking mechanism does not require that link information be provided in a specific response format at runtime. @@ -1138,7 +1165,8 @@ Field Name | Type | Description Field Pattern | Type | Description ---|:---:|--- -link name | [Link Object](#linkObject) | A short name for the link, following the naming constraints of the definitions name. The link shall reference a single Link Object, or a JSON Reference to a single link object +link name | [Link Object](#linkObject) | A short name for the link, following the naming constraints of the definitions name. +The link shall reference a single Link Object, or a JSON Reference to a single link object ### Link Object @@ -1153,11 +1181,15 @@ headers | Link Headers Object | an Object representing headers to pass to description | string | a description of the link, supports [CommonMark syntax](http://spec.commonmark.org/). ^x- | Any | Allows extensions to the OpenAPI Schema. The field name MUST begin with `x-`, for example, `x-internal-id`. The value can be `null`, a primitive, an array or an object. See [Specification Extensions](#specificationExtensions) for further details. -Locating a linked resource may be performed by either a `href` or `operationId`. In the case of an `operationId`, it must be unique and resolved in the scope of the OAS document. Because of the potential for name clashes, consider the `href` syntax as the preferred method for specifications with external references. +Locating a linked resource may be performed by either a `href` or `operationId`. +In the case of an `operationId`, it must be unique and resolved in the scope of the OAS document. +Because of the potential for name clashes, consider the `href` syntax as the preferred method for specifications with external references. #### Response Payload Values -Payload values are only available in parseable response payloads which match the advertised media-type. In all cases, if a value does _not_ exist, the parameter will be considered a `null` value (as opposed to an empty value) and _not_ passed as a parameter to the linked resource. In cases where a value is required, and a parameter is not supplied, the client _may_ choose to not follow the link definition. +Payload values are only available in parseable response payloads which match the advertised media-type. +In all cases, if a value does _not_ exist, the parameter will be considered a `null` value (as opposed to an empty value) and _not_ passed as a parameter to the linked resource. +In cases where a value is required, and a parameter is not supplied, the client _may_ choose to not follow the link definition. ### Example @@ -1178,7 +1210,8 @@ lastname: Williams missingValue: null ``` -In situations where variables appear in an array, an array of variables will be extracted. For example: +In situations where variables appear in an array, an array of variables will be extracted. +For example: ```json [ @@ -1198,7 +1231,8 @@ The variables generated can be used in locations prescribed by the definition. ### Variable substitution -In all cases, _variables_ from request and responses may be substituted for link generation. The table below designates the source of the substitution value and the syntax for accessing it: +In all cases, _variables_ from request and responses may be substituted for link generation. +The table below designates the source of the substitution value and the syntax for accessing it: Source Location | reference identifier | example value | example reference | notes ---|:---|:---|:---|:--- @@ -1210,7 +1244,9 @@ Request URL | `$url` | `/track?url={$url}` | Response value | `$response` | `{$response.uuid}` | Only the payload in the response can be accessed with the `$response` syntax Response header | `$responseHeader` | `{$responseHeader.Server}` | Single header values only are available. -From the request, the `parameter`s used in calling the operation are made available through the `$request` syntax. For responses, the response payload may be used with the `$response` syntax. For both requests and responses, values will be substituted in the link in sections designated with the `$request` or `$response` keyword, surrounded by curly brackets `{}`. +From the request, the `parameter`s used in calling the operation are made available through the `$request` syntax. +For responses, the response payload may be used with the `$response` syntax. +For both requests and responses, values will be substituted in the link in sections designated with the `$request` or `$response` keyword, surrounded by curly brackets `{}`. ### Request parameter example Computing a link from a request operation like such: @@ -1243,7 +1279,8 @@ Addresses: href: '/users/{$request.id}/department' ``` -Where the `$request.id` is the value passed in the request to `/users/{id}`. For a `id` value of `10101110`, the generated link would be: +Where the `$request.id` is the value passed in the request to `/users/{id}`. +For a `id` value of `10101110`, the generated link would be: ```yaml href: '/users/10101110/department' @@ -1485,9 +1522,11 @@ components: ### Link Parameters -Using the `operationId` to reference an operation in the definition has many benefits, including the ability to define media-type options, security requirements, response and error payloads. Many operations require parameters to be passed, and these may be dynamic depending on the response itself. +Using the `operationId` to reference an operation in the definition has many benefits, including the ability to define media-type options, security requirements, response and error payloads. +Many operations require parameters to be passed, and these may be dynamic depending on the response itself. -To specify parameters required by the operation, we can use a **Link Parameters Object**. This object contains parameter names along with static or dynamic valus: +To specify parameters required by the operation, we can use a **Link Parameters Object**. +This object contains parameter names along with static or dynamic valus: ```yaml paths: @@ -1563,7 +1602,8 @@ type: integer #### Tag Object -Allows adding meta data to a single tag that is used by the [Operation Object](#operationObject). It is not mandatory to have a Tag Object per tag used there. +Allows adding meta data to a single tag that is used by the [Operation Object](#operationObject). +It is not mandatory to have a Tag Object per tag used there. ##### Fixed Fields Field Name | Type | Description @@ -1593,11 +1633,13 @@ description: Pets operations #### Examples Object -Anywhere an `example` may be given, allow a $ref object. This does mean that `example`, structurally, can be either a string primitive or an object, like `additionalProperties`. +Anywhere an `example` may be given, allow a $ref object. +This does mean that `example`, structurally, can be either a string primitive or an object, like `additionalProperties`. In locations where the field being provided an `example` is a scalar value _or_ has it's content-type definition determined by a higher-level construct (a response payload, for example, uses the `produces` attribute to select the correct message format), the plural `examples` shall be used, and the payload format be specified as a key to the example. -In all cases, the payload is expected to be compatible with the type schema for the value that it is accompanying. Tooling Specifications may choose to valide compatibility automatically, and reject the example value(s) if they are not compatible. +In all cases, the payload is expected to be compatible with the type schema for the value that it is accompanying. +Tooling Specifications may choose to valide compatibility automatically, and reject the example value(s) if they are not compatible. ```yaml # in a model @@ -1644,9 +1686,11 @@ definitions: #### Reference Object -A simple object to allow referencing other definitions in the specification. It can be used to reference parameters and responses that are defined at the top level for reuse. +A simple object to allow referencing other definitions in the specification. +It can be used to reference parameters and responses that are defined at the top level for reuse. -The Reference Object is a [JSON Reference](http://tools.ietf.org/html/draft-pbryan-zyp-json-ref-02) that uses a [JSON Pointer](http://tools.ietf.org/html/rfc6901) as its value. For this specification, only [canonical dereferencing](http://json-schema.org/latest/json-schema-core.html#anchor27) is supported. +The Reference Object is a [JSON Reference](http://tools.ietf.org/html/draft-pbryan-zyp-json-ref-02) that uses a [JSON Pointer](http://tools.ietf.org/html/rfc6901) as its value. +For this specification, only [canonical dereferencing](http://json-schema.org/latest/json-schema-core.html#anchor27) is supported. ##### Fixed Fields Field Name | Type | Description @@ -1689,9 +1733,13 @@ $ref: 'definitions.yaml#/Pet' #### Schema Object -The Schema Object allows the definition of input and output data types. These types can be objects, but also primitives and arrays. This object is based on the [JSON Schema Specification Draft 4](http://json-schema.org/) and uses a predefined subset of it. On top of this subset, there are extensions provided by this specification to allow for more complete documentation. +The Schema Object allows the definition of input and output data types. +These types can be objects, but also primitives and arrays. +This object is based on the [JSON Schema Specification Draft 4](http://json-schema.org/) and uses a predefined subset of it. +On top of this subset, there are extensions provided by this specification to allow for more complete documentation. -Further information about the properties can be found in [JSON Schema Core](http://json-schema.org/latest/json-schema-core.html) and [JSON Schema Validation](http://json-schema.org/latest/json-schema-validation.html). Unless stated otherwise, the property definitions follow the JSON Schema specification as referenced here. +Further information about the properties can be found in [JSON Schema Core](http://json-schema.org/latest/json-schema-core.html) and [JSON Schema Validation](http://json-schema.org/latest/json-schema-validation.html). +Unless stated otherwise, the property definitions follow the JSON Schema specification as referenced here. The following properties are taken directly from the JSON Schema definition and follow the same specifications: - $ref - As a [JSON Reference](https://tools.ietf.org/html/draft-pbryan-zyp-json-ref-03) @@ -1716,7 +1764,8 @@ The following properties are taken directly from the JSON Schema definition and - enum - type -The following properties are taken from the JSON Schema definition but their definitions were adjusted to the OpenAPI Specification. Their definition is the same as the one from JSON Schema, only where the original definition references the JSON Schema definition, the [Schema Object](#schemaObject) definition is used instead. +The following properties are taken from the JSON Schema definition but their definitions were adjusted to the OpenAPI Specification. +Their definition is the same as the one from JSON Schema, only where the original definition references the JSON Schema definition, the [Schema Object](#schemaObject) definition is used instead. - items - allOf - properties @@ -1742,13 +1791,20 @@ Field Pattern | Type | Description ###### Composition and Inheritance (Polymorphism) -The OpenAPI Specification allows combining and extending model definitions using the `allOf` property of JSON Schema, in effect offering model composition. `allOf` takes in an array of object definitions that are validated *independently* but together compose a single object. +The OpenAPI Specification allows combining and extending model definitions using the `allOf` property of JSON Schema, in effect offering model composition. +`allOf` takes in an array of object definitions that are validated *independently* but together compose a single object. -While composition offers model extensibility, it does not imply a hierarchy between the models. To support polymorphism, OpenAPI Specification adds the support of the `discriminator` field. When used, the `discriminator` will be the name of the property used to decide which schema definition is used to validate the structure of the model. As such, the `discriminator` field MUST be a required field. The value of the chosen property has to be the friendly name given to the model under the `definitions` property. As such, inline schema definitions, which do not have a given id, *cannot* be used in polymorphism. +While composition offers model extensibility, it does not imply a hierarchy between the models. +To support polymorphism, OpenAPI Specification adds the support of the `discriminator` field. +When used, the `discriminator` will be the name of the property used to decide which schema definition is used to validate the structure of the model. +As such, the `discriminator` field MUST be a required field. +The value of the chosen property has to be the friendly name given to the model under the `definitions` property. +As such, inline schema definitions, which do not have a given id, *cannot* be used in polymorphism. ###### XML Modeling -The [xml](#schemaXml) property allows extra definitions when translating the JSON definition to XML. The [XML Object](#xmlObject) contains additional information about the available options. +The [xml](#schemaXml) property allows extra definitions when translating the JSON definition to XML. +The [XML Object](#xmlObject) contains additional information about the available options. ##### Schema Object Examples @@ -2076,7 +2132,8 @@ definitions: A metadata object that allows for more fine-tuned XML model definitions. -When using arrays, XML element names are *not* inferred (for singular/plural forms) and the `name` property should be used to add that information. See examples for expected behavior. +When using arrays, XML element names are *not* inferred (for singular/plural forms) and the `name` property should be used to add that information. +See examples for expected behavior. ##### Fixed Fields Field Name | Type | Description @@ -2430,13 +2487,15 @@ animals: #### Definitions Object -An object to hold data types that can be consumed and produced by operations. These data types can be primitives, arrays or models. +An object to hold data types that can be consumed and produced by operations. +These data types can be primitives, arrays or models. ##### Patterned Fields Field Pattern | Type | Description ---|:---:|--- -{name} | [Schema Object](#schemaObject) | A single definition, mapping a "name" to the schema it defines. The following characters are legal in the `definitionsName`: `a-zA-Z0-9.-_\`. All other characters, including extended ASCII characters, are not legal in the `definitionsName`. The name may be used to namespace the definitions--it is the tooling Specification's job to ensure that the namespace is honored. +{name} | [Schema Object](#schemaObject) | A single definition, mapping a "name" to the schema it defines. +The following characters are legal in the `definitionsName`: `a-zA-Z0-9.-_\`. All other characters, including extended ASCII characters, are not legal in the `definitionsName`. The name may be used to namespace the definitions--it is the tooling Specification's job to ensure that the namespace is honored. Examples: @@ -2501,7 +2560,8 @@ Tag: #### Parameters Definitions Object -An object to hold parameters to be reused across operations. Parameter definitions can be referenced to the ones defined here. +An object to hold parameters to be reused across operations. +Parameter definitions can be referenced to the ones defined here. This does *not* define global operation parameters. @@ -2554,7 +2614,8 @@ limitParam: #### Responses Definitions Object -An object to hold responses to be reused across operations. Response definitions can be referenced to the ones defined here. +An object to hold responses to be reused across operations. +Response definitions can be referenced to the ones defined here. This does *not* define global operation responses. @@ -2596,7 +2657,8 @@ GeneralError: #### Security Definitions Object -A declaration of the security schemes available to be used in the specification. This does not enforce the security schemes on the operations and only serves to provide the relevant details for each scheme. +A declaration of the security schemes available to be used in the specification. +This does not enforce the security schemes on the operations and only serves to provide the relevant details for each scheme. ##### Patterned Fields Field Pattern | Type | Description @@ -2640,7 +2702,8 @@ petstore_auth: #### Security Scheme Object -Allows the definition of a security scheme that can be used by the operations. Supported schemes are basic authentication, an API key (either as a header or as a query parameter) and OAuth2's common flows (implicit, password, application and access code). +Allows the definition of a security scheme that can be used by the operations. +Supported schemes are basic authentication, an API key (either as a header or as a query parameter) and OAuth2's common flows (implicit, password, application and access code). ##### Fixed Fields Field Name | Type | Validity | Description @@ -2745,7 +2808,8 @@ read:pets: read your pets #### Security Requirement Object -Lists the required security schemes to execute this operation. The object can have multiple security schemes declared in it which are all required (that is, there is a logical AND between the schemes). +Lists the required security schemes to execute this operation. +The object can have multiple security schemes declared in it which are all required (that is, there is a logical AND between the schemes). The name used for each property MUST correspond to a security scheme declared in the [Security Definitions](#securityDefinitionsObject). @@ -2798,7 +2862,8 @@ The extensions may or may not be supported by the available tooling, but those m Some objects in the OpenAPI Specification may be declared and remain empty, or completely be removed, even though they are inherently the core of the API documentation. -The reasoning behind it is to allow an additional layer of access control over the documentation itself. While not part of the specification itself, certain libraries may choose to allow access to parts of the documentation based on some form of authentication/authorization. +The reasoning behind it is to allow an additional layer of access control over the documentation itself. +While not part of the specification itself, certain libraries may choose to allow access to parts of the documentation based on some form of authentication/authorization. Two examples for this: From 01eb5afe4e55d20da9d7d255929c8bde876ac2c2 Mon Sep 17 00:00:00 2001 From: Erik Wilde Date: Mon, 4 Jul 2016 12:14:27 +0200 Subject: [PATCH 2/6] tweak HTTP status code language --- versions/3.0.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/versions/3.0.md b/versions/3.0.md index 32a373053a..2b6a98e1e4 100644 --- a/versions/3.0.md +++ b/versions/3.0.md @@ -47,8 +47,7 @@ Some examples of possible media type definitions: application/vnd.github.v3.patch ``` ##### HTTP Status Codes -The HTTP Status Codes are used to indicate the status of the executed operation. -The available status codes are described by [RFC 7231](http://tools.ietf.org/html/rfc7231#section-6) and in the [IANA Status Code Registry](http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml). +The HTTP Status Codes are used to indicate the status of the executed operation. The available status codes are initially defined by [RFC 7231](http://tools.ietf.org/html/rfc7231#section-6) and registered status codes are listed in the [IANA Status Code Registry](http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml). ## Specification From 3acbab09c378e5e73c7aad548a3aecf360ff3c65 Mon Sep 17 00:00:00 2001 From: Tony Tam Date: Mon, 19 Sep 2016 14:37:43 -0700 Subject: [PATCH 3/6] Jason is no longer 'n Austin --- CONTRIBUTORS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 0b635decd8..5a5ab82e15 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -1,5 +1,5 @@ * Darrel Miller [@darrelmiller](https://github.com/darrelmiller) -* Jason Harmon [@jasonh-n-austin](https://github.com/jasonh-n-austin) +* Jason Harmon [@jharmn](https://github.com/jharmn) * Jeremy Whitlock [@whitlockjc](https://github.com/whitlockjc) * Marsh Gardiner [@earth2marsh](https://github.com/earth2marsh) * Ron Ratovsky [@webron](https://github.com/webron) From 84f7f471217912cad484ba42cf72df8817e337bd Mon Sep 17 00:00:00 2001 From: Mike Ralphson Date: Thu, 22 Sep 2016 16:49:11 +0100 Subject: [PATCH 4/6] Typo fixes --- versions/3.0.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/versions/3.0.md b/versions/3.0.md index 2b6a98e1e4..dcaaeb57db 100644 --- a/versions/3.0.md +++ b/versions/3.0.md @@ -95,7 +95,7 @@ An additional primitive data type `"file"` is used by the [Parameter Object](#pa Primitives have an optional modifier property `format`. OAS uses several known formats to more finely define the data type being used. However, the `format` property is an open `string`-valued property, and can have any value to support documentation needs. -Formats such as `"email"`, `"uuid"`, etc., can be used even though they are not defined by this specification +Formats such as `"email"`, `"uuid"`, etc., can be used even though they are not defined by this specification. Types that are not accompanied by a `format` property follow their definition from the JSON Schema (except for `file` type which is defined above). The formats defined by the OAS are: @@ -1525,7 +1525,7 @@ Using the `operationId` to reference an operation in the definition has many ben Many operations require parameters to be passed, and these may be dynamic depending on the response itself. To specify parameters required by the operation, we can use a **Link Parameters Object**. -This object contains parameter names along with static or dynamic valus: +This object contains parameter names along with static or dynamic values: ```yaml paths: @@ -1638,7 +1638,7 @@ This does mean that `example`, structurally, can be either a string primitive or In locations where the field being provided an `example` is a scalar value _or_ has it's content-type definition determined by a higher-level construct (a response payload, for example, uses the `produces` attribute to select the correct message format), the plural `examples` shall be used, and the payload format be specified as a key to the example. In all cases, the payload is expected to be compatible with the type schema for the value that it is accompanying. -Tooling Specifications may choose to valide compatibility automatically, and reject the example value(s) if they are not compatible. +Tooling Specifications may choose to validate compatibility automatically, and reject the example value(s) if they are not compatible. ```yaml # in a model From 111edaa61edcd2e7d8703ee505ffaff6827f99bb Mon Sep 17 00:00:00 2001 From: it33 Date: Wed, 28 Sep 2016 21:50:09 -0700 Subject: [PATCH 5/6] Hyphenate adjective Sorry, total nit, if "Swagger-specific" is a term describing "annotations", maybe it's easier to read with a hyphen? I don't think what's there is wrong, I was just scanning this document and got tripped up over "The Swagger specific annotations...", so if I tripped, maybe others will too. Just a thought. Overall, love the project! --- guidelines/EXTENSIONS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guidelines/EXTENSIONS.md b/guidelines/EXTENSIONS.md index c0ead4be21..be10b14984 100644 --- a/guidelines/EXTENSIONS.md +++ b/guidelines/EXTENSIONS.md @@ -89,4 +89,4 @@ An API consumer reading these parameter definitions could interpret this as havi ## Annotations -The Swagger specific annotations currently available for jax-rs APIs do not support the addition of extension data. +The Swagger-specific annotations currently available for jax-rs APIs do not support the addition of extension data. From 1af07543b788bf95d3b8f63044f46314e99107d6 Mon Sep 17 00:00:00 2001 From: Tony Tam Date: Wed, 28 Sep 2016 23:19:33 -0700 Subject: [PATCH 6/6] updated #761 for naming consistency --- versions/3.0.md | 520 ++++++++++++++++++++++++++++-------------------- 1 file changed, 308 insertions(+), 212 deletions(-) diff --git a/versions/3.0.md b/versions/3.0.md index dcaaeb57db..6119777f95 100644 --- a/versions/3.0.md +++ b/versions/3.0.md @@ -58,7 +58,7 @@ YAML, being a superset of JSON, can be used as well to represent a OAS (OpenAPI For example, if a field is said to have an array value, the JSON array representation will be used: -```js +```json { "field" : [...] } @@ -128,8 +128,6 @@ Field Name | Type | Description openapi | `string` | **Required.** Specifies the OpenAPI Specification version being used. It can be used by tooling Specifications and clients to interpret the version. The structure shall be `major`.`minor`.`patch`, where `patch` versions _must_ be compatible with the existing `major`.`minor` tooling. Typically patch versions will be introduced to address errors in the documentation, and tooling should typically be compatible with the corresponding `major`.`minor` (3.0.*). Patch versions will correspond to patches of this document. info | [Info Object](#infoObject) | **Required.** Provides metadata about the API. The metadata can be used by the clients if needed. hosts | [Hosts Object](#hostsObject) | An array of Host objects which provide `scheme`, `host`, `port`, and `basePath` in an associative manner. -consumes | [`string`] | A list of media types the APIs can consume. This is global to all APIs but can be overridden on specific API calls. Value MUST be as described under [Media Types](#mediaTypes). -produces | [`string`] | A list of media types the APIs can produce. This is global to all APIs but can be overridden on specific API calls. Value MUST be as described under [Media Types](#mediaTypes). responses | [Responses] paths | [Paths Object](#pathsObject) | **Required.** The available paths and operations for the API. components | [Components Object](#componentsObject) | An element to hold various schemas for the specification. @@ -167,7 +165,7 @@ Field Pattern | Type | Description ##### Info Object Example: -```js +```json { "title": "Swagger Sample App", "description": "This is a sample server Petstore server.", @@ -231,7 +229,7 @@ Field Pattern | Type | Description ##### Contact Object Example: -```js +```json { "name": "API Support", "url": "http://www.swagger.io/support", @@ -264,7 +262,7 @@ Field Pattern | Type | Description ##### License Object Example: -```js +```json { "name": "Apache 2.0", "url": "http://www.apache.org/licenses/LICENSE-2.0.html" @@ -307,21 +305,22 @@ Field Pattern | Type | Description ##### Paths Object Example -```js +```json { "/pets": { "get": { "description": "Returns all pets from the system that the user has access to", - "produces": [ - "application/json" - ], "responses": { "200": { "description": "A list of pets.", - "schema": { - "type": "array", - "items": { - "$ref": "#/definitions/pet" + "representations": { + "application/json": { + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/pet" + } + } } } } @@ -335,15 +334,15 @@ Field Pattern | Type | Description /pets: get: description: Returns all pets from the system that the user has access to - produces: - - application/json responses: '200': description: A list of pets. - schema: - type: array - items: - $ref: '#/definitions/pet' + representations: + application/json: + schema: + type: array + items: + $ref: '#/definitions/pet' ``` #### Path Item Object @@ -379,30 +378,34 @@ Field Pattern | Type | Description ##### Path Item Object Example -```js +```json { "get": { "description": "Returns pets based on ID", "summary": "Find pets by ID", "operationId": "getPetsById", - "produces": [ - "application/json", - "text/html" - ], "responses": { "200": { "description": "pet response", - "schema": { - "type": "array", - "items": { - "$ref": "#/definitions/Pet" + "representations": { + "*": { + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/Pet" + } + } } } }, "default": { "description": "error payload", - "schema": { - "$ref": "#/definitions/ErrorModel" + "representations": { + "*": { + "schema": { + "$ref": "#/definitions/ErrorModel" + } + } } } } @@ -428,20 +431,21 @@ get: description: Returns pets based on ID summary: Find pets by ID operationId: getPetsById - produces: - - application/json - - text/html responses: '200': description: pet response - schema: - type: array - items: - $ref: '#/definitions/Pet' + representations: + application/json: + schema: + type: array + items: + $ref: '#/definitions/Pet' default: description: error payload - schema: - $ref: '#/definitions/ErrorModel' + representations: + "*": + schema: + $ref: '#/definitions/ErrorModel' parameters: - name: id in: path @@ -466,8 +470,6 @@ Field Name | Type | Description description | `string` | A verbose explanation of the operation behavior. [CommonMark syntax](http://spec.commonmark.org/) can be used for rich text representation. externalDocs | [External Documentation Object](#externalDocumentationObject) | Additional external documentation for this operation. operationId | `string` | Unique string used to identify the operation. The id MUST be unique among all operations described in the API. Tools and libraries MAY use the operationId to uniquely identify an operation, therefore, it is recommended to follow common programming naming conventions. -consumes | [`string`] | A list of media types the operation can consume. This overrides the [`consumes`](#oasConsumes) definition at the OpenAPI Object. An empty value MAY be used to clear the global definition. Value MUST be as described under [Media Types](#mediaTypes). -produces | [`string`] | A list of media types the operation can produce. This overrides the [`produces`](#oasProduces) definition at the OpenAPI Object. An empty value MAY be used to clear the global definition. Value MUST be as described under [Media Types](#mediaTypes). parameters | [[Parameter Object](#parameterObject) | [Reference Object](#referenceObject)] | A list of parameters that are applicable for this operation. If a parameter is already defined at the [Path Item](#pathItemParameters), the new definition will override it, but can never remove it. The list MUST NOT include duplicated parameters. A unique parameter is defined by a combination of a [name](#parameterName) and [location](#parameterIn). The list can use the [Reference Object](#referenceObject) to link to parameters that are defined at the [OpenAPI Object's parameters](#oasParameters). requestBody | [[Request Body Object](#requestBodyObject) | [Reference Object](#referenceObject)] | The request body applicable for this operation. responses | [Responses Object](#responsesObject) | **Required.** The list of possible responses as they are returned from executing this operation. @@ -486,7 +488,7 @@ Field Pattern | Type | Description ##### Operation Object Example -```js +```json { "tags": [ "pet" @@ -494,13 +496,6 @@ Field Pattern | Type | Description "summary": "Updates a pet in the store with form data", "description": "", "operationId": "updatePetWithForm", - "consumes": [ - "application/x-www-form-urlencoded" - ], - "produces": [ - "application/json", - "application/xml" - ], "parameters": [ { "name": "petId", @@ -549,11 +544,6 @@ tags: summary: Updates a pet in the store with form data description: "" operationId: updatePetWithForm -consumes: -- application/x-www-form-urlencoded -produces: -- application/json -- application/xml parameters: - name: petId in: path @@ -601,7 +591,7 @@ Field Pattern | Type | Description ##### External Documentation Object Example -```js +```json { "description": "Find more info here", "url": "https://swagger.io" @@ -623,7 +613,7 @@ There are five possible parameter types. * Path - Used together with [Path Templating](#pathTemplating), where the parameter value is actually part of the operation's URL. This does not include the host or base path of the API. For example, in `/items/{itemId}`, the path parameter is `itemId`. * Query - Parameters that are appended to the URL. For example, in `/items?id=###`, the query parameter is `id`. * Header - Custom headers that are expected as part of the request. -* Form - Used to describe the payload of an HTTP request when either `application/x-www-form-urlencoded`, `multipart/form-data` or both are used as the content type of the request (in the OpenAPI Specification's definition, the [`consumes`](#operationConsumes) property of an operation). This is the only parameter type that can be used to send files, thus supporting the `file` type. Since form parameters are sent in the payload, they cannot be declared together with a body parameter for the same operation. Form parameters have a different format based on the content-type used (for further details, consult http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4): +* Form - Used to describe the payload of an HTTP request when either `application/x-www-form-urlencoded`, `multipart/form-data` or both are used as the content type of the request representations. This is the only parameter type that can be used to send files, thus supporting the `file` type. Since form parameters are sent in the payload, they cannot be declared together with a body parameter for the same operation. Form parameters have a different format based on the content-type used (for further details, consult http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4): * `application/x-www-form-urlencoded` - Similar to the format of Query parameters but as a payload. For example, `foo=1&bar=swagger` - both `foo` and `bar` are form parameters. This is normally used for simple parameters that are being transferred. * `multipart/form-data` - each parameter takes a section in the payload with an internal header. For example, for the header `Content-Disposition: form-data; name="submit-name"` the name of the parameter is `submit-name`. This type of form parameters is more commonly used for file transfers. @@ -654,7 +644,7 @@ Field Pattern | Type | Description A header parameter with an array of 64 bit integer numbers: -```js +```json { "name": "token", "in": "header", @@ -685,7 +675,7 @@ schema: ``` A path parameter of a string value: -```js +```json { "name": "username", "in": "path", @@ -707,7 +697,7 @@ schema: ``` An optional query parameter of a string value, allowing multiple values by repeating the query parameter: -```js +```json { "name": "id", "in": "query", @@ -736,7 +726,7 @@ schema: ``` A form data with file type for a file upload: -```js +```json { "name": "avatar", "in": "formData", @@ -761,13 +751,10 @@ schema: Describes a single request body. -The `Content-Type` of the request body must be specified by the `consumes` attribute, either at the [top-level](#oasConsumes) or [operation level](#operationConsumes). - ##### Fixed Fields Field Name | Type | Description ---|:---:|--- description | `string` | A brief description of the request body. This could contain examples of use. [CommonMark syntax](http://spec.commonmark.org/) can be used for rich text representation. -schema | [Schema Object](#schemaObject) | The schema defining the type used for the request body. examples | [Examples Object](#examplesObject) | Examples of the request body, referenced by media type. required | `boolean` | Determines if the request body is required in the request. Defaults to `true`. @@ -775,53 +762,72 @@ Field Name | Type | Description ##### Patterned Fields Field Pattern | Type | Description ---|:---:|--- +`*` | [Schema Object](#schemaObject) | The schema defining the request body. ^x- | Any | Allows extensions to the OpenAPI Schema. The field name MUST begin with `x-`, for example, `x-internal-id`. The value can be `null`, a primitive, an array or an object. See [Vendor Extensions](#vendorExtensions) for further details. ##### Request Body Examples A request body with a referenced model definition. -```js +```json { "description": "user to add to the system", - "schema": { - "$ref": "#/definitions/User" - }, - "examples": { - "application/json": { - "$ref": 'http://foo.bar#/examples/address-example.json' - 'application/xml': - $ref: 'http://foo.bar#/examples/address-example.xml' - 'text/plain': - $ref: 'http://foo.bar#/examples/address-example.txt' - default: - $ref: 'http://foo.bar#/examples/address-example.whatever' + "representations": { + "application/json": { + "schema": { + "$ref": "#/definitions/User" + }, + "example": { + "$ref": "http://foo.bar#/examples/address-example.json" + } + }, + "application/xml": { + "schema": { + "$ref": "#/definitions/User" + }, + "example": { + "$ref": "http://foo.bar#/examples/address-example.xml" + } + }, + "*": { + "example": { + $ref: "http://foo.bar#/examples/address-example.whatever" + } + } + } } ``` ```yaml description: user to add to the system -schema: - $ref: '#/definitions/User' -examples: - 'application/json': - $ref: 'http://foo.bar/examples/user-example.json' - 'application/xml': - $ref: 'http://foo.bar/examples/user-example.xml' - 'text/plain': - $ref: 'http://foo.bar/examples/user-example.txt' - default: - $ref: 'http://foo.bar/examples/user-example.whatever' +representations: + 'application/json': + schema: + $ref: '#/definitions/User' + example: + $ref: 'http://foo.bar/examples/user-example.json' + 'application/xml': + schema: + $ref: '#/definitions/User' + example: + $ref: 'http://foo.bar/examples/user-example.xml' + '*': + schema: + $ref: 'http://foo.bar/examples/user-example.whatever' ``` A body parameter that is an array of string values: -```js +```json { "description": "user to add to the system", - "schema": { - "type": "array", - "items": { - "type": "string" + "representations": { + "text/plain": { + "schema": { + "type": "array", + "items": { + "type": "string" + } + } } } } @@ -830,10 +836,12 @@ A body parameter that is an array of string values: ```yaml description: user to add to the system required: true -schema: - type: array - items: - type: string +representations: + text/plain: + schema: + type: array + items: + type: string ``` #### Items Object @@ -872,7 +880,7 @@ Field Pattern | Type | Description Items must be of type string and have the minimum length of 2 characters: -```js +```json { "type": "string", "minLength": 2 @@ -886,14 +894,14 @@ minLength: 2 An array of arrays, the internal array being of type integer, numbers must be between 0 and 63 (inclusive): -```js +```json { - "type": "array", - "items": { - "type": "integer", - "minimum": 0, - "maximum": 63 - } + "type": "array", + "items": { + "type": "integer", + "minimum": 0, + "maximum": 63 + } } ``` @@ -926,7 +934,7 @@ It can be used to cover undeclared responses. ##### Patterned Fields Field Pattern | Type | Description ---|:---:|--- -{[HTTP Status Code](#httpCodes)} | [Response Object](#responseObject) | [Reference Object](#referenceObject) | Any [HTTP status code](#httpCodes) can be used as the property name (one property per HTTP status code). Describes the expected response for that HTTP status code. [Reference Object](#referenceObject) can be used to link to a response that is defined at the [OpenAPI Object's responses](#oasResponses) section. This field must quoted for compatibility between JSON and YAML (i.e. "200"), and may contain the uppercase character, `X` to designate a wildcard, such as `2XX` to represent all response codes between `[200-299]`. +[HTTP Status Code](#httpCodes) | [Response Object](#responseObject) | [Reference Object](#referenceObject) | Any [HTTP status code](#httpCodes) can be used as the property name (one property per HTTP status code). Describes the expected response for that HTTP status code. [Reference Object](#referenceObject) can be used to link to a response that is defined at the [OpenAPI Object's responses](#oasResponses) section. This field must quoted for compatibility between JSON and YAML (i.e. "200"), and may contain the uppercase character, `X` to designate a wildcard, such as `2XX` to represent all response codes between `[200-299]`. ^x- | Any | Allows extensions to the OpenAPI Schema. The field name MUST begin with `x-`, for example, `x-internal-id`. The value can be `null`, a primitive, an array or an object. See [Specification Extensions](#specificationExtensions) for further details. @@ -934,18 +942,26 @@ Field Pattern | Type | Description A 200 response for successful operation and a default response for others (implying an error): -```js +```json { "200": { "description": "a pet to be returned", - "schema": { - "$ref": "#/definitions/Pet" + "representations": { + "application/json": { + "schema": { + "$ref": "#/definitions/Pet" + } + } } }, "default": { "description": "Unexpected error", - "schema": { - "$ref": "#/definitions/ErrorModel" + "representations": { + "application/json": { + "schema": { + "$ref": "#/definitions/ErrorModel" + } + } } } } @@ -954,12 +970,16 @@ A 200 response for successful operation and a default response for others (imply ```yaml '200': description: a pet to be returned - schema: - $ref: '#/definitions/Pet' + representations: + application/json + schema: + $ref: '#/definitions/Pet' default: description: Unexpected error - schema: - $ref: '#/definitions/ErrorModel' + representations: + '*': + schema: + $ref: '#/definitions/ErrorModel' ``` #### Response Object @@ -969,7 +989,6 @@ Describes a single response from an API Operation, including design-time, static Field Name | Type | Description ---|:---:|--- description | `string` | **Required.** A short description of the response. [CommonMark syntax](http://spec.commonmark.org/) can be used for rich text representation. -schema | [Schema Object](#schemaObject) | A definition of the response structure. It can be a primitive, an array or an object. If this field does not exist, it means no content is returned as part of the response. As an extension to the [Schema Object](#schemaObject), its root `type` value may also be `"file"`. This SHOULD be accompanied by a relevant `produces` media type. headers | [Headers Object](#headersObject) | A list of headers that are sent with the response. examples | [Example Object](#exampleObject) | An example of the response message. links | [Links Object](#linksObject) | An object representing operations related to the response payload. @@ -979,19 +998,26 @@ Field Name | Type | Description Field Pattern | Type | Description ---|:---:|--- +`*` | [Schema Object](#schemaObject)| [Reference Object](#referenceObject) | A schema describing the response value for a specific `Content-Type` ^x- | Any | Allows extensions to the OpenAPI Schema. The field name MUST begin with `x-`, for example, `x-internal-id`. The value can be `null`, a primitive, an array or an object. See [Specification Extensions](#specificationExtensions) for further details. +Representations may take the form of a wildcard (`*`) to designate any `Content-Type`, or a regular expression for matching a specific type + ##### Response Object Examples Response of an array of a complex type: -```js +```json { "description": "A complex object array response", - "schema": { - "type": "array", - "items": { - "$ref": "#/definitions/VeryComplexType" + "representations": { + "application/json": { + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/VeryComplexType" + } + } } } } @@ -999,36 +1025,48 @@ Response of an array of a complex type: ```yaml description: A complex object array response -schema: - type: array - items: - $ref: '#/definitions/VeryComplexType' +representations: + application/json: + schema: + type: array + items: + $ref: '#/definitions/VeryComplexType' ``` Response with a string type: -```js +```json { "description": "A simple string response", - "schema": { - "type": "string" + "representations": { + "schema": { + "text/plain": { + "type": "string" + } + } } } ``` ```yaml description: A simple string response -schema: - type: string +representations: + text/plain: + schema: + type: string ``` Response with headers: -```js +```json { "description": "A simple string response", - "schema": { - "type": "string" + "representations": { + "text/plain": { + "schema": { + "type": "string" + } + } }, "headers": { "X-Rate-Limit-Limit": { @@ -1049,8 +1087,11 @@ Response with headers: ```yaml description: A simple string response -schema: - type: string +representations: + text/plain: + schema: + type: string + example: 'whoa!' headers: X-Rate-Limit-Limit: description: The number of allowed requests in the current period @@ -1065,7 +1106,7 @@ headers: Response with no return value: -```js +```json { "description": "object created" } @@ -1087,7 +1128,7 @@ Field Pattern | Type | Description Rate-limit headers: -```js +```json { "X-Rate-Limit-Limit": { "description": "The number of allowed requests in the current period", @@ -1129,7 +1170,7 @@ Field Pattern | Type | Description Example request or response for application/json media type of a Pet data type: -```js +```json { "application/json": { "name": "Puma", @@ -1214,9 +1255,9 @@ For example: ```json [ - { "color": "red" }, - { "color": "green" }, - { "color": "blue" } + { "color": "red" }, + { "color": "green" }, + { "color": "blue" } ] ``` @@ -1263,12 +1304,14 @@ paths: responses: 200: description: the user being returned - schema: - type: object - properties: - uuid: the unique user id - type: string - format: uuid + representations: + application/json: + schema: + type: object + properties: + uuid: the unique user id + type: string + format: uuid ``` Can be used in a link like this: @@ -1334,8 +1377,10 @@ paths: responses: 200: description: The User - schema: - $ref: '#/components/definitions/user' + representations: + application/json: + schema: + $ref: '#/components/definitions/user' links: userRepositories: $ref: '#/components/links/UserRepositories' @@ -1350,10 +1395,12 @@ paths: responses: 200: description: repositories owned by the supplied user - schema: - type: array - items: - $ref: '#/components/definitions/repository' + representations: + application/json: + schema: + type: array + items: + $ref: '#/components/definitions/repository' links: userRepository: $ref: '#/components/links/UserRepository' @@ -1372,8 +1419,10 @@ paths: responses: 200: description: The repository - schema: - $ref: '#/components/definitions/repository' + representations: + application/json: + schema: + $ref: '#/components/definitions/repository' links: repositoryPullRequests: $ref: '#/components/links/RepositoryPullRequests' @@ -1399,10 +1448,12 @@ paths: responses: 200: description: an array of pull request objects - schema: - type: array - items: - $ref: '#/components/definitions/pullrequest' + representations: + application/json: + schema: + type: array + items: + $ref: '#/components/definitions/pullrequest' /2.0/repositories/{username}/{slug}/pullrequests/{pid}: get: operationId: getPullRequestsById @@ -1422,8 +1473,10 @@ paths: responses: 200: description: a pull request object - schema: - $ref: '#/components/definitions/pullrequest' + representations: + application/json: + schema: + $ref: '#/components/definitions/pullrequest' links: $ref: '#/components/links/PullRequestMerge' /2.0/repositories/{username}/{slug}/pullrequests/{pid}/merge: @@ -1587,7 +1640,7 @@ Field Pattern | Type | Description A simple header with of an integer type: -```js +```json { "description": "The number of allowed requests in the current period", "type": "integer" @@ -1618,7 +1671,7 @@ Field Pattern | Type | Description ##### Tag Object Example -```js +```json { "name": "pet", "description": "Pets operations" @@ -1649,19 +1702,15 @@ definitions: example: $ref: http://foo.bar#/examples/name-example -# in a request body, note the plural `examples` as the content-type is set by `consumes`: +# in a request body, note the plural `examples` as the content-type is set to `*`: requestBody: - schema: - $ref: '#/definitions/Address' - examples: - 'application/json': - $ref: 'http://foo.bar#/examples/address-example.json' - 'application/xml': - $ref: 'http://foo.bar#/examples/address-example.xml' - 'text/plain': - $ref: 'http://foo.bar#/examples/address-example.txt' - default: - $ref: 'http://foo.bar#/examples/address-example.whatever' + representations: + 'application/json': + schema: + $ref: '#/definitions/Address' + examples: + - {"foo": "bar"} + - {"bar": "baz"} # in a parameter @@ -1676,11 +1725,12 @@ definitions: responses: 200: description: your car appointment has been booked - schema: - $ref: '#/definitions/SuccessResponse' - examples: - 'application/json': - $ref: http://foo.bar#/examples/address-example.json + representations: + application/json: + schema: + $ref: '#/definitions/SuccessResponse' + example: + $ref: http://foo.bar#/examples/address-example.json ``` #### Reference Object @@ -1698,7 +1748,7 @@ Field Name | Type | Description ##### Reference Object Example -```js +```json { "$ref": "#/definitions/Pet" } @@ -1709,7 +1759,7 @@ $ref: '#/definitions/Pet' ``` ##### Relative Schema File Example -```js +```json { "$ref": "Pet.json" } @@ -1720,7 +1770,7 @@ $ref: 'Pet.yaml' ``` ##### Relative Files With Embedded Schema Example -```js +```json { "$ref": "definitions.json#/Pet" } @@ -1780,6 +1830,7 @@ Field Name | Type | Description xml | [XML Object](#xmlObject) | This MAY be used only on properties schemas. It has no effect on root schemas. Adds Additional metadata to describe the XML representation format of this property. externalDocs | [External Documentation Object](#externalDocumentationObject) | Additional external documentation for this schema. example | Any | A free-form property to include an example of an instance for this schema. +examples | Any | An array of free-formed properties to include examples for this schema. deprecated | `boolean` | Specifies that a schema is deprecated and should be transitioned out of usage. ##### Patterned Objects @@ -1811,10 +1862,10 @@ The [XML Object](#xmlObject) contains additional information about the available Unlike previous versions of Swagger, OpenAPI Schema definitions can be used to describe primitive and arrays as well. -```js +```json { - "type": "string", - "format": "email" + "type": "string", + "format": "email" } ``` @@ -1825,7 +1876,7 @@ format: email ###### Simple Model -```js +```json { "type": "object", "required": [ @@ -1866,7 +1917,7 @@ properties: For a simple string to string mapping: -```js +```json { "type": "object", "additionalProperties": { @@ -1883,7 +1934,7 @@ additionalProperties: For a string to model mapping: -```js +```json { "type": "object", "additionalProperties": { @@ -1900,7 +1951,7 @@ additionalProperties: ###### Model with Example -```js +```json { "type": "object", "properties": { @@ -1937,9 +1988,54 @@ example: id: 1 ``` +###### Model with Examples + +```json +{ + "type": "object", + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "name": { + "type": "string" + } + }, + "required": [ + "name" + ], + "examples": [ + { + "name": "Puma", + "id": 1 + }, { + "name": "Ferguson", + "id": 2 + }] +} +``` + +```yaml +type: object +properties: + id: + type: integer + format: int64 + name: + type: string +required: +- name +examples: + - name: Puma + id: 1 + - name: Ferguson + id: 2 +``` + ###### Models with Composition -```js +```json { "definitions": { "ErrorModel": { @@ -2008,7 +2104,7 @@ definitions: ###### Models with Polymorphism Support -```js +```json { "definitions": { "Pet": { @@ -2157,7 +2253,7 @@ The examples of the XML object definitions are included inside a property defini Basic string property: -```js +```json { "animals": { "type": "string" @@ -2176,7 +2272,7 @@ animals: Basic string array property ([`wrapped`](#xmlWrapped) is `false` by default): -```js +```json { "animals": { "type": "array", @@ -2202,7 +2298,7 @@ animals: ###### XML Name Replacement -```js +```json { "animals": { "type": "string", @@ -2229,7 +2325,7 @@ animals: In this example, a full model definition is shown. -```js +```json { "Person": { "type": "object", @@ -2279,7 +2375,7 @@ Person: Changing the element names: -```js +```json { "animals": { "type": "array", @@ -2309,7 +2405,7 @@ animals: The external `name` property has no effect on the XML: -```js +```json { "animals": { "type": "array", @@ -2344,7 +2440,7 @@ animals: Even when the array is wrapped, if no name is explicitly defined, the same name will be used both internally and externally: -```js +```json { "animals": { "type": "array", @@ -2376,7 +2472,7 @@ animals: To overcome the above example, the following definition can be used: -```js +```json { "animals": { "type": "array", @@ -2413,7 +2509,7 @@ animals: Affecting both internal and external names: -```js +```json { "animals": { "type": "array", @@ -2452,7 +2548,7 @@ animals: If we change the external element but not the internal ones: -```js +```json { "animals": { "type": "array", @@ -2509,7 +2605,7 @@ my\org\User ##### Definitions Object Example -```js +```json { "Category": { "type": "object", @@ -2572,7 +2668,7 @@ Field Pattern | Type | Description ##### Parameters Definition Object Example -```js +```json { "skipParam": { "name": "skip", @@ -2626,7 +2722,7 @@ Field Pattern | Type | Description ##### Responses Definitions Object Example -```js +```json { "NotFound": { "description": "Entity not found." @@ -2666,7 +2762,7 @@ Field Pattern | Type | Description ##### Security Definitions Object Example -```js +```json { "api_key": { "type": "apiKey", @@ -2726,7 +2822,7 @@ Field Name | Type | Description ###### Basic Authentication Sample -```js +```json { "type": "basic" } @@ -2738,7 +2834,7 @@ type: basic ###### API Key Sample -```js +```json { "type": "apiKey", "name": "api_key", @@ -2754,7 +2850,7 @@ in: header ###### Implicit OAuth2 Sample -```js +```json { "type": "oauth2", "authorizationUrl": "http://swagger.io/api/oauth/dialog", @@ -2793,7 +2889,7 @@ Field Pattern | Type | Description ##### Scopes Object Example -```js +```json { "write:pets": "modify pets in your account", "read:pets": "read your pets" @@ -2822,7 +2918,7 @@ Field Pattern | Type | Description ###### Non-OAuth2 Security Requirement -```js +```json { "api_key": [] } @@ -2834,7 +2930,7 @@ api_key: [] ###### OAuth2 Security Requirement -```js +```json { "petstore_auth": [ "write:pets",