From 8e849d6693b0589305800996cecb106c6636a0c3 Mon Sep 17 00:00:00 2001 From: Paul Ebermann Date: Tue, 12 Apr 2016 19:30:22 +0200 Subject: [PATCH 1/2] Issue #577: draft specification changes. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This simply reuses the $ref property of a path item – not sure if that is the right thing to do, or if we should use an `interface` property instead. --- versions/3.0.md | 176 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 173 insertions(+), 3 deletions(-) diff --git a/versions/3.0.md b/versions/3.0.md index f85900cec6..c9e133def7 100644 --- a/versions/3.0.md +++ b/versions/3.0.md @@ -333,7 +333,7 @@ A Path Item may be empty, due to [ACL constraints](#securityFiltering). The path Field Name | Type | Description ---|:---:|--- -$ref | `string` | Allows for an external definition of this path item. The referenced structure MUST be in the format of a [Path Item Object](#pathItemObject). If there are conflicts between the referenced definition and this Path Item's definition, the behavior is *undefined*. +$ref | `string` | Allows for an external definition of this path item. The referenced structure MUST be in the format of a [Path Item Object](#pathItemObject). If there are conflicts between the referenced definition and this Path Item's definition, the behavior is *undefined*. The referenced structure also can be an [interface object](#interfaceObject). In this case the path is implementing the interface. If the path contains any parameter placeholders, these need to be declared in the [parameters property](#pathItemParameters), as an interface can't declare path parameters itself. summary | An optional, string summary, intended to apply to all operations in this path. description | An optional, string description, intended to apply to all operations in this path. get | [Operation Object](#operationObject) | A definition of a GET operation on this path. @@ -430,9 +430,178 @@ parameters: collectionFormat: csv ``` +##### Path Item Object example (using an interface) + +This example refers to the pet-list example in the [Interface object](#interfaceObject). + +```js +{ + "$ref": "#/interfaces/pet-list", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "IDs of pets to use", + "required": true, + "type": "array", + "items": { + "type": "string" + }, + "collectionFormat": "csv" + } + ] +} +``` + +```yaml +$ref: '#/interfaces/pet-list' +parameters: +- name: id + in: path + description: ID of pet to use + required: true + type: array + items: + type: string + collectionFormat: csv +``` + +#### Interfaces Object + +The Interfaces objects defines named interfaces which can then be implemented by [path items](#pathItemObject) declared in the [Paths object](#pathsObject) or by URI properties in schemas. + +##### Patterned Fields + +Field Pattern | Type | Description +---|:---:|--- +{name} | [Interface Object](#schemaObject) | A single interface, mapping a "name" to the interface it defines. + +##### Interfaces Object Example + +```js +{ + "pet-list": { + "get": { + "description": "Returns a list of pets", + "produces": [ + "application/json" + ], + "responses": { + "200": { + "description": "A list of pets.", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/pet" + } + } + } + } + } + } +} +``` + +```yaml +pet-list: + get: + description: Returns a list of pets + produces: + - application/json + responses: + '200': + description: A list of pets. + schema: + type: array + items: + $ref: '#/definitions/pet' +``` + + +#### Interface object + +An interface defines a set of operations which can be implemented by a path item, or by a URI property in a schema. +An interface object might be empty, due to [ACL constraints](#securityFiltering). The existence of the interface itself is still exposed to the documentation viewer but they will not know which operations and parameters are available. + +An interface doesn't define any path parameters, and also can't define any host, scheme or port properties. These come either from the path item or are included in the URI implementing this interface. The same applies for operation objects included in an interface. + +##### Fixed Fields + +Field Name | Type | Description +---|:---:|--- +get | [Operation Object](#operationObject) | A definition of a GET operation on this path. +put | [Operation Object](#operationObject) | A definition of a PUT operation on this path. +post | [Operation Object](#operationObject) | A definition of a POST operation on this path. +delete | [Operation Object](#operationObject) | A definition of a DELETE operation on this path. +options | [Operation Object](#operationObject) | A definition of a OPTIONS operation on this path. +head | [Operation Object](#operationObject) | A definition of a HEAD operation on this path. +patch | [Operation Object](#operationObject) | A definition of a PATCH operation on this path. +parameters | [[Parameter Object](#parameterObject) | [Reference Object](#referenceObject)] | A list of parameters that are applicable for all the operations described under this interface. These parameters can be overridden at the operation level, but cannot be removed there. 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). There can be one "body" parameter at most. There MUST be no parameters with location "path" in this list. + + +##### Patterned Fields + +Field Pattern | Type | Description +---|:---:|--- +^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. + +##### Interface Item Object Example + + + +```js +{ + "get": { + "description": "Returns list of pets", + "summary": "retrieve list of pets", + "produces": [ + "application/json", + "text/html" + ], + "responses": { + "200": { + "description": "pet response", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/Pet" + } + } + }, + "default": { + "description": "error payload", + "schema": { + "$ref": "#/definitions/ErrorModel" + } + } + } + } +} +``` + +```yaml +get: + description: returns a list of pets + summary: retrieve list of pets + produces: + - application/json + - text/html + responses: + '200': + description: pet response + schema: + type: array + items: + $ref: '#/definitions/Pet' + default: + description: error payload + schema: + $ref: '#/definitions/ErrorModel' +``` + #### Operation Object -Describes a single API operation on a path. +Describes a single API operation on a path or an interface. ##### Fixed Fields @@ -445,7 +614,7 @@ Field Name | Type | Description 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 MIME 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 [Mime Types](#mimeTypes). produces | [`string`] | A list of MIME 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 [Mime Types](#mimeTypes). -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). There can be one "body" parameter at most. +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) or [Interface](#interfaceParameters), 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). There can be one "body" parameter at most. If this operation is contained in an interface definition, the parameters can't have a location of `path` (because there is no path which could contain the corresponding placeholder). responses | [Responses Object](#responsesObject) | **Required.** The list of possible responses as they are returned from executing this operation. schemes | [`string`] | The transfer protocol for the operation. Values MUST be from the list: `"http"`, `"https"`, `"ws"`, `"wss"`. The value overrides the OpenAPI Object [`schemes`](#oasSchemes) definition. deprecated | `boolean` | Declares this operation to be deprecated. Usage of the declared operation should be refrained. Default value is `false`. @@ -1314,6 +1483,7 @@ Field Name | Type | Description ---|:---:|--- discriminator | `string` | 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. readOnly | `boolean` | Relevant only for Schema `"properties"` definitions. Declares the property as "read only". This means that it MAY be sent as part of a response but MUST NOT be sent as part of the request. Properties marked as `readOnly` being `true` SHOULD NOT be in the `required` list of the defined schema. Default value is `false`. +interface | [Interface Object](#interfaceObject)|[Reference Object](#referenceObject) | For properties of type `string`, this (optional) property declares that the value is an URI, and the resource identified by this URI implements the given (or usually referred) interface. (This allows the receiver to actually use the URI without trying to parse it.) 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 a an example of an instance for this schema. From 19f8cfd9c4f61629ff492dada03505c0615753c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pa=C5=ADlo=20Ebermann?= Date: Wed, 20 Apr 2016 22:18:40 +0200 Subject: [PATCH 2/2] Issue #577: put the interfaces object into the components object from #633. Also, rename it to "Interfaces Definitions Object". --- versions/3.0.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/versions/3.0.md b/versions/3.0.md index c9e133def7..15815df126 100644 --- a/versions/3.0.md +++ b/versions/3.0.md @@ -269,6 +269,7 @@ Field Pattern | Type | Description | [Parameters Definitions Object](#parametersDefinitionsObject) | An object to hold parameters to be reused across operations. Parameter definitions can be referenced to the ones defined here. | [Response Headers Definitions Object](#responseHeadersDefinitionsObject) | Response headers to reuse across the specification. | [Security Definitions Object](#securityDefinitionsObject) | Security definitions to reuse across the specification. + interfaces | [Interface Definitions Object](#interfacesDefinitionsObject) | Interface definitions to reuse in paths or URI properties in schemas. #### Paths Object @@ -436,7 +437,7 @@ This example refers to the pet-list example in the [Interface object](#interface ```js { - "$ref": "#/interfaces/pet-list", + "$ref": "#/components/interfaces/pet-list", "parameters": [ { "name": "id", @@ -454,7 +455,7 @@ This example refers to the pet-list example in the [Interface object](#interface ``` ```yaml -$ref: '#/interfaces/pet-list' +$ref: '#/components/interfaces/pet-list' parameters: - name: id in: path @@ -466,9 +467,9 @@ parameters: collectionFormat: csv ``` -#### Interfaces Object +#### Interfaces Definitions Object -The Interfaces objects defines named interfaces which can then be implemented by [path items](#pathItemObject) declared in the [Paths object](#pathsObject) or by URI properties in schemas. +The Interfaces definitions object defines named interfaces which can then be implemented by [path items](#pathItemObject) declared in the [Paths object](#pathsObject) or by URI properties in schemas. ##### Patterned Fields