From 208914f29065f80522ed0d6380986a98c4479c22 Mon Sep 17 00:00:00 2001 From: Frank Kilcommins Date: Wed, 20 Dec 2023 12:02:55 +0000 Subject: [PATCH 1/5] feat(reference): add Workflows 1.0.0 JSON parser plugin --- packages/apidom-reference/README.md | 19 ++ packages/apidom-reference/package.json | 7 + .../src/configuration/saturated.ts | 2 + .../parse/parsers/workflows-json-1/index.ts | 43 ++++ .../fixtures/sample-workflow.json | 92 ++++++++ .../parse/parsers/workflows-json-1/index.ts | 196 ++++++++++++++++++ 6 files changed, 359 insertions(+) create mode 100644 packages/apidom-reference/src/parse/parsers/workflows-json-1/index.ts create mode 100644 packages/apidom-reference/test/parse/parsers/workflows-json-1/fixtures/sample-workflow.json create mode 100644 packages/apidom-reference/test/parse/parsers/workflows-json-1/index.ts diff --git a/packages/apidom-reference/README.md b/packages/apidom-reference/README.md index 350cfb93c..d9a120693 100644 --- a/packages/apidom-reference/README.md +++ b/packages/apidom-reference/README.md @@ -251,6 +251,20 @@ Supported media types are: ] ``` +#### [workflows-json-1](https://github.com/swagger-api/apidom/tree/main/packages/apidom-reference/src/parse/parsers/workflows-json-1) + +Wraps [@swagger-api/apidom-parser-adapter-workflows-json-1](https://github.com/swagger-api/apidom/tree/main/packages/apidom-parser-adapter-workflows-json-1) package +and is uniquely identified by `workflows-json-1` name. + +Supported media types are: + +```js +[ + 'application/vnd.oai.workflows;version=1.0.0', + 'application/vnd.oai.workflows+json;version=1.0.0', +] +``` + #### [api-design-systems-json](https://github.com/swagger-api/apidom/tree/main/packages/apidom-reference/src/parse/parsers/api-design-systems-json) Wraps [@swagger-api/apidom-parser-adapter-api-design-systsems-json](https://github.com/swagger-api/apidom/tree/main/packages/apidom-parser-adapter-api-design-systems-json) package @@ -338,6 +352,7 @@ returns `true` or until entire list of parser plugins is exhausted (throws error OpenApiYaml3_1Parser({ allowEmpty: true, sourceMap: false }), AsyncApiJson2Parser({ allowEmpty: true, sourceMap: false }), AsyncApiYaml2Parser({ allowEmpty: true, sourceMap: false }), + WorkflowsJson1Parser({ allowEmpty: true, sourceMap: false }), ApiDesignSystemsJsonParser({ allowEmpty: true, sourceMap: false }), ApiDesignSystemsYamlParser({ allowEmpty: true, sourceMap: false }), JsonParser({ allowEmpty: true, sourceMap: false }), @@ -359,6 +374,7 @@ import OpenApiJson3_1Parser from '@swagger-api/apidom-reference/parse/parsers/op import OpenApiYaml3_1Parser from '@swagger-api/apidom-reference/parse/parsers/openapi-yaml-3-1' import AsyncApiJson2Parser from '@swagger-api/apidom-reference/parse/parsers/asyncapi-json-2'; import AsyncApiYaml2Parser from '@swagger-api/apidom-reference/parse/parsers/asyncapi-yaml-2'; +import WorkflowsJson1Parser from '@swagger-api/apidom-reference/parse/parsers/workflows-json-1'; import ApiDesignSystemsJsonParser from '@swagger-api/apidom-reference/parse/parsers/api-design-systems-json'; import ApiDesignSystemsYamlParser from '@swagger-api/apidom-reference/parse/parsers/api-design-systems-json'; import JsonParser from '@swagger-api/apidom-reference/parse/parsers/json'; @@ -375,6 +391,7 @@ options.parse.parsers = [ OpenApiYaml3_1Parser({ allowEmpty: true, sourceMap: false }), AsyncApiJson2Parser({ allowEmpty: true, sourceMap: false }), AsyncApiYaml2Parser({ allowEmpty: true, sourceMap: false }), + WorkflowsJson1Parser({ allowEmpty: true, sourceMap: false }), ApiDesignSystemsJsonParser({ allowEmpty: true, sourceMap: false }), ApiDesignSystemsYamlParser({ allowEmpty: true, sourceMap: false }), YamlParser({ allowEmpty: true, sourceMap: false }), @@ -395,6 +412,7 @@ import OpenApiJson3_1Parser from '@swagger-api/apidom-reference/parse/parsers/op import OpenApiYaml3_1Parser from '@swagger-api/apidom-reference/parse/parsers/openapi-yaml-3-1' import AsyncApiJson2Parser from '@swagger-api/apidom-reference/parse/parsers/asyncapi-json-2'; import AsyncApiYaml2Parser from '@swagger-api/apidom-reference/parse/parsers/asyncapi-yaml-2'; +import WorkflowsJson1Parser from '@swagger-api/apidom-reference/parse/parsers/workflows-json-2'; import ApiDesignSystemsJsonParser from '@swagger-api/apidom-reference/parse/parsers/api-design-systems-json'; import ApiDesignSystemsYamlParser from '@swagger-api/apidom-reference/parse/parsers/api-design-systems-json'; import JsonParser from '@swagger-api/apidom-reference/parse/parsers/json'; @@ -413,6 +431,7 @@ await parse('/home/user/oas.json', { OpenApiYaml3_0Parser({ allowEmpty: true, sourceMap: false }), AsyncApiJson2Parser({ allowEmpty: true, sourceMap: false }), AsyncApiYaml2Parser({ allowEmpty: true, sourceMap: false }), + WorkflowsJson1Parser({ allowEmpty: true, sourceMap: false }), ApiDesignSystemsJsonParser({ allowEmpty: true, sourceMap: false }), ApiDesignSystemsYamlParser({ allowEmpty: true, sourceMap: false }), YamlParser({ allowEmpty: true, sourceMap: false }), diff --git a/packages/apidom-reference/package.json b/packages/apidom-reference/package.json index 852720d95..2aee66f34 100644 --- a/packages/apidom-reference/package.json +++ b/packages/apidom-reference/package.json @@ -93,6 +93,11 @@ "require": "./cjs/parse/parsers/asyncapi-yaml-2/index.cjs", "types": "./types/parse/parsers/asyncapi-yaml-2/index.d.ts" }, + "./parse/parsers/workflows-json-1": { + "import": "./es/parse/parsers/workflows-json-1/index.mjs", + "require": "./cjs/parse/parsers/workflows-json-1/index.cjs", + "types": "./types/parse/parsers/workflows-json-1/index.d.ts" + }, "./parse/parsers/binary": { "browser": { "import": "./es/parse/parsers/binary/index-browser.mjs", @@ -255,6 +260,7 @@ "@swagger-api/apidom-parser-adapter-openapi-yaml-2": "^0.89.0", "@swagger-api/apidom-parser-adapter-openapi-yaml-3-0": "^0.89.0", "@swagger-api/apidom-parser-adapter-openapi-yaml-3-1": "^0.89.0", + "@swagger-api/apidom-ns-workflows-1": "0.89.0", "@swagger-api/apidom-parser-adapter-yaml-1-2": "^0.89.0" }, "devDependencies": { @@ -275,6 +281,7 @@ "@swagger-api/apidom-parser-adapter-openapi-yaml-2": "*", "@swagger-api/apidom-parser-adapter-openapi-yaml-3-0": "*", "@swagger-api/apidom-parser-adapter-openapi-yaml-3-1": "*", + "@swagger-api/apidom-ns-workflows-1": "*", "@swagger-api/apidom-parser-adapter-yaml-1-2": "*", "axios-mock-adapter": "^1.21.4" }, diff --git a/packages/apidom-reference/src/configuration/saturated.ts b/packages/apidom-reference/src/configuration/saturated.ts index 8f178b8a1..633326d48 100644 --- a/packages/apidom-reference/src/configuration/saturated.ts +++ b/packages/apidom-reference/src/configuration/saturated.ts @@ -14,6 +14,7 @@ import OpenApiJson3_1Parser from '../parse/parsers/openapi-json-3-1'; import OpenApiYaml3_1Parser from '../parse/parsers/openapi-yaml-3-1'; import AsyncApiJson2Parser from '../parse/parsers/asyncapi-json-2'; import AsyncApiYaml2Parser from '../parse/parsers/asyncapi-yaml-2'; +import WorkflowsJson1Parser from '../parse/parsers/workflows-json-1'; import JsonParser from '../parse/parsers/json'; import YamlParser from '../parse/parsers/yaml-1-2'; import BinaryParser from '../parse/parsers/binary/index-node'; @@ -33,6 +34,7 @@ options.parse.parsers = [ OpenApiYaml3_1Parser({ allowEmpty: true, sourceMap: false }), AsyncApiJson2Parser({ allowEmpty: true, sourceMap: false }), AsyncApiYaml2Parser({ allowEmpty: true, sourceMap: false }), + WorkflowsJson1Parser({ allowEmpty: true, sourceMap: false }), ApiDesignSystemsJsonParser({ allowEmpty: true, sourceMap: false }), ApiDesignSystemsYamlParser({ allowEmpty: true, sourceMap: false }), JsonParser({ allowEmpty: true, sourceMap: false }), diff --git a/packages/apidom-reference/src/parse/parsers/workflows-json-1/index.ts b/packages/apidom-reference/src/parse/parsers/workflows-json-1/index.ts new file mode 100644 index 000000000..aee031828 --- /dev/null +++ b/packages/apidom-reference/src/parse/parsers/workflows-json-1/index.ts @@ -0,0 +1,43 @@ +import stampit from 'stampit'; +import { pick } from 'ramda'; +import { ParseResultElement } from '@swagger-api/apidom-core'; +import { parse, mediaTypes, detect } from '@swagger-api/apidom-parser-adapter-workflows-json-1'; + +import ParserError from '../../../errors/ParserError'; +import { File as IFile, Parser as IParser } from '../../../types'; +import Parser from '../Parser'; + +const WorkflowsJson1Parser: stampit.Stamp = stampit(Parser, { + props: { + name: 'workflows-json-1', + fileExtensions: ['.json'], + mediaTypes, + }, + methods: { + async canParse(file: IFile): Promise { + const hasSupportedFileExtension = + this.fileExtensions.length === 0 ? true : this.fileExtensions.includes(file.extension); + const hasSupportedMediaType = this.mediaTypes.includes(file.mediaType); + + if (!hasSupportedFileExtension) return false; + if (hasSupportedMediaType) return true; + if (!hasSupportedMediaType) { + return detect(file.toString()); + } + return false; + }, + async parse(file: IFile): Promise { + const source = file.toString(); + + try { + const parserOpts = pick(['sourceMap', 'syntacticAnalysis', 'refractorOpts'], this); + return await parse(source, parserOpts); + } catch (error: any) { + // eslint-disable-next-line @typescript-eslint/no-throw-literal + throw new ParserError(`Error parsing "${file.uri}"`, { cause: error }); + } + }, + }, +}); + +export default WorkflowsJson1Parser; diff --git a/packages/apidom-reference/test/parse/parsers/workflows-json-1/fixtures/sample-workflow.json b/packages/apidom-reference/test/parse/parsers/workflows-json-1/fixtures/sample-workflow.json new file mode 100644 index 000000000..9e20ae9b4 --- /dev/null +++ b/packages/apidom-reference/test/parse/parsers/workflows-json-1/fixtures/sample-workflow.json @@ -0,0 +1,92 @@ +{ + "workflowsSpec": "1.0.0", + "info": { + "title": "A pet purchasing workflow", + "summary": "This workflow showcases how to purchase a pet through a sequence of API calls", + "description": "This workflow walks you through the steps of `searching` for, `selecting`, and `purchasing` an available pet.\n", + "version": "1.0.1" + }, + "sourceDescriptions": [ + { + "name": "petStoreDescription", + "url": "https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml", + "type": "openapi" + } + ], + "workflows": [ + { + "workflowId": "loginUserRetrievePet", + "summary": "Login User and then retrieve pets", + "description": "This procedure lays out the steps to login a user and then retrieve pets", + "inputs": { + "type": "object", + "properties": { + "username": { + "type": "string" + }, + "password": { + "type": "string" + } + } + }, + "steps": [ + { + "stepId": "loginStep", + "description": "This step demonstrates the user login step", + "operationId": "petStoreDescription.loginUser", + "parameters": [ + { + "name": "username", + "in": "query", + "value": "$inputs.username" + }, + { + "name": "password", + "in": "query", + "value": "$inputs.password" + } + ], + "successCriteria": [ + { + "condition": "$statusCode == 200" + } + ], + "outputs": { + "tokenExpires": "$response.header.X-Expires-After", + "rateLimit": "$response.header.X-Rate-Limit", + "sessionToken": "$response.body" + } + }, + { + "stepId": "getPetStep", + "description": "retrieve a pet by status from the GET pets endpoint", + "operationRef": "https://petstore3.swagger.io/api/v3/openapi.json#/paths/users/~findbystatus~1{status}/get", + "dependsOn": "loginStep", + "parameters": [ + { + "name": "status", + "in": "query", + "value": "available" + }, + { + "name": "Authorization", + "in": "header", + "value": "$steps.loginUser.outputs.sessionToken" + } + ], + "successCriteria": [ + { + "condition": "$statusCode == 200" + } + ], + "outputs": { + "availablePets": "$response.body" + } + } + ], + "outputs": { + "available": "$steps.getPetStep.availablePets" + } + } + ] + } \ No newline at end of file diff --git a/packages/apidom-reference/test/parse/parsers/workflows-json-1/index.ts b/packages/apidom-reference/test/parse/parsers/workflows-json-1/index.ts new file mode 100644 index 000000000..ec103dde5 --- /dev/null +++ b/packages/apidom-reference/test/parse/parsers/workflows-json-1/index.ts @@ -0,0 +1,196 @@ +import fs from 'node:fs'; +import path from 'node:path'; +import { assert } from 'chai'; +import { NumberElement, isParseResultElement, isSourceMapElement } from '@swagger-api/apidom-core'; +import { mediaTypes } from '@swagger-api/apidom-parser-adapter-workflows-json-1'; + +import File from '../../../../src/util/File'; +import WorkflowsJson1Parser from '../../../../src/parse/parsers/workflows-json-1'; + +describe('parsers', function () { + context('WorkflowsJson1Parser', function () { + context('canParse', function () { + context('given file with .json extension', function () { + context('and with proper media type', function () { + specify('should return true', async function () { + const file1 = File({ + uri: '/path/to/workflows.json', + mediaType: mediaTypes.latest('generic'), + }); + const file2 = File({ + uri: '/path/to/workflows.json', + mediaType: mediaTypes.latest('json'), + }); + const parser = WorkflowsJson1Parser(); + + assert.isTrue(await parser.canParse(file1)); + assert.isTrue(await parser.canParse(file2)); + }); + }); + + context('and with improper media type', function () { + specify('should return false', async function () { + const file = File({ + uri: '/path/to/workflows.json', + mediaType: 'application/vnd.aai.asyncapi+json;version=2.6.0', + }); + const parser = WorkflowsJson1Parser(); + + assert.isFalse(await parser.canParse(file)); + }); + }); + }); + + context('given file with unknown extension', function () { + specify('should return false', async function () { + const file = File({ + uri: '/path/to/workflows.yaml', + mediaType: mediaTypes.latest('json'), + }); + const parser = WorkflowsJson1Parser(); + + assert.isFalse(await parser.canParse(file)); + }); + }); + + context('given file with no extension', function () { + specify('should return false', async function () { + const file = File({ + uri: '/path/to/workflows', + mediaType: mediaTypes.latest('json'), + }); + const parser = WorkflowsJson1Parser(); + + assert.isFalse(await parser.canParse(file)); + }); + }); + + context('given file with supported extension', function () { + context('and file data is buffer and can be detected as OpenAPI 2.0', function () { + specify('should return true', async function () { + const url = path.join(__dirname, 'fixtures', 'sample-workflow.json'); + const file = File({ + uri: '/path/to/workflows.json', + data: fs.readFileSync(url), + }); + const parser = WorkflowsJson1Parser(); + + assert.isTrue(await parser.canParse(file)); + }); + }); + + context('and file data is string and can be detected as Workflows 1.0.0', function () { + specify('should return true', async function () { + const url = path.join(__dirname, 'fixtures', 'sample-workflow.json'); + const file = File({ + uri: '/path/to/workflows.json', + data: fs.readFileSync(url).toString(), + }); + const parser = WorkflowsJson1Parser(); + + assert.isTrue(await parser.canParse(file)); + }); + }); + }); + }); + + context('parse', function () { + context('given Workflows 1.0.0 JSON data', function () { + specify('should return parse result', async function () { + const url = path.join(__dirname, 'fixtures', 'sample-workflow.json'); + const data = fs.readFileSync(url).toString(); + const file = File({ + url, + data, + mediaType: mediaTypes.latest('json'), + }); + const parser = WorkflowsJson1Parser(); + const parseResult = await parser.parse(file); + + assert.isTrue(isParseResultElement(parseResult)); + }); + }); + + context('given Workflows 1.0.0 JSON data as buffer', function () { + specify('should return parse result', async function () { + const url = path.join(__dirname, 'fixtures', 'sample-workflow.json'); + const data = fs.readFileSync(url); + const file = File({ + url, + data, + mediaType: mediaTypes.latest('json'), + }); + const parser = WorkflowsJson1Parser(); + const parseResult = await parser.parse(file); + + assert.isTrue(isParseResultElement(parseResult)); + }); + }); + + context('given data that is not a Workflows 1.0.0 JSON data', function () { + specify('should coerce to string and parse', async function () { + const file = File({ + uri: '/path/to/file.json', + data: 1, + mediaType: mediaTypes.latest('json'), + }); + const parser = WorkflowsJson1Parser(); + const parseResult = await parser.parse(file); + const numberElement: NumberElement = parseResult.get(0); + + assert.isTrue(isParseResultElement(parseResult)); + assert.isTrue(numberElement.equals(1)); + }); + }); + + context('given empty file', function () { + specify('should return empty parse result', async function () { + const file = File({ + uri: '/path/to/file.json', + data: '', + mediaType: mediaTypes.latest('json'), + }); + const parser = WorkflowsJson1Parser(); + const parseResult = await parser.parse(file); + + assert.isTrue(isParseResultElement(parseResult)); + assert.isTrue(parseResult.isEmpty); + }); + }); + + context('sourceMap', function () { + context('given sourceMap enabled', function () { + specify('should decorate ApiDOM with source maps', async function () { + const url = path.join(__dirname, 'fixtures', 'sample-workflow.json'); + const data = fs.readFileSync(url).toString(); + const file = File({ + url, + data, + mediaType: mediaTypes.latest('json'), + }); + const parser = WorkflowsJson1Parser({ sourceMap: true }); + const parseResult = await parser.parse(file); + + assert.isTrue(isSourceMapElement(parseResult.api?.meta.get('sourceMap'))); + }); + }); + + context('given sourceMap disabled', function () { + specify('should not decorate ApiDOM with source maps', async function () { + const url = path.join(__dirname, 'fixtures', 'sample-workflow.json'); + const data = fs.readFileSync(url).toString(); + const file = File({ + url, + data, + mediaType: mediaTypes.latest('json'), + }); + const parser = WorkflowsJson1Parser(); + const parseResult = await parser.parse(file); + + assert.isUndefined(parseResult.api?.meta.get('sourceMap')); + }); + }); + }); + }); + }); +}); From 8611884ab001036128613c35b244b604b0afc436 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Gorej?= Date: Thu, 21 Dec 2023 06:44:01 +0100 Subject: [PATCH 2/5] Update packages/apidom-reference/src/parse/parsers/workflows-json-1/index.ts --- .../apidom-reference/src/parse/parsers/workflows-json-1/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/apidom-reference/src/parse/parsers/workflows-json-1/index.ts b/packages/apidom-reference/src/parse/parsers/workflows-json-1/index.ts index aee031828..3fc440b68 100644 --- a/packages/apidom-reference/src/parse/parsers/workflows-json-1/index.ts +++ b/packages/apidom-reference/src/parse/parsers/workflows-json-1/index.ts @@ -33,7 +33,6 @@ const WorkflowsJson1Parser: stampit.Stamp = stampit(Parser, { const parserOpts = pick(['sourceMap', 'syntacticAnalysis', 'refractorOpts'], this); return await parse(source, parserOpts); } catch (error: any) { - // eslint-disable-next-line @typescript-eslint/no-throw-literal throw new ParserError(`Error parsing "${file.uri}"`, { cause: error }); } }, From e1e91d710ee584443da9d66429b98d7ed2bc4edc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Gorej?= Date: Thu, 21 Dec 2023 06:44:10 +0100 Subject: [PATCH 3/5] Update packages/apidom-reference/package.json --- packages/apidom-reference/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/apidom-reference/package.json b/packages/apidom-reference/package.json index 2aee66f34..9435585c0 100644 --- a/packages/apidom-reference/package.json +++ b/packages/apidom-reference/package.json @@ -260,7 +260,7 @@ "@swagger-api/apidom-parser-adapter-openapi-yaml-2": "^0.89.0", "@swagger-api/apidom-parser-adapter-openapi-yaml-3-0": "^0.89.0", "@swagger-api/apidom-parser-adapter-openapi-yaml-3-1": "^0.89.0", - "@swagger-api/apidom-ns-workflows-1": "0.89.0", + "@swagger-api/apidom-ns-workflows-1": "^0.89.0", "@swagger-api/apidom-parser-adapter-yaml-1-2": "^0.89.0" }, "devDependencies": { From d1f7014953e4bb00a528838707ff175931e02b93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Gorej?= Date: Thu, 21 Dec 2023 06:44:25 +0100 Subject: [PATCH 4/5] Update packages/apidom-reference/test/parse/parsers/workflows-json-1/index.ts --- .../test/parse/parsers/workflows-json-1/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/apidom-reference/test/parse/parsers/workflows-json-1/index.ts b/packages/apidom-reference/test/parse/parsers/workflows-json-1/index.ts index ec103dde5..8f315c453 100644 --- a/packages/apidom-reference/test/parse/parsers/workflows-json-1/index.ts +++ b/packages/apidom-reference/test/parse/parsers/workflows-json-1/index.ts @@ -66,7 +66,7 @@ describe('parsers', function () { }); context('given file with supported extension', function () { - context('and file data is buffer and can be detected as OpenAPI 2.0', function () { + context('and file data is buffer and can be detected as Workflows 1.0.0', function () { specify('should return true', async function () { const url = path.join(__dirname, 'fixtures', 'sample-workflow.json'); const file = File({ From bf2c39edd6a507786b172a85f218ed30531cd160 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Gorej?= Date: Thu, 21 Dec 2023 06:45:41 +0100 Subject: [PATCH 5/5] Update index.ts --- .../parse/parsers/workflows-json-1/index.ts | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/packages/apidom-reference/test/parse/parsers/workflows-json-1/index.ts b/packages/apidom-reference/test/parse/parsers/workflows-json-1/index.ts index 8f315c453..98627c469 100644 --- a/packages/apidom-reference/test/parse/parsers/workflows-json-1/index.ts +++ b/packages/apidom-reference/test/parse/parsers/workflows-json-1/index.ts @@ -68,10 +68,10 @@ describe('parsers', function () { context('given file with supported extension', function () { context('and file data is buffer and can be detected as Workflows 1.0.0', function () { specify('should return true', async function () { - const url = path.join(__dirname, 'fixtures', 'sample-workflow.json'); + const uri = path.join(__dirname, 'fixtures', 'sample-workflow.json'); const file = File({ uri: '/path/to/workflows.json', - data: fs.readFileSync(url), + data: fs.readFileSync(uri), }); const parser = WorkflowsJson1Parser(); @@ -81,10 +81,10 @@ describe('parsers', function () { context('and file data is string and can be detected as Workflows 1.0.0', function () { specify('should return true', async function () { - const url = path.join(__dirname, 'fixtures', 'sample-workflow.json'); + const uri = path.join(__dirname, 'fixtures', 'sample-workflow.json'); const file = File({ uri: '/path/to/workflows.json', - data: fs.readFileSync(url).toString(), + data: fs.readFileSync(uri).toString(), }); const parser = WorkflowsJson1Parser(); @@ -97,10 +97,10 @@ describe('parsers', function () { context('parse', function () { context('given Workflows 1.0.0 JSON data', function () { specify('should return parse result', async function () { - const url = path.join(__dirname, 'fixtures', 'sample-workflow.json'); - const data = fs.readFileSync(url).toString(); + const uri = path.join(__dirname, 'fixtures', 'sample-workflow.json'); + const data = fs.readFileSync(uri).toString(); const file = File({ - url, + uri, data, mediaType: mediaTypes.latest('json'), }); @@ -113,10 +113,10 @@ describe('parsers', function () { context('given Workflows 1.0.0 JSON data as buffer', function () { specify('should return parse result', async function () { - const url = path.join(__dirname, 'fixtures', 'sample-workflow.json'); - const data = fs.readFileSync(url); + const uri = path.join(__dirname, 'fixtures', 'sample-workflow.json'); + const data = fs.readFileSync(uri); const file = File({ - url, + uri, data, mediaType: mediaTypes.latest('json'), }); @@ -161,10 +161,10 @@ describe('parsers', function () { context('sourceMap', function () { context('given sourceMap enabled', function () { specify('should decorate ApiDOM with source maps', async function () { - const url = path.join(__dirname, 'fixtures', 'sample-workflow.json'); - const data = fs.readFileSync(url).toString(); + const uri = path.join(__dirname, 'fixtures', 'sample-workflow.json'); + const data = fs.readFileSync(uri).toString(); const file = File({ - url, + uri, data, mediaType: mediaTypes.latest('json'), }); @@ -177,10 +177,10 @@ describe('parsers', function () { context('given sourceMap disabled', function () { specify('should not decorate ApiDOM with source maps', async function () { - const url = path.join(__dirname, 'fixtures', 'sample-workflow.json'); - const data = fs.readFileSync(url).toString(); + const uri = path.join(__dirname, 'fixtures', 'sample-workflow.json'); + const data = fs.readFileSync(uri).toString(); const file = File({ - url, + uri, data, mediaType: mediaTypes.latest('json'), });