Skip to content

Commit

Permalink
feat(ls): additional oas31 lint rules
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-lai committed Oct 5, 2022
1 parent 766f74a commit f758bca
Show file tree
Hide file tree
Showing 12 changed files with 199 additions and 4 deletions.
16 changes: 13 additions & 3 deletions packages/apidom-ls/src/config/codes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -696,10 +696,20 @@ enum ApilintCodes {
OPENAPI3_1_OPENAPI_VALUE_PATTERN_3_1_0 = 7000100,

OPENAPI3_1_OPEN_API = 7010000,
OPENAPI3_1_OPEN_API_FIELD_WEBHOOKS_TYPE = 7010100,
OPENAPI3_1_OPEN_API_FIELD_JSON_SCHEMA_FORMAT_URI = 7010200,
OPENAPI3_1_OPEN_API_FIELD_INFO_TYPE = 7010300,
OPENAPI3_1_OPEN_API_FIELD_INFO_TYPE = 7010100,
OPENAPI3_1_OPEN_API_FIELD_INFO_TYPE_REQUIRED,
OPENAPI3_1_OPEN_API_FIELD_SERVERS_TYPE = 7010200,
OPENAPI3_1_OPEN_API_FIELD_SERVERS_ITEMS_TYPE,
OPENAPI3_1_OPEN_API_FIELD_PATHS_TYPE = 7010300,
OPENAPI3_1_OPEN_API_FIELD_PATHS_REQUIRED,
OPENAPI3_1_OPEN_API_FIELD_COMPONENTS_TYPE = 7010400,
OPENAPI3_1_OPEN_API_FIELD_SECURITY_TYPE = 7010500,
OPENAPI3_1_OPEN_API_FIELD_SECURITY_ITEMS_TYPE,
OPENAPI3_1_OPEN_API_FIELD_TAGS_TYPE = 7010600,
OPENAPI3_1_OPEN_API_FIELD_TAGS_ITEMS_TYPE,
OPENAPI3_1_OPEN_API_FIELD_EXTERNAL_DOCS_TYPE = 7010700,
OPENAPI3_1_OPEN_API_FIELD_WEBHOOKS_TYPE = 7010800,
OPENAPI3_1_OPEN_API_FIELD_JSON_SCHEMA_FORMAT_URI = 7010900,

OPENAPI3_1_INFO = 7020000,
OPENAPI3_1_INFO_FIELD_SUMMARY_TYPE = 7020100,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import ApilintCodes from '../../../codes';
import { LinterMeta } from '../../../../apidom-language-types';

const componentsTypeLint: LinterMeta = {
code: ApilintCodes.OPENAPI3_1_OPEN_API_FIELD_COMPONENTS_TYPE,
source: 'apilint',
message: 'components must be an object',
severity: 1,
linterFunction: 'apilintElementOrClass',
linterParams: ['components'],
marker: 'value',
target: 'components',
data: {},
};

export default componentsTypeLint;
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import ApilintCodes from '../../../codes';
import { LinterMeta } from '../../../../apidom-language-types';

const externalDocsTypeLint: LinterMeta = {
code: ApilintCodes.OPENAPI3_1_OPEN_API_FIELD_EXTERNAL_DOCS_TYPE,
source: 'apilint',
message: 'externalDocs must be an object',
severity: 1,
linterFunction: 'apilintElementOrClass',
linterParams: ['externalDocumentation'],
marker: 'value',
target: 'externalDocs',
data: {},
};

export default externalDocsTypeLint;
27 changes: 26 additions & 1 deletion packages/apidom-ls/src/config/openapi/openapi3_1/lint/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,33 @@
import allowedFieldsLint from './allowed-fields';
import componentsTypeLint from './components--type';
import externalDocsTypeLint from './external-docs--type';
import infoRequiredLint from './info--required';
import infoTypeLint from './info--type';
import jsonSchemaDialectFormatURILint from './jsonSchemaDialect--format-uri';
import pathsTypeLint from './paths--type';
import securityItemsTypeLint from './security--items-type';
import securityTypeLint from './security--type';
import serversItemsTypeLint from './servers--items-type';
import serversTypeLint from './servers--type';
import tagsItemsTypeLint from './tags--items-type';
import tagsTypeLint from './tags--type';
import webhooksLint from './webhooks--type';

const lints = [allowedFieldsLint, infoRequiredLint, jsonSchemaDialectFormatURILint, webhooksLint];
const lints = [
allowedFieldsLint,
componentsTypeLint,
externalDocsTypeLint,
infoRequiredLint,
infoTypeLint,
jsonSchemaDialectFormatURILint,
pathsTypeLint,
securityItemsTypeLint,
securityTypeLint,
serversItemsTypeLint,
serversTypeLint,
tagsItemsTypeLint,
tagsTypeLint,
webhooksLint,
];

export default lints;
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import ApilintCodes from '../../../codes';
import { LinterMeta } from '../../../../apidom-language-types';

const infoTypeLint: LinterMeta = {
code: ApilintCodes.OPENAPI3_1_OPEN_API_FIELD_INFO_TYPE,
source: 'apilint',
message: 'info must be an object',
severity: 1,
linterFunction: 'apilintElementOrClass',
linterParams: ['info'],
marker: 'value',
target: 'info',
data: {},
};

export default infoTypeLint;
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import ApilintCodes from '../../../codes';
import { LinterMeta } from '../../../../apidom-language-types';

const pathsTypeLint: LinterMeta = {
code: ApilintCodes.OPENAPI3_1_OPEN_API_FIELD_PATHS_TYPE,
source: 'apilint',
message: 'paths must be an object',
severity: 1,
linterFunction: 'apilintElementOrClass',
linterParams: ['paths'],
marker: 'value',
target: 'paths',
data: {},
};

export default pathsTypeLint;
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import ApilintCodes from '../../../codes';
import { LinterMeta } from '../../../../apidom-language-types';

const securityItemsTypeLint: LinterMeta = {
code: ApilintCodes.OPENAPI3_1_OPEN_API_FIELD_SECURITY_ITEMS_TYPE,
source: 'apilint',
message: 'security must be an array of Security Requirement Objects',
severity: 1,
linterFunction: 'apilintArrayOfElementsOrClasses',
linterParams: [['securityRequirement']],
marker: 'key',
target: 'security',
data: {},
};

export default securityItemsTypeLint;
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import ApilintCodes from '../../../codes';
import { LinterMeta } from '../../../../apidom-language-types';

const securityTypeLint: LinterMeta = {
code: ApilintCodes.OPENAPI3_1_OPEN_API_FIELD_SECURITY_TYPE,
source: 'apilint',
message: 'security must be an array',
severity: 1,
linterFunction: 'apilintElementOrClass',
linterParams: ['security'],
marker: 'value',
target: 'security',
data: {},
};

export default securityTypeLint;
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import ApilintCodes from '../../../codes';
import { LinterMeta } from '../../../../apidom-language-types';

const serverItemsTypeLint: LinterMeta = {
code: ApilintCodes.OPENAPI3_1_OPEN_API_FIELD_SERVERS_ITEMS_TYPE,
source: 'apilint',
message: 'servers must be an array of Server Objects',
severity: 1,
linterFunction: 'apilintArrayOfElementsOrClasses',
linterParams: [['server']],
marker: 'key',
target: 'servers',
data: {},
};

export default serverItemsTypeLint;
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import ApilintCodes from '../../../codes';
import { LinterMeta } from '../../../../apidom-language-types';

const serversTypeLint: LinterMeta = {
code: ApilintCodes.OPENAPI3_1_OPEN_API_FIELD_SERVERS_TYPE,
source: 'apilint',
message: 'servers must be an array',
severity: 1,
linterFunction: 'apilintElementOrClass',
linterParams: ['servers'],
marker: 'value',
target: 'servers',
data: {},
};

export default serversTypeLint;
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import ApilintCodes from '../../../codes';
import { LinterMeta } from '../../../../apidom-language-types';

const tagsItemsTypeLint: LinterMeta = {
code: ApilintCodes.OPENAPI3_1_OPEN_API_FIELD_TAGS_ITEMS_TYPE,
source: 'apilint',
message: 'tags must be an array of Tag Objects',
severity: 1,
linterFunction: 'apilintArrayOfElementsOrClasses',
linterParams: [['tag']],
marker: 'key',
target: 'tags',
data: {},
};

export default tagsItemsTypeLint;
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import ApilintCodes from '../../../codes';
import { LinterMeta } from '../../../../apidom-language-types';

const tagsTypeLint: LinterMeta = {
code: ApilintCodes.OPENAPI3_1_OPEN_API_FIELD_TAGS_TYPE,
source: 'apilint',
message: 'tags must be an array',
severity: 1,
linterFunction: 'apilintElementOrClass',
linterParams: ['tags'],
marker: 'value',
target: 'tags',
data: {},
};

export default tagsTypeLint;

0 comments on commit f758bca

Please sign in to comment.