Skip to content

Commit

Permalink
feat(ls): OpenAPI 3.x.x mutually exclusive lint rule for Media Type (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-lai authored Oct 21, 2022
1 parent 4b437ff commit de53a13
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/apidom-ls/src/config/codes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,7 @@ enum ApilintCodes {
OPENAPI3_0_MEDIA_TYPE_FIELD_SCHEMA_VALUES_TYPE = 5170100,
OPENAPI3_0_MEDIA_TYPE_FIELD_EXAMPLES_VALUES_TYPE = 5170200,
OPENAPI3_0_MEDIA_TYPE_FIELD_ENCODING_VALUES_TYPE = 5170300,
OPENAPI3_0_MEDIA_TYPE_FIELD_EXAMPLES_MUTUALLY_EXCLUSIVE,

OPENAPI3_0_ENCODING = 5180000,
OPENAPI3_0_ENCODING_FIELD_CONTENT_TYPE_TYPE = 5180100,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import ApilintCodes from '../../../codes';
import { LinterMeta } from '../../../../apidom-language-types';

const examplesMutuallyExclusiveLint: LinterMeta = {
code: ApilintCodes.OPENAPI3_0_MEDIA_TYPE_FIELD_EXAMPLES_MUTUALLY_EXCLUSIVE,
source: 'apilint',
message: 'The `example` field and `examples` field are mutually exclusive.',
severity: 1,
linterFunction: 'missingFields',
linterParams: [['examples']],
marker: 'key',
markerTarget: 'examples',
conditions: [
{
function: 'existFields',
params: [['example']],
},
],
};

export default examplesMutuallyExclusiveLint;
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ import allowedFieldsLint from './allowed-fields';
import schemaTypeLint from './schema--type';
import examplesValuesTypeLint from './examples--values-type';
import encodingValuesTypeLint from './encoding--values-type';
import examplesMutuallyExclusiveLint from './examples--mutually-exclusive';

const lints = [schemaTypeLint, examplesValuesTypeLint, encodingValuesTypeLint, allowedFieldsLint];
const lints = [
schemaTypeLint,
examplesValuesTypeLint,
encodingValuesTypeLint,
allowedFieldsLint,
examplesMutuallyExclusiveLint,
];

export default lints;

1 comment on commit de53a13

@char0n
Copy link
Member

@char0n char0n commented on de53a13 Oct 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've issued a PR which fixes the assignment of the error code to OPENAPI3_0_MEDIA_TYPE_FIELD_EXAMPLES_MUTUALLY_EXCLUSIVE : #2177

Reasoning: consistency + single field validations should be groups together

Please sign in to comment.