Skip to content

feat(ls): provide OpenAPI 3.1.0 License lint rules #2136

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 5 commits into from
Oct 18, 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
3 changes: 3 additions & 0 deletions packages/apidom-ls/src/config/codes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,9 @@ enum ApilintCodes {
OPENAPI3_1_COMPONENTS = 7020000,
OPENAPI3_1_COMPONENTS_FIELD_PATH_ITEMS_VALUES_TYPE = 7020100,

OPENAPI3_1_LICENSE_FIELD_IDENTIFIER_TYPE = 7040300,
OPENAPI3_1_LICENSE_FIELD_IDENTIFIER_MUTUALLY_EXCLUSIVE = 7040600,

ADS = 8000000,
ADS_INFO = 8010000,
ADS_INFO_REQUIRED = 8010010,
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';

// eslint-disable-next-line @typescript-eslint/naming-convention
const allowedFields3_1Lint: LinterMeta = {
code: ApilintCodes.NOT_ALLOWED_FIELDS,
source: 'apilint',
message: 'Object includes not allowed fields',
severity: 1,
linterFunction: 'allowedFields',
linterParams: [['name', 'url', 'identifier'], 'x-'],
marker: 'key',
targetSpecs: [{ namespace: 'openapi', version: '3.1.0' }],
};

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

const identifierMutuallyExclusiveLint: LinterMeta = {
code: ApilintCodes.OPENAPI3_1_LICENSE_FIELD_IDENTIFIER_MUTUALLY_EXCLUSIVE,
source: 'apilint',
message: 'The identifier field and url field are mutually exclusive.',
severity: 1,
linterFunction: 'missingFields',
linterParams: [['identifier']],
marker: 'key',
markerTarget: 'identifier',
conditions: [
{
function: 'existFields',
params: [['url']],
},
],
targetSpecs: [{ namespace: 'openapi', version: '3.1.0' }],
};

export default identifierMutuallyExclusiveLint;
Empty file.
11 changes: 10 additions & 1 deletion packages/apidom-ls/src/config/openapi/license/lint/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import allowedFields3_0Lint from './allowed-fields-3-0';
import allowedFields3_1Lint from './allowed-fields-3-1';
import nameTypeLint from './name--type';
import nameRequiredLint from './name--required';
import identifierMutuallyExclusiveLint from './identifier--mutually-exclusive';
import urlFormatURILint from './url--format-uri';

const lints = [nameTypeLint, nameRequiredLint, urlFormatURILint, allowedFields3_0Lint];
const lints = [
nameTypeLint,
nameRequiredLint,
identifierMutuallyExclusiveLint,
urlFormatURILint,
allowedFields3_0Lint,
allowedFields3_1Lint,
];

export default lints;
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import ApilintCodes from '../../../codes';
import { LinterMeta } from '../../../../apidom-language-types';

const nameTypeLint: LinterMeta = {
code: ApilintCodes.OPENAPI3_0_LICENSE_FIELD_NAME_TYPE,
code: ApilintCodes.OPENAPI3_1_LICENSE_FIELD_IDENTIFIER_TYPE,
source: 'apilint',
message: "'name' must be a string",
message: "'identifier' must be a string",
severity: 1,
linterFunction: 'apilintType',
linterParams: ['string'],
Expand Down
16 changes: 16 additions & 0 deletions packages/apidom-ls/test/openapi-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,22 @@ describe('apidom-ls', function () {
severity: 1,
source: 'apilint',
},
{
code: 7040600,
message: 'The identifier field and url field are mutually exclusive.',
range: {
end: {
character: 18,
line: 14,
},
start: {
character: 6,
line: 14,
},
},
severity: 1,
source: 'apilint',
},
{
code: 5130600,
data: {},
Expand Down
16 changes: 16 additions & 0 deletions packages/apidom-ls/test/openapi-yaml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,22 @@ describe('apidom-ls-yaml', function () {
severity: 1,
source: 'apilint',
},
{
code: 7040600,
message: 'The identifier field and url field are mutually exclusive.',
range: {
end: {
character: 14,
line: 15,
},
start: {
character: 4,
line: 15,
},
},
severity: 1,
source: 'apilint',
},
{
code: 5130600,
data: {},
Expand Down
16 changes: 16 additions & 0 deletions packages/apidom-ls/test/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2870,6 +2870,22 @@ describe('apidom-ls-validate', function () {

const result = await languageService.doValidation(doc, validationContext);
const expected: Diagnostic[] = [
{
code: 7040600,
message: 'The identifier field and url field are mutually exclusive.',
range: {
end: {
character: 14,
line: 6,
},
start: {
character: 4,
line: 6,
},
},
severity: 1,
source: 'apilint',
},
{
range: {
start: {
Expand Down