Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(ls): scope OpenAPI 3.x.y rules explicitly (batch 3) #3503

Merged
merged 2 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 8 additions & 21 deletions packages/apidom-ls/src/config/openapi/oauth-flow/completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
CompletionFormat,
CompletionType,
} from '../../../apidom-language-types';
import { OpenAPI30, OpenAPI31, OpenAPI3 } from '../target-specs';

const completion: ApidomCompletionItem[] = [
{
Expand All @@ -17,12 +18,7 @@ const completion: ApidomCompletionItem[] = [
value:
'Applies to `oauth2` (`"implicit"`, `"authorizationCode"`). **REQUIRED**. The authorization URL to be used for this flow. This MUST be in the form of a URL.',
},
targetSpecs: [
{ namespace: 'openapi', version: '3.0.0' },
{ namespace: 'openapi', version: '3.0.1' },
{ namespace: 'openapi', version: '3.0.2' },
{ namespace: 'openapi', version: '3.0.3' },
],
targetSpecs: OpenAPI30,
},
{
label: 'authorizationUrl',
Expand All @@ -36,7 +32,7 @@ const completion: ApidomCompletionItem[] = [
value:
'Applies to `oauth2` (`"implicit"`, `"authorizationCode"`). **REQUIRED**. The authorization URL to be used for this flow. This MUST be in the form of a URL. The OAuth2 standard requires the use of TLS.',
},
targetSpecs: [{ namespace: 'openapi', version: '3.1.0' }],
targetSpecs: OpenAPI31,
},
{
label: 'tokenUrl',
Expand All @@ -50,12 +46,7 @@ const completion: ApidomCompletionItem[] = [
value:
'Applies to `oauth2` (`"password"`, `"clientCredentials"`, `"authorizationCode"`). **REQUIRED**. The token URL to be used for this flow. This MUST be in the form of a URL.',
},
targetSpecs: [
{ namespace: 'openapi', version: '3.0.0' },
{ namespace: 'openapi', version: '3.0.1' },
{ namespace: 'openapi', version: '3.0.2' },
{ namespace: 'openapi', version: '3.0.3' },
],
targetSpecs: OpenAPI30,
},
{
label: 'tokenUrl',
Expand All @@ -69,7 +60,7 @@ const completion: ApidomCompletionItem[] = [
value:
'Applies to `oauth2` (`"password"`, `"clientCredentials"`, `"authorizationCode"`). **REQUIRED**. The token URL to be used for this flow. This MUST be in the form of a URL. The OAuth2 standard requires the use of TLS.',
},
targetSpecs: [{ namespace: 'openapi', version: '3.1.0' }],
targetSpecs: OpenAPI31,
},
{
label: 'refreshUrl',
Expand All @@ -83,12 +74,7 @@ const completion: ApidomCompletionItem[] = [
value:
'Applies to `oauth2`. The URL to be used for obtaining refresh tokens. This MUST be in the form of a URL.',
},
targetSpecs: [
{ namespace: 'openapi', version: '3.0.0' },
{ namespace: 'openapi', version: '3.0.1' },
{ namespace: 'openapi', version: '3.0.2' },
{ namespace: 'openapi', version: '3.0.3' },
],
targetSpecs: OpenAPI30,
},
{
label: 'refreshUrl',
Expand All @@ -102,7 +88,7 @@ const completion: ApidomCompletionItem[] = [
value:
'Applies to `oauth2`. The URL to be used for obtaining refresh tokens. This MUST be in the form of a URL. The OAuth2 standard requires the use of TLS.',
},
targetSpecs: [{ namespace: 'openapi', version: '3.1.0' }],
targetSpecs: OpenAPI31,
},
{
label: 'scopes',
Expand All @@ -116,6 +102,7 @@ const completion: ApidomCompletionItem[] = [
value:
'**REQUIRED**. The available scopes for the OAuth2 security scheme. A map between the scope name and a short description for it. The map MAY be empty.',
},
targetSpecs: OpenAPI3,
},
];

