diff --git a/packages/apidom-ls/src/config/codes.ts b/packages/apidom-ls/src/config/codes.ts index 6f4b8ec0d..bccd251a0 100644 --- a/packages/apidom-ls/src/config/codes.ts +++ b/packages/apidom-ls/src/config/codes.ts @@ -763,6 +763,9 @@ enum ApilintCodes { OPENAPI2_HEADERS = 3130000, OPENAPI2_HEADERS_VALUES_TYPE = 3130100, + OPENAPI2_DEFINITIONS = 3140000, + OPENAPI2_DEFINITIONS_VALUES_TYPE = 3140100, + OPENAPI3_0 = 5000000, OPENAPI3_0_OPENAPI_VALUE_PATTERN_3_0_0 = 5000100, diff --git a/packages/apidom-ls/src/config/openapi/config.ts b/packages/apidom-ls/src/config/openapi/config.ts index b9debaaa1..b99439d22 100644 --- a/packages/apidom-ls/src/config/openapi/config.ts +++ b/packages/apidom-ls/src/config/openapi/config.ts @@ -8,6 +8,7 @@ import componentsMeta from './components/meta'; import contactMeta from './contact/meta'; import contentMeta from './content/meta'; import discriminatorMeta from './discriminator/meta'; +import definitionsMeta from './definitions/meta'; import encodingMeta from './encoding/meta'; import exampleMeta from './example/meta'; import externalDocumentationMeta from './external-documentation/meta'; @@ -60,6 +61,7 @@ export default { contact: contactMeta, content: contentMeta, discriminator: discriminatorMeta, + definitions: definitionsMeta, encoding: encodingMeta, example: exampleMeta, externalDocumentation: externalDocumentationMeta, diff --git a/packages/apidom-ls/src/config/openapi/definitions/documentation.ts b/packages/apidom-ls/src/config/openapi/definitions/documentation.ts new file mode 100644 index 000000000..44aa6615b --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/definitions/documentation.ts @@ -0,0 +1,10 @@ +import { OpenAPI2 } from '../target-specs'; + +const documentation = [ + { + docs: '#### [Definitions Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#definitions-object)\n\nAn object to hold data types that can be consumed and produced by operations. These data types can be primitives, arrays or models.\n\n##### Patterned Fields\n\nField Pattern | Type | Description\n---|:---:|---\n{name} | [Schema Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#schemaObject) | A single definition, mapping a "name" to the schema it defines.\n\n##### Definitions Object Example\n\n```js\n{\n "Category": {\n "type": "object",\n "properties": {\n "id": {\n "type": "integer",\n "format": "int64"\n },\n "name": {\n "type": "string"\n }\n }\n },\n "Tag": {\n "type": "object",\n "properties": {\n "id": {\n "type": "integer",\n "format": "int64"\n },\n "name": {\n "type": "string"\n }\n }\n }\n}\n```\n\n\n\\\nYAML\n```yaml\nCategory:\n type: object\n properties:\n id:\n type: integer\n format: int64\n name:\n type: string\nTag:\n type: object\n properties:\n id:\n type: integer\n format: int64\n name:\n type: string\n```', + targetSpecs: OpenAPI2, + }, +]; + +export default documentation; diff --git a/packages/apidom-ls/src/config/openapi/definitions/lint/index.ts b/packages/apidom-ls/src/config/openapi/definitions/lint/index.ts new file mode 100644 index 000000000..f49a5fe79 --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/definitions/lint/index.ts @@ -0,0 +1,5 @@ +import valuesTypeLint from './values--type'; + +const lints = [valuesTypeLint]; + +export default lints; diff --git a/packages/apidom-ls/src/config/openapi/definitions/lint/values--type.ts b/packages/apidom-ls/src/config/openapi/definitions/lint/values--type.ts new file mode 100644 index 000000000..13a37dd13 --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/definitions/lint/values--type.ts @@ -0,0 +1,19 @@ +import { DiagnosticSeverity } from 'vscode-languageserver-types'; + +import ApilintCodes from '../../../codes'; +import { LinterMeta } from '../../../../apidom-language-types'; +import { OpenAPI2 } from '../../target-specs'; + +const valuesTypeLint: LinterMeta = { + code: ApilintCodes.OPENAPI2_DEFINITIONS_VALUES_TYPE, + source: 'apilint', + message: 'Definitions Object values must be of Schema Object shape', + severity: DiagnosticSeverity.Error, + linterFunction: 'apilintChildrenOfElementsOrClasses', + linterParams: [['schema']], + marker: 'key', + data: {}, + targetSpecs: OpenAPI2, +}; + +export default valuesTypeLint; diff --git a/packages/apidom-ls/src/config/openapi/definitions/meta.ts b/packages/apidom-ls/src/config/openapi/definitions/meta.ts new file mode 100644 index 000000000..687725779 --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/definitions/meta.ts @@ -0,0 +1,10 @@ +import lint from './lint'; +import documentation from './documentation'; +import { FormatMeta } from '../../../apidom-language-types'; + +const meta: FormatMeta = { + lint, + documentation, +}; + +export default meta;