Skip to content

Commit

Permalink
feat(ls): add rules for OpenAPI 2.0 Scopes Object (#3663)
Browse files Browse the repository at this point in the history
Refs #3620
  • Loading branch information
char0n committed Jan 12, 2024
1 parent 2323129 commit b8e2b41
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/apidom-ls/src/config/codes.ts
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions packages/apidom-ls/src/config/openapi/config.ts
Expand Up @@ -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';

Expand Down Expand Up @@ -95,6 +96,7 @@ export default {
tag: tagMeta,
xml: xmlMeta,
items: itemsMeta,
scopes: scopesMeta,
schema: schemaMeta,
'path-template': pathTemplateMeta,
};
10 changes: 10 additions & 0 deletions 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;
5 changes: 5 additions & 0 deletions 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;
19 changes: 19 additions & 0 deletions 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;
10 changes: 10 additions & 0 deletions 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;

0 comments on commit b8e2b41

Please sign in to comment.