Skip to content

Commit 75c46f4

Browse files
authored
feat(ls): add rules for OpenAPI 2.0 License Object (#3551)
Refs #3104
1 parent cf4fd26 commit 75c46f4

File tree

8 files changed

+44
-17
lines changed

8 files changed

+44
-17
lines changed

packages/apidom-ls/src/config/codes.ts

+5
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,11 @@ enum ApilintCodes {
663663
OPENAPI2_PATH_TEMPLATE_VALUE_WELL_FORMED = 3040100,
664664
OPENAPI2_PATH_TEMPLATE_VALUE_VALID,
665665

666+
OPENAPI2_LICENSE = 3050000,
667+
OPENAPI2_LICENSE_FIELD_NAME_TYPE = 3050100,
668+
OPENAPI2_LICENSE_FIELD_NAME_REQUIRED = 3050200,
669+
OPENAPI2_LICENSE_FIELD_URL_FORMAT_URI = 3050300,
670+
666671
OPENAPI3_0 = 5000000,
667672

668673
OPENAPI3_0_OPENAPI_VALUE_PATTERN_3_0_0 = 5000100,

packages/apidom-ls/src/config/openapi/license/completion.ts

+15-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,22 @@ import {
33
CompletionFormat,
44
CompletionType,
55
} from '../../../apidom-language-types';
6-
import { OpenAPI30, OpenAPI31, OpenAPI3 } from '../target-specs';
6+
import { OpenAPI2, OpenAPI30, OpenAPI31, OpenAPI3 } from '../target-specs';
77

88
const completion: ApidomCompletionItem[] = [
9+
{
10+
label: 'name',
11+
insertText: 'name',
12+
kind: 14,
13+
format: CompletionFormat.QUOTED,
14+
type: CompletionType.PROPERTY,
15+
insertTextFormat: 2,
16+
documentation: {
17+
kind: 'markdown',
18+
value: '**Required**. The license name used for the API.',
19+
},
20+
targetSpecs: OpenAPI2,
21+
},
922
{
1023
label: 'name',
1124
insertText: 'name',
@@ -44,7 +57,7 @@ const completion: ApidomCompletionItem[] = [
4457
kind: 'markdown',
4558
value: 'A URL to the license used for the API. MUST be in the format of a URL.',
4659
},
47-
targetSpecs: OpenAPI30,
60+
targetSpecs: [...OpenAPI2, ...OpenAPI30],
4861
},
4962
{
5063
label: 'url',

packages/apidom-ls/src/config/openapi/license/documentation.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
import { OpenAPI30, OpenAPI31, OpenAPI3 } from '../target-specs';
1+
import { OpenAPI2, OpenAPI30, OpenAPI31, OpenAPI3 } from '../target-specs';
22

33
const documentation = [
4+
{
5+
target: 'name',
6+
docs: '**Required.** The license name used for the API.',
7+
targetSpecs: OpenAPI2,
8+
},
49
{
510
target: 'name',
611
docs: '**REQUIRED**. The license name used for the API.',
@@ -14,13 +19,17 @@ const documentation = [
1419
{
1520
target: 'url',
1621
docs: 'A URL to the license used for the API. MUST be in the format of a URL.',
17-
targetSpecs: OpenAPI30,
22+
targetSpecs: [...OpenAPI2, ...OpenAPI30],
1823
},
1924
{
2025
target: 'url',
2126
docs: 'A URL to the license used for the API. This MUST be in the form of a URL. The `url` field is mutually exclusive of the `identifier` field.',
2227
targetSpecs: OpenAPI31,
2328
},
29+
{
30+
docs: '#### [License Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#license-object)\n\nLicense information for the exposed API.\n\n##### Fixed Fields\n\nField Name | Type | Description\n---|:---:|---\nname | `string` | **Required.** The license name used for the API.\nurl | `string` | A URL to the license used for the API. MUST be in the format of a URL.\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##### License Object Example:\n\n```js\n{\n "name": "Apache 2.0",\n "url": "http://www.apache.org/licenses/LICENSE-2.0.html"\n}\n```\n\n\n\\\nYAML\n```yaml\nname: Apache 2.0\nurl: http://www.apache.org/licenses/LICENSE-2.0.html\n```',
31+
targetSpecs: OpenAPI2,
32+
},
2433
{
2534
docs: '#### [License Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#licenseObject)\n\nLicense information for the exposed API.\n\n##### Fixed Fields\n\nField Name | Type | Description\n---|:---:|---\nname | `string` | **REQUIRED**. The license name used for the API.\nurl | `string` | A URL to the license used for the API. MUST be in the format of a URL.\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##### License Object Example\n\n\n\\\nJSON\n```json\n{\n "name": "Apache 2.0",\n "url": "https://www.apache.org/licenses/LICENSE-2.0.html"\n}\n```\n\n\n\\\nYAML\n```yaml\nname: Apache 2.0\nurl: https://www.apache.org/licenses/LICENSE-2.0.html\n```',
2635
targetSpecs: OpenAPI30,

packages/apidom-ls/src/config/openapi/license/lint/allowed-fields-3-0.ts renamed to packages/apidom-ls/src/config/openapi/license/lint/allowed-fields-2-0--3-0.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types';
22

33
import ApilintCodes from '../../../codes';
44
import { LinterMeta } from '../../../../apidom-language-types';
5-
import { OpenAPI30 } from '../../target-specs';
5+
import { OpenAPI2, OpenAPI30 } from '../../target-specs';
66

77
// eslint-disable-next-line @typescript-eslint/naming-convention
8-
const allowedFields3_0Lint: LinterMeta = {
8+
const allowedFields2_0__3_0Lint: LinterMeta = {
99
code: ApilintCodes.NOT_ALLOWED_FIELDS,
1010
source: 'apilint',
1111
message: 'Object includes not allowed fields',
1212
severity: DiagnosticSeverity.Error,
1313
linterFunction: 'allowedFields',
1414
linterParams: [['name', 'url'], 'x-'],
1515
marker: 'key',
16-
targetSpecs: OpenAPI30,
16+
targetSpecs: [...OpenAPI2, ...OpenAPI30],
1717
};
1818

19-
export default allowedFields3_0Lint;
19+
export default allowedFields2_0__3_0Lint;

packages/apidom-ls/src/config/openapi/license/lint/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import allowedFields3_0Lint from './allowed-fields-3-0';
1+
import allowedFields2_0__3_0Lint from './allowed-fields-2-0--3-0';
22
import allowedFields3_1Lint from './allowed-fields-3-1';
33
import nameTypeLint from './name--type';
44
import nameRequiredLint from './name--required';
@@ -12,7 +12,7 @@ const lints = [
1212
identifierTypeLint,
1313
identifierMutuallyExclusiveLint,
1414
urlFormatURILint,
15-
allowedFields3_0Lint,
15+
allowedFields2_0__3_0Lint,
1616
allowedFields3_1Lint,
1717
];
1818

packages/apidom-ls/src/config/openapi/license/lint/name--required.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types';
22

33
import ApilintCodes from '../../../codes';
44
import { LinterMeta } from '../../../../apidom-language-types';
5-
import { OpenAPI3 } from '../../target-specs';
5+
import { OpenAPI } from '../../target-specs';
66

77
const nameRequiredLint: LinterMeta = {
8-
code: ApilintCodes.OPENAPI3_0_LICENSE_FIELD_NAME_REQUIRED,
8+
code: ApilintCodes.OPENAPI2_LICENSE_FIELD_NAME_REQUIRED,
99
source: 'apilint',
1010
message: "should always have a 'name'",
1111
severity: DiagnosticSeverity.Error,
@@ -22,7 +22,7 @@ const nameRequiredLint: LinterMeta = {
2222
},
2323
],
2424
},
25-
targetSpecs: OpenAPI3,
25+
targetSpecs: OpenAPI,
2626
};
2727

2828
export default nameRequiredLint;

packages/apidom-ls/src/config/openapi/license/lint/name--type.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types';
22

33
import ApilintCodes from '../../../codes';
44
import { LinterMeta } from '../../../../apidom-language-types';
5-
import { OpenAPI3 } from '../../target-specs';
5+
import { OpenAPI } from '../../target-specs';
66

77
const nameTypeLint: LinterMeta = {
8-
code: ApilintCodes.OPENAPI3_0_LICENSE_FIELD_NAME_TYPE,
8+
code: ApilintCodes.OPENAPI2_LICENSE_FIELD_NAME_TYPE,
99
source: 'apilint',
1010
message: "'identifier' must be a string",
1111
severity: DiagnosticSeverity.Error,
@@ -14,7 +14,7 @@ const nameTypeLint: LinterMeta = {
1414
marker: 'value',
1515
target: 'name',
1616
data: {},
17-
targetSpecs: OpenAPI3,
17+
targetSpecs: OpenAPI,
1818
};
1919

2020
export default nameTypeLint;

packages/apidom-ls/src/config/openapi/license/lint/url--format-uri.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { LinterMeta } from '../../../../apidom-language-types';
55
import { OpenAPI3 } from '../../target-specs';
66

77
const urlFormatURILint: LinterMeta = {
8-
code: ApilintCodes.OPENAPI3_0_LICENSE_FIELD_URL_FORMAT_URI,
8+
code: ApilintCodes.OPENAPI2_LICENSE_FIELD_URL_FORMAT_URI,
99
source: 'apilint',
1010
message: "'url' value must be a valid URL",
1111
severity: DiagnosticSeverity.Error,

0 commit comments

Comments
 (0)