From d9b476a00c9803092dc886041438f8262d592c31 Mon Sep 17 00:00:00 2001 From: frantuma Date: Fri, 29 Sep 2023 16:48:35 +0200 Subject: [PATCH] test(ls): add test for ref validation of valid async spec --- .../test/fixtures/deref/valid-async.yaml | 33 +++++++++++++++++ .../apidom-ls/test/validate-references.ts | 36 ++++++++++++++++++- 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 packages/apidom-ls/test/fixtures/deref/valid-async.yaml diff --git a/packages/apidom-ls/test/fixtures/deref/valid-async.yaml b/packages/apidom-ls/test/fixtures/deref/valid-async.yaml new file mode 100644 index 0000000000..377db5c437 --- /dev/null +++ b/packages/apidom-ls/test/fixtures/deref/valid-async.yaml @@ -0,0 +1,33 @@ +asyncapi: '2.6.0' +info: + version: '1.0.0' + title: 'streetlights' +channels: + test: + publish: + operationId: receiveLightMeasurement + message: + $ref: '#/components/messages/lightMeasured' +components: + messages: + lightMeasured: + name: lightMeasured + title: Light measured + summary: Inform about environmental lighting conditions of a particular streetlight. + contentType: application/json + payload: + $ref: "#/components/schemas/lightMeasuredPayload" + schemas: + lightMeasuredPayload: + type: object + properties: + lumens: + type: integer + minimum: 0 + description: Light intensity measured in lumens. + sentAt: + $ref: "#/components/schemas/sentAt" + sentAt: + type: string + format: date-time + description: Date and time when the message was sent. diff --git a/packages/apidom-ls/test/validate-references.ts b/packages/apidom-ls/test/validate-references.ts index 6b1e460b5a..51f899e148 100644 --- a/packages/apidom-ls/test/validate-references.ts +++ b/packages/apidom-ls/test/validate-references.ts @@ -19,6 +19,9 @@ const spec = fs.readFileSync(path.join(__dirname, 'fixtures', 'deref', 'invalid. const specValid = fs .readFileSync(path.join(__dirname, 'fixtures', 'deref', 'valid-same-ref.json')) .toString(); +const specValidAsync = fs + .readFileSync(path.join(__dirname, 'fixtures', 'deref', 'valid-async.yaml')) + .toString(); describe('reference validation', function () { const lsContext: LanguageServiceContext = { @@ -30,7 +33,7 @@ describe('reference validation', function () { const languageService: LanguageService = getLanguageService(lsContext); - context('given doc with invalid references', function () { + context('given doc with references', function () { const httpPort = 8123; let httpServer: ServerTerminable; @@ -355,5 +358,36 @@ describe('reference validation', function () { }) as Diagnostic[], ); }); + specify('should validate valid async spec with apidom-reference', async function () { + this.timeout(10000); + const validationContext: ValidationContext = { + comments: DiagnosticSeverity.Error, + maxNumberOfProblems: 100, + relatedInformation: false, + referenceValidationMode: ReferenceValidationMode.APIDOM_INDIRECT_EXTERNAL, + }; + + const doc: TextDocument = TextDocument.create( + 'foo://bar/specValidAsync.json', + 'json', + 0, + specValidAsync, + ); + + const valRes = await languageService.doValidation(doc, validationContext); + const exp: Diagnostic[] = []; + assert.deepEqual( + valRes.map((value) => { + // eslint-disable-next-line no-param-reassign + value.code = 'test'; + return value; + }), + exp.map((value) => { + // eslint-disable-next-line no-param-reassign + value.code = 'test'; + return value; + }) as Diagnostic[], + ); + }); }); });