diff --git a/package.json b/package.json index 471853f5..4a2d698c 100644 --- a/package.json +++ b/package.json @@ -66,7 +66,6 @@ "commander": "^8.0.0", "form-data": "^4.0.0", "handlebars": "^4.7.6", - "js-yaml": "^4.0.0", "json-schema-ref-parser": "^9.0.7", "mkdirp": "^1.0.4", "node-fetch": "^2.6.5", @@ -82,7 +81,6 @@ "@types/express": "4.17.13", "@types/glob": "7.1.4", "@types/jest": "27.0.2", - "@types/js-yaml": "4.0.3", "@types/node": "16.10.3", "@types/qs": "6.9.7", "@typescript-eslint/eslint-plugin": "4.33.0", diff --git a/src/utils/getOpenApiSpec.spec.ts b/src/utils/getOpenApiSpec.spec.ts deleted file mode 100644 index 8f3f0aa2..00000000 --- a/src/utils/getOpenApiSpec.spec.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { exists, readFile } from './fileSystem'; -import { getOpenApiSpec } from './getOpenApiSpec'; - -jest.mock('./fileSystem'); - -const existsMocked = exists as jest.MockedFunction; -const readFileMocked = readFile as jest.MockedFunction; - -function mockPromise(value: T): Promise { - return new Promise(resolve => resolve(value)); -} - -describe('getOpenApiSpec', () => { - it('should read the json file', async () => { - existsMocked.mockReturnValue(mockPromise(true)); - readFileMocked.mockReturnValue(mockPromise('{"message": "Hello World!"}')); - const spec = await getOpenApiSpec('spec.json'); - expect(spec.message).toEqual('Hello World!'); - }); - - it('should read the yaml file', async () => { - existsMocked.mockReturnValue(mockPromise(true)); - readFileMocked.mockReturnValue(mockPromise('message: "Hello World!"')); - const spec = await getOpenApiSpec('spec.yaml'); - expect(spec.message).toEqual('Hello World!'); - }); -}); diff --git a/src/utils/getOpenApiSpec.ts b/src/utils/getOpenApiSpec.ts index 920d4fb4..8302d238 100644 --- a/src/utils/getOpenApiSpec.ts +++ b/src/utils/getOpenApiSpec.ts @@ -1,8 +1,4 @@ -import { load } from 'js-yaml'; import RefParser from 'json-schema-ref-parser'; -import { extname } from 'path'; - -import { readSpec } from './readSpec'; /** * Load and parse te open api spec. If the file extension is ".yml" or ".yaml" @@ -11,26 +7,5 @@ import { readSpec } from './readSpec'; * @param input */ export async function getOpenApiSpec(input: string): Promise { - const extension = extname(input).toLowerCase(); - const content = await readSpec(input); - let rootObject: any; - switch (extension) { - case '.yml': - case '.yaml': - try { - rootObject = load(content); - } catch (e) { - throw new Error(`Could not parse OpenApi YAML: "${input}"`); - } - break; - - default: - try { - rootObject = JSON.parse(content); - } catch (e) { - throw new Error(`Could not parse OpenApi JSON: "${input}"`); - } - break; - } - return await RefParser.bundle(rootObject); + return await RefParser.bundle(input); }