diff --git a/packages/apidom-ls/src/config/codes.ts b/packages/apidom-ls/src/config/codes.ts index 03c9e36ce9..e1b09cc0f5 100644 --- a/packages/apidom-ls/src/config/codes.ts +++ b/packages/apidom-ls/src/config/codes.ts @@ -775,6 +775,9 @@ enum ApilintCodes { OPENAPI2_SECURITY_DEFINITIONS = 3170000, OPENAPI2_SECURITY_DEFINITIONS_VALUES_TYPE = 3170100, + OPENAPI2_SCOPES = 3180000, + OPENAPI2_SCOPES_VALUES_TYPE = 3180100, + 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 b6e38ab533..5de10b7347 100644 --- a/packages/apidom-ls/src/config/openapi/config.ts +++ b/packages/apidom-ls/src/config/openapi/config.ts @@ -40,6 +40,7 @@ import tagMeta from './tag/meta'; import xmlMeta from './xml/meta'; import pathTemplateMeta from './path-template/meta'; import itemsMeta from './items/meta'; +import scopesMeta from './scopes/meta'; import schemaMeta from '../common/schema/meta'; import ApilintCodes from '../codes'; @@ -95,6 +96,7 @@ export default { tag: tagMeta, xml: xmlMeta, items: itemsMeta, + scopes: scopesMeta, schema: schemaMeta, 'path-template': pathTemplateMeta, }; diff --git a/packages/apidom-ls/src/config/openapi/scopes/documentation.ts b/packages/apidom-ls/src/config/openapi/scopes/documentation.ts new file mode 100644 index 0000000000..5843495cf9 --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/scopes/documentation.ts @@ -0,0 +1,10 @@ +import { OpenAPI2 } from '../target-specs'; + +const documentation = [ + { + docs: '#### [Scopes Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#scopes-object)\n\nLists the available scopes for an OAuth2 security scheme.\n\n##### Patterned Fields\n\nField Pattern | Type | Description\n---|:---:|---\n{name} | `string` | Maps between a name of a scope to a short description of it (as the value of the property).\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##### Scopes Object Example\n\n```js\n{\n "write:pets": "modify pets in your account",\n "read:pets": "read your pets"\n}\n```\n\n\n\\\nYAML\n```yaml\nwrite:pets: modify pets in your account\nread:pets: read your pets\n```', + targetSpecs: OpenAPI2, + }, +]; + +export default documentation; diff --git a/packages/apidom-ls/src/config/openapi/scopes/lint/index.ts b/packages/apidom-ls/src/config/openapi/scopes/lint/index.ts new file mode 100644 index 0000000000..f49a5fe791 --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/scopes/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/scopes/lint/values--type.ts b/packages/apidom-ls/src/config/openapi/scopes/lint/values--type.ts new file mode 100644 index 0000000000..e719a67fce --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/scopes/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_SCOPES_VALUES_TYPE, + source: 'apilint', + message: 'Scopes Object values must be strings', + severity: DiagnosticSeverity.Error, + linterFunction: 'apilintChildrenOfElementsOrClasses', + linterParams: [['string']], + marker: 'key', + data: {}, + targetSpecs: OpenAPI2, +}; + +export default valuesTypeLint; diff --git a/packages/apidom-ls/src/config/openapi/scopes/meta.ts b/packages/apidom-ls/src/config/openapi/scopes/meta.ts new file mode 100644 index 0000000000..687725779c --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/scopes/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;