diff --git a/packages/apidom-ls/src/config/codes.ts b/packages/apidom-ls/src/config/codes.ts index 325b2e701..d1ec1ed64 100644 --- a/packages/apidom-ls/src/config/codes.ts +++ b/packages/apidom-ls/src/config/codes.ts @@ -671,6 +671,18 @@ enum ApilintCodes { OPENAPI2_PATHS = 3060000, OPENAPI2_PATHS_VALUES_TYPE = 3060100, + OPENAPI2_PATH_ITEM = 3070000, + OPENAPI2_PATH_ITEM_FIELD_$REF_FORMAT_URI = 3070100, + OPENAPI2_PATH_ITEM_FIELD_GET_TYPE = 3070200, + OPENAPI2_PATH_ITEM_FIELD_PUT_TYPE = 3070300, + OPENAPI2_PATH_ITEM_FIELD_POST_TYPE = 3070400, + OPENAPI2_PATH_ITEM_FIELD_DELETE_TYPE = 3070500, + OPENAPI2_PATH_ITEM_FIELD_OPTIONS_TYPE = 3070600, + OPENAPI2_PATH_ITEM_FIELD_HEAD_TYPE = 3070700, + OPENAPI2_PATH_ITEM_FIELD_PATCH_TYPE = 3070800, + OPENAPI2_PATH_ITEM_FIELD_PARAMETERS_TYPE = 3070900, + OPENAPI2_PATH_ITEM_FIELD_PARAMETERS_ITEMS_TYPE = 3071000, + OPENAPI3_0 = 5000000, OPENAPI3_0_OPENAPI_VALUE_PATTERN_3_0_0 = 5000100, diff --git a/packages/apidom-ls/src/config/openapi/path-item/completion.ts b/packages/apidom-ls/src/config/openapi/path-item/completion.ts index 30130f979..32ef854f7 100644 --- a/packages/apidom-ls/src/config/openapi/path-item/completion.ts +++ b/packages/apidom-ls/src/config/openapi/path-item/completion.ts @@ -3,9 +3,23 @@ import { CompletionFormat, CompletionType, } from '../../../apidom-language-types'; -import { OpenAPI30, OpenAPI31, OpenAPI3 } from '../target-specs'; +import { OpenAPI2, OpenAPI30, OpenAPI31, OpenAPI3 } from '../target-specs'; const completion: ApidomCompletionItem[] = [ + { + label: '$ref', + insertText: '\\$ref', + kind: 14, + format: CompletionFormat.QUOTED, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + 'Allows for an external definition of this path item. The referenced structure MUST be in the format of a [Path Item Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#pathItemObject). If there are conflicts between the referenced', + }, + targetSpecs: OpenAPI2, + }, { label: '$ref', insertText: '\\$ref', @@ -60,6 +74,20 @@ const completion: ApidomCompletionItem[] = [ }, targetSpecs: OpenAPI3, }, + { + label: 'get', + insertText: 'get', + kind: 14, + format: CompletionFormat.OBJECT, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + '[Operation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#operationObject)\n\\\n\\\nA definition of a GET operation on this path.', + }, + targetSpecs: OpenAPI2, + }, { label: 'get', insertText: 'get', @@ -102,6 +130,20 @@ const completion: ApidomCompletionItem[] = [ }, targetSpecs: OpenAPI30, }, + { + label: 'put', + insertText: 'put', + kind: 14, + format: CompletionFormat.OBJECT, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + '[Operation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#operationObject)\n\\\n\\\nA definition of a PUT operation on this path.', + }, + targetSpecs: OpenAPI2, + }, { label: 'put', insertText: 'put', @@ -116,6 +158,20 @@ const completion: ApidomCompletionItem[] = [ }, targetSpecs: OpenAPI31, }, + { + label: 'post', + insertText: 'post', + kind: 14, + format: CompletionFormat.OBJECT, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + '[Operation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#operationObject)\n\\\n\\\nA definition of a POST operation on this path.', + }, + targetSpecs: OpenAPI2, + }, { label: 'post', insertText: 'post', @@ -144,6 +200,20 @@ const completion: ApidomCompletionItem[] = [ }, targetSpecs: OpenAPI31, }, + { + label: 'delete', + insertText: 'delete', + kind: 14, + format: CompletionFormat.OBJECT, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + '[Operation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#operationObject)\n\\\n\\\nA definition of a DELETE operation on this path.', + }, + targetSpecs: OpenAPI2, + }, { label: 'delete', insertText: 'delete', @@ -172,6 +242,20 @@ const completion: ApidomCompletionItem[] = [ }, targetSpecs: OpenAPI31, }, + { + label: 'options', + insertText: 'options', + kind: 14, + format: CompletionFormat.OBJECT, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + '[Operation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#operationObject)\n\\\n\\\nA definition of a OPTIONS operation on this path.', + }, + targetSpecs: OpenAPI2, + }, { label: 'options', insertText: 'options', @@ -200,6 +284,20 @@ const completion: ApidomCompletionItem[] = [ }, targetSpecs: OpenAPI31, }, + { + label: 'head', + insertText: 'head', + kind: 14, + format: CompletionFormat.OBJECT, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + '[Operation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#operationObject)\n\\\n\\\nA definition of a HEAD operation on this path.', + }, + targetSpecs: OpenAPI2, + }, { label: 'head', insertText: 'head', @@ -228,6 +326,20 @@ const completion: ApidomCompletionItem[] = [ }, targetSpecs: OpenAPI31, }, + { + label: 'patch', + insertText: 'patch', + kind: 14, + format: CompletionFormat.OBJECT, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + '[Operation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#operationObject)\n\\\n\\\nA definition of a PATCH operation on this path.', + }, + targetSpecs: OpenAPI2, + }, { label: 'patch', insertText: 'patch', @@ -312,6 +424,20 @@ const completion: ApidomCompletionItem[] = [ }, targetSpecs: OpenAPI31, }, + { + label: 'parameters', + insertText: 'parameters', + kind: 14, + format: CompletionFormat.ARRAY, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + '[[Parameter Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#parameterObject) | [Reference Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#referenceObject)]\n\\\n\\\nA list of parameters that are applicable for all the operations described under this path. 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](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#parameterName) and [location](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#parameterIn). The list can use the [Reference Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#referenceObject) to link to parameters that are defined at the [Swagger Object\'s parameters](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#swaggerParameters). There can be one "body" parameter at most.', + }, + targetSpecs: OpenAPI2, + }, { label: 'parameters', insertText: 'parameters', diff --git a/packages/apidom-ls/src/config/openapi/path-item/documentation.ts b/packages/apidom-ls/src/config/openapi/path-item/documentation.ts index a088f4f47..72fba3f43 100644 --- a/packages/apidom-ls/src/config/openapi/path-item/documentation.ts +++ b/packages/apidom-ls/src/config/openapi/path-item/documentation.ts @@ -1,4 +1,4 @@ -import { OpenAPI30, OpenAPI31, OpenAPI3 } from '../target-specs'; +import { OpenAPI2, OpenAPI30, OpenAPI31, OpenAPI3 } from '../target-specs'; /** * Omitted fixed fields: @@ -9,7 +9,7 @@ import { OpenAPI30, OpenAPI31, OpenAPI3 } from '../target-specs'; * - options * - head * - patch - * - trace + * - trace (OpenAPI 3.x.y) * * Field omission reason: omitted fields do have a non-union type. Thus, * documentation for these fields doesn't need to be specified here and will @@ -18,6 +18,11 @@ import { OpenAPI30, OpenAPI31, OpenAPI3 } from '../target-specs'; */ const documentation = [ + { + target: '$ref', + docs: 'Allows for an external definition of this path item. The referenced structure MUST be in the format of a [Path Item Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#pathItemObject). If there are conflicts between the referenced', + targetSpecs: OpenAPI2, + }, { target: '$ref', docs: 'Allows for an external definition of this path item. The referenced structure MUST be in the format of a [Path Item Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#pathItemObject). In case a Path Item Object field appears both in the defined object and the referenced object, the behavior is undefined.', @@ -25,7 +30,7 @@ const documentation = [ }, { target: '$ref', - docs: '**REQUIRED**. The reference identifier. This MUST be in the form of a URI.', + docs: 'Allows for a referenced definition of this path item. The referenced structure MUST be in the form of a [Path Item Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#pathItemObject). In case a Path Item Object field appears both in the defined object and the referenced object, the behavior is undefined. See the rules for resolving [Relative References](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#relativeReferencesURI).', targetSpecs: OpenAPI31, }, { @@ -50,14 +55,23 @@ const documentation = [ }, { target: 'parameters', - docs: "[[Parameter](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#parameterObject) | [Reference Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#referenceObject)]\n\\\n\\\nA list of parameters that are applicable for all the operations described under this path. 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](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#parameterName) and [location](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#parameterIn). The list can use the [Reference Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#referenceObject) to link to parameters that are defined at the [OpenAPI Object's components/parameters](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#componentsParameters).", + docs: '[[Parameter Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#parameterObject) | [Reference Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#referenceObject)]\n\\\n\\\nA list of parameters that are applicable for all the operations described under this path. 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](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#parameterName) and [location](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#parameterIn). The list can use the [Reference Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#referenceObject) to link to parameters that are defined at the [Swagger Object\'s parameters](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#swaggerParameters). There can be one "body" parameter at most.', + targetSpecs: OpenAPI2, + }, + { + target: 'parameters', + docs: "[[Parameter Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#parameterObject) | [Reference Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#referenceObject)]\n\\\n\\\nA list of parameters that are applicable for all the operations described under this path. 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](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#parameterName) and [location](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#parameterIn). The list can use the [Reference Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#referenceObject) to link to parameters that are defined at the [OpenAPI Object's components/parameters](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#componentsParameters).", targetSpecs: OpenAPI30, }, { target: 'parameters', - docs: "[[Parameter](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#parameterObject) | [Reference Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#referenceObject)]\n\\\n\\\nA list of parameters that are applicable for all the operations described under this path. 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](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#parameterName) and [location](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#parameterIn). The list can use the [Reference Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#referenceObject) to link to parameters that are defined at the [OpenAPI Object's components/parameters](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#componentsParameters).", + docs: "[[Parameter Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#parameterObject) | [Reference Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#referenceObject)]\n\\\n\\\nA list of parameters that are applicable for all the operations described under this path. 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](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#parameterName) and [location](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#parameterIn). The list can use the [Reference Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#referenceObject) to link to parameters that are defined at the [OpenAPI Object's components/parameters](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#componentsParameters).", targetSpecs: OpenAPI31, }, + { + docs: '#### [Path Item Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#path-item-object)\n\nDescribes the operations available on a single path.\nA Path Item may be empty, due to [ACL constraints](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#securityFiltering). The path itself is still exposed to the documentation viewer but they will not know which operations and parameters are available.\n\n##### Fixed Fields\n\nField Name | Type | Description\n---|:---:|---\n$ref | `string` | Allows for an external definition of this path item. The referenced structure MUST be in the format of a [Path Item Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#pathItemObject). If there are conflicts between the referenced definition and this Path Item\'s definition, the behavior is *undefined*.\nget | [Operation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#operationObject) | A definition of a GET operation on this path.\nput | [Operation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#operationObject) | A definition of a PUT operation on this path.\npost | [Operation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#operationObject) | A definition of a POST operation on this path.\ndelete | [Operation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#operationObject) | A definition of a DELETE operation on this path.\noptions | [Operation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#operationObject) | A definition of a OPTIONS operation on this path.\nhead | [Operation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#operationObject) | A definition of a HEAD operation on this path.\npatch | [Operation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#operationObject) | A definition of a PATCH operation on this path.\nparameters | [[Parameter Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#parameterObject) \\| [Reference Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#referenceObject)] | A list of parameters that are applicable for all the operations described under this path. 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](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#parameterName) and [location](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#parameterIn). The list can use the [Reference Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#referenceObject) to link to parameters that are defined at the [Swagger Object\'s parameters](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#swaggerParameters). There can be one "body" parameter at most.\n\n##### Patterned Fields\n\nField Pattern | Type | Description\n---|:---:|---\n^x- | Any | Allows extensions to the Swagger 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](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#vendorExtensions) for further details.\n\n##### Path Item Object Example\n\n```js\n{\n "get": {\n "description": "Returns pets based on ID",\n "summary": "Find pets by ID",\n "operationId": "getPetsById",\n "produces": [\n "application/json",\n "text/html"\n ],\n "responses": {\n "200": {\n "description": "pet response",\n "schema": {\n "type": "array",\n "items": {\n "$ref": "#/definitions/Pet"\n }\n }\n },\n "default": {\n "description": "error payload",\n "schema": {\n "$ref": "#/definitions/ErrorModel"\n }\n }\n }\n },\n "parameters": [\n {\n "name": "id",\n "in": "path",\n "description": "ID of pet to use",\n "required": true,\n "type": "array",\n "items": {\n "type": "string"\n },\n "collectionFormat": "csv"\n }\n ]\n}\n```\n\n\n\\\nYAML\n```yaml\nget:\n description: Returns pets based on ID\n summary: Find pets by ID\n operationId: getPetsById\n produces:\n - application/json\n - text/html\n responses:\n \'200\':\n description: pet response\n schema:\n type: array\n items:\n $ref: \'#/definitions/Pet\'\n default:\n description: error payload\n schema:\n $ref: \'#/definitions/ErrorModel\'\nparameters:\n- name: id\n in: path\n description: ID of pet to use\n required: true\n type: array\n items:\n type: string\n collectionFormat: csv\n```', + targetSpecs: OpenAPI2, + }, { docs: '#### [Path Item Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#path-item-object)\n\nDescribes the operations available on a single path.\nA Path Item MAY be empty, due to [ACL constraints](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#securityFiltering).\nThe path itself is still exposed to the documentation viewer but they will not know which operations and parameters are available.\n\n##### Fixed Fields\n\nField Name | Type | Description\n---|:---:|---\n$ref | `string` | Allows for an external definition of this path item. The referenced structure MUST be in the format of a [Path Item Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#pathItemObject). In case a Path Item Object field appears both in the defined object and the referenced object, the behavior is undefined.\nsummary| `string` | An optional, string summary, intended to apply to all operations in this path.\ndescription | `string` | An optional, string description, intended to apply to all operations in this path. [CommonMark syntax](https://spec.commonmark.org/) MAY be used for rich text representation.\nget | [Operation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#operationObject) | A definition of a GET operation on this path.\nput | [Operation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#operationObject) | A definition of a PUT operation on this path.\npost | [Operation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#operationObject) | A definition of a POST operation on this path.\ndelete | [Operation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#operationObject) | A definition of a DELETE operation on this path.\noptions | [Operation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#operationObject) | A definition of a OPTIONS operation on this path.\nhead | [Operation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#operationObject) | A definition of a HEAD operation on this path.\npatch | [Operation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#operationObject) | A definition of a PATCH operation on this path.\ntrace | [Operation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#operationObject) | A definition of a TRACE operation on this path.\nservers | [[Server Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#serverObject)] | An alternative `server` array to service all operations in this path.\nparameters | [[Parameter Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#parameterObject) \\| [Reference Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#referenceObject)] | A list of parameters that are applicable for all the operations described under this path. 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](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#parameterName) and [location](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#parameterIn). The list can use the [Reference Object](#referenceObject) to link to parameters that are defined at the [OpenAPI Object\'s components/parameters](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#componentsParameters).\n\n\nThis object MAY be extended with [Specification Extensions](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#specificationExtensions).\n\n##### Path Item Object Example\n\n\n\\\nJSON\n```json\n{\n "get": {\n "description": "Returns pets based on ID",\n "summary": "Find pets by ID",\n "operationId": "getPetsById",\n "responses": {\n "200": {\n "description": "pet response",\n "content": {\n "*/*": {\n "schema": {\n "type": "array",\n "items": {\n "$ref": "#/components/schemas/Pet"\n }\n }\n }\n }\n },\n "default": {\n "description": "error payload",\n "content": {\n "text/html": {\n "schema": {\n "$ref": "#/components/schemas/ErrorModel"\n }\n }\n }\n }\n }\n },\n "parameters": [\n {\n "name": "id",\n "in": "path",\n "description": "ID of pet to use",\n "required": true,\n "schema": {\n "type": "array",\n "items": {\n "type": "string"\n }\n },\n "style": "simple"\n }\n ]\n}\n```\n\n\n\\\nYAML\n```yaml\nget:\n description: Returns pets based on ID\n summary: Find pets by ID\n operationId: getPetsById\n responses:\n \'200\':\n description: pet response\n content:\n \'*/*\' :\n schema:\n type: array\n items:\n $ref: \'#/components/schemas/Pet\'\n default:\n description: error payload\n content:\n \'text/html\':\n schema:\n $ref: \'#/components/schemas/ErrorModel\'\nparameters:\n- name: id\n in: path\n description: ID of pet to use\n required: true\n schema:\n type: array\n items:\n type: string\n style: simple\n```', targetSpecs: OpenAPI30, diff --git a/packages/apidom-ls/src/config/openapi/path-item/lint/$ref--format-uri.ts b/packages/apidom-ls/src/config/openapi/path-item/lint/$ref--format-uri.ts new file mode 100644 index 000000000..caab809d1 --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/path-item/lint/$ref--format-uri.ts @@ -0,0 +1,19 @@ +import { DiagnosticSeverity } from 'vscode-languageserver-types'; + +import ApilintCodes from '../../../codes'; +import { LinterMeta } from '../../../../apidom-language-types'; +import { OpenAPI2, OpenAPI3 } from '../../target-specs'; + +const $refFormatURILint: LinterMeta = { + code: ApilintCodes.OPENAPI2_PATH_ITEM_FIELD_$REF_FORMAT_URI, + source: 'apilint', + message: "'$ref' value must be a valid URI-reference", + severity: DiagnosticSeverity.Error, + linterFunction: 'apilintValidURI', + marker: 'value', + target: '$ref', + data: {}, + targetSpecs: [...OpenAPI2, ...OpenAPI3], +}; + +export default $refFormatURILint; diff --git a/packages/apidom-ls/src/config/openapi/path-item/lint/allowed-fields-2-0.ts b/packages/apidom-ls/src/config/openapi/path-item/lint/allowed-fields-2-0.ts new file mode 100644 index 000000000..2d5459fbf --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/path-item/lint/allowed-fields-2-0.ts @@ -0,0 +1,33 @@ +import { DiagnosticSeverity } from 'vscode-languageserver-types'; + +import ApilintCodes from '../../../codes'; +import { LinterMeta } from '../../../../apidom-language-types'; +import { OpenAPI2 } from '../../target-specs'; + +// eslint-disable-next-line @typescript-eslint/naming-convention +const allowedFields2_0Lint: LinterMeta = { + code: ApilintCodes.NOT_ALLOWED_FIELDS, + source: 'apilint', + message: 'Object includes not allowed fields', + severity: DiagnosticSeverity.Error, + linterFunction: 'allowedFields', + linterParams: [ + [ + '$ref', + 'summary', + 'description', + 'get', + 'put', + 'post', + 'delete', + 'options', + 'head', + 'patch', + 'parameters', + ], + 'x-', + ], + marker: 'key', + targetSpecs: OpenAPI2, +}; +export default allowedFields2_0Lint; diff --git a/packages/apidom-ls/src/config/openapi/path-item/lint/delete--type.ts b/packages/apidom-ls/src/config/openapi/path-item/lint/delete--type.ts index 61d20cdcc..6d9db868c 100644 --- a/packages/apidom-ls/src/config/openapi/path-item/lint/delete--type.ts +++ b/packages/apidom-ls/src/config/openapi/path-item/lint/delete--type.ts @@ -2,10 +2,10 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types'; import ApilintCodes from '../../../codes'; import { LinterMeta } from '../../../../apidom-language-types'; -import { OpenAPI3 } from '../../target-specs'; +import { OpenAPI2, OpenAPI3 } from '../../target-specs'; const deleteTypeLint: LinterMeta = { - code: ApilintCodes.OPENAPI3_0_PATH_ITEM_FIELD_DELETE_TYPE, + code: ApilintCodes.OPENAPI2_PATH_ITEM_FIELD_DELETE_TYPE, source: 'apilint', message: '"delete" must be in a shape of the Operation Object', severity: DiagnosticSeverity.Error, @@ -14,7 +14,7 @@ const deleteTypeLint: LinterMeta = { marker: 'value', target: 'delete', data: {}, - targetSpecs: OpenAPI3, + targetSpecs: [...OpenAPI2, ...OpenAPI3], }; export default deleteTypeLint; diff --git a/packages/apidom-ls/src/config/openapi/path-item/lint/get--type.ts b/packages/apidom-ls/src/config/openapi/path-item/lint/get--type.ts index 84478288a..e0ee4db89 100644 --- a/packages/apidom-ls/src/config/openapi/path-item/lint/get--type.ts +++ b/packages/apidom-ls/src/config/openapi/path-item/lint/get--type.ts @@ -2,10 +2,10 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types'; import ApilintCodes from '../../../codes'; import { LinterMeta } from '../../../../apidom-language-types'; -import { OpenAPI3 } from '../../target-specs'; +import { OpenAPI2, OpenAPI3 } from '../../target-specs'; const getTypeLint: LinterMeta = { - code: ApilintCodes.OPENAPI3_0_PATH_ITEM_FIELD_GET_TYPE, + code: ApilintCodes.OPENAPI2_PATH_ITEM_FIELD_GET_TYPE, source: 'apilint', message: '"get" must be in a shape of the Operation Object', severity: DiagnosticSeverity.Error, @@ -14,7 +14,7 @@ const getTypeLint: LinterMeta = { marker: 'value', target: 'get', data: {}, - targetSpecs: OpenAPI3, + targetSpecs: [...OpenAPI2, ...OpenAPI3], }; export default getTypeLint; diff --git a/packages/apidom-ls/src/config/openapi/path-item/lint/head--type.ts b/packages/apidom-ls/src/config/openapi/path-item/lint/head--type.ts index 9143480e0..b7cf82f45 100644 --- a/packages/apidom-ls/src/config/openapi/path-item/lint/head--type.ts +++ b/packages/apidom-ls/src/config/openapi/path-item/lint/head--type.ts @@ -2,10 +2,10 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types'; import ApilintCodes from '../../../codes'; import { LinterMeta } from '../../../../apidom-language-types'; -import { OpenAPI3 } from '../../target-specs'; +import { OpenAPI2, OpenAPI3 } from '../../target-specs'; const headTypeLint: LinterMeta = { - code: ApilintCodes.OPENAPI3_0_PATH_ITEM_FIELD_HEAD_TYPE, + code: ApilintCodes.OPENAPI2_PATH_ITEM_FIELD_HEAD_TYPE, source: 'apilint', message: '"head" must be in a shape of the Operation Object', severity: DiagnosticSeverity.Error, @@ -14,7 +14,7 @@ const headTypeLint: LinterMeta = { marker: 'value', target: 'head', data: {}, - targetSpecs: OpenAPI3, + targetSpecs: [...OpenAPI2, ...OpenAPI3], }; export default headTypeLint; diff --git a/packages/apidom-ls/src/config/openapi/path-item/lint/index.ts b/packages/apidom-ls/src/config/openapi/path-item/lint/index.ts index bb674624a..4173dfbe8 100644 --- a/packages/apidom-ls/src/config/openapi/path-item/lint/index.ts +++ b/packages/apidom-ls/src/config/openapi/path-item/lint/index.ts @@ -1,5 +1,7 @@ +import allowedFields2_0Lint from './allowed-fields-2-0'; import allowedFields3_0Lint from './allowed-fields-3-0'; import allowedFields3_1Lint from './allowed-fields-3-1'; +import $refFormatURILint from './$ref--format-uri'; import summaryTypeLint from './summary--type'; import descriptionTypeLint from './description--type'; import getTypeLint from './get--type'; @@ -16,6 +18,7 @@ import parametersTypeLint from './parameters--type'; import parametersItemsTypeLint from './parameters--items-type'; const lints = [ + $refFormatURILint, summaryTypeLint, descriptionTypeLint, getTypeLint, @@ -30,6 +33,7 @@ const lints = [ serversItemsTypeLint, parametersTypeLint, parametersItemsTypeLint, + allowedFields2_0Lint, allowedFields3_0Lint, allowedFields3_1Lint, ]; diff --git a/packages/apidom-ls/src/config/openapi/path-item/lint/options--type.ts b/packages/apidom-ls/src/config/openapi/path-item/lint/options--type.ts index 587cf9a82..201f70d93 100644 --- a/packages/apidom-ls/src/config/openapi/path-item/lint/options--type.ts +++ b/packages/apidom-ls/src/config/openapi/path-item/lint/options--type.ts @@ -2,10 +2,10 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types'; import ApilintCodes from '../../../codes'; import { LinterMeta } from '../../../../apidom-language-types'; -import { OpenAPI3 } from '../../target-specs'; +import { OpenAPI2, OpenAPI3 } from '../../target-specs'; const optionsTypeLint: LinterMeta = { - code: ApilintCodes.OPENAPI3_0_PATH_ITEM_FIELD_OPTIONS_TYPE, + code: ApilintCodes.OPENAPI2_PATH_ITEM_FIELD_OPTIONS_TYPE, source: 'apilint', message: '"options" must be in a shape of the Operation Object', severity: DiagnosticSeverity.Error, @@ -14,7 +14,7 @@ const optionsTypeLint: LinterMeta = { marker: 'value', target: 'options', data: {}, - targetSpecs: OpenAPI3, + targetSpecs: [...OpenAPI2, ...OpenAPI3], }; export default optionsTypeLint; diff --git a/packages/apidom-ls/src/config/openapi/path-item/lint/parameters--items-type.ts b/packages/apidom-ls/src/config/openapi/path-item/lint/parameters--items-type.ts index d622286cb..458303099 100644 --- a/packages/apidom-ls/src/config/openapi/path-item/lint/parameters--items-type.ts +++ b/packages/apidom-ls/src/config/openapi/path-item/lint/parameters--items-type.ts @@ -2,10 +2,10 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types'; import ApilintCodes from '../../../codes'; import { LinterMeta } from '../../../../apidom-language-types'; -import { OpenAPI3 } from '../../target-specs'; +import { OpenAPI2, OpenAPI3 } from '../../target-specs'; const parametersItemsTypeLint: LinterMeta = { - code: ApilintCodes.OPENAPI3_0_PATH_ITEM_FIELD_PARAMETERS_ITEMS_TYPE, + code: ApilintCodes.OPENAPI2_PATH_ITEM_FIELD_PARAMETERS_ITEMS_TYPE, source: 'apilint', message: 'parameters must be an array of Parameter Objects', severity: DiagnosticSeverity.Error, @@ -14,7 +14,7 @@ const parametersItemsTypeLint: LinterMeta = { marker: 'key', target: 'parameters', data: {}, - targetSpecs: OpenAPI3, + targetSpecs: [...OpenAPI2, ...OpenAPI3], }; export default parametersItemsTypeLint; diff --git a/packages/apidom-ls/src/config/openapi/path-item/lint/parameters--type.ts b/packages/apidom-ls/src/config/openapi/path-item/lint/parameters--type.ts index e6594a3b8..08c12efd5 100644 --- a/packages/apidom-ls/src/config/openapi/path-item/lint/parameters--type.ts +++ b/packages/apidom-ls/src/config/openapi/path-item/lint/parameters--type.ts @@ -2,10 +2,10 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types'; import ApilintCodes from '../../../codes'; import { LinterMeta } from '../../../../apidom-language-types'; -import { OpenAPI3 } from '../../target-specs'; +import { OpenAPI2, OpenAPI3 } from '../../target-specs'; const parametersTypeLint: LinterMeta = { - code: ApilintCodes.OPENAPI3_0_PATH_ITEM_FIELD_PARAMETERS_TYPE, + code: ApilintCodes.OPENAPI2_PATH_ITEM_FIELD_PARAMETERS_TYPE, source: 'apilint', message: 'parameters must be an array', severity: DiagnosticSeverity.Error, @@ -14,7 +14,7 @@ const parametersTypeLint: LinterMeta = { marker: 'value', target: 'parameters', data: {}, - targetSpecs: OpenAPI3, + targetSpecs: [...OpenAPI2, ...OpenAPI3], }; export default parametersTypeLint; diff --git a/packages/apidom-ls/src/config/openapi/path-item/lint/patch--type.ts b/packages/apidom-ls/src/config/openapi/path-item/lint/patch--type.ts index 7335daa39..a0ec287ca 100644 --- a/packages/apidom-ls/src/config/openapi/path-item/lint/patch--type.ts +++ b/packages/apidom-ls/src/config/openapi/path-item/lint/patch--type.ts @@ -2,10 +2,10 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types'; import ApilintCodes from '../../../codes'; import { LinterMeta } from '../../../../apidom-language-types'; -import { OpenAPI3 } from '../../target-specs'; +import { OpenAPI2, OpenAPI3 } from '../../target-specs'; const patchTypeLint: LinterMeta = { - code: ApilintCodes.OPENAPI3_0_PATH_ITEM_FIELD_PATCH_TYPE, + code: ApilintCodes.OPENAPI2_PATH_ITEM_FIELD_PATCH_TYPE, source: 'apilint', message: '"patch" must be in a shape of the Operation Object', severity: DiagnosticSeverity.Error, @@ -14,7 +14,7 @@ const patchTypeLint: LinterMeta = { marker: 'value', target: 'patch', data: {}, - targetSpecs: OpenAPI3, + targetSpecs: [...OpenAPI2, ...OpenAPI3], }; export default patchTypeLint; diff --git a/packages/apidom-ls/src/config/openapi/path-item/lint/post--type.ts b/packages/apidom-ls/src/config/openapi/path-item/lint/post--type.ts index ac0bb10f0..5ac29ae20 100644 --- a/packages/apidom-ls/src/config/openapi/path-item/lint/post--type.ts +++ b/packages/apidom-ls/src/config/openapi/path-item/lint/post--type.ts @@ -2,10 +2,10 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types'; import ApilintCodes from '../../../codes'; import { LinterMeta } from '../../../../apidom-language-types'; -import { OpenAPI3 } from '../../target-specs'; +import { OpenAPI2, OpenAPI3 } from '../../target-specs'; const postTypeLint: LinterMeta = { - code: ApilintCodes.OPENAPI3_0_PATH_ITEM_FIELD_POST_TYPE, + code: ApilintCodes.OPENAPI2_PATH_ITEM_FIELD_POST_TYPE, source: 'apilint', message: '"post" must be in a shape of the Operation Object', severity: DiagnosticSeverity.Error, @@ -14,7 +14,7 @@ const postTypeLint: LinterMeta = { marker: 'value', target: 'post', data: {}, - targetSpecs: OpenAPI3, + targetSpecs: [...OpenAPI2, ...OpenAPI3], }; export default postTypeLint; diff --git a/packages/apidom-ls/src/config/openapi/path-item/lint/put--type.ts b/packages/apidom-ls/src/config/openapi/path-item/lint/put--type.ts index cb6beef56..b3b3da750 100644 --- a/packages/apidom-ls/src/config/openapi/path-item/lint/put--type.ts +++ b/packages/apidom-ls/src/config/openapi/path-item/lint/put--type.ts @@ -2,10 +2,10 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types'; import ApilintCodes from '../../../codes'; import { LinterMeta } from '../../../../apidom-language-types'; -import { OpenAPI3 } from '../../target-specs'; +import { OpenAPI2, OpenAPI3 } from '../../target-specs'; const putTypeLint: LinterMeta = { - code: ApilintCodes.OPENAPI3_0_PATH_ITEM_FIELD_PUT_TYPE, + code: ApilintCodes.OPENAPI2_PATH_ITEM_FIELD_PUT_TYPE, source: 'apilint', message: '"put" must be in a shape of the Operation Object', severity: DiagnosticSeverity.Error, @@ -14,7 +14,7 @@ const putTypeLint: LinterMeta = { marker: 'value', target: 'put', data: {}, - targetSpecs: OpenAPI3, + targetSpecs: [...OpenAPI2, ...OpenAPI3], }; export default putTypeLint; diff --git a/packages/apidom-ls/test/openapi-json.ts b/packages/apidom-ls/test/openapi-json.ts index 9e215671a..fbea24980 100644 --- a/packages/apidom-ls/test/openapi-json.ts +++ b/packages/apidom-ls/test/openapi-json.ts @@ -513,7 +513,7 @@ describe('apidom-ls', function () { range: { start: { line: 185, character: 20 }, end: { line: 190, character: 7 } }, message: 'parameters must be an array', severity: 1, - code: 5121300, + code: 3070900, source: 'apilint', data: {}, }, @@ -521,7 +521,7 @@ describe('apidom-ls', function () { range: { start: { line: 92, character: 4 }, end: { line: 92, character: 12 } }, message: 'parameters must be an array of Parameter Objects', severity: 1, - code: 5121301, + code: 3071000, source: 'apilint', data: {}, }, diff --git a/packages/apidom-ls/test/openapi-yaml.ts b/packages/apidom-ls/test/openapi-yaml.ts index 022c29ec0..350bb4e15 100644 --- a/packages/apidom-ls/test/openapi-yaml.ts +++ b/packages/apidom-ls/test/openapi-yaml.ts @@ -521,7 +521,7 @@ describe('apidom-ls-yaml', function () { range: { start: { line: 128, character: 6 }, end: { line: 132, character: 0 } }, message: 'parameters must be an array', severity: 1, - code: 5121300, + code: 3070900, source: 'apilint', data: {}, }, @@ -529,7 +529,7 @@ describe('apidom-ls-yaml', function () { range: { start: { line: 65, character: 2 }, end: { line: 65, character: 10 } }, message: 'parameters must be an array of Parameter Objects', severity: 1, - code: 5121301, + code: 3071000, source: 'apilint', data: {}, },