From 1ae31b7636980824c27567af0a4ce6ca7115a6db Mon Sep 17 00:00:00 2001 From: Vladimir Gorej Date: Mon, 15 Jan 2024 18:07:23 +0100 Subject: [PATCH] feat(ls): add rules for OpenAPI 2.0 Header Object Refs #3610 --- packages/apidom-ls/src/config/codes.ts | 30 +- .../src/config/openapi/header/completion.ts | 432 +++++++++++++++++- .../config/openapi/header/documentation.ts | 96 +++- .../openapi/header/lint/allowed-fields-2-0.ts | 40 ++ .../header/lint/collection-format--equals.ts | 20 + .../openapi/header/lint/description--type.ts | 6 +- .../config/openapi/header/lint/enum--type.ts | 20 + .../header/lint/exclusive-maximum--type.ts | 20 + .../header/lint/exclusive-minimum--type.ts | 20 + .../openapi/header/lint/format--type.ts | 20 + .../src/config/openapi/header/lint/index.ts | 39 ++ .../openapi/header/lint/items--required.ts | 35 ++ .../config/openapi/header/lint/items--type.ts | 20 + .../openapi/header/lint/max-items--type.ts | 20 + .../openapi/header/lint/max-length--type.ts | 20 + .../openapi/header/lint/maximum--type.ts | 20 + .../openapi/header/lint/min-items--type.ts | 20 + .../openapi/header/lint/min-length--type.ts | 20 + .../openapi/header/lint/minimum--type.ts | 20 + .../openapi/header/lint/multiple-of--type.ts | 20 + .../openapi/header/lint/pattern--type.ts | 20 + .../openapi/header/lint/type--equals.ts | 20 + .../openapi/header/lint/type--required.ts | 28 ++ .../openapi/header/lint/unique-items--type.ts | 20 + .../src/config/openapi/items/completion.ts | 4 +- .../src/config/openapi/items/documentation.ts | 4 +- .../src/config/openapi/items/lint/index.ts | 6 + .../openapi/items/lint/max-items--type.ts | 20 + .../openapi/items/lint/min-items--type.ts | 20 + .../openapi/items/lint/pattern--type.ts | 20 + 30 files changed, 1088 insertions(+), 12 deletions(-) create mode 100644 packages/apidom-ls/src/config/openapi/header/lint/allowed-fields-2-0.ts create mode 100644 packages/apidom-ls/src/config/openapi/header/lint/collection-format--equals.ts create mode 100644 packages/apidom-ls/src/config/openapi/header/lint/enum--type.ts create mode 100644 packages/apidom-ls/src/config/openapi/header/lint/exclusive-maximum--type.ts create mode 100644 packages/apidom-ls/src/config/openapi/header/lint/exclusive-minimum--type.ts create mode 100644 packages/apidom-ls/src/config/openapi/header/lint/format--type.ts create mode 100644 packages/apidom-ls/src/config/openapi/header/lint/items--required.ts create mode 100644 packages/apidom-ls/src/config/openapi/header/lint/items--type.ts create mode 100644 packages/apidom-ls/src/config/openapi/header/lint/max-items--type.ts create mode 100644 packages/apidom-ls/src/config/openapi/header/lint/max-length--type.ts create mode 100644 packages/apidom-ls/src/config/openapi/header/lint/maximum--type.ts create mode 100644 packages/apidom-ls/src/config/openapi/header/lint/min-items--type.ts create mode 100644 packages/apidom-ls/src/config/openapi/header/lint/min-length--type.ts create mode 100644 packages/apidom-ls/src/config/openapi/header/lint/minimum--type.ts create mode 100644 packages/apidom-ls/src/config/openapi/header/lint/multiple-of--type.ts create mode 100644 packages/apidom-ls/src/config/openapi/header/lint/pattern--type.ts create mode 100644 packages/apidom-ls/src/config/openapi/header/lint/type--equals.ts create mode 100644 packages/apidom-ls/src/config/openapi/header/lint/type--required.ts create mode 100644 packages/apidom-ls/src/config/openapi/header/lint/unique-items--type.ts create mode 100644 packages/apidom-ls/src/config/openapi/items/lint/max-items--type.ts create mode 100644 packages/apidom-ls/src/config/openapi/items/lint/min-items--type.ts create mode 100644 packages/apidom-ls/src/config/openapi/items/lint/pattern--type.ts diff --git a/packages/apidom-ls/src/config/codes.ts b/packages/apidom-ls/src/config/codes.ts index b351a276bc..180f321cef 100644 --- a/packages/apidom-ls/src/config/codes.ts +++ b/packages/apidom-ls/src/config/codes.ts @@ -749,9 +749,12 @@ enum ApilintCodes { OPENAPI2_ITEMS_FIELD_EXCLUSIVE_MINIMUM_TYPE = 3110800, OPENAPI2_ITEMS_FIELD_MAX_LENGTH_TYPE = 3110900, OPENAPI2_ITEMS_FIELD_MIN_LENGTH_TYPE = 3111000, - OPENAPI2_ITEMS_FIELD_UNIQUE_ITEMS_TYPE = 3111100, - OPENAPI2_ITEMS_FIELD_ENUM_TYPE = 3111200, - OPENAPI2_ITEMS_FIELD_MULTIPLE_OF_TYPE = 3111300, + OPENAPI2_ITEMS_FIELD_PATTERN_TYPE = 3111100, + OPENAPI2_ITEMS_FIELD_MAX_ITEMS_TYPE = 3111200, + OPENAPI2_ITEMS_FIELD_MIN_ITEMS_TYPE = 3111300, + OPENAPI2_ITEMS_FIELD_UNIQUE_ITEMS_TYPE = 3111400, + OPENAPI2_ITEMS_FIELD_ENUM_TYPE = 3111500, + OPENAPI2_ITEMS_FIELD_MULTIPLE_OF_TYPE = 3111600, OPENAPI2_RESPONSE = 3120000, OPENAPI2_RESPONSE_FIELD_DESCRIPTION_TYPE = 3120100, @@ -810,6 +813,27 @@ enum ApilintCodes { OPENAPI2_SECURITY_SCHEME_FIELD_SCOPES_TYPE = 3220800, OPENAPI2_SECURITY_SCHEME_FIELD_SCOPES_REQUIRED, + OPENAPI2_HEADER = 3230000, + OPENAPI2_HEADER_FIELD_DESCRIPTION_TYPE = 3230100, + OPENAPI2_HEADER_FIELD_TYPE_EQUALS = 3230200, + OPENAPI2_HEADER_FIELD_TYPE_REQUIRED, + OPENAPI2_HEADER_FIELD_FORMAT_TYPE = 3230300, + OPENAPI2_HEADER_FIELD_ITEMS_TYPE = 3230400, + OPENAPI2_HEADER_FIELD_ITEMS_REQUIRED, + OPENAPI2_HEADER_FIELD_COLLECTION_FORMAT_EQUALS = 3230500, + OPENAPI2_HEADER_FIELD_MAXIMUM_TYPE = 3230600, + OPENAPI2_HEADER_FIELD_EXCLUSIVE_MAXIMUM_TYPE = 3230700, + OPENAPI2_HEADER_FIELD_MINIMUM_TYPE = 3230800, + OPENAPI2_HEADER_FIELD_EXCLUSIVE_MINIMUM_TYPE = 3230900, + OPENAPI2_HEADER_FIELD_MAX_LENGTH_TYPE = 3231000, + OPENAPI2_HEADER_FIELD_MIN_LENGTH_TYPE = 3231100, + OPENAPI2_HEADER_FIELD_PATTERN_TYPE = 3231200, + OPENAPI2_HEADER_FIELD_MAX_ITEMS_TYPE = 3231300, + OPENAPI2_HEADER_FIELD_MIN_ITEMS_TYPE = 3231400, + OPENAPI2_HEADER_FIELD_UNIQUE_ITEMS_TYPE = 3231500, + OPENAPI2_HEADER_FIELD_ENUM_TYPE = 3231600, + OPENAPI2_HEADER_FIELD_MULTIPLE_OF_TYPE = 3231700, + OPENAPI3_0 = 5000000, OPENAPI3_0_OPENAPI_VALUE_PATTERN_3_0_0 = 5000100, diff --git a/packages/apidom-ls/src/config/openapi/header/completion.ts b/packages/apidom-ls/src/config/openapi/header/completion.ts index c9ae4579c9..7a4658df08 100644 --- a/packages/apidom-ls/src/config/openapi/header/completion.ts +++ b/packages/apidom-ls/src/config/openapi/header/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[] = [ { @@ -19,6 +19,256 @@ const completion: ApidomCompletionItem[] = [ }, targetSpecs: OpenAPI3, }, + { + label: 'type', + insertText: 'type', + kind: 14, + format: CompletionFormat.QUOTED, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + '**Required.** The internal type of the array. The value MUST be one of `"string"`, `"number"`, `"integer"`, `"boolean"`, or `"array"`.', + }, + targetSpecs: OpenAPI2, + }, + { + label: 'format', + insertText: 'format', + kind: 14, + format: CompletionFormat.QUOTED, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + 'The extending format for the previously mentioned [`type`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#stType). See [Data Type Formats](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#dataTypeFormat) for further details.', + }, + targetSpecs: OpenAPI2, + }, + { + label: 'items', + insertText: 'items', + kind: 14, + format: CompletionFormat.OBJECT, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + '[Items Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#itemsObject)\n\\\n\\\n**Required if [`type`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#stType) is "array".** Describes the type of items in the array.', + }, + targetSpecs: OpenAPI2, + }, + { + label: 'collectionFormat', + insertText: 'collectionFormat', + kind: 14, + format: CompletionFormat.QUOTED, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + 'Determines the format of the array if type array is used. Possible values are:\n\n* `csv` - comma separated values `foo,bar`.\n* `ssv` - space separated values `foo bar`.\n* `tsv` - tab separated values `foo\\tbar`.\n* `pipes` - pipe separated values `foo|bar`.\n\nDefault value is `csv`.', + }, + targetSpecs: OpenAPI2, + }, + { + label: 'default', + insertText: 'default', + kind: 14, + format: CompletionFormat.UNQUOTED, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + '`Any`\n\\\n\\\nDeclares the value of the item that the server will use if none is provided. (Note: "default" has no meaning for required items.) See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-6.2. Unlike JSON Schema this value MUST conform to the defined [`type`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#itemsType) for the data type.', + }, + targetSpecs: OpenAPI2, + }, + { + label: 'maximum', + insertText: 'maximum', + kind: 14, + format: CompletionFormat.UNQUOTED, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + '`number`\n\\\n\\\nSee https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.1.2.', + }, + targetSpecs: OpenAPI2, + }, + { + label: 'exclusiveMaximum', + insertText: 'exclusiveMaximum', + kind: 14, + format: CompletionFormat.UNQUOTED, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + '`boolean`\n\\\n\\\nSee https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.1.2.', + }, + targetSpecs: OpenAPI2, + }, + { + label: 'minimum', + insertText: 'minimum', + kind: 14, + format: CompletionFormat.UNQUOTED, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + '`number`\n\\\n\\\nSee https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.1.3.', + }, + targetSpecs: OpenAPI2, + }, + { + label: 'exclusiveMinimum', + insertText: 'exclusiveMinimum', + kind: 14, + format: CompletionFormat.UNQUOTED, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + '`boolean`\n\\\n\\\nSee https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.1.3.', + }, + targetSpecs: OpenAPI2, + }, + { + label: 'maxLength', + insertText: 'maxLength', + kind: 14, + format: CompletionFormat.UNQUOTED, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + '`integer`\n\\\n\\\nSee https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.2.1.', + }, + targetSpecs: OpenAPI2, + }, + { + label: 'minLength', + insertText: 'minLength', + kind: 14, + format: CompletionFormat.UNQUOTED, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + '`integer`\n\\\n\\\nSee https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.2.2.', + }, + targetSpecs: OpenAPI2, + }, + { + label: 'pattern', + insertText: 'pattern', + kind: 14, + format: CompletionFormat.QUOTED, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: 'See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.2.3.', + }, + targetSpecs: OpenAPI2, + }, + { + label: 'maxItems', + insertText: 'maxItems', + kind: 14, + format: CompletionFormat.UNQUOTED, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + '`integer`\n\\\n\\\nSee https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.3.2.', + }, + targetSpecs: OpenAPI2, + }, + { + label: 'minItems', + insertText: 'minItems', + kind: 14, + format: CompletionFormat.UNQUOTED, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + '`integer`\n\\\n\\\nSee https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.3.3.', + }, + targetSpecs: OpenAPI2, + }, + { + label: 'uniqueItems', + insertText: 'uniqueItems', + kind: 14, + format: CompletionFormat.UNQUOTED, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + '`boolean`\n\\\n\\\nSee https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.3.4.', + }, + targetSpecs: OpenAPI2, + }, + { + label: 'enum', + insertText: 'enum', + kind: 14, + format: CompletionFormat.ARRAY, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + '`[*]`\n\\\n\\\nSee https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.5.1.', + }, + targetSpecs: OpenAPI2, + }, + { + label: 'multipleOf', + insertText: 'multipleOf', + kind: 14, + format: CompletionFormat.UNQUOTED, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: + '`number`\n\\\n\\\nSee https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.1.1.', + }, + targetSpecs: OpenAPI2, + }, + { + label: 'description', + insertText: 'description', + kind: 14, + format: CompletionFormat.QUOTED, + type: CompletionType.PROPERTY, + insertTextFormat: 2, + documentation: { + kind: 'markdown', + value: 'A brief description of the header.', + }, + targetSpecs: OpenAPI2, + }, { label: 'description', insertText: 'description', @@ -214,6 +464,186 @@ const completion: ApidomCompletionItem[] = [ }, targetSpecs: OpenAPI31, }, + { + target: 'type', + label: 'string', + insertText: 'string', + kind: 12, + format: CompletionFormat.QUOTED, + type: CompletionType.VALUE, + insertTextFormat: 2, + targetSpecs: OpenAPI2, + }, + { + target: 'type', + label: 'number', + insertText: 'number', + kind: 12, + format: CompletionFormat.QUOTED, + type: CompletionType.VALUE, + insertTextFormat: 2, + targetSpecs: OpenAPI2, + }, + { + target: 'type', + label: 'integer', + insertText: 'integer', + kind: 12, + format: CompletionFormat.QUOTED, + type: CompletionType.VALUE, + insertTextFormat: 2, + targetSpecs: OpenAPI2, + }, + { + target: 'type', + label: 'boolean', + insertText: 'boolean', + kind: 12, + format: CompletionFormat.QUOTED, + type: CompletionType.VALUE, + insertTextFormat: 2, + targetSpecs: OpenAPI2, + }, + { + target: 'type', + label: 'array', + insertText: 'array', + kind: 12, + format: CompletionFormat.QUOTED, + type: CompletionType.VALUE, + insertTextFormat: 2, + targetSpecs: OpenAPI2, + }, + { + target: 'format', + label: 'int32', + insertText: 'int32', + kind: 12, + format: CompletionFormat.QUOTED, + type: CompletionType.VALUE, + insertTextFormat: 2, + targetSpecs: OpenAPI2, + }, + { + target: 'format', + label: 'int64', + insertText: 'int64', + kind: 12, + format: CompletionFormat.QUOTED, + type: CompletionType.VALUE, + insertTextFormat: 2, + targetSpecs: OpenAPI2, + }, + { + target: 'format', + label: 'float', + insertText: 'float', + kind: 12, + format: CompletionFormat.QUOTED, + type: CompletionType.VALUE, + insertTextFormat: 2, + targetSpecs: OpenAPI2, + }, + { + target: 'format', + label: 'double', + insertText: 'double', + kind: 12, + format: CompletionFormat.QUOTED, + type: CompletionType.VALUE, + insertTextFormat: 2, + targetSpecs: OpenAPI2, + }, + { + target: 'format', + label: 'byte', + insertText: 'byte', + kind: 12, + format: CompletionFormat.QUOTED, + type: CompletionType.VALUE, + insertTextFormat: 2, + targetSpecs: OpenAPI2, + }, + { + target: 'format', + label: 'binary', + insertText: 'binary', + kind: 12, + format: CompletionFormat.QUOTED, + type: CompletionType.VALUE, + insertTextFormat: 2, + targetSpecs: OpenAPI2, + }, + { + target: 'format', + label: 'date', + insertText: 'date', + kind: 12, + format: CompletionFormat.QUOTED, + type: CompletionType.VALUE, + insertTextFormat: 2, + targetSpecs: OpenAPI2, + }, + { + target: 'format', + label: 'date-time', + insertText: 'date-time', + kind: 12, + format: CompletionFormat.QUOTED, + type: CompletionType.VALUE, + insertTextFormat: 2, + targetSpecs: OpenAPI2, + }, + { + target: 'format', + label: 'password', + insertText: 'password', + kind: 12, + format: CompletionFormat.QUOTED, + type: CompletionType.VALUE, + insertTextFormat: 2, + targetSpecs: OpenAPI2, + }, + { + target: 'collectionFormat', + label: 'csv', + insertText: 'csv', + kind: 12, + format: CompletionFormat.QUOTED, + type: CompletionType.VALUE, + insertTextFormat: 2, + targetSpecs: OpenAPI2, + }, + { + target: 'collectionFormat', + label: 'ssv', + insertText: 'ssv', + kind: 12, + format: CompletionFormat.QUOTED, + type: CompletionType.VALUE, + insertTextFormat: 2, + targetSpecs: OpenAPI2, + }, + { + target: 'collectionFormat', + label: 'tsv', + insertText: 'tsv', + kind: 12, + format: CompletionFormat.QUOTED, + type: CompletionType.VALUE, + insertTextFormat: 2, + targetSpecs: OpenAPI2, + }, + { + target: 'collectionFormat', + label: 'pipes', + insertText: 'pipes', + kind: 12, + format: CompletionFormat.QUOTED, + type: CompletionType.VALUE, + insertTextFormat: 2, + targetSpecs: OpenAPI2, + }, ]; export default completion; diff --git a/packages/apidom-ls/src/config/openapi/header/documentation.ts b/packages/apidom-ls/src/config/openapi/header/documentation.ts index d7427c59a8..ea0244f7f8 100644 --- a/packages/apidom-ls/src/config/openapi/header/documentation.ts +++ b/packages/apidom-ls/src/config/openapi/header/documentation.ts @@ -1,4 +1,4 @@ -import { OpenAPI30, OpenAPI31, OpenAPI3 } from '../target-specs'; +import { OpenAPI2, OpenAPI30, OpenAPI31, OpenAPI3 } from '../target-specs'; /** * Omitted fixed fields for OpenAPI 3.1.0: @@ -10,6 +10,96 @@ import { OpenAPI30, OpenAPI31, OpenAPI3 } from '../target-specs'; * contain significant information. */ const documentation = [ + { + target: 'type', + docs: '**Required.** The internal type of the array. The value MUST be one of `"string"`, `"number"`, `"integer"`, `"boolean"`, or `"array"`.', + targetSpecs: OpenAPI2, + }, + { + target: 'format', + docs: 'The extending format for the previously mentioned [`type`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#stType). See [Data Type Formats](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#dataTypeFormat) for further details.', + targetSpecs: OpenAPI2, + }, + { + target: 'items', + docs: '[Items Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#itemsObject)\n\\\n\\\n**Required if [`type`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#stType) is "array".** Describes the type of items in the array.', + targetSpecs: OpenAPI2, + }, + { + target: 'collectionFormat', + docs: 'Determines the format of the array if type array is used. Possible values are:\n\n* `csv` - comma separated values `foo,bar`.\n* `ssv` - space separated values `foo bar`.\n* `tsv` - tab separated values `foo\\tbar`.\n* `pipes` - pipe separated values `foo|bar`.\n\nDefault value is `csv`.', + targetSpecs: OpenAPI2, + }, + { + target: 'default', + docs: '`Any`\n\\\n\\\nDeclares the value of the item that the server will use if none is provided. (Note: "default" has no meaning for required items.) See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-6.2. Unlike JSON Schema this value MUST conform to the defined [`type`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#itemsType) for the data type.', + targetSpecs: OpenAPI2, + }, + { + target: 'maximum', + docs: '`number`\n\\\n\\\nSee https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.1.2.', + targetSpecs: OpenAPI2, + }, + { + target: 'exclusiveMaximum', + docs: '`boolean`\n\\\n\\\nSee https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.1.2.', + targetSpecs: OpenAPI2, + }, + { + target: 'minimum', + docs: '`number`\n\\\n\\\nSee https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.1.3.', + targetSpecs: OpenAPI2, + }, + { + target: 'exclusiveMinimum', + docs: '`boolean`\n\\\n\\\nSee https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.1.3.', + targetSpecs: OpenAPI2, + }, + { + target: 'maxLength', + docs: '`integer`\n\\\n\\\nSee https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.2.1.', + targetSpecs: OpenAPI2, + }, + { + target: 'minLength', + docs: '`integer`\n\\\n\\\nSee https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.2.2.', + targetSpecs: OpenAPI2, + }, + { + target: 'pattern', + docs: 'See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.2.3.', + targetSpecs: OpenAPI2, + }, + { + target: 'maxItems', + docs: '`integer`\n\\\n\\\nSee https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.3.2.', + targetSpecs: OpenAPI2, + }, + { + target: 'minItems', + docs: '`integer`\n\\\n\\\nSee https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.3.3.', + targetSpecs: OpenAPI2, + }, + { + target: 'uniqueItems', + docs: '`boolean`\n\\\n\\\nSee https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.3.4.', + targetSpecs: OpenAPI2, + }, + { + target: 'enum', + docs: '`[*]`\n\\\n\\\nSee https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.5.1.', + targetSpecs: OpenAPI2, + }, + { + target: 'multipleOf', + docs: '`number`\n\\\n\\\nSee https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.1.1.', + targetSpecs: OpenAPI2, + }, + { + target: 'description', + docs: 'A brief description of the header.', + targetSpecs: OpenAPI2, + }, { target: 'description', docs: 'A brief description of the header. This could contain examples of use. [CommonMark syntax](https://spec.commonmark.org/) MAY be used for rich text representation.', @@ -75,6 +165,10 @@ const documentation = [ docs: 'Map[string, [Media Type Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#mediaTypeObject)]\n\\\n\\\nA map containing the representations for the header. The key is the media type and the value describes it. The map MUST only contain one entry.', targetSpecs: OpenAPI31, }, + { + docs: '#### [Header Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#header-object)\n\nField Name | Type | Description\n---|:---:|---\ndescription | `string` | A short description of the header.\ntype | `string` | **Required.** The type of the object. The value MUST be one of `"string"`, `"number"`, `"integer"`, `"boolean"`, or `"array"`.\nformat | `string` | The extending format for the previously mentioned [`type`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#stType). See [Data Type Formats](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#dataTypeFormat) for further details.\nitems | [Items Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#itemsObject) | **Required if [`type`](#stType) is "array".** Describes the type of items in the array.\ncollectionFormat | `string` | Determines the format of the array if type array is used. Possible values are: `csv` - comma separated values `foo,bar`. `ssv` - space separated values `foo bar`. `tsv` - tab separated values `foo\\tbar`. `pipes` - pipe separated values foo|bar. Default value is `csv`.\ndefault | * | Declares the value of the header that the server will use if none is provided. (Note: "default" has no meaning for required headers.) See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-6.2. Unlike JSON Schema this value MUST conform to the defined [`type`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#headerDefault) for the header.\nmaximum | `number` | See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.1.2.\nexclusiveMaximum | `boolean` | See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.1.2.\nminimum | `number` | See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.1.3.\nexclusiveMinimum | `boolean` | See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.1.3.\nmaxLength | `integer` | See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.2.1.\nminLength | `integer` | See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.2.2.\npattern | `string` | See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.2.3.\nmaxItems | `integer` | See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.3.2.\nminItems | `integer` | See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.3.3.\nuniqueItems | `boolean` | https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.3.4.\nenum | [*] | See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.5.1.\nmultipleOf | `number` | See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.1.1.\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##### Header Object Example\n\nA simple header with of an integer type:\n\n```js\n{\n "description": "The number of allowed requests in the current period",\n "type": "integer"\n}\n```\n\n\n\\\nYAML\n```yaml\ndescription: The number of allowed requests in the current period\ntype: integer\n```', + targetSpecs: OpenAPI2, + }, { docs: '#### [Header Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#headerObject)\n\nThe Header Object follows the structure of the [Parameter Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#parameterObject) with the following changes:\n\n1. `name` MUST NOT be specified, it is given in the corresponding `headers` map.\n1. `in` MUST NOT be specified, it is implicitly in `header`.\n1. All traits that are affected by the location MUST be applicable to a location of `header` (for example, [`style`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#parameterStyle)).\n\n##### Header Object Example\n\nA simple header of type `integer`:\n\n\n\\\nJSON\n```json\n{\n "description": "The number of allowed requests in the current period",\n "schema": {\n "type": "integer"\n }\n}\n```\n\n\n\\\nYAML\n```yaml\ndescription: The number of allowed requests in the current period\nschema:\n type: integer\n```', targetSpecs: OpenAPI30, diff --git a/packages/apidom-ls/src/config/openapi/header/lint/allowed-fields-2-0.ts b/packages/apidom-ls/src/config/openapi/header/lint/allowed-fields-2-0.ts new file mode 100644 index 0000000000..c0c6d6d1fa --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/header/lint/allowed-fields-2-0.ts @@ -0,0 +1,40 @@ +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: [ + [ + 'type', + 'format', + 'items', + 'collectionFormat', + 'default', + 'maximum', + 'exclusiveMaximum', + 'minimum', + 'exclusiveMinimum', + 'maxLength', + 'minLength', + 'pattern', + 'maxItems', + 'minItems', + 'uniqueItems', + 'enum', + 'multipleOf', + ], + 'x-', + ], + marker: 'key', + targetSpecs: OpenAPI2, +}; + +export default allowedFields2_0Lint; diff --git a/packages/apidom-ls/src/config/openapi/header/lint/collection-format--equals.ts b/packages/apidom-ls/src/config/openapi/header/lint/collection-format--equals.ts new file mode 100644 index 0000000000..832176e7b9 --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/header/lint/collection-format--equals.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 collectionFormatEqualsLint: LinterMeta = { + code: ApilintCodes.OPENAPI2_HEADER_FIELD_COLLECTION_FORMAT_EQUALS, + source: 'apilint', + message: "'collectionFormat' must be one of allowed values: 'csv', 'ssv', 'tsv', 'pipes'", + severity: DiagnosticSeverity.Error, + linterFunction: 'apilintValueOrArray', + linterParams: [['csv', 'ssv', 'tsv', 'pipes']], + marker: 'value', + target: 'collectionFormat', + data: {}, + targetSpecs: OpenAPI2, +}; + +export default collectionFormatEqualsLint; diff --git a/packages/apidom-ls/src/config/openapi/header/lint/description--type.ts b/packages/apidom-ls/src/config/openapi/header/lint/description--type.ts index c363f9efc5..95822aed80 100644 --- a/packages/apidom-ls/src/config/openapi/header/lint/description--type.ts +++ b/packages/apidom-ls/src/config/openapi/header/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_HEADER_FIELD_DESCRIPTION_TYPE, + code: ApilintCodes.OPENAPI2_HEADER_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/header/lint/enum--type.ts b/packages/apidom-ls/src/config/openapi/header/lint/enum--type.ts new file mode 100644 index 0000000000..3702b26c85 --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/header/lint/enum--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 enumTypeLint: LinterMeta = { + code: ApilintCodes.OPENAPI2_HEADER_FIELD_ENUM_TYPE, + source: 'apilint', + message: 'enum must be an array', + severity: DiagnosticSeverity.Error, + linterFunction: 'apilintType', + linterParams: ['array'], + marker: 'value', + target: 'enum', + data: {}, + targetSpecs: OpenAPI2, +}; + +export default enumTypeLint; diff --git a/packages/apidom-ls/src/config/openapi/header/lint/exclusive-maximum--type.ts b/packages/apidom-ls/src/config/openapi/header/lint/exclusive-maximum--type.ts new file mode 100644 index 0000000000..11992df85c --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/header/lint/exclusive-maximum--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 exclusiveMaximumTypeLint: LinterMeta = { + code: ApilintCodes.OPENAPI2_HEADER_FIELD_EXCLUSIVE_MAXIMUM_TYPE, + source: 'apilint', + message: 'exclusiveMaximum must be a boolean', + severity: DiagnosticSeverity.Error, + linterFunction: 'apilintType', + linterParams: ['boolean'], + marker: 'value', + target: 'exclusiveMaximum', + data: {}, + targetSpecs: OpenAPI2, +}; + +export default exclusiveMaximumTypeLint; diff --git a/packages/apidom-ls/src/config/openapi/header/lint/exclusive-minimum--type.ts b/packages/apidom-ls/src/config/openapi/header/lint/exclusive-minimum--type.ts new file mode 100644 index 0000000000..36dbba7724 --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/header/lint/exclusive-minimum--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 exclusiveMinimumTypeLint: LinterMeta = { + code: ApilintCodes.OPENAPI2_HEADER_FIELD_EXCLUSIVE_MINIMUM_TYPE, + source: 'apilint', + message: 'exclusiveMinimum must be a boolean', + severity: DiagnosticSeverity.Error, + linterFunction: 'apilintType', + linterParams: ['boolean'], + marker: 'value', + target: 'exclusiveMinimum', + data: {}, + targetSpecs: OpenAPI2, +}; + +export default exclusiveMinimumTypeLint; diff --git a/packages/apidom-ls/src/config/openapi/header/lint/format--type.ts b/packages/apidom-ls/src/config/openapi/header/lint/format--type.ts new file mode 100644 index 0000000000..7c1321127d --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/header/lint/format--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 formatTypeLint: LinterMeta = { + code: ApilintCodes.OPENAPI2_HEADER_FIELD_FORMAT_TYPE, + source: 'apilint', + message: 'format must be a string', + severity: DiagnosticSeverity.Error, + linterFunction: 'apilintType', + linterParams: ['string'], + marker: 'value', + target: 'format', + data: {}, + targetSpecs: OpenAPI2, +}; + +export default formatTypeLint; diff --git a/packages/apidom-ls/src/config/openapi/header/lint/index.ts b/packages/apidom-ls/src/config/openapi/header/lint/index.ts index 983c6268e7..c71653b904 100644 --- a/packages/apidom-ls/src/config/openapi/header/lint/index.ts +++ b/packages/apidom-ls/src/config/openapi/header/lint/index.ts @@ -1,3 +1,4 @@ +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 requiredFieldsLint from './required-fields'; @@ -15,6 +16,24 @@ import examplesMutuallyExclusiveLint from './examples--mutually-exclusive'; import contentValuesTypeLint from './content--values-type'; import contentAllowedFields3_0Lint from './content--allowed-fields-3-0'; import contentAllowedFields3_1Lint from './content--allowed-fields-3-1'; +import typeEqualsLint from './type--equals'; +import typeRequiredLint from './type--required'; +import formatTypeLint from './format--type'; +import itemsTypeLint from './items--type'; +import itemsRequiredLint from './items--required'; +import collectionFormatEqualsLint from './collection-format--equals'; +import maximumTypeLint from './maximum--type'; +import exclusiveMaximumTypeLint from './exclusive-maximum--type'; +import minimumTypeLint from './minimum--type'; +import exclusiveMinimumTypeLint from './exclusive-minimum--type'; +import maxLengthTypeLint from './max-length--type'; +import minLengthTypeLint from './min-length--type'; +import patternTypeLint from './pattern--type'; +import maxItemsTypeLint from './max-items--type'; +import minItemsTypeLint from './min-items--type'; +import uniqueItemsTypeLint from './unique-items--type'; +import enumTypeLint from './enum--type'; +import multipleOfTypeLint from './multiple-of--type'; const lints = [ descriptionTypeLint, @@ -31,7 +50,27 @@ const lints = [ contentValuesTypeLint, contentAllowedFields3_0Lint, contentAllowedFields3_1Lint, + typeEqualsLint, + typeRequiredLint, + typeEqualsLint, + formatTypeLint, + itemsTypeLint, + itemsRequiredLint, + collectionFormatEqualsLint, + maximumTypeLint, + exclusiveMaximumTypeLint, + minimumTypeLint, + exclusiveMinimumTypeLint, + maxLengthTypeLint, + minLengthTypeLint, + patternTypeLint, + maxItemsTypeLint, + minItemsTypeLint, + uniqueItemsTypeLint, + enumTypeLint, + multipleOfTypeLint, requiredFieldsLint, + allowedFields2_0Lint, allowedFields3_0Lint, allowedFields3_1Lint, ]; diff --git a/packages/apidom-ls/src/config/openapi/header/lint/items--required.ts b/packages/apidom-ls/src/config/openapi/header/lint/items--required.ts new file mode 100644 index 0000000000..3ffcdc693a --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/header/lint/items--required.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'; + +const itemsRequiredLint: LinterMeta = { + code: ApilintCodes.OPENAPI2_HEADER_FIELD_ITEMS_REQUIRED, + source: 'apilint', + message: "should have an 'items' if 'type'=array", + severity: DiagnosticSeverity.Error, + linterFunction: 'hasRequiredField', + linterParams: ['items'], + marker: 'key', + conditions: [ + { + targets: [{ path: 'type' }], + function: 'apilintContainsValue', + params: ['array'], + }, + ], + data: { + quickFix: [ + { + message: "add 'items' field", + action: 'addChild', + snippetYaml: 'items: \n \n', + snippetJson: '"items": {\n \n },\n', + }, + ], + }, + targetSpecs: OpenAPI2, +}; + +export default itemsRequiredLint; diff --git a/packages/apidom-ls/src/config/openapi/header/lint/items--type.ts b/packages/apidom-ls/src/config/openapi/header/lint/items--type.ts new file mode 100644 index 0000000000..d14ee9a307 --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/header/lint/items--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 itemsTypeLint: LinterMeta = { + code: ApilintCodes.OPENAPI2_HEADER_FIELD_ITEMS_TYPE, + source: 'apilint', + message: "'items' must be an object", + severity: DiagnosticSeverity.Error, + linterFunction: 'apilintElementOrClass', + linterParams: ['items'], + marker: 'value', + target: 'items', + data: {}, + targetSpecs: OpenAPI2, +}; + +export default itemsTypeLint; diff --git a/packages/apidom-ls/src/config/openapi/header/lint/max-items--type.ts b/packages/apidom-ls/src/config/openapi/header/lint/max-items--type.ts new file mode 100644 index 0000000000..9ffd4f4235 --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/header/lint/max-items--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 maxItemsTypeLint: LinterMeta = { + code: ApilintCodes.OPENAPI2_HEADER_FIELD_MAX_ITEMS_TYPE, + source: 'apilint', + message: 'maxItems must be a non-negative integer', + severity: DiagnosticSeverity.Error, + linterFunction: 'apilintNumber', + linterParams: [true, true, true], + marker: 'value', + target: 'maxItems', + data: {}, + targetSpecs: OpenAPI2, +}; + +export default maxItemsTypeLint; diff --git a/packages/apidom-ls/src/config/openapi/header/lint/max-length--type.ts b/packages/apidom-ls/src/config/openapi/header/lint/max-length--type.ts new file mode 100644 index 0000000000..44443a2454 --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/header/lint/max-length--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 maxLengthTypeLint: LinterMeta = { + code: ApilintCodes.OPENAPI2_HEADER_FIELD_MAX_LENGTH_TYPE, + source: 'apilint', + message: 'maxLength must be an integer', + severity: DiagnosticSeverity.Error, + linterFunction: 'apilintNumber', + linterParams: [true, true, true], + marker: 'value', + target: 'maxLength', + data: {}, + targetSpecs: OpenAPI2, +}; + +export default maxLengthTypeLint; diff --git a/packages/apidom-ls/src/config/openapi/header/lint/maximum--type.ts b/packages/apidom-ls/src/config/openapi/header/lint/maximum--type.ts new file mode 100644 index 0000000000..af236ba2aa --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/header/lint/maximum--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 maximumTypeLint: LinterMeta = { + code: ApilintCodes.OPENAPI2_HEADER_FIELD_MAXIMUM_TYPE, + source: 'apilint', + message: 'maximum must be a number', + severity: DiagnosticSeverity.Error, + linterFunction: 'apilintType', + linterParams: ['number'], + marker: 'value', + target: 'maximum', + data: {}, + targetSpecs: OpenAPI2, +}; + +export default maximumTypeLint; diff --git a/packages/apidom-ls/src/config/openapi/header/lint/min-items--type.ts b/packages/apidom-ls/src/config/openapi/header/lint/min-items--type.ts new file mode 100644 index 0000000000..afca712051 --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/header/lint/min-items--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 minItemsTypeLint: LinterMeta = { + code: ApilintCodes.OPENAPI2_HEADER_FIELD_MIN_ITEMS_TYPE, + source: 'apilint', + message: 'minItems must be a non-negative integer', + severity: DiagnosticSeverity.Error, + linterFunction: 'apilintNumber', + linterParams: [true, true, true], + marker: 'value', + target: 'minItems', + data: {}, + targetSpecs: OpenAPI2, +}; + +export default minItemsTypeLint; diff --git a/packages/apidom-ls/src/config/openapi/header/lint/min-length--type.ts b/packages/apidom-ls/src/config/openapi/header/lint/min-length--type.ts new file mode 100644 index 0000000000..fd70112f90 --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/header/lint/min-length--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 minLengthTypeLint: LinterMeta = { + code: ApilintCodes.OPENAPI2_HEADER_FIELD_MIN_LENGTH_TYPE, + source: 'apilint', + message: 'minLength must be an integer', + severity: DiagnosticSeverity.Error, + linterFunction: 'apilintNumber', + linterParams: [true, true, true], + marker: 'value', + target: 'minLength', + data: {}, + targetSpecs: OpenAPI2, +}; + +export default minLengthTypeLint; diff --git a/packages/apidom-ls/src/config/openapi/header/lint/minimum--type.ts b/packages/apidom-ls/src/config/openapi/header/lint/minimum--type.ts new file mode 100644 index 0000000000..d5604d6fad --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/header/lint/minimum--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 minimumTypeLint: LinterMeta = { + code: ApilintCodes.OPENAPI2_HEADER_FIELD_MINIMUM_TYPE, + source: 'apilint', + message: 'minimum must be a number', + severity: DiagnosticSeverity.Error, + linterFunction: 'apilintType', + linterParams: ['number'], + marker: 'value', + target: 'minimum', + data: {}, + targetSpecs: OpenAPI2, +}; + +export default minimumTypeLint; diff --git a/packages/apidom-ls/src/config/openapi/header/lint/multiple-of--type.ts b/packages/apidom-ls/src/config/openapi/header/lint/multiple-of--type.ts new file mode 100644 index 0000000000..77a1a69567 --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/header/lint/multiple-of--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 multipleOfTypeLint: LinterMeta = { + code: ApilintCodes.OPENAPI2_HEADER_FIELD_MULTIPLE_OF_TYPE, + source: 'apilint', + message: 'multipleOf must be a number', + severity: DiagnosticSeverity.Error, + linterFunction: 'apilintType', + linterParams: ['number'], + marker: 'value', + target: 'multipleOf', + data: {}, + targetSpecs: OpenAPI2, +}; + +export default multipleOfTypeLint; diff --git a/packages/apidom-ls/src/config/openapi/header/lint/pattern--type.ts b/packages/apidom-ls/src/config/openapi/header/lint/pattern--type.ts new file mode 100644 index 0000000000..5d902d0919 --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/header/lint/pattern--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 patternTypeLint: LinterMeta = { + code: ApilintCodes.OPENAPI2_HEADER_FIELD_PATTERN_TYPE, + source: 'apilint', + message: 'pattern must be a string', + severity: DiagnosticSeverity.Warning, + linterFunction: 'apilintType', + linterParams: ['string'], + marker: 'value', + target: 'pattern', + data: {}, + targetSpecs: OpenAPI2, +}; + +export default patternTypeLint; diff --git a/packages/apidom-ls/src/config/openapi/header/lint/type--equals.ts b/packages/apidom-ls/src/config/openapi/header/lint/type--equals.ts new file mode 100644 index 0000000000..dcf8d57f49 --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/header/lint/type--equals.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 typeEqualsLint: LinterMeta = { + code: ApilintCodes.OPENAPI2_HEADER_FIELD_TYPE_EQUALS, + source: 'apilint', + message: "'type' must be one of allowed values: string, number, integer, boolean, array", + severity: DiagnosticSeverity.Error, + linterFunction: 'apilintValueOrArray', + linterParams: [['string', 'number', 'integer', 'boolean', 'array']], + marker: 'value', + target: 'type', + data: {}, + targetSpecs: OpenAPI2, +}; + +export default typeEqualsLint; diff --git a/packages/apidom-ls/src/config/openapi/header/lint/type--required.ts b/packages/apidom-ls/src/config/openapi/header/lint/type--required.ts new file mode 100644 index 0000000000..2c8f2dcd14 --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/header/lint/type--required.ts @@ -0,0 +1,28 @@ +import { DiagnosticSeverity } from 'vscode-languageserver-types'; + +import ApilintCodes from '../../../codes'; +import { LinterMeta } from '../../../../apidom-language-types'; +import { OpenAPI2 } from '../../target-specs'; + +const typeRequiredLint: LinterMeta = { + code: ApilintCodes.OPENAPI2_HEADER_FIELD_TYPE_REQUIRED, + source: 'apilint', + message: "should always have a 'type'", + severity: DiagnosticSeverity.Error, + linterFunction: 'hasRequiredField', + linterParams: ['type'], + marker: 'key', + data: { + quickFix: [ + { + message: "add 'type' field", + action: 'addChild', + snippetYaml: 'type: \n ', + snippetJson: '"type": ,\n ', + }, + ], + }, + targetSpecs: OpenAPI2, +}; + +export default typeRequiredLint; diff --git a/packages/apidom-ls/src/config/openapi/header/lint/unique-items--type.ts b/packages/apidom-ls/src/config/openapi/header/lint/unique-items--type.ts new file mode 100644 index 0000000000..177f752cea --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/header/lint/unique-items--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 uniqueItemsTypeLint: LinterMeta = { + code: ApilintCodes.OPENAPI2_HEADER_FIELD_UNIQUE_ITEMS_TYPE, + source: 'apilint', + message: 'uniqueItems must be a boolean', + severity: DiagnosticSeverity.Error, + linterFunction: 'apilintType', + linterParams: ['boolean'], + marker: 'value', + target: 'uniqueItems', + data: {}, + targetSpecs: OpenAPI2, +}; + +export default uniqueItemsTypeLint; diff --git a/packages/apidom-ls/src/config/openapi/items/completion.ts b/packages/apidom-ls/src/config/openapi/items/completion.ts index c2c14763eb..989d64de9d 100644 --- a/packages/apidom-ls/src/config/openapi/items/completion.ts +++ b/packages/apidom-ls/src/config/openapi/items/completion.ts @@ -30,7 +30,7 @@ const completion: ApidomCompletionItem[] = [ documentation: { kind: 'markdown', value: - 'The extending format for the previously mentioned [`type`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#parameterType). See [Data Type Formats](#dataTypeFormat) for further details.', + 'The extending format for the previously mentioned [`type`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#parameterType). See [Data Type Formats](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#dataTypeFormat) for further details.', }, targetSpecs: OpenAPI2, }, @@ -44,7 +44,7 @@ const completion: ApidomCompletionItem[] = [ documentation: { kind: 'markdown', value: - '[Items Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#itemsObject)\n\\\n\\\n**Required if [`type`](#parameterType) is "array".** Describes the type of items in the array.', + '[Items Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#itemsObject)\n\\\n\\\n**Required if [`type`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#itemsType) is "array".** Describes the type of items in the array.', }, targetSpecs: OpenAPI2, }, diff --git a/packages/apidom-ls/src/config/openapi/items/documentation.ts b/packages/apidom-ls/src/config/openapi/items/documentation.ts index 33a12aa15a..cdb8432048 100644 --- a/packages/apidom-ls/src/config/openapi/items/documentation.ts +++ b/packages/apidom-ls/src/config/openapi/items/documentation.ts @@ -8,12 +8,12 @@ const documentation = [ }, { target: 'format', - docs: 'The extending format for the previously mentioned [`type`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#parameterType). See [Data Type Formats](#dataTypeFormat) for further details.', + docs: 'The extending format for the previously mentioned [`type`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#parameterType). See [Data Type Formats](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#dataTypeFormat) for further details.', targetSpecs: OpenAPI2, }, { target: 'items', - docs: '[Items Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#itemsObject)\n\\\n\\\n**Required if [`type`](#parameterType) is "array".** Describes the type of items in the array.', + docs: '[Items Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#itemsObject)\n\\\n\\\n**Required if [`type`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#itemsType) is "array".** Describes the type of items in the array.', targetSpecs: OpenAPI2, }, { diff --git a/packages/apidom-ls/src/config/openapi/items/lint/index.ts b/packages/apidom-ls/src/config/openapi/items/lint/index.ts index 730e767a3a..8e306bb666 100644 --- a/packages/apidom-ls/src/config/openapi/items/lint/index.ts +++ b/packages/apidom-ls/src/config/openapi/items/lint/index.ts @@ -11,6 +11,9 @@ import minimumTypeLint from './minimum--type'; import exclusiveMinimumTypeLint from './exclusive-minimum--type'; import maxLengthTypeLint from './max-length--type'; import minLengthTypeLint from './min-length--type'; +import patternTypeLint from './pattern--type'; +import maxItemsTypeLint from './max-items--type'; +import minItemsTypeLint from './min-items--type'; import uniqueItemsTypeLint from './unique-items--type'; import enumTypeLint from './enum--type'; import multipleOfTypeLint from './multiple-of--type'; @@ -28,6 +31,9 @@ const lints = [ exclusiveMinimumTypeLint, maxLengthTypeLint, minLengthTypeLint, + patternTypeLint, + maxItemsTypeLint, + minItemsTypeLint, uniqueItemsTypeLint, enumTypeLint, multipleOfTypeLint, diff --git a/packages/apidom-ls/src/config/openapi/items/lint/max-items--type.ts b/packages/apidom-ls/src/config/openapi/items/lint/max-items--type.ts new file mode 100644 index 0000000000..71fc464f3b --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/items/lint/max-items--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 maxItemsTypeLint: LinterMeta = { + code: ApilintCodes.OPENAPI2_ITEMS_FIELD_MAX_ITEMS_TYPE, + source: 'apilint', + message: 'maxItems must be a non-negative integer', + severity: DiagnosticSeverity.Error, + linterFunction: 'apilintNumber', + linterParams: [true, true, true], + marker: 'value', + target: 'maxItems', + data: {}, + targetSpecs: OpenAPI2, +}; + +export default maxItemsTypeLint; diff --git a/packages/apidom-ls/src/config/openapi/items/lint/min-items--type.ts b/packages/apidom-ls/src/config/openapi/items/lint/min-items--type.ts new file mode 100644 index 0000000000..cbf7e8ffc6 --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/items/lint/min-items--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 minItemsTypeLint: LinterMeta = { + code: ApilintCodes.OPENAPI2_ITEMS_FIELD_MIN_ITEMS_TYPE, + source: 'apilint', + message: 'minItems must be a non-negative integer', + severity: DiagnosticSeverity.Error, + linterFunction: 'apilintNumber', + linterParams: [true, true, true], + marker: 'value', + target: 'minItems', + data: {}, + targetSpecs: OpenAPI2, +}; + +export default minItemsTypeLint; diff --git a/packages/apidom-ls/src/config/openapi/items/lint/pattern--type.ts b/packages/apidom-ls/src/config/openapi/items/lint/pattern--type.ts new file mode 100644 index 0000000000..c51561dcb9 --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/items/lint/pattern--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 patternTypeLint: LinterMeta = { + code: ApilintCodes.OPENAPI2_ITEMS_FIELD_PATTERN_TYPE, + source: 'apilint', + message: 'pattern must be a string', + severity: DiagnosticSeverity.Warning, + linterFunction: 'apilintType', + linterParams: ['string'], + marker: 'value', + target: 'pattern', + data: {}, + targetSpecs: OpenAPI2, +}; + +export default patternTypeLint;