diff --git a/packages/apidom-ls/src/config/codes.ts b/packages/apidom-ls/src/config/codes.ts index d1ec1ed648..1aa0dd003a 100644 --- a/packages/apidom-ls/src/config/codes.ts +++ b/packages/apidom-ls/src/config/codes.ts @@ -683,6 +683,24 @@ enum ApilintCodes { OPENAPI2_PATH_ITEM_FIELD_PARAMETERS_TYPE = 3070900, OPENAPI2_PATH_ITEM_FIELD_PARAMETERS_ITEMS_TYPE = 3071000, + OPENAPI2_OPERATION = 3080000, + OPENAPI2_OPERATION_FIELD_TAGS_TYPE = 3080100, + OPENAPI2_OPERATION_FIELD_SUMMARY_TYPE = 3080200, + OPENAPI2_OPERATION_FIELD_DESCRIPTION_TYPE = 3080300, + OPENAPI2_OPERATION_FIELD_EXTERNAL_DOCS_TYPE = 3080400, + OPENAPI2_OPERATION_FIELD_OPERATION_ID_TYPE = 3080500, + OPENAPI2_OPERATION_FIELD_OPERATION_ID_UNIQUE, + OPENAPI2_OPERATION_FIELD_CONSUMES_TYPE = 3080600, + OPENAPI2_OPERATION_FIELD_PRODUCES_TYPE = 3080700, + OPENAPI2_OPERATION_FIELD_PARAMETERS_TYPE = 3080800, + OPENAPI2_OPERATION_FIELD_PARAMETERS_ITEMS_TYPE = 3080900, + OPENAPI2_OPERATION_FIELD_RESPONSES_TYPE = 3081000, + OPENAPI2_OPERATION_FIELD_RESPONSES_REQUIRED, + OPENAPI2_OPERATION_FIELD_SCHEMES_TYPE = 3081100, + OPENAPI2_OPERATION_FIELD_DEPRECATED_TYPE = 3081200, + OPENAPI2_OPERATION_FIELD_SECURITY_TYPE = 3081300, + OPENAPI2_OPERATION_FIELD_SECURITY_ITEMS_TYPE, + OPENAPI3_0 = 5000000, OPENAPI3_0_OPENAPI_VALUE_PATTERN_3_0_0 = 5000100, @@ -801,7 +819,7 @@ enum ApilintCodes { OPENAPI3_0_OPERATION_FIELD_CALLBACKS_VALUES_TYPE = 5130900, OPENAPI3_0_OPERATION_FIELD_DEPRECATED_TYPE = 5131000, OPENAPI3_0_OPERATION_FIELD_SECURITY_TYPE = 5131100, - OPENAPI3_0_OPERATION_FIELD_SECURITY_VALUES_TYPE, + OPENAPI3_0_OPERATION_FIELD_SECURITY_ITEMS_TYPE, OPENAPI3_0_OPERATION_FIELD_SERVERS_TYPE = 5131200, OPENAPI3_0_OPERATION_FIELD_SERVERS_ITEMS_TYPE, diff --git a/packages/apidom-ls/src/config/openapi/operation/completion.ts b/packages/apidom-ls/src/config/openapi/operation/completion.ts index 698a403a87..244fb2ec97 100644 --- a/packages/apidom-ls/src/config/openapi/operation/completion.ts +++ b/packages/apidom-ls/src/config/openapi/operation/completion.ts @@ -3,7 +3,7 @@ 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[] = [ { @@ -18,7 +18,21 @@ const completion: ApidomCompletionItem[] = [ value: '[`string`]\n\\\n\\\nA list of tags for API documentation control. Tags can be used for logical grouping of operations by resources or any other qualifier.', }, - targetSpecs: OpenAPI3, + targetSpecs: [...OpenAPI2, ...OpenAPI3], + }, + { + label: 'summary', + insertText: 'summary', + kind: 14, + format: CompletionFormat.QUOTED, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + 'A short summary of what the operation does. For maximum readability in the swagger-ui, this field SHOULD be less than 120 characters.', + }, + targetSpecs: OpenAPI2, }, { label: 'summary', @@ -33,6 +47,20 @@ const completion: ApidomCompletionItem[] = [ }, targetSpecs: OpenAPI3, }, + { + label: 'description', + insertText: 'description', + kind: 14, + format: CompletionFormat.QUOTED, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + 'A verbose explanation of the operation behavior. [GFM syntax](https://guides.github.com/features/mastering-markdown/#GitHub-flavored-markdown) can be used for rich text representation.', + }, + targetSpecs: OpenAPI2, + }, { label: 'description', insertText: 'description', @@ -47,6 +75,20 @@ const completion: ApidomCompletionItem[] = [ }, targetSpecs: OpenAPI3, }, + { + label: 'externalDocs', + insertText: 'externalDocs', + kind: 14, + format: CompletionFormat.OBJECT, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + '[External Documentation](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#externalDocumentationObject)\n\\\n\\\nAdditional external documentation for this operation.', + }, + targetSpecs: OpenAPI2, + }, { label: 'externalDocs', insertText: 'externalDocs', @@ -75,6 +117,20 @@ const completion: ApidomCompletionItem[] = [ }, targetSpecs: OpenAPI31, }, + { + label: 'operationId', + insertText: 'operationId', + kind: 14, + format: CompletionFormat.QUOTED, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + '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.', + }, + targetSpecs: OpenAPI2, + }, { label: 'operationId', insertText: 'operationId', @@ -89,6 +145,48 @@ const completion: ApidomCompletionItem[] = [ }, targetSpecs: OpenAPI3, }, + { + label: 'consumes', + insertText: 'consumes', + kind: 14, + format: CompletionFormat.ARRAY, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + '[`string`]\n\\\n\\\nA list of MIME types the operation can consume. This overrides the [`consumes`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#swaggerConsumes) definition at the Swagger Object. An empty value MAY be used to clear the global definition. Value MUST be as described under [Mime Types](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#mimeTypes).', + }, + targetSpecs: OpenAPI2, + }, + { + label: 'produces', + insertText: 'produces', + kind: 14, + format: CompletionFormat.ARRAY, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + '[`string`]\n\\\n\\\nA list of MIME types the operation can produce. This overrides the [`produces`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#swaggerProduces) definition at the Swagger Object. An empty value MAY be used to clear the global definition. Value MUST be as described under [Mime Types](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#mimeTypes).', + }, + targetSpecs: OpenAPI2, + }, + { + 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 this operation. If a parameter is already defined at the [Path Item](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#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](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', @@ -145,6 +243,20 @@ const completion: ApidomCompletionItem[] = [ }, targetSpecs: OpenAPI31, }, + { + label: 'responses', + insertText: 'responses', + kind: 14, + format: CompletionFormat.OBJECT, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + '[Responses Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#responsesObject)\n\\\n\\\n**Required.** The list of possible responses as they are returned from executing this operation.', + }, + targetSpecs: OpenAPI2, + }, { label: 'responses', insertText: 'responses', @@ -173,6 +285,20 @@ const completion: ApidomCompletionItem[] = [ }, targetSpecs: OpenAPI31, }, + { + label: 'schemes', + insertText: 'schemes', + kind: 14, + format: CompletionFormat.ARRAY, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + '[`string`]\n\\\n\\\nThe transfer protocol for the operation. Values MUST be from the list: `"http"`, `"https"`, `"ws"`, `"wss"`. The value overrides the Swagger Object [`schemes`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#swaggerSchemes) definition.', + }, + targetSpecs: OpenAPI2, + }, { label: 'callbacks', insertText: 'callbacks', @@ -211,10 +337,38 @@ const completion: ApidomCompletionItem[] = [ documentation: { kind: 'markdown', value: - 'Declares this operation to be deprecated. Consumers SHOULD refrain from usage of the declared operation. Default value is `false`.', + '`boolean`\n\\\n\\\nDeclares this operation to be deprecated. Consumers SHOULD refrain from usage of the declared operation. Default value is `false`.', + }, + targetSpecs: OpenAPI2, + }, + { + label: 'deprecated', + insertText: 'deprecated', + kind: 14, + format: CompletionFormat.UNQUOTED, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + '`boolean`\n\\\n\\\nDeclares this operation to be deprecated. Consumers SHOULD refrain from usage of the declared operation. Default value is `false`.', }, targetSpecs: OpenAPI3, }, + { + label: 'security', + insertText: 'security', + kind: 14, + format: CompletionFormat.ARRAY, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + '[[Security Requirement Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#serverObject)]\n\\\n\\\nA declaration of which security schemes are applied for this operation. The list of values describes alternative security schemes that can be used (that is, there is a logical OR between the security requirements). This definition overrides any declared top-level [`security`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#swaggerSecurity). To remove a top-level security declaration, an empty array can be used.', + }, + targetSpecs: OpenAPI2, + }, { label: 'security', insertText: 'security', diff --git a/packages/apidom-ls/src/config/openapi/operation/documentation.ts b/packages/apidom-ls/src/config/openapi/operation/documentation.ts index 2cc85278e5..7ddbf6b424 100644 --- a/packages/apidom-ls/src/config/openapi/operation/documentation.ts +++ b/packages/apidom-ls/src/config/openapi/operation/documentation.ts @@ -1,9 +1,9 @@ -import { OpenAPI30, OpenAPI31, OpenAPI3 } from '../target-specs'; +import { OpenAPI2, OpenAPI30, OpenAPI31, OpenAPI3 } from '../target-specs'; /** * Omitted fixed fields: * - externalDocs - * - responses + * - responses (OpenAPI 3.1.0) * * 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 @@ -15,23 +15,53 @@ const documentation = [ { target: 'tags', docs: '[`string`]\n\\\n\\\nA list of tags for API documentation control. Tags can be used for logical grouping of operations by resources or any other qualifier.', - targetSpecs: OpenAPI3, + targetSpecs: [...OpenAPI2, ...OpenAPI3], + }, + { + target: 'summary', + docs: 'A short summary of what the operation does. For maximum readability in the swagger-ui, this field SHOULD be less than 120 characters.', + targetSpecs: OpenAPI2, }, { target: 'summary', docs: 'A short summary of what the operation does.', targetSpecs: OpenAPI3, }, + { + target: 'description', + docs: 'A verbose explanation of the operation behavior. [GFM syntax](https://guides.github.com/features/mastering-markdown/#GitHub-flavored-markdown) can be used for rich text representation.', + targetSpecs: OpenAPI2, + }, { target: 'description', docs: 'A verbose explanation of the operation behavior. [CommonMark syntax](https://spec.commonmark.org/) MAY be used for rich text representation.', targetSpecs: OpenAPI3, }, + { + target: 'operationId', + docs: '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.', + targetSpecs: OpenAPI2, + }, { target: 'operationId', docs: 'Unique string used to identify the operation. The id MUST be unique among all operations described in the API. The operationId value is **case-sensitive**. Tools and libraries MAY use the operationId to uniquely identify an operation, therefore, it is RECOMMENDED to follow common programming naming conventions.', targetSpecs: OpenAPI3, }, + { + target: 'consumes', + docs: '[`string`]\n\\\n\\\nA list of MIME types the operation can consume. This overrides the [`consumes`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#swaggerConsumes) definition at the Swagger Object. An empty value MAY be used to clear the global definition. Value MUST be as described under [Mime Types](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#mimeTypes).', + targetSpecs: OpenAPI2, + }, + { + target: 'produces', + docs: '[`string`]\n\\\n\\\nA list of MIME types the operation can produce. This overrides the [`produces`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#swaggerProduces) definition at the Swagger Object. An empty value MAY be used to clear the global definition. Value MUST be as described under [Mime Types](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#mimeTypes).', + targetSpecs: OpenAPI2, + }, + { + target: 'parameters', + 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 this operation. If a parameter is already defined at the [Path Item](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#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](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 this operation. If a parameter is already defined at the [Path Item](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#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](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).", @@ -52,6 +82,21 @@ const documentation = [ docs: '[[Request Body Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#requestBodyObject) | [Reference Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#referenceObject)]\n\\\n\\\nThe request body applicable for this operation. The requestBody is fully supported in HTTP methods where the HTTP 1.1 specification [RFC7231](https://tools.ietf.org/html/rfc7231#section-4.3.1) has explicitly defined semantics for request bodies. In other cases where the HTTP spec is vague (such as [GET](https://tools.ietf.org/html/rfc7231#section-4.3.1), [HEAD](https://tools.ietf.org/html/rfc7231#section-4.3.2) and [DELETE](https://tools.ietf.org/html/rfc7231#section-4.3.5)), `requestBody` is permitted but does not have well-defined semantics and SHOULD be avoided if possible.', targetSpecs: OpenAPI31, }, + { + target: 'responses', + docs: '[Responses Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#responsesObject)\n\\\n\\\n**Required.** The list of possible responses as they are returned from executing this operation.', + targetSpecs: OpenAPI2, + }, + { + target: 'responses', + docs: '[Responses Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#responsesObject)\n\\\n\\\n**REQUIRED**. The list of possible responses as they are returned from executing this operation.', + targetSpecs: OpenAPI30, + }, + { + target: 'schemes', + docs: '[`string`]\n\\\n\\\nThe transfer protocol for the operation. Values MUST be from the list: `"http"`, `"https"`, `"ws"`, `"wss"`. The value overrides the Swagger Object [`schemes`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#swaggerSchemes) definition.', + targetSpecs: OpenAPI2, + }, { target: 'callbacks', docs: 'Map[`string`, [Callback Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#callbackObject) | [Reference Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#referenceObject)]]\n\\\n\\\nA map of possible out-of band callbacks related to the parent operation. The key is a unique identifier for the Callback Object. Each value in the map is a [Callback Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#callbackObject) that describes a request that may be initiated by the API provider and the expected responses.', @@ -64,9 +109,19 @@ const documentation = [ }, { target: 'deprecated', - docs: 'Declares this operation to be deprecated. Consumers SHOULD refrain from usage of the declared operation. Default value is `false`.', + docs: '`boolean`\n\\\n\\\nDeclares this operation to be deprecated. Usage of the declared operation should be refrained. Default value is `false`.', + targetSpecs: OpenAPI2, + }, + { + target: 'deprecated', + docs: '`boolean`\n\\\n\\\nDeclares this operation to be deprecated. Consumers SHOULD refrain from usage of the declared operation. Default value is `false`.', targetSpecs: OpenAPI3, }, + { + target: 'security', + docs: '[[Security Requirement Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#serverObject)]\n\\\n\\\nA declaration of which security schemes are applied for this operation. The list of values describes alternative security schemes that can be used (that is, there is a logical OR between the security requirements). This definition overrides any declared top-level [`security`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#swaggerSecurity). To remove a top-level security declaration, an empty array can be used.', + targetSpecs: OpenAPI2, + }, { target: 'security', docs: '[[Security Requirement Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#serverObject)]\n\\\n\\\nA declaration of which security mechanisms can be used for this operation. The list of values includes alternative security requirement objects that can be used. Only one of the security requirement objects need to be satisfied to authorize a request. To make security optional, an empty security requirement (`{}`) can be included in the array. This definition overrides any declared top-level [`security`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#oasSecurity). To remove a top-level security declaration, an empty array can be used.', @@ -87,6 +142,10 @@ const documentation = [ docs: '[[Server Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#serverObject)]\n\\\n\\\nAn alternative `server` array to service this operation. If an alternative `server` object is specified at the Path Item Object or Root level, it will be overridden by this value.', targetSpecs: OpenAPI31, }, + { + docs: '#### [Operation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#operation-object)\n\nDescribes a single API operation on a path.\n\n##### Fixed Fields\n\nField Name | Type | Description\n---|:---:|---\ntags | [`string`] | A list of tags for API documentation control. Tags can be used for logical grouping of operations by resources or any other qualifier.\nsummary | `string` | A short summary of what the operation does. For maximum readability in the swagger-ui, this field SHOULD be less than 120 characters.\ndescription | `string` | A verbose explanation of the operation behavior. [GFM syntax](https://guides.github.com/features/mastering-markdown/#GitHub-flavored-markdown) can be used for rich text representation.\nexternalDocs | [External Documentation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#externalDocumentationObject) | Additional external documentation for this operation.\noperationId | `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.\nconsumes | [`string`] | A list of MIME types the operation can consume. This overrides the [`consumes`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#swaggerConsumes) definition at the Swagger Object. An empty value MAY be used to clear the global definition. Value MUST be as described under [Mime Types](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#mimeTypes).\nproduces | [`string`] | A list of MIME types the operation can produce. This overrides the [`produces`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#swaggerProduces) definition at the Swagger Object. An empty value MAY be used to clear the global definition. Value MUST be as described under [Mime Types](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#mimeTypes).\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 this operation. If a parameter is already defined at the [Path Item](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#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](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](#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.\nresponses | [Responses Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#responsesObject) | **Required.** The list of possible responses as they are returned from executing this operation.\nschemes | [`string`] | The transfer protocol for the operation. Values MUST be from the list: `"http"`, `"https"`, `"ws"`, `"wss"`. The value overrides the Swagger Object [`schemes`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#swaggerSchemes) definition.\ndeprecated | `boolean` | Declares this operation to be deprecated. Usage of the declared operation should be refrained. Default value is `false`.\nsecurity | [[Security Requirement Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#securityRequirementObject)] | A declaration of which security schemes are applied for this operation. The list of values describes alternative security schemes that can be used (that is, there is a logical OR between the security requirements). This definition overrides any declared top-level [`security`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#swaggerSecurity). To remove a top-level security declaration, an empty array can be used.\n\n##### Patterned Objects\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##### Operation Object Example\n\n```js\n{\n "tags": [\n "pet"\n ],\n "summary": "Updates a pet in the store with form data",\n "description": "",\n "operationId": "updatePetWithForm",\n "consumes": [\n "application/x-www-form-urlencoded"\n ],\n "produces": [\n "application/json",\n "application/xml"\n ],\n "parameters": [\n {\n "name": "petId",\n "in": "path",\n "description": "ID of pet that needs to be updated",\n "required": true,\n "type": "string"\n },\n {\n "name": "name",\n "in": "formData",\n "description": "Updated name of the pet",\n "required": false,\n "type": "string"\n },\n {\n "name": "status",\n "in": "formData",\n "description": "Updated status of the pet",\n "required": false,\n "type": "string"\n }\n ],\n "responses": {\n "200": {\n "description": "Pet updated."\n },\n "405": {\n "description": "Invalid input"\n }\n },\n "security": [\n {\n "petstore_auth": [\n "write:pets",\n "read:pets"\n ]\n }\n ]\n}\n```\n\n\n\\\nYAML\n```yaml\ntags:\n- pet\nsummary: Updates a pet in the store with form data\ndescription: ""\noperationId: updatePetWithForm\nconsumes:\n- application/x-www-form-urlencoded\nproduces:\n- application/json\n- application/xml\nparameters:\n- name: petId\n in: path\n description: ID of pet that needs to be updated\n required: true\n type: string\n- name: name\n in: formData\n description: Updated name of the pet\n required: false\n type: string\n- name: status\n in: formData\n description: Updated status of the pet\n required: false\n type: string\nresponses:\n \'200\':\n description: Pet updated.\n \'405\':\n description: Invalid input\nsecurity:\n- petstore_auth:\n - write:pets\n - read:pets\n```', + targetSpecs: OpenAPI2, + }, { docs: '#### [Operation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#operation-object)\n\nDescribes a single API operation on a path.\n\n##### Fixed Fields\n\nField Name | Type | Description\n---|:---:|---\ntags | [`string`] | A list of tags for API documentation control. Tags can be used for logical grouping of operations by resources or any other qualifier.\nsummary | `string` | A short summary of what the operation does.\ndescription | `string` | A verbose explanation of the operation behavior. [CommonMark syntax](https://spec.commonmark.org/) MAY be used for rich text representation.\nexternalDocs | [External Documentation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#externalDocumentationObject) | Additional external documentation for this operation.\noperationId | `string` | Unique string used to identify the operation. The id MUST be unique among all operations described in the API. The operationId value is **case-sensitive**. Tools and libraries MAY use the operationId to uniquely identify an operation, therefore, it is RECOMMENDED to follow common programming naming conventions.\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 this operation. If a parameter is already defined at the [Path Item](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#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](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).\nrequestBody | [Request Body Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#requestBodyObject) \\| [Reference Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#referenceObject) | The request body applicable for this operation. The `requestBody` is only supported in HTTP methods where the HTTP 1.1 specification [RFC7231](https://tools.ietf.org/html/rfc7231#section-4.3.1) has explicitly defined semantics for request bodies. In other cases where the HTTP spec is vague, `requestBody` SHALL be ignored by consumers.\nresponses | [Responses Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#responsesObject) | **REQUIRED**. The list of possible responses as they are returned from executing this operation.\ncallbacks | Map[`string`, [Callback Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#callbackObject) \\| [Reference Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#referenceObject)] | A map of possible out-of band callbacks related to the parent operation. The key is a unique identifier for the Callback Object. Each value in the map is a [Callback Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#callbackObject) that describes a request that may be initiated by the API provider and the expected responses.\ndeprecated | `boolean` | Declares this operation to be deprecated. Consumers SHOULD refrain from usage of the declared operation. Default value is `false`.\nsecurity | [[Security Requirement Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#securityRequirementObject)] | A declaration of which security mechanisms can be used for this operation. The list of values includes alternative security requirement objects that can be used. Only one of the security requirement objects need to be satisfied to authorize a request. To make security optional, an empty security requirement (`{}`) can be included in the array. This definition overrides any declared top-level [`security`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#oasSecurity). To remove a top-level security declaration, an empty array can be used.\nservers | [[Server Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#serverObject)] | An alternative `server` array to service this operation. If an alternative `server` object is specified at the Path Item Object or Root level, it will be overridden by this value.\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##### Operation Object Example\n\n\n\\\nJSON\n```json\n{\n "tags": [\n "pet"\n ],\n "summary": "Updates a pet in the store with form data",\n "operationId": "updatePetWithForm",\n "parameters": [\n {\n "name": "petId",\n "in": "path",\n "description": "ID of pet that needs to be updated",\n "required": true,\n "schema": {\n "type": "string"\n }\n }\n ],\n "requestBody": {\n "content": {\n "application/x-www-form-urlencoded": {\n "schema": {\n "type": "object",\n "properties": {\n "name": {\n "description": "Updated name of the pet",\n "type": "string"\n },\n "status": {\n "description": "Updated status of the pet",\n "type": "string"\n }\n },\n "required": ["status"]\n }\n }\n }\n },\n "responses": {\n "200": {\n "description": "Pet updated.",\n "content": {\n "application/json": {},\n "application/xml": {}\n }\n },\n "405": {\n "description": "Method Not Allowed",\n "content": {\n "application/json": {},\n "application/xml": {}\n }\n }\n },\n "security": [\n {\n "petstore_auth": [\n "write:pets",\n "read:pets"\n ]\n }\n ]\n}\n```\n\n\n\\\nYAML\n```yaml\ntags:\n- pet\nsummary: Updates a pet in the store with form data\noperationId: updatePetWithForm\nparameters:\n- name: petId\n in: path\n description: ID of pet that needs to be updated\n required: true\n schema:\n type: string\nrequestBody:\n content:\n \'application/x-www-form-urlencoded\':\n schema:\n properties:\n name:\n description: Updated name of the pet\n type: string\n status:\n description: Updated status of the pet\n type: string\n required:\n - status\nresponses:\n \'200\':\n description: Pet updated.\n content:\n \'application/json\': {}\n \'application/xml\': {}\n \'405\':\n description: Method Not Allowed\n content:\n \'application/json\': {}\n \'application/xml\': {}\nsecurity:\n- petstore_auth:\n - write:pets\n - read:pets\n```', targetSpecs: OpenAPI30, diff --git a/packages/apidom-ls/src/config/openapi/operation/lint/allowed-fields-2-0.ts b/packages/apidom-ls/src/config/openapi/operation/lint/allowed-fields-2-0.ts new file mode 100644 index 0000000000..a6903fe2ba --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/operation/lint/allowed-fields-2-0.ts @@ -0,0 +1,35 @@ +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: [ + [ + 'tags', + 'summary', + 'description', + 'externalDocs', + 'operationId', + 'consumes', + 'produces', + 'parameters', + 'responses', + 'schemes', + 'deprecated', + 'security', + ], + 'x-', + ], + marker: 'key', + targetSpecs: OpenAPI2, +}; + +export default allowedFields2_0Lint; diff --git a/packages/apidom-ls/src/config/openapi/operation/lint/allowed-fields.ts b/packages/apidom-ls/src/config/openapi/operation/lint/allowed-fields-3-0--3-1.ts similarity index 82% rename from packages/apidom-ls/src/config/openapi/operation/lint/allowed-fields.ts rename to packages/apidom-ls/src/config/openapi/operation/lint/allowed-fields-3-0--3-1.ts index 18ff42a4b9..2acbae726e 100644 --- a/packages/apidom-ls/src/config/openapi/operation/lint/allowed-fields.ts +++ b/packages/apidom-ls/src/config/openapi/operation/lint/allowed-fields-3-0--3-1.ts @@ -4,7 +4,8 @@ import ApilintCodes from '../../../codes'; import { LinterMeta } from '../../../../apidom-language-types'; import { OpenAPI3 } from '../../target-specs'; -const allowedFieldsLint: LinterMeta = { +// eslint-disable-next-line @typescript-eslint/naming-convention +const allowedFields3_0__3_1Lint: LinterMeta = { code: ApilintCodes.NOT_ALLOWED_FIELDS, source: 'apilint', message: 'Object includes not allowed fields', @@ -31,4 +32,4 @@ const allowedFieldsLint: LinterMeta = { targetSpecs: OpenAPI3, }; -export default allowedFieldsLint; +export default allowedFields3_0__3_1Lint; diff --git a/packages/apidom-ls/src/config/openapi/operation/lint/consumes--type.ts b/packages/apidom-ls/src/config/openapi/operation/lint/consumes--type.ts new file mode 100644 index 0000000000..1d1bb9586e --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/operation/lint/consumes--type.ts @@ -0,0 +1,20 @@ +import { DiagnosticSeverity } from 'vscode-languageserver-types'; + +import ApilintCodes from '../../../codes'; +import { LinterMeta } from '../../../../apidom-language-types'; +import { OpenAPI2 } from '../../target-specs'; + +const consumesTypeLint: LinterMeta = { + code: ApilintCodes.OPENAPI2_OPERATION_FIELD_CONSUMES_TYPE, + source: 'apilint', + message: "'consumes' must be an array of strings", + severity: DiagnosticSeverity.Error, + linterFunction: 'apilintArrayOfType', + linterParams: ['string'], + marker: 'key', + target: 'consumes', + data: {}, + targetSpecs: OpenAPI2, +}; + +export default consumesTypeLint; diff --git a/packages/apidom-ls/src/config/openapi/operation/lint/deprecated--type.ts b/packages/apidom-ls/src/config/openapi/operation/lint/deprecated--type.ts index 323047ae4a..deabe6168e 100644 --- a/packages/apidom-ls/src/config/openapi/operation/lint/deprecated--type.ts +++ b/packages/apidom-ls/src/config/openapi/operation/lint/deprecated--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 deprecatedTypeLint: LinterMeta = { - code: ApilintCodes.OPENAPI3_0_OPERATION_FIELD_DEPRECATED_TYPE, + code: ApilintCodes.OPENAPI2_OPERATION_FIELD_DEPRECATED_TYPE, source: 'apilint', message: 'deprecated must be a boolean', severity: DiagnosticSeverity.Error, @@ -14,7 +14,7 @@ const deprecatedTypeLint: LinterMeta = { marker: 'value', target: 'deprecated', data: {}, - targetSpecs: OpenAPI3, + targetSpecs: [...OpenAPI2, ...OpenAPI3], }; export default deprecatedTypeLint; diff --git a/packages/apidom-ls/src/config/openapi/operation/lint/description--type.ts b/packages/apidom-ls/src/config/openapi/operation/lint/description--type.ts index a8a8fe33e8..756030722f 100644 --- a/packages/apidom-ls/src/config/openapi/operation/lint/description--type.ts +++ b/packages/apidom-ls/src/config/openapi/operation/lint/description--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 descriptionTypeLint: LinterMeta = { - code: ApilintCodes.OPENAPI3_0_OPERATION_FIELD_DESCRIPTION_TYPE, + code: ApilintCodes.OPENAPI2_OPERATION_FIELD_DESCRIPTION_TYPE, source: 'apilint', message: 'description must be a string', severity: DiagnosticSeverity.Error, @@ -14,7 +14,7 @@ const descriptionTypeLint: LinterMeta = { marker: 'value', target: 'description', data: {}, - targetSpecs: OpenAPI3, + targetSpecs: [...OpenAPI2, ...OpenAPI3], }; export default descriptionTypeLint; diff --git a/packages/apidom-ls/src/config/openapi/operation/lint/external-docs--type.ts b/packages/apidom-ls/src/config/openapi/operation/lint/external-docs--type.ts index 5793166d94..443695dd55 100644 --- a/packages/apidom-ls/src/config/openapi/operation/lint/external-docs--type.ts +++ b/packages/apidom-ls/src/config/openapi/operation/lint/external-docs--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 externalDocsTypeLint: LinterMeta = { - code: ApilintCodes.OPENAPI3_0_OPERATION_FIELD_EXTERNAL_DOCS_TYPE, + code: ApilintCodes.OPENAPI2_OPERATION_FIELD_EXTERNAL_DOCS_TYPE, source: 'apilint', message: 'externalDocs must be an object', severity: DiagnosticSeverity.Error, @@ -14,7 +14,7 @@ const externalDocsTypeLint: LinterMeta = { marker: 'value', target: 'externalDocs', data: {}, - targetSpecs: OpenAPI3, + targetSpecs: [...OpenAPI2, ...OpenAPI3], }; export default externalDocsTypeLint; diff --git a/packages/apidom-ls/src/config/openapi/operation/lint/index.ts b/packages/apidom-ls/src/config/openapi/operation/lint/index.ts index f5013643b4..edb4e258fc 100644 --- a/packages/apidom-ls/src/config/openapi/operation/lint/index.ts +++ b/packages/apidom-ls/src/config/openapi/operation/lint/index.ts @@ -1,15 +1,19 @@ -import allowedFieldsLint from './allowed-fields'; +import allowedFields2_0Lint from './allowed-fields-2-0'; +import allowedFields3_0__3_1Lint from './allowed-fields-3-0--3-1'; import tagsTypeLint from './tags--type'; import summaryTypeLint from './summary--type'; import descriptionTypeLint from './description--type'; import externalDocsTypeLint from './external-docs--type'; import operationIdTypeLint from './operation-id--type'; import operationIdUniqueLint from './operation-id--unique'; +import consumesTypeLint from './consumes--type'; +import producesTypeLint from './produces--type'; import parametersTypeLint from './parameters--type'; import parametersItemsTypeLint from './parameters--items-type'; import requestBodyTypeLint from './request-body--type'; import responsesTypeLint from './responses--type'; -import responsesRequired3_0Lint from './responses-3-0--required'; +import responsesRequired2_0__3_0Lint from './responses-2-0--3-0--required'; +import schemesTypeLint from './schemes--type'; import callbacksValuesTypeLint from './callbacks--values-type'; import deprecatedTypeLint from './deprecated--type'; import securityTypeLint from './security--type'; @@ -26,18 +30,22 @@ const lints = [ externalDocsTypeLint, operationIdTypeLint, operationIdUniqueLint, + consumesTypeLint, + producesTypeLint, parametersTypeLint, parametersItemsTypeLint, requestBodyTypeLint, responsesTypeLint, - responsesRequired3_0Lint, + responsesRequired2_0__3_0Lint, + schemesTypeLint, callbacksValuesTypeLint, deprecatedTypeLint, securityTypeLint, securityItemsTypeLint, serversTypeLint, serversItemsTypeLint, - allowedFieldsLint, + allowedFields2_0Lint, + allowedFields3_0__3_1Lint, requestBodyAllowedLint, requestBodyTentativelyAllowed, ]; diff --git a/packages/apidom-ls/src/config/openapi/operation/lint/operation-id--type.ts b/packages/apidom-ls/src/config/openapi/operation/lint/operation-id--type.ts index 2611302607..f917432e33 100644 --- a/packages/apidom-ls/src/config/openapi/operation/lint/operation-id--type.ts +++ b/packages/apidom-ls/src/config/openapi/operation/lint/operation-id--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 operationIdTypeLint: LinterMeta = { - code: ApilintCodes.OPENAPI3_0_OPERATION_FIELD_OPERATION_ID_TYPE, + code: ApilintCodes.OPENAPI2_OPERATION_FIELD_OPERATION_ID_TYPE, source: 'apilint', message: 'operationId must be a string', severity: DiagnosticSeverity.Error, @@ -14,7 +14,7 @@ const operationIdTypeLint: LinterMeta = { marker: 'value', target: 'operationId', data: {}, - targetSpecs: OpenAPI3, + targetSpecs: [...OpenAPI2, ...OpenAPI3], }; export default operationIdTypeLint; diff --git a/packages/apidom-ls/src/config/openapi/operation/lint/operation-id--unique.ts b/packages/apidom-ls/src/config/openapi/operation/lint/operation-id--unique.ts index fd7b732b3e..e9b3fbe767 100644 --- a/packages/apidom-ls/src/config/openapi/operation/lint/operation-id--unique.ts +++ b/packages/apidom-ls/src/config/openapi/operation/lint/operation-id--unique.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 operationIdUniqueLint: LinterMeta = { - code: ApilintCodes.OPENAPI3_0_OPERATION_FIELD_OPERATION_ID_UNIQUE, + code: ApilintCodes.OPENAPI2_OPERATION_FIELD_OPERATION_ID_UNIQUE, source: 'apilint', message: "operationId' must be unique among all operations", severity: DiagnosticSeverity.Error, @@ -15,7 +15,7 @@ const operationIdUniqueLint: LinterMeta = { markerTarget: 'operationId', target: 'operationId', data: {}, - targetSpecs: OpenAPI3, + targetSpecs: [...OpenAPI2, ...OpenAPI3], }; export default operationIdUniqueLint; diff --git a/packages/apidom-ls/src/config/openapi/operation/lint/parameters--items-type.ts b/packages/apidom-ls/src/config/openapi/operation/lint/parameters--items-type.ts index 5e32db4d9e..fc6d21097d 100644 --- a/packages/apidom-ls/src/config/openapi/operation/lint/parameters--items-type.ts +++ b/packages/apidom-ls/src/config/openapi/operation/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_OPERATION_FIELD_PARAMETERS_ITEMS_TYPE, + code: ApilintCodes.OPENAPI2_OPERATION_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/operation/lint/parameters--type.ts b/packages/apidom-ls/src/config/openapi/operation/lint/parameters--type.ts index dcb9672c28..dfab66f943 100644 --- a/packages/apidom-ls/src/config/openapi/operation/lint/parameters--type.ts +++ b/packages/apidom-ls/src/config/openapi/operation/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_OPERATION_FIELD_PARAMETERS_TYPE, + code: ApilintCodes.OPENAPI2_OPERATION_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/operation/lint/produces--type.ts b/packages/apidom-ls/src/config/openapi/operation/lint/produces--type.ts new file mode 100644 index 0000000000..cf2d2b5de3 --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/operation/lint/produces--type.ts @@ -0,0 +1,20 @@ +import { DiagnosticSeverity } from 'vscode-languageserver-types'; + +import ApilintCodes from '../../../codes'; +import { LinterMeta } from '../../../../apidom-language-types'; +import { OpenAPI2 } from '../../target-specs'; + +const producesTypeLint: LinterMeta = { + code: ApilintCodes.OPENAPI2_OPERATION_FIELD_PRODUCES_TYPE, + source: 'apilint', + message: "'produces' must be an array of strings", + severity: DiagnosticSeverity.Error, + linterFunction: 'apilintArrayOfType', + linterParams: ['string'], + marker: 'key', + target: 'produces', + data: {}, + targetSpecs: OpenAPI2, +}; + +export default producesTypeLint; diff --git a/packages/apidom-ls/src/config/openapi/operation/lint/responses--type.ts b/packages/apidom-ls/src/config/openapi/operation/lint/responses--type.ts index 7f891f7c67..6296c45f93 100644 --- a/packages/apidom-ls/src/config/openapi/operation/lint/responses--type.ts +++ b/packages/apidom-ls/src/config/openapi/operation/lint/responses--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 responsesTypeLint: LinterMeta = { - code: ApilintCodes.OPENAPI3_0_OPERATION_FIELD_RESPONSES_TYPE, + code: ApilintCodes.OPENAPI2_OPERATION_FIELD_RESPONSES_TYPE, source: 'apilint', message: 'responses must be an object', severity: DiagnosticSeverity.Error, @@ -14,7 +14,7 @@ const responsesTypeLint: LinterMeta = { marker: 'value', target: 'responses', data: {}, - targetSpecs: OpenAPI3, + targetSpecs: [...OpenAPI2, ...OpenAPI3], }; export default responsesTypeLint; diff --git a/packages/apidom-ls/src/config/openapi/operation/lint/responses-3-0--required.ts b/packages/apidom-ls/src/config/openapi/operation/lint/responses-2-0--3-0--required.ts similarity index 70% rename from packages/apidom-ls/src/config/openapi/operation/lint/responses-3-0--required.ts rename to packages/apidom-ls/src/config/openapi/operation/lint/responses-2-0--3-0--required.ts index 7ecb3aa920..66f8559b2f 100644 --- a/packages/apidom-ls/src/config/openapi/operation/lint/responses-3-0--required.ts +++ b/packages/apidom-ls/src/config/openapi/operation/lint/responses-2-0--3-0--required.ts @@ -2,11 +2,11 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types'; import ApilintCodes from '../../../codes'; import { LinterMeta } from '../../../../apidom-language-types'; -import { OpenAPI30 } from '../../target-specs'; +import { OpenAPI2, OpenAPI30 } from '../../target-specs'; // eslint-disable-next-line @typescript-eslint/naming-convention -const responsesRequired3_0Lint: LinterMeta = { - code: ApilintCodes.OPENAPI3_0_OPERATION_FIELD_RESPONSES_REQUIRED, +const responsesRequired2_0__3_0Lint: LinterMeta = { + code: ApilintCodes.OPENAPI2_OPERATION_FIELD_RESPONSES_REQUIRED, source: 'apilint', message: "should always have a 'responses'", severity: DiagnosticSeverity.Error, @@ -23,7 +23,7 @@ const responsesRequired3_0Lint: LinterMeta = { }, ], }, - targetSpecs: OpenAPI30, + targetSpecs: [...OpenAPI2, ...OpenAPI30], }; -export default responsesRequired3_0Lint; +export default responsesRequired2_0__3_0Lint; diff --git a/packages/apidom-ls/src/config/openapi/operation/lint/schemes--type.ts b/packages/apidom-ls/src/config/openapi/operation/lint/schemes--type.ts new file mode 100644 index 0000000000..afd90efa00 --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/operation/lint/schemes--type.ts @@ -0,0 +1,20 @@ +import { DiagnosticSeverity } from 'vscode-languageserver-types'; + +import ApilintCodes from '../../../codes'; +import { LinterMeta } from '../../../../apidom-language-types'; +import { OpenAPI2 } from '../../target-specs'; + +const schemesTypeLint: LinterMeta = { + code: ApilintCodes.OPENAPI2_OPERATION_FIELD_SCHEMES_TYPE, + source: 'apilint', + message: "'schemes' must be an array of strings", + severity: DiagnosticSeverity.Error, + linterFunction: 'apilintArrayOfType', + linterParams: ['string'], + marker: 'key', + target: 'schemes', + data: {}, + targetSpecs: OpenAPI2, +}; + +export default schemesTypeLint; diff --git a/packages/apidom-ls/src/config/openapi/operation/lint/security--items-type.ts b/packages/apidom-ls/src/config/openapi/operation/lint/security--items-type.ts index 8277c44e5d..a79663d5aa 100644 --- a/packages/apidom-ls/src/config/openapi/operation/lint/security--items-type.ts +++ b/packages/apidom-ls/src/config/openapi/operation/lint/security--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 securityItemsTypeLint: LinterMeta = { - code: ApilintCodes.OPENAPI3_0_OPERATION_FIELD_SECURITY_VALUES_TYPE, + code: ApilintCodes.OPENAPI2_OPERATION_FIELD_SECURITY_ITEMS_TYPE, source: 'apilint', message: 'security must be an array of Security Requirement Objects', severity: DiagnosticSeverity.Error, @@ -14,7 +14,7 @@ const securityItemsTypeLint: LinterMeta = { marker: 'key', target: 'security', data: {}, - targetSpecs: OpenAPI3, + targetSpecs: [...OpenAPI2, ...OpenAPI3], }; export default securityItemsTypeLint; diff --git a/packages/apidom-ls/src/config/openapi/operation/lint/security--type.ts b/packages/apidom-ls/src/config/openapi/operation/lint/security--type.ts index 5023922daf..6bb1996fcf 100644 --- a/packages/apidom-ls/src/config/openapi/operation/lint/security--type.ts +++ b/packages/apidom-ls/src/config/openapi/operation/lint/security--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 securityTypeLint: LinterMeta = { - code: ApilintCodes.OPENAPI3_0_OPERATION_FIELD_SECURITY_TYPE, + code: ApilintCodes.OPENAPI2_OPERATION_FIELD_SECURITY_TYPE, source: 'apilint', message: 'security must be an array', severity: DiagnosticSeverity.Error, @@ -14,7 +14,7 @@ const securityTypeLint: LinterMeta = { marker: 'value', target: 'security', data: {}, - targetSpecs: OpenAPI3, + targetSpecs: [...OpenAPI2, ...OpenAPI3], }; export default securityTypeLint; diff --git a/packages/apidom-ls/src/config/openapi/operation/lint/summary--type.ts b/packages/apidom-ls/src/config/openapi/operation/lint/summary--type.ts index 4c4136918e..81863cf881 100644 --- a/packages/apidom-ls/src/config/openapi/operation/lint/summary--type.ts +++ b/packages/apidom-ls/src/config/openapi/operation/lint/summary--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 summaryTypeLint: LinterMeta = { - code: ApilintCodes.OPENAPI3_0_OPERATION_FIELD_SUMMARY_TYPE, + code: ApilintCodes.OPENAPI2_OPERATION_FIELD_SUMMARY_TYPE, source: 'apilint', message: 'summary must be a string', severity: DiagnosticSeverity.Error, @@ -14,7 +14,7 @@ const summaryTypeLint: LinterMeta = { marker: 'value', target: 'summary', data: {}, - targetSpecs: OpenAPI3, + targetSpecs: [...OpenAPI2, ...OpenAPI3], }; export default summaryTypeLint; diff --git a/packages/apidom-ls/src/config/openapi/operation/lint/tags--type.ts b/packages/apidom-ls/src/config/openapi/operation/lint/tags--type.ts index 41b62fbc20..d9dbd355c3 100644 --- a/packages/apidom-ls/src/config/openapi/operation/lint/tags--type.ts +++ b/packages/apidom-ls/src/config/openapi/operation/lint/tags--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 tagsTypeLint: LinterMeta = { - code: ApilintCodes.OPENAPI3_0_OPERATION_FIELD_TAGS_TYPE, + code: ApilintCodes.OPENAPI2_OPERATION_FIELD_TAGS_TYPE, source: 'apilint', message: "'tags' must be an array of strings", severity: DiagnosticSeverity.Error, @@ -14,7 +14,7 @@ const tagsTypeLint: LinterMeta = { marker: 'key', target: 'tags', data: {}, - targetSpecs: OpenAPI3, + targetSpecs: [...OpenAPI2, ...OpenAPI3], }; export default tagsTypeLint; diff --git a/packages/apidom-ls/test/openapi-json.ts b/packages/apidom-ls/test/openapi-json.ts index fbea24980c..619542fe8a 100644 --- a/packages/apidom-ls/test/openapi-json.ts +++ b/packages/apidom-ls/test/openapi-json.ts @@ -529,7 +529,7 @@ describe('apidom-ls', function () { range: { start: { line: 104, character: 22 }, end: { line: 109, character: 9 } }, message: 'parameters must be an array', severity: 1, - code: 5130600, + code: 3080800, source: 'apilint', data: {}, }, @@ -537,7 +537,7 @@ describe('apidom-ls', function () { range: { start: { line: 95, character: 6 }, end: { line: 95, character: 11 } }, message: 'parameters must be an array of Parameter Objects', severity: 1, - code: 5130601, + code: 3080900, source: 'apilint', data: {}, }, diff --git a/packages/apidom-ls/test/openapi-yaml.ts b/packages/apidom-ls/test/openapi-yaml.ts index 350bb4e15b..6f7b093dbf 100644 --- a/packages/apidom-ls/test/openapi-yaml.ts +++ b/packages/apidom-ls/test/openapi-yaml.ts @@ -537,7 +537,7 @@ describe('apidom-ls-yaml', function () { range: { start: { line: 79, character: 8 }, end: { line: 82, character: 22 } }, message: 'parameters must be an array', severity: 1, - code: 5130600, + code: 3080800, source: 'apilint', data: {}, }, @@ -545,7 +545,7 @@ describe('apidom-ls-yaml', function () { range: { start: { line: 68, character: 4 }, end: { line: 68, character: 7 } }, message: 'parameters must be an array of Parameter Objects', severity: 1, - code: 5130601, + code: 3080900, source: 'apilint', data: {}, }, diff --git a/packages/apidom-ls/test/validate.ts b/packages/apidom-ls/test/validate.ts index 8e4aa66588..38084135b7 100644 --- a/packages/apidom-ls/test/validate.ts +++ b/packages/apidom-ls/test/validate.ts @@ -3067,7 +3067,7 @@ describe('apidom-ls-validate', function () { range: { start: { line: 7, character: 6 }, end: { line: 7, character: 17 } }, message: "operationId' must be unique among all operations", severity: 1, - code: 5130501, + code: 3080501, source: 'apilint', data: {}, }, @@ -3118,7 +3118,7 @@ describe('apidom-ls-validate', function () { range: { start: { line: 58, character: 6 }, end: { line: 58, character: 17 } }, message: "operationId' must be unique among all operations", severity: 1, - code: 5130501, + code: 3080501, source: 'apilint', data: {}, },