Skip to content

Commit

Permalink
feat(ls): add rules for OpenAPI 2.0 Reference Object (#3685)
Browse files Browse the repository at this point in the history
Refs #3612
  • Loading branch information
char0n committed Jan 17, 2024
1 parent 342fca7 commit dbdb2a1
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 11 deletions.
3 changes: 3 additions & 0 deletions packages/apidom-ls/src/config/codes.ts
Expand Up @@ -834,6 +834,9 @@ enum ApilintCodes {
OPENAPI2_HEADER_FIELD_ENUM_TYPE = 3231600,
OPENAPI2_HEADER_FIELD_MULTIPLE_OF_TYPE = 3231700,

OPENAPI2_REFERENCE = 3240000,
OPENAPI2_REFERENCE_FIELD_$REF_FORMAT_URI = 3240100,

OPENAPI3_0 = 5000000,

OPENAPI3_0_OPENAPI_VALUE_PATTERN_3_0_0 = 5000100,
Expand Down
28 changes: 27 additions & 1 deletion packages/apidom-ls/src/config/openapi/reference/completion.ts
Expand Up @@ -3,9 +3,35 @@ import {
CompletionFormat,
CompletionType,
} from '../../../apidom-language-types';
import { OpenAPI31 } from '../target-specs';
import { OpenAPI2, OpenAPI30, OpenAPI31 } from '../target-specs';

const completion: ApidomCompletionItem[] = [
{
label: '$ref',
insertText: '\\$ref',
kind: 14,
format: CompletionFormat.QUOTED,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value: '**Required**. The reference string.',
},
targetSpecs: OpenAPI2,
},
{
label: '$ref',
insertText: '\\$ref',
kind: 14,
format: CompletionFormat.QUOTED,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value: '**REQUIRED**. The reference string.',
},
targetSpecs: OpenAPI30,
},
{
label: '$ref',
insertText: '\\$ref',
Expand Down
12 changes: 11 additions & 1 deletion packages/apidom-ls/src/config/openapi/reference/documentation.ts
@@ -1,6 +1,16 @@
import { OpenAPI31 } from '../target-specs';
import { OpenAPI2, OpenAPI30, OpenAPI31 } from '../target-specs';

const documentation = [
{
target: '$ref',
docs: '**Required**. The reference string.',
targetSpecs: OpenAPI2,
},
{
target: '$ref',
docs: '**REQUIRED**. The reference string.',
targetSpecs: OpenAPI30,
},
{
target: '$ref',
docs: '**REQUIRED**. The reference identifier. This MUST be in the form of a URI.',
Expand Down
Expand Up @@ -2,18 +2,18 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types';

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

const $refFormatURILint: LinterMeta = {
code: ApilintCodes.OPENAPI3_0_REFERENCE_FIELD_$REF_FORMAT_URI,
code: ApilintCodes.OPENAPI2_REFERENCE_FIELD_$REF_FORMAT_URI,
source: 'apilint',
message: "'$ref' value must be a valid URI-reference",
severity: DiagnosticSeverity.Error,
linterFunction: 'apilintValidURI',
marker: 'value',
target: '$ref',
data: {},
targetSpecs: OpenAPI3,
targetSpecs: [...OpenAPI2, ...OpenAPI3],
};

export default $refFormatURILint;
Expand Up @@ -2,10 +2,10 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types';

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

// eslint-disable-next-line @typescript-eslint/naming-convention
const $ref3_0NoSiblingsLint: LinterMeta = {
const $ref2_0__3_0NoSiblingsLint: LinterMeta = {
code: ApilintCodes.OPENAPI3_0_REFERENCE_FIELD_$REF_NO_SIBLINGS,
source: 'apilint',
message: 'All other properties in a "$ref" object are ignored',
Expand All @@ -29,7 +29,7 @@ const $ref3_0NoSiblingsLint: LinterMeta = {
},
],
},
targetSpecs: OpenAPI30,
targetSpecs: [...OpenAPI2, ...OpenAPI30],
};

export default $ref3_0NoSiblingsLint;
export default $ref2_0__3_0NoSiblingsLint;
4 changes: 2 additions & 2 deletions packages/apidom-ls/src/config/openapi/reference/lint/index.ts
@@ -1,12 +1,12 @@
import $refFormatURILint from './$ref--format-uri';
import $ref3_0NoSiblingsLint from './$ref-3-0--no-siblings';
import $ref2_0__3_0NoSiblingsLint from './$ref-2-0--3-0--no-siblings';
import $ref3_1AllowedSiblingsLint from './$ref-3-1--allowed-siblings';
import description3_1TypeLint from './description-3-1--type';
import summary3_1TypeLint from './summary-3-1--type';

const lints = [
$refFormatURILint,
$ref3_0NoSiblingsLint,
$ref2_0__3_0NoSiblingsLint,
$ref3_1AllowedSiblingsLint,
description3_1TypeLint,
summary3_1TypeLint,
Expand Down

0 comments on commit dbdb2a1

Please sign in to comment.