Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ const valueMutuallyExclusiveLint: LinterMeta = {
source: 'apilint',
message: 'The value field and externalValue field are mutually exclusive.',
severity: 1,
linterFunction: 'allowedFields',
linterParams: [['summary', 'description', 'externalValue'], 'x-'],
linterFunction: 'missingFields',
linterParams: [['value']],
marker: 'key',
markerTarget: 'value',
conditions: [
{
function: 'existFields',
Expand Down
38 changes: 38 additions & 0 deletions packages/apidom-ls/test/fixtures/validation/oas/issue2141.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
openapi: 3.1.0
info:
title: deref
version: 1.0.0
license:
name: Apache 2.0
identifier: Apache-2.0
url: http://should.not.exist.with.identifier.com

paths:
/a:
get:
operationId: aget
responses:
'200':
content:
application/json:
schema:
type: object
examples:
confirmation-success:
summary: short confirmation success
value: testString
externalValue: outsideLink
confirmation-error:
summary: short confirmation success
value:
test: object
externalValue: outsideLink
confirmation-errors:
summary: short confirmation success
value:
- test1
- test2
externalValue: outsideLink
confirmation-noerror:
summary: short confirmation success
value: testString
77 changes: 77 additions & 0 deletions packages/apidom-ls/test/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ describe('apidom-ls-validate', function () {
logLevel,
};

const contextNoSchema: LanguageServiceContext = {
metadata: metadata(),
performanceLogs: logPerformance,
logLevel,
};

it('test validation for asyncapi and openapi', async function () {
const validationContext: ValidationContext = {
comments: DiagnosticSeverity.Error,
Expand Down Expand Up @@ -2846,4 +2852,75 @@ describe('apidom-ls-validate', function () {

languageService.terminate();
});

it('oas / yaml - test issue 2141 / example value', async function () {
const validationContext: ValidationContext = {
comments: DiagnosticSeverity.Error,
maxNumberOfProblems: 100,
relatedInformation: false,
};

const spec = fs
.readFileSync(path.join(__dirname, 'fixtures', 'validation', 'oas', 'issue2141.yaml'))
.toString();

const doc: TextDocument = TextDocument.create('foo://bar/issue2141.yaml', 'yaml', 0, spec);

const languageService: LanguageService = getLanguageService(contextNoSchema);

const result = await languageService.doValidation(doc, validationContext);
const expected: Diagnostic[] = [
{
range: {
start: {
line: 22,
character: 18,
},
end: {
line: 22,
character: 23,
},
},
message: 'The value field and externalValue field are mutually exclusive.',
severity: 1,
code: 5200300,
source: 'apilint',
},
{
range: {
start: {
line: 26,
character: 18,
},
end: {
line: 26,
character: 23,
},
},
message: 'The value field and externalValue field are mutually exclusive.',
severity: 1,
code: 5200300,
source: 'apilint',
},
{
range: {
start: {
line: 31,
character: 18,
},
end: {
line: 31,
character: 23,
},
},
message: 'The value field and externalValue field are mutually exclusive.',
severity: 1,
code: 5200300,
source: 'apilint',
},
];
assert.deepEqual(result, expected as Diagnostic[]);

languageService.terminate();
});
});