Expand Down
39 changes: 11 additions & 28 deletions packages/apidom-ls/src/config/openapi/oauth-flow/documentation.ts
Original file line number Diff line number Diff line change
@@ -1,65 +1,48 @@
import { OpenAPI30, OpenAPI31, OpenAPI3 } from '../target-specs';

const documentation = [
{
target: 'authorizationUrl',
docs: 'Applies to `oauth2` (`"implicit"`, `"authorizationCode"`). **REQUIRED**. The authorization URL to be used for this flow. This MUST be in the form of a URL.',
targetSpecs: [
{ namespace: 'openapi', version: '3.0.0' },
{ namespace: 'openapi', version: '3.0.1' },
{ namespace: 'openapi', version: '3.0.2' },
{ namespace: 'openapi', version: '3.0.3' },
],
targetSpecs: OpenAPI30,
},
{
target: 'authorizationUrl',
docs: 'Applies to `oauth2` (`"implicit"`, `"authorizationCode"`). **REQUIRED**. The authorization URL to be used for this flow. This MUST be in the form of a URL. The OAuth2 standard requires the use of TLS.',
targetSpecs: [{ namespace: 'openapi', version: '3.1.0' }],
targetSpecs: OpenAPI31,
},
{
target: 'tokenUrl',
docs: 'Applies to `oauth2` (`"password"`, `"clientCredentials"`, `"authorizationCode"`). **REQUIRED**. The token URL to be used for this flow. This MUST be in the form of a URL.',
targetSpecs: [
{ namespace: 'openapi', version: '3.0.0' },
{ namespace: 'openapi', version: '3.0.1' },
{ namespace: 'openapi', version: '3.0.2' },
{ namespace: 'openapi', version: '3.0.3' },
],
targetSpecs: OpenAPI30,
},
{
target: 'tokenUrl',
docs: 'Applies to `oauth2` (`"password"`, `"clientCredentials"`, `"authorizationCode"`). **REQUIRED**. The token URL to be used for this flow. This MUST be in the form of a URL. The OAuth2 standard requires the use of TLS.',
targetSpecs: [{ namespace: 'openapi', version: '3.1.0' }],
targetSpecs: OpenAPI31,
},
{
target: 'refreshUrl',
docs: 'Applies to `oauth2`. The URL to be used for obtaining refresh tokens. This MUST be in the form of a URL.',
targetSpecs: [
{ namespace: 'openapi', version: '3.0.0' },
{ namespace: 'openapi', version: '3.0.1' },
{ namespace: 'openapi', version: '3.0.2' },
{ namespace: 'openapi', version: '3.0.3' },
],
targetSpecs: OpenAPI30,
},
{
target: 'refreshUrl',
docs: 'Applies to `oauth2`. The URL to be used for obtaining refresh tokens. This MUST be in the form of a URL. The OAuth2 standard requires the use of TLS.',
targetSpecs: [{ namespace: 'openapi', version: '3.1.0' }],
targetSpecs: OpenAPI31,
},
{
target: 'scopes',
docs: 'Map[`string`, `string`]\n\\\n\\\nApplies to `oauth2`. **REQUIRED**. The available scopes for the OAuth2 security scheme. A map between the scope name and a short description for it. The map MAY be empty.',
targetSpecs: OpenAPI3,
},
{
docs: '#### [OAuth Flow Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#oauth-flow-object)\n\nConfiguration details for a supported OAuth Flow\n\n##### Fixed Fields\nField Name | Type | Applies To | Description\n---|:---:|---|---\nauthorizationUrl | `string` | `oauth2` (`"implicit"`, `"authorizationCode"`) | **REQUIRED**. The authorization URL to be used for this flow. This MUST be in the form of a URL.\ntokenUrl | `string` | `oauth2` (`"password"`, `"clientCredentials"`, `"authorizationCode"`) | **REQUIRED**. The token URL to be used for this flow. This MUST be in the form of a URL.\nrefreshUrl | `string` | `oauth2` | The URL to be used for obtaining refresh tokens. This MUST be in the form of a URL.\nscopes | Map[`string`, `string`] | `oauth2` | **REQUIRED**. The available scopes for the OAuth2 security scheme. A map between the scope name and a short description for it. The map MAY be empty.\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##### OAuth Flow Object Examples\n\n```JSON\n{\n "type": "oauth2",\n "flows": {\n "implicit": {\n "authorizationUrl": "https://example.com/api/oauth/dialog",\n "scopes": {\n "write:pets": "modify pets in your account",\n "read:pets": "read your pets"\n }\n },\n "authorizationCode": {\n "authorizationUrl": "https://example.com/api/oauth/dialog",\n "tokenUrl": "https://example.com/api/oauth/token",\n "scopes": {\n "write:pets": "modify pets in your account",\n "read:pets": "read your pets"\n }\n }\n }\n}\n```\n\n\n\\\nYAML\n```yaml\ntype: oauth2\nflows:\n implicit:\n authorizationUrl: https://example.com/api/oauth/dialog\n scopes:\n write:pets: modify pets in your account\n read:pets: read your pets\n authorizationCode:\n authorizationUrl: https://example.com/api/oauth/dialog\n tokenUrl: https://example.com/api/oauth/token\n scopes:\n write:pets: modify pets in your account\n read:pets: read your pets\n```',
targetSpecs: [
{ namespace: 'openapi', version: '3.0.0' },
{ namespace: 'openapi', version: '3.0.1' },
{ namespace: 'openapi', version: '3.0.2' },
{ namespace: 'openapi', version: '3.0.3' },
],
targetSpecs: OpenAPI30,
},
{
docs: '#### [OAuth Flow Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#oauthFlowObject)\n\nConfiguration details for a supported OAuth Flow\n##### Fixed Fields\nField Name | Type | Applies To | Description\n---|:---:|---|:---\nauthorizationUrl | `string` | `oauth2` (`"implicit"`, `"authorizationCode"`) | **REQUIRED**. The authorization URL to be used for this flow. This MUST be in the form of a URL. The OAuth2 standard requires the use of TLS.\ntokenUrl | `string` | `oauth2` (`"password"`, `"clientCredentials"`, `"authorizationCode"`) | **REQUIRED**. The token URL to be used for this flow. This MUST be in the form of a URL. The OAuth2 standard requires the use of TLS.\nrefreshUrl | `string` | `oauth2` | The URL to be used for obtaining refresh tokens. This MUST be in the form of a URL. The OAuth2 standard requires the use of TLS.\nscopes | Map[`string`, `string`] | `oauth2` | **REQUIRED**. The available scopes for the OAuth2 security scheme. A map between the scope name and a short description for it. The map MAY be empty.\n\n\\\nThis object MAY be extended with [Specification Extensions](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#specificationExtensions).\n##### OAuth Flow Object Examples\n\n\\\nJSON\n```json\n{\n "type": "oauth2",\n "flows": {\n "implicit": {\n "authorizationUrl": "https://example.com/api/oauth/dialog",\n "scopes": {\n "write:pets": "modify pets in your account",\n "read:pets": "read your pets"\n }\n },\n "authorizationCode": {\n "authorizationUrl": "https://example.com/api/oauth/dialog",\n "tokenUrl": "https://example.com/api/oauth/token",\n "scopes": {\n "write:pets": "modify pets in your account",\n "read:pets": "read your pets"\n }\n }\n }\n}\n```\n\n\n\\\nYAML\n```yaml\ntype: oauth2\nflows: \n implicit:\n authorizationUrl: https://example.com/api/oauth/dialog\n scopes:\n write:pets: modify pets in your account\n read:pets: read your pets\n authorizationCode:\n authorizationUrl: https://example.com/api/oauth/dialog\n tokenUrl: https://example.com/api/oauth/token\n scopes:\n write:pets: modify pets in your account\n read:pets: read your pets\n```\n',
targetSpecs: [{ namespace: 'openapi', version: '3.1.0' }],
targetSpecs: OpenAPI31,
},
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types';

import ApilintCodes from '../../../codes';
import { LinterMeta } from '../../../../apidom-language-types';
import { OpenAPI3 } from '../../target-specs';

const allowedFieldsLint: LinterMeta = {
code: ApilintCodes.NOT_ALLOWED_FIELDS,
Expand All @@ -11,6 +12,7 @@ const allowedFieldsLint: LinterMeta = {
linterFunction: 'allowedFields',
linterParams: [['authorizationUrl', 'tokenUrl', 'refreshUrl', 'scopes'], 'x-'],
marker: 'key',
targetSpecs: OpenAPI3,
};

export default allowedFieldsLint;
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types';

import ApilintCodes from '../../../codes';
import { LinterMeta } from '../../../../apidom-language-types';
import { OpenAPI3 } from '../../target-specs';

const authorizationUrlFormatURILint: LinterMeta = {
code: ApilintCodes.OPENAPI3_0_OAUTH_FLOW_FIELD_AUTHORIZATION_URL_FORMAT_URI,
Expand All @@ -12,6 +13,7 @@ const authorizationUrlFormatURILint: LinterMeta = {
marker: 'value',
target: 'authorizationUrl',
data: {},
targetSpecs: OpenAPI3,
};

export default authorizationUrlFormatURILint;
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types';

import ApilintCodes from '../../../codes';
import { LinterMeta } from '../../../../apidom-language-types';
import { OpenAPI3 } from '../../target-specs';

const refreshUrlFormatURILint: LinterMeta = {
code: ApilintCodes.OPENAPI3_0_OAUTH_FLOW_FIELD_REFRESH_URL_FORMAT_URI,
Expand All @@ -12,6 +13,7 @@ const refreshUrlFormatURILint: LinterMeta = {
marker: 'value',
target: 'refreshUrl',
data: {},
targetSpecs: OpenAPI3,
};

export default refreshUrlFormatURILint;
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types';

import ApilintCodes from '../../../codes';
import { LinterMeta } from '../../../../apidom-language-types';
import { OpenAPI3 } from '../../target-specs';

const scopesTypeLint: LinterMeta = {
code: ApilintCodes.OPENAPI3_0_OAUTH_FLOW_FIELD_SCOPES_TYPE,
Expand All @@ -13,6 +14,7 @@ const scopesTypeLint: LinterMeta = {
marker: 'value',
target: 'scopes',
data: {},
targetSpecs: OpenAPI3,
};

export default scopesTypeLint;
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types';

import ApilintCodes from '../../../codes';
import { LinterMeta } from '../../../../apidom-language-types';
import { OpenAPI3 } from '../../target-specs';

const tokenUrlFormatURILint: LinterMeta = {
code: ApilintCodes.OPENAPI3_0_OAUTH_FLOW_FIELD_TOKEN_URL_FORMAT_URI,
Expand All @@ -12,6 +13,7 @@ const tokenUrlFormatURILint: LinterMeta = {
marker: 'value',
target: 'tokenUrl',
data: {},
targetSpecs: OpenAPI3,
};

export default tokenUrlFormatURILint;
37 changes: 9 additions & 28 deletions packages/apidom-ls/src/config/openapi/oauth-flows/completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
CompletionFormat,
CompletionType,
} from '../../../apidom-language-types';
import { OpenAPI30, OpenAPI31 } from '../target-specs';

const completion: ApidomCompletionItem[] = [
{
Expand All @@ -17,12 +18,7 @@ const completion: ApidomCompletionItem[] = [
value:
'[OAuth Flow Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#oauthFlowObject)\n\\\n\\\nConfiguration for the OAuth Implicit flow.',
},
targetSpecs: [
{ namespace: 'openapi', version: '3.0.0' },
{ namespace: 'openapi', version: '3.0.1' },
{ namespace: 'openapi', version: '3.0.2' },
{ namespace: 'openapi', version: '3.0.3' },
],
targetSpecs: OpenAPI30,
},
{
label: 'implicit',
Expand All @@ -36,7 +32,7 @@ const completion: ApidomCompletionItem[] = [
value:
'[OAuth Flow Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#oauthFlowObject)\n\\\n\\\nConfiguration for the OAuth Implicit flow.',
},
targetSpecs: [{ namespace: 'openapi', version: '3.1.0' }],
targetSpecs: OpenAPI31,
},
{
label: 'password',
Expand All @@ -50,12 +46,7 @@ const completion: ApidomCompletionItem[] = [
value:
'[OAuth Flow Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#oauthFlowObject)\n\\\n\\\nConfiguration for the OAuth Resource Owner Password flow.',
},
targetSpecs: [
{ namespace: 'openapi', version: '3.0.0' },
{ namespace: 'openapi', version: '3.0.1' },
{ namespace: 'openapi', version: '3.0.2' },
{ namespace: 'openapi', version: '3.0.3' },
],
targetSpecs: OpenAPI30,
},
{
label: 'password',
Expand All @@ -69,7 +60,7 @@ const completion: ApidomCompletionItem[] = [
value:
'[OAuth Flow Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#oauthFlowObject)\n\\\n\\\nConfiguration for the OAuth Resource Owner Password flow.',
},
targetSpecs: [{ namespace: 'openapi', version: '3.1.0' }],
targetSpecs: OpenAPI31,
},
{
label: 'clientCredentials',
Expand All @@ -83,12 +74,7 @@ const completion: ApidomCompletionItem[] = [
value:
'[OAuth Flow Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#oauthFlowObject)\n\\\n\\\nConfiguration for the OAuth Client Credentials flow. Previously called `application` in OpenAPI 2.0.',
},
targetSpecs: [
{ namespace: 'openapi', version: '3.0.0' },
{ namespace: 'openapi', version: '3.0.1' },
{ namespace: 'openapi', version: '3.0.2' },
{ namespace: 'openapi', version: '3.0.3' },
],
targetSpecs: OpenAPI30,
},
{
label: 'clientCredentials',
Expand All @@ -102,7 +88,7 @@ const completion: ApidomCompletionItem[] = [
value:
'[OAuth Flow Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#oauthFlowObject)\n\\\n\\\nConfiguration for the OAuth Client Credentials flow. Previously called `application` in OpenAPI 2.0.',
},
targetSpecs: [{ namespace: 'openapi', version: '3.1.0' }],
targetSpecs: OpenAPI31,
},
{
label: 'authorizationCode',
Expand All @@ -116,12 +102,7 @@ const completion: ApidomCompletionItem[] = [
value:
'[OAuth Flow Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#oauthFlowObject)\n\\\n\\\nConfiguration for the OAuth Authorization Code flow. Previously called accessCode in OpenAPI 2.0.',
},
targetSpecs: [
{ namespace: 'openapi', version: '3.0.0' },
{ namespace: 'openapi', version: '3.0.1' },
{ namespace: 'openapi', version: '3.0.2' },
{ namespace: 'openapi', version: '3.0.3' },
],
targetSpecs: OpenAPI30,
},
{
label: 'authorizationCode',
Expand All @@ -135,7 +116,7 @@ const completion: ApidomCompletionItem[] = [
value:
'[OAuth Flow Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#oauthFlowObject)\n\\\n\\\nConfiguration for the OAuth Authorization Code flow. Previously called accessCode in OpenAPI 2.0.',
},
targetSpecs: [{ namespace: 'openapi', version: '3.1.0' }],
targetSpecs: OpenAPI31,
},
];

Expand Down
Loading
Loading