Skip to content

OpenAPI 3.0.x language server completion rules #2090

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

Merged
merged 3 commits into from
Sep 30, 2022
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
12 changes: 12 additions & 0 deletions packages/apidom-ls/src/config/codes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,18 @@ enum ApilintCodes {
OPENAPI3_0_COMPONENTS_FIELD_LINKS_VALUES_TYPE = 5060800,
OPENAPI3_0_COMPONENTS_FIELD_CALLBACKS_VALUES_TYPE = 5060900,

OPENAPI3_O_SERVER = 5070000,
OPENAPI3_O_SERVER_FIELD_URL_FORMAT_URI = 5070100,
OPENAPI3_O_SERVER_FIELD_URL_REQUIRED,
OPENAPI3_O_SERVER_FIELD_DESCRIPTION_TYPE = 5070200,
OPENAPI3_O_SERVER_FIELD_VARIABLES_VALUES_TYPE = 5070300,

OPENAPI3_O_SERVER_VARIABLE = 5080000,
OPENAPI3_O_SERVER_VARIABLE_FIELD_ENUM_TYPE = 5080100,
OPENAPI3_O_SERVER_VARIABLE_FIELD_DEFAULT_TYPE = 5080200,
OPENAPI3_O_SERVER_VARIABLE_FIELD_DEFAULT_REQUIRED,
OPENAPI3_O_SERVER_VARIABLE_FIELD_DESCRIPTION_TYPE = 5080300,

OPENAPI3_1 = 7000000,

OPENAPI3_1_OPENAPI_VALUE_PATTERN_3_1_0 = 7000100,
Expand Down
4 changes: 2 additions & 2 deletions packages/apidom-ls/src/config/openapi/contact/lint/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import emailFormatEmailLint from './email--format-email';
import nameTypeLint from './name--type';
import urlFormatURILint from './url--format-uri';

const contactLints = [emailFormatEmailLint, nameTypeLint, urlFormatURILint, allowedFieldsLint];
const lints = [emailFormatEmailLint, nameTypeLint, urlFormatURILint, allowedFieldsLint];

export default contactLints;
export default lints;
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import descriptionTypeLint from './description--type';
import urlRequiredLint from './url--required';
import urlFormatURILint from './url--format-uri';

const contactLints = [descriptionTypeLint, urlRequiredLint, urlFormatURILint, allowedFieldsLint];
const lints = [descriptionTypeLint, urlRequiredLint, urlFormatURILint, allowedFieldsLint];

export default contactLints;
export default lints;
4 changes: 2 additions & 2 deletions packages/apidom-ls/src/config/openapi/info/lint/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import licenseTypeLint from './license--type';
import versionTypeLint from './version--type';
import versionRequiredLint from './version--required';

const infoLints = [
const lints = [
titleTypeLint,
titleRequiredLint,
summaryTypeLint,
Expand All @@ -26,4 +26,4 @@ const infoLints = [
allowedFields3_1Lint,
];

export default infoLints;
export default lints;
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@ const termsOfServiceFormatURILint: LinterMeta = {
marker: 'value',
target: 'termsOfService',
data: {},
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' },
{ namespace: 'openapi', version: '3.1.0' },
],
};

export default termsOfServiceFormatURILint;
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@ const termsOfServiceTypeLint: LinterMeta = {
marker: 'value',
target: 'termsOfService',
data: {},
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' },
{ namespace: 'openapi', version: '3.1.0' },
],
};

export default termsOfServiceTypeLint;
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@ const titleRequiredLint: LinterMeta = {
},
],
},
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' },
{ namespace: 'openapi', version: '3.1.0' },
],
};

export default titleRequiredLint;
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@ const titleTypeLint: LinterMeta = {
marker: 'value',
target: 'title',
data: {},
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' },
{ namespace: 'openapi', version: '3.1.0' },
],
};

export default titleTypeLint;
4 changes: 2 additions & 2 deletions packages/apidom-ls/src/config/openapi/license/lint/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import nameTypeLint from './name--type';
import nameRequiredLint from './name--required';
import urlFormatURILint from './url--format-uri';

const contactLints = [nameTypeLint, nameRequiredLint, urlFormatURILint, allowedFields3_0Lint];
const lints = [nameTypeLint, nameRequiredLint, urlFormatURILint, allowedFields3_0Lint];

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

const allowedFieldsLint: LinterMeta = {
code: ApilintCodes.NOT_ALLOWED_FIELDS,
source: 'apilint',
message: 'Object includes not allowed fields',
severity: 1,
linterFunction: 'allowedFields',
linterParams: [['enum', 'default', 'description'], 'x-'],
marker: 'key',
};

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

const defaultRequiredLint: LinterMeta = {
code: ApilintCodes.OPENAPI3_O_SERVER_VARIABLE_FIELD_DEFAULT_REQUIRED,
source: 'apilint',
message: "should always have a 'default'",
severity: 1,
linterFunction: 'hasRequiredField',
linterParams: ['default'],
marker: 'key',
data: {
quickFix: [
{
message: "add 'default' field",
action: 'addChild',
snippetYaml: 'default: \n ',
snippetJson: '"default": "",\n ',
},
],
},
};

export default defaultRequiredLint;
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 defaultTypeLint: LinterMeta = {
code: ApilintCodes.OPENAPI3_O_SERVER_VARIABLE_FIELD_DEFAULT_TYPE,
source: 'apilint',
message: "'default' must be a string",
severity: 1,
linterFunction: 'apilintType',
linterParams: ['string'],
marker: 'value',
target: 'default',
data: {},
};

export default defaultTypeLint;
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 descriptionTypeLint: LinterMeta = {
code: ApilintCodes.OPENAPI3_O_SERVER_VARIABLE_FIELD_DESCRIPTION_TYPE,
source: 'apilint',
message: "'description' must be a string",
severity: 1,
linterFunction: 'apilintType',
linterParams: ['string'],
marker: 'value',
target: 'description',
data: {},
};

export default descriptionTypeLint;
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 enumTypeLint: LinterMeta = {
code: ApilintCodes.OPENAPI3_O_SERVER_VARIABLE_FIELD_ENUM_TYPE,
source: 'apilint',
message: "'enum' must be an array of strings",
severity: 1,
linterFunction: 'apilintArrayOfType',
linterParams: ['string'],
marker: 'key',
target: 'enum',
data: {},
};

export default enumTypeLint;
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import allowedFieldsLint from './allowed-fields';
import enumTypeLint from './enum--type';
import defaultTypeLint from './default--type';
import defaultRequiredLint from './default--required';
import descriptionTypeLint from './description--type';

const lints = [
enumTypeLint,
defaultTypeLint,
defaultRequiredLint,
descriptionTypeLint,
allowedFieldsLint,
];

export default lints;
2 changes: 2 additions & 0 deletions packages/apidom-ls/src/config/openapi/server-variable/meta.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import lint from './lint';
import completion from './completion';
import documentation from './documentation';
import { FormatMeta } from '../../../apidom-language-types';

const meta: FormatMeta = {
lint,
completion,
documentation,
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import ApilintCodes from '../../../codes';
import { LinterMeta } from '../../../../apidom-language-types';

const allowedFieldsLint: LinterMeta = {
code: ApilintCodes.NOT_ALLOWED_FIELDS,
source: 'apilint',
message: 'Object includes not allowed fields',
severity: 1,
linterFunction: 'allowedFields',
linterParams: [['url', 'description', 'variables'], 'x-'],
marker: 'key',
};

export default allowedFieldsLint;
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 descriptionTypeLint: LinterMeta = {
code: ApilintCodes.OPENAPI3_O_SERVER_FIELD_DESCRIPTION_TYPE,
source: 'apilint',
message: "'description' must be a string",
severity: 1,
linterFunction: 'apilintType',
linterParams: ['string'],
marker: 'value',
target: 'description',
data: {},
};

export default descriptionTypeLint;
15 changes: 15 additions & 0 deletions packages/apidom-ls/src/config/openapi/server/lint/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import allowedFieldsLint from './allowed-fields';
import urlFormatURILint from './url--format-uri';
import urlRequiredLint from './url--required';
import descriptionTypeLint from './description--type';
import variablesValuesTypeLint from './variables--values-type';

const lints = [
urlFormatURILint,
urlRequiredLint,
descriptionTypeLint,
variablesValuesTypeLint,
allowedFieldsLint,
];

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

const urlFormatURILint: LinterMeta = {
code: ApilintCodes.OPENAPI3_O_SERVER_FIELD_URL_FORMAT_URI,
source: 'apilint',
message: 'url MUST be in the format of an URL.',
severity: 1,
linterFunction: 'apilintValidURI',
marker: 'value',
target: 'url',
data: {},
};

export default urlFormatURILint;
24 changes: 24 additions & 0 deletions packages/apidom-ls/src/config/openapi/server/lint/url--required.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import ApilintCodes from '../../../codes';
import { LinterMeta } from '../../../../apidom-language-types';

const urlRequiredLint: LinterMeta = {
code: ApilintCodes.OPENAPI3_O_SERVER_FIELD_URL_REQUIRED,
source: 'apilint',
message: "should always have a 'url'",
severity: 1,
linterFunction: 'hasRequiredField',
linterParams: ['url'],
marker: 'key',
data: {
quickFix: [
{
message: "add 'url' field",
action: 'addChild',
snippetYaml: 'url: \n ',
snippetJson: '"url": "",\n ',
},
],
},
};

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

const variablesValuesTypeLint: LinterMeta = {
code: ApilintCodes.OPENAPI3_O_SERVER_FIELD_VARIABLES_VALUES_TYPE,
source: 'apilint',
message: '"varialbes" members must be Server Variable Object',
severity: 1,
linterFunction: 'apilintChildrenOfElementsOrClasses',
linterParams: [['serverVariable']],
marker: 'key',
markerTarget: 'variables',
target: 'variables',
data: {},
};

export default variablesValuesTypeLint;
2 changes: 2 additions & 0 deletions packages/apidom-ls/src/config/openapi/server/meta.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import lint from './lint';
import completion from './completion';
import documentation from './documentation';
import { FormatMeta } from '../../../apidom-language-types';

const meta: FormatMeta = {
lint,
completion,
documentation,
};
Expand Down