diff --git a/lib/__tests__/index.test.ts b/lib/__tests__/index.test.ts new file mode 100644 index 00000000..56694202 --- /dev/null +++ b/lib/__tests__/index.test.ts @@ -0,0 +1,43 @@ +import path from 'node:path'; + +import { describe, expect, it } from 'vitest'; + +import { getResolvedInput } from '../index'; + +describe('getResolvedInput', () => { + it('handles url', async () => { + const pathOrUrlOrSchema = 'https://foo.com'; + const resolvedInput = await getResolvedInput({ pathOrUrlOrSchema }); + expect(resolvedInput.type).toBe('url'); + expect(resolvedInput.schema).toBeUndefined(); + expect(resolvedInput.path).toBe('https://foo.com/'); + }); + + it('handles file', async () => { + const pathOrUrlOrSchema = './path/to/openapi.json'; + const resolvedInput = await getResolvedInput({ pathOrUrlOrSchema }); + expect(resolvedInput.type).toBe('file'); + expect(resolvedInput.schema).toBeUndefined(); + expect(resolvedInput.path).toBe(path.resolve('./path/to/openapi.json')); + }); + + it('handles raw spec', async () => { + const pathOrUrlOrSchema = { + info: { + version: '1.0.0', + }, + openapi: '3.1.0', + paths: {}, + }; + const resolvedInput = await getResolvedInput({ pathOrUrlOrSchema }); + expect(resolvedInput.type).toBe('json'); + expect(resolvedInput.schema).toEqual({ + info: { + version: '1.0.0', + }, + openapi: '3.1.0', + paths: {}, + }); + expect(resolvedInput.path).toBe(''); + }); +}); diff --git a/lib/index.ts b/lib/index.ts index 836f97f0..e23d3e4a 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -38,7 +38,7 @@ export const getResolvedInput = ({ // So we're being generous here and doing the conversion automatically. // This is not intended to be a 100% bulletproof solution. // If it doesn't work for your use-case, then use a URL instead. - if (url.isFileSystemPath(resolvedInput.path)) { + if (resolvedInput.path && url.isFileSystemPath(resolvedInput.path)) { resolvedInput.path = url.fromFileSystemPath(resolvedInput.path); resolvedInput.type = 'file'; } else if (!resolvedInput.path && pathOrUrlOrSchema && typeof pathOrUrlOrSchema === 'object') { @@ -54,8 +54,10 @@ export const getResolvedInput = ({ } } - // resolve the absolute path of the schema - resolvedInput.path = url.resolve(url.cwd(), resolvedInput.path); + if (resolvedInput.type !== 'json') { + // resolve the absolute path of the schema + resolvedInput.path = url.resolve(url.cwd(), resolvedInput.path); + } return resolvedInput; } diff --git a/lib/resolvers/url.ts b/lib/resolvers/url.ts index 007b8a41..cb452f11 100644 --- a/lib/resolvers/url.ts +++ b/lib/resolvers/url.ts @@ -14,57 +14,45 @@ export const sendRequest = async ({ timeout?: number; url: URL | string; }): Promise<{ + init?: RequestInit; response: Response; }> => { url = new URL(url); redirects.push(url.href); - try { - const controller = new AbortController(); - const timeoutId = setTimeout(() => { - controller.abort(); - }, timeout); - const response = await fetch(url, { - signal: controller.signal, - ...init, - }); - clearTimeout(timeoutId); - - if (response.status >= 400) { - // gracefully handle HEAD method not allowed - if (response.status === 405 && init?.method === 'HEAD') { - return { response }; - } + const controller = new AbortController(); + const timeoutId = setTimeout(() => { + controller.abort(); + }, timeout); + const response = await fetch(url, { + signal: controller.signal, + ...init, + }); + clearTimeout(timeoutId); - throw ono({ status: response.status }, `HTTP ERROR ${response.status}`); + if (response.status >= 300 && response.status <= 399) { + if (redirects.length > 5) { + throw new ResolverError( + ono( + { status: response.status }, + `Error requesting ${redirects[0]}. \nToo many redirects: \n ${redirects.join(" \n ")}`, + ), + ); } - - if (response.status >= 300) { - if (redirects.length > 5) { - throw new ResolverError( - ono( - { status: response.status }, - `Error requesting ${redirects[0]}. \nToo many redirects: \n ${redirects.join(" \n ")}`, - ), - ); - } - - if (!("location" in response.headers) || !response.headers.location) { - throw ono({ status: response.status }, `HTTP ${response.status} redirect with no location header`); - } - - return sendRequest({ - init, - redirects, - timeout, - url: resolve(url.href, response.headers.location as string), - }); + + if (!("location" in response.headers) || !response.headers.location) { + throw ono({ status: response.status }, `HTTP ${response.status} redirect with no location header`); } - return { response }; - } catch (error: any) { - throw new ResolverError(ono(error, `Error requesting ${url.href}`), url.href); + return sendRequest({ + init, + redirects, + timeout, + url: resolve(url.href, response.headers.location as string), + }); } + + return { init, response }; } export const urlResolver = { @@ -72,15 +60,27 @@ export const urlResolver = { let data = arrayBuffer; if (!data) { - const { response } = await sendRequest({ - init: { - method: 'GET', - }, - url: file.url, - }); - data = response.body ? await response.arrayBuffer() : new ArrayBuffer(0) + try { + const { init, response } = await sendRequest({ + init: { + method: 'GET', + }, + url: file.url, + }); + + if (response.status >= 400) { + // gracefully handle HEAD method not allowed + if (response.status !== 405 || init?.method !== 'HEAD') { + throw ono({ status: response.status }, `HTTP ERROR ${response.status}`); + } + + data = response.body ? await response.arrayBuffer() : new ArrayBuffer(0) + } + } catch (error: any) { + throw new ResolverError(ono(error, `Error requesting ${file.url}`), file.url); + } } - file.data = Buffer.from(data); + file.data = Buffer.from(data!); }, }; diff --git a/package.json b/package.json index 1f667c8a..f7bd85d0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@hey-api/json-schema-ref-parser", - "version": "1.0.2", + "version": "1.0.3", "description": "Parse, Resolve, and Dereference JSON Schema $ref pointers", "homepage": "https://heyapi.dev/", "repository": { @@ -48,8 +48,8 @@ "test:browser": "cross-env BROWSER=\"true\" yarn test", "test:node": "yarn test", "test:update": "vitest -u", - "test:watch": "vitest -w", - "test": "vitest --coverage", + "test:watch": "vitest watch --config vitest.config.unit.ts", + "test": "vitest run --config vitest.config.unit.ts", "typecheck": "tsc --noEmit" }, "devDependencies": { diff --git a/test/__IGNORED__/__({[ % & $ # @ ` ~ ,)}]__/__({[ % & $ # @ ` ~ ,)}]__.yaml b/test/__IGNORED__/__({[ % & $ # @ ` ~ ,)}]__/__({[ % & $ # @ ` ~ ,)}]__.yaml deleted file mode 100644 index 51ea25b9..00000000 --- a/test/__IGNORED__/__({[ % & $ # @ ` ~ ,)}]__/__({[ % & $ # @ ` ~ ,)}]__.yaml +++ /dev/null @@ -1,5 +0,0 @@ -definitions: - foo: - $ref: "__(%7B%5B%20%25%20%26%20%24%20%23%20%40%20%60%20~%20%2C)%7D%5D__/__(%7B%5B%20%25%20%26%20%24%20%23%20%40%20%60%20~%20%2C)%7D%5D__.json#/definitions/foo" - "__<({[ % & $ # @ + = ? \\ / \" ' ' ` ~ , ; : >)}]__": - $ref: "__(%7B%5B%20%25%20%26%20%24%20%23%20%40%20%60%20~%20%2C)%7D%5D__/__(%7B%5B%20%25%20%26%20%24%20%23%20%40%20%60%20~%20%2C)%7D%5D__.json#/definitions/__%3C(%7B%5B%20%25%20%26%20%24%20%23%20%40%20%2B%20%3D%20%3F%20%5C%20%2F%20%22%20'%20'%20%60%20~%20%2C%20%3B%20%3A%20%3E)%7D%5D__" diff --git a/test/__IGNORED__/__({[ % & $ # @ ` ~ ,)}]__/__({[ % & $ # @ ` ~ ,)}]__/__({[ % & $ # @ ` ~ ,)}]__.json b/test/__IGNORED__/__({[ % & $ # @ ` ~ ,)}]__/__({[ % & $ # @ ` ~ ,)}]__/__({[ % & $ # @ ` ~ ,)}]__.json deleted file mode 100644 index 320cfe5c..00000000 --- a/test/__IGNORED__/__({[ % & $ # @ ` ~ ,)}]__/__({[ % & $ # @ ` ~ ,)}]__/__({[ % & $ # @ ` ~ ,)}]__.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "definitions": { - "foo": { - "type": "object", - "description": "Testing file/folder names with spaces and special characters" - }, - "__<({[ % & $ # @ + = ? \\ / \" ' ' ` ~ , ; : >)}]__": { - "type": "object", - "description": "Testing internal $refs with spaces and special characters" - } - } -} diff --git a/test/__IGNORED__/__({[ % & $ # @ ` ~ ,)}]__/dereferenced.ts b/test/__IGNORED__/__({[ % & $ # @ ` ~ ,)}]__/dereferenced.ts deleted file mode 100644 index d3419816..00000000 --- a/test/__IGNORED__/__({[ % & $ # @ ` ~ ,)}]__/dereferenced.ts +++ /dev/null @@ -1,12 +0,0 @@ -export default { - definitions: { - foo: { - type: "object", - description: "Testing file/folder names with spaces and special characters", - }, - "__<({[ % & $ # @ + = ? \\ / \" ' ' ` ~ , ; : >)}]__": { - type: "object", - description: "Testing internal $refs with spaces and special characters", - }, - }, -}; diff --git a/test/__IGNORED__/__({[ % & $ # @ ` ~ ,)}]__/parsed.ts b/test/__IGNORED__/__({[ % & $ # @ ` ~ ,)}]__/parsed.ts deleted file mode 100644 index 41316fab..00000000 --- a/test/__IGNORED__/__({[ % & $ # @ ` ~ ,)}]__/parsed.ts +++ /dev/null @@ -1,25 +0,0 @@ -export default { - schema: { - definitions: { - foo: { - $ref: "__(%7B%5B%20%25%20%26%20%24%20%23%20%40%20%60%20~%20%2C)%7D%5D__/__(%7B%5B%20%25%20%26%20%24%20%23%20%40%20%60%20~%20%2C)%7D%5D__.json#/definitions/foo", - }, - "__<({[ % & $ # @ + = ? \\ / \" ' ' ` ~ , ; : >)}]__": { - $ref: "__(%7B%5B%20%25%20%26%20%24%20%23%20%40%20%60%20~%20%2C)%7D%5D__/__(%7B%5B%20%25%20%26%20%24%20%23%20%40%20%60%20~%20%2C)%7D%5D__.json#/definitions/__%3C(%7B%5B%20%25%20%26%20%24%20%23%20%40%20%2B%20%3D%20%3F%20%5C%20%2F%20%22%20'%20'%20%60%20~%20%2C%20%3B%20%3A%20%3E)%7D%5D__", - }, - }, - }, - - file: { - definitions: { - foo: { - type: "object", - description: "Testing file/folder names with spaces and special characters", - }, - "__<({[ % & $ # @ + = ? \\ / \" ' ' ` ~ , ; : >)}]__": { - type: "object", - description: "Testing internal $refs with spaces and special characters", - }, - }, - }, -}; diff --git a/test/__IGNORED__/__({[ % & $ # @ ` ~ ,)}]__/special-characters.spec.ts b/test/__IGNORED__/__({[ % & $ # @ ` ~ ,)}]__/special-characters.spec.ts deleted file mode 100644 index 9f39c344..00000000 --- a/test/__IGNORED__/__({[ % & $ # @ ` ~ ,)}]__/special-characters.spec.ts +++ /dev/null @@ -1,53 +0,0 @@ -import $RefParser from "../../../lib"; -import helper from "../../utils/helper"; -import path from "../../utils/path"; -import { describe, it } from "vitest"; -import parsedSchema from "./parsed"; -import dereferencedSchema from "./dereferenced"; - -import { expect } from "vitest"; - -describe("File names with special characters", () => { - it("should parse successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.parse( - path.rel("test/specs/__({[ % & $ # @ ` ~ ,)}]__/__({[ % & $ # @ ` ~ ,)}]__.yaml"), - ); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(parsedSchema.schema); - expect(parser.$refs.paths()).to.deep.equal([ - path.abs("test/specs/__({[ % & $ # @ ` ~ ,)}]__/__({[ % & $ # @ ` ~ ,)}]__.yaml"), - ]); - }); - - it( - "should resolve successfully", - helper.testResolve( - path.rel("test/specs/__({[ % & $ # @ ` ~ ,)}]__/__({[ % & $ # @ ` ~ ,)}]__.yaml"), - path.abs("test/specs/__({[ % & $ # @ ` ~ ,)}]__/__({[ % & $ # @ ` ~ ,)}]__.yaml"), - parsedSchema.schema, - path.abs("test/specs/__({[ % & $ # @ ` ~ ,)}]__/__({[ % & $ # @ ` ~ ,)}]__/__({[ % & $ # @ ` ~ ,)}]__.json"), - parsedSchema.file, - ), - ); - - it("should dereference successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.dereference( - path.rel("test/specs/__({[ % & $ # @ ` ~ ,)}]__/__({[ % & $ # @ ` ~ ,)}]__.yaml"), - ); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(dereferencedSchema); - // The "circular" flag should NOT be set - expect(parser.$refs.circular).to.equal(false); - }); - - it("should bundle successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.bundle( - path.rel("test/specs/__({[ % & $ # @ ` ~ ,)}]__/__({[ % & $ # @ ` ~ ,)}]__.yaml"), - ); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(dereferencedSchema); - }); -}); diff --git a/test/fixtures/server.ts b/test/fixtures/server.ts deleted file mode 100644 index f0fd2881..00000000 --- a/test/fixtures/server.ts +++ /dev/null @@ -1,68 +0,0 @@ -console.log(` - -Setting up vitest in browser env... - -`); -import { dirname, join } from "path"; -import http from "http"; -import fs from "fs"; -import path from "path"; - -const __dirname = dirname(__filename); -const root = path.join(__dirname, "..", ".."); -const setup = async () => { - const server = http - .createServer(function (request, response) { - const filePath = "." + request.url; - - const extname = path.extname(filePath); - let contentType = "text/html"; - switch (extname) { - case ".js": - contentType = "text/javascript"; - break; - case ".css": - contentType = "text/css"; - break; - case ".json": - contentType = "application/json"; - break; - case ".png": - contentType = "image/png"; - break; - case ".jpg": - contentType = "image/jpg"; - break; - case ".wav": - contentType = "audio/wav"; - break; - } - - fs.readFile(join(root, filePath), function (error, content) { - if (error) { - if (error.code == "ENOENT") { - response.writeHead(404); - response.end("Sorry, check with the site admin for error: " + error.code + " ..\n"); - response.end(); - } else { - response.writeHead(500); - response.end("Sorry, check with the site admin for error: " + error.code + " ..\n"); - response.end(); - } - } else { - response.writeHead(200, { "Content-Type": contentType }); - response.end(content, "utf-8"); - } - }); - }) - .listen(3000); - - return () => { - // teardown - if (server) { - server.close(); - } - }; -}; - -export default setup; diff --git a/test/specs/absolute-root/absolute-root.spec.ts b/test/specs/absolute-root/absolute-root.spec.ts deleted file mode 100644 index 60143914..00000000 --- a/test/specs/absolute-root/absolute-root.spec.ts +++ /dev/null @@ -1,125 +0,0 @@ -import { describe, it, beforeEach, afterEach } from "vitest"; -import { resolve } from "path"; -import $RefParser from "../../../lib/index.js"; -import path from "../../utils/path.js"; -import helper from "../../utils/helper.js"; -import * as urlModule from "../../../lib/util/url.js"; -import parsedSchema from "./parsed.js"; -import dereferencedSchema from "./dereferenced.js"; -import bundledSchema from "./bundled.js"; - -import { expect } from "vitest"; -const url = { cwd: urlModule.cwd }; - -describe("When executed in the context of root directory", () => { - // Store the OS root directory - const root = resolve("/"); - - // Store references to the original methods - const originalProcessCwd = process.cwd; - const originalUrlCwd = url.cwd; - - /** - * A mock `process.cwd()` implementation that always returns the root diretory - */ - function mockProcessCwd() { - return root; - } - - /** - * Temporarily mocks `process.cwd()` while calling the real `url.cwd()` implemenation - */ - function mockUrlCwd() { - try { - process.cwd = mockProcessCwd; - // @ts-expect-error TS(2345): Argument of type 'IArguments' is not assignable to... Remove this comment to see the full error message - return originalUrlCwd.apply(null, arguments); - } finally { - process.cwd = originalProcessCwd; - } - } - - beforeEach(() => { - url.cwd = mockUrlCwd; - }); - - afterEach(() => { - url.cwd = originalUrlCwd; - process.cwd = originalProcessCwd; // already restored by the finally block above, but just in case - }); - - it("should parse successfully from an absolute path", async () => { - const parser = new $RefParser(); - const schema = await parser.parse(path.abs("test/specs/absolute-root/absolute-root.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(parsedSchema.schema); - expect(parser.$refs.paths()).to.deep.equal([path.abs("test/specs/absolute-root/absolute-root.yaml")]); - }); - - it("should parse successfully from a url", async () => { - const parser = new $RefParser(); - const schema = await parser.parse(path.url("test/specs/absolute-root/absolute-root.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(parsedSchema.schema); - expect(parser.$refs.paths()).to.deep.equal([path.url("test/specs/absolute-root/absolute-root.yaml")]); - }); - - it( - "should resolve successfully from an absolute path", - helper.testResolve( - path.abs("test/specs/absolute-root/absolute-root.yaml"), - path.abs("test/specs/absolute-root/absolute-root.yaml"), - parsedSchema.schema, - path.abs("test/specs/absolute-root/definitions/definitions.json"), - parsedSchema.definitions, - path.abs("test/specs/absolute-root/definitions/name.yaml"), - parsedSchema.name, - path.abs("test/specs/absolute-root/definitions/required-string.yaml"), - parsedSchema.requiredString, - ), - ); - - it( - "should resolve successfully from a url", - helper.testResolve( - path.url("test/specs/absolute-root/absolute-root.yaml"), - path.url("test/specs/absolute-root/absolute-root.yaml"), - parsedSchema.schema, - path.url("test/specs/absolute-root/definitions/definitions.json"), - parsedSchema.definitions, - path.url("test/specs/absolute-root/definitions/name.yaml"), - parsedSchema.name, - path.url("test/specs/absolute-root/definitions/required-string.yaml"), - parsedSchema.requiredString, - ), - ); - - it("should dereference successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.dereference(path.abs("test/specs/absolute-root/absolute-root.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(dereferencedSchema); - // Reference equality - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - expect(schema.properties.name).to.equal(schema.definitions.name); - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - expect(schema.definitions["required string"]) - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - .to.equal(schema.definitions.name.properties.first) - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - .to.equal(schema.definitions.name.properties.last) - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - .to.equal(schema.properties.name.properties.first) - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - .to.equal(schema.properties.name.properties.last); - // The "circular" flag should NOT be set - expect(parser.$refs.circular).to.equal(false); - }); - - it("should bundle successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.bundle(path.abs("test/specs/absolute-root/absolute-root.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(bundledSchema); - }); -}); diff --git a/test/specs/absolute-root/absolute-root.yaml b/test/specs/absolute-root/absolute-root.yaml deleted file mode 100644 index 89464c9d..00000000 --- a/test/specs/absolute-root/absolute-root.yaml +++ /dev/null @@ -1,17 +0,0 @@ -title: Person -type: object -required: - - name -properties: - name: - $ref: "#/definitions/name" - age: - type: integer - minimum: 0 - gender: - type: string - enum: - - male - - female -definitions: - $ref: definitions/definitions.json diff --git a/test/specs/absolute-root/bundled.ts b/test/specs/absolute-root/bundled.ts deleted file mode 100644 index 950730a1..00000000 --- a/test/specs/absolute-root/bundled.ts +++ /dev/null @@ -1,58 +0,0 @@ -export default { - title: "Person", - type: "object", - required: ["name"], - properties: { - name: { - $ref: "#/definitions/name", - }, - age: { - type: "integer", - minimum: 0, - }, - gender: { - type: "string", - enum: ["male", "female"], - }, - }, - definitions: { - "required string": { - title: "required string", - type: "string", - minLength: 1, - }, - string: { - $ref: "#/definitions/required%20string/type", - }, - name: { - title: "name", - type: "object", - required: ["first", "last"], - properties: { - first: { - $ref: "#/definitions/required%20string", - }, - last: { - $ref: "#/definitions/required%20string", - }, - middle: { - type: { - $ref: "#/definitions/required%20string/type", - }, - minLength: { - $ref: "#/definitions/required%20string/minLength", - }, - }, - prefix: { - $ref: "#/definitions/required%20string", - minLength: 3, - }, - suffix: { - $ref: "#/definitions/name/properties/prefix", - type: "string", - maxLength: 3, - }, - }, - }, - }, -}; diff --git a/test/specs/absolute-root/definitions/definitions.json b/test/specs/absolute-root/definitions/definitions.json deleted file mode 100644 index 9c1cd400..00000000 --- a/test/specs/absolute-root/definitions/definitions.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "required string": { - "$ref": "required-string.yaml" - }, - "string": { - "$ref": "#/required%20string/type" - }, - "name": { - "$ref": "../definitions/name.yaml" - } -} diff --git a/test/specs/absolute-root/definitions/name.yaml b/test/specs/absolute-root/definitions/name.yaml deleted file mode 100644 index 1210ac45..00000000 --- a/test/specs/absolute-root/definitions/name.yaml +++ /dev/null @@ -1,22 +0,0 @@ -title: name -type: object -required: - - first - - last -properties: - first: - $ref: ../definitions/definitions.json#/required string - last: - $ref: ./required-string.yaml - middle: - type: - $ref: "#/properties/first/type" - minLength: - $ref: "#/properties/first/minLength" - prefix: - $ref: "#/properties/last" - minLength: 3 - suffix: - type: string - $ref: "#/properties/prefix" - maxLength: 3 diff --git a/test/specs/absolute-root/definitions/required-string.yaml b/test/specs/absolute-root/definitions/required-string.yaml deleted file mode 100644 index 7e538a3c..00000000 --- a/test/specs/absolute-root/definitions/required-string.yaml +++ /dev/null @@ -1,3 +0,0 @@ -title: required string -type: string -minLength: 1 diff --git a/test/specs/absolute-root/dereferenced.ts b/test/specs/absolute-root/dereferenced.ts deleted file mode 100644 index 08a960f7..00000000 --- a/test/specs/absolute-root/dereferenced.ts +++ /dev/null @@ -1,87 +0,0 @@ -export default { - title: "Person", - type: "object", - required: ["name"], - properties: { - name: { - title: "name", - type: "object", - required: ["first", "last"], - properties: { - first: { - title: "required string", - type: "string", - minLength: 1, - }, - last: { - title: "required string", - type: "string", - minLength: 1, - }, - middle: { - type: "string", - minLength: 1, - }, - prefix: { - title: "required string", - type: "string", - minLength: 3, - }, - suffix: { - title: "required string", - type: "string", - minLength: 3, - maxLength: 3, - }, - }, - }, - age: { - type: "integer", - minimum: 0, - }, - gender: { - type: "string", - enum: ["male", "female"], - }, - }, - definitions: { - "required string": { - title: "required string", - type: "string", - minLength: 1, - }, - string: "string", - name: { - title: "name", - type: "object", - required: ["first", "last"], - properties: { - first: { - title: "required string", - type: "string", - minLength: 1, - }, - last: { - title: "required string", - type: "string", - minLength: 1, - }, - middle: { - type: "string", - minLength: 1, - }, - prefix: { - title: "required string", - type: "string", - minLength: 3, - }, - suffix: { - title: "required string", - type: "string", - minLength: 3, - maxLength: 3, - }, - }, - }, - }, -}; diff --git a/test/specs/absolute-root/empty-object.json b/test/specs/absolute-root/empty-object.json deleted file mode 100644 index 0967ef42..00000000 --- a/test/specs/absolute-root/empty-object.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/test/specs/absolute-root/parsed.ts b/test/specs/absolute-root/parsed.ts deleted file mode 100644 index 982658ff..00000000 --- a/test/specs/absolute-root/parsed.ts +++ /dev/null @@ -1,72 +0,0 @@ -export default { - schema: { - definitions: { - $ref: "definitions/definitions.json", - }, - required: ["name"], - type: "object", - properties: { - gender: { - enum: ["male", "female"], - type: "string", - }, - age: { - minimum: 0, - type: "integer", - }, - name: { - $ref: "#/definitions/name", - }, - }, - title: "Person", - }, - - definitions: { - "required string": { - $ref: "required-string.yaml", - }, - string: { - $ref: "#/required%20string/type", - }, - name: { - $ref: "../definitions/name.yaml", - }, - }, - - name: { - required: ["first", "last"], - type: "object", - properties: { - middle: { - minLength: { - $ref: "#/properties/first/minLength", - }, - type: { - $ref: "#/properties/first/type", - }, - }, - prefix: { - minLength: 3, - $ref: "#/properties/last", - }, - last: { - $ref: "./required-string.yaml", - }, - suffix: { - $ref: "#/properties/prefix", - type: "string", - maxLength: 3, - }, - first: { - $ref: "../definitions/definitions.json#/required string", - }, - }, - title: "name", - }, - - requiredString: { - minLength: 1, - type: "string", - title: "required string", - }, -}; diff --git a/test/specs/blank/blank.spec.ts b/test/specs/blank/blank.spec.ts deleted file mode 100644 index 37dc8443..00000000 --- a/test/specs/blank/blank.spec.ts +++ /dev/null @@ -1,112 +0,0 @@ -import { describe, it } from "vitest"; -import $RefParser from "../../../lib/index.js"; -import helper from "../../utils/helper.js"; -import path from "../../utils/path.js"; -import parsedSchema from "./parsed.js"; -import dereferencedSchema from "./dereferenced.js"; - -import { expect } from "vitest"; - -describe("Blank files", () => { - describe("main file", () => { - it("should throw an error for a blank YAML file", async () => { - try { - await $RefParser.parse(path.rel("test/specs/blank/files/blank.yaml")); - helper.shouldNotGetCalled(); - } catch (err) { - expect(err).to.be.an.instanceOf(SyntaxError); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain("blank/files/blank.yaml"); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain("is not a valid JSON Schema"); - } - }); - - it('should throw a different error if "parse.yaml.allowEmpty" is disabled', async () => { - try { - await $RefParser.parse(path.rel("test/specs/blank/files/blank.yaml"), { - parse: { yaml: { allowEmpty: false } }, - }); - helper.shouldNotGetCalled(); - } catch (err) { - expect(err).to.be.an.instanceOf(SyntaxError); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain("Error parsing "); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain("blank/files/blank.yaml"); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain("Parsed value is empty"); - } - }); - - it("should throw an error for a blank JSON file", async () => { - try { - await $RefParser.parse(path.rel("test/specs/blank/files/blank.json"), { - parse: { json: { allowEmpty: false } }, - }); - helper.shouldNotGetCalled(); - } catch (err) { - expect(err).to.be.an.instanceOf(SyntaxError); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain("Error parsing "); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain("blank/files/blank.json"); - } - }); - }); - - describe("referenced files", () => { - it("should parse successfully", async () => { - const schema = await $RefParser.parse(path.rel("test/specs/blank/blank.yaml")); - expect(schema).to.deep.equal(parsedSchema.schema); - }); - - it( - "should resolve successfully", - helper.testResolve( - path.rel("test/specs/blank/blank.yaml"), - path.abs("test/specs/blank/blank.yaml"), - parsedSchema.schema, - path.abs("test/specs/blank/files/blank.yaml"), - parsedSchema.yaml, - path.abs("test/specs/blank/files/blank.json"), - parsedSchema.json, - path.abs("test/specs/blank/files/blank.txt"), - parsedSchema.text, - path.abs("test/specs/blank/files/blank.png"), - parsedSchema.binary, - path.abs("test/specs/blank/files/blank.foo"), - parsedSchema.unknown, - ), - ); - - it("should dereference successfully", async () => { - const schema = await $RefParser.dereference(path.rel("test/specs/blank/blank.yaml")); - schema.binary = helper.convertNodeBuffersToPOJOs(schema.binary); - expect(schema).to.deep.equal(dereferencedSchema); - }); - - it("should bundle successfully", async () => { - const schema = await $RefParser.bundle(path.rel("test/specs/blank/blank.yaml")); - schema.binary = helper.convertNodeBuffersToPOJOs(schema.binary); - expect(schema).to.deep.equal(dereferencedSchema); - }); - - it('should throw an error if "allowEmpty" is disabled', async () => { - try { - await $RefParser.dereference(path.rel("test/specs/blank/blank.yaml"), { - parse: { binary: { allowEmpty: false } }, - }); - helper.shouldNotGetCalled(); - } catch (err) { - expect(err).to.be.an.instanceOf(SyntaxError); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain("Error parsing "); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain("blank/files/blank.png"); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain("Parsed value is empty"); - } - }); - }); -}); diff --git a/test/specs/blank/blank.yaml b/test/specs/blank/blank.yaml deleted file mode 100644 index 5d174739..00000000 --- a/test/specs/blank/blank.yaml +++ /dev/null @@ -1,10 +0,0 @@ -json: - $ref: files/blank.json -yaml: - $ref: files/blank.yaml -text: - $ref: files/blank.txt -binary: - $ref: files/blank.png -unknown: - $ref: files/blank.foo diff --git a/test/specs/blank/dereferenced.ts b/test/specs/blank/dereferenced.ts deleted file mode 100644 index c94cb4ab..00000000 --- a/test/specs/blank/dereferenced.ts +++ /dev/null @@ -1,7 +0,0 @@ -export default { - json: undefined, - yaml: undefined, - text: "", - binary: { type: "Buffer", data: [] }, - unknown: undefined, -}; diff --git a/test/specs/blank/files/blank.foo b/test/specs/blank/files/blank.foo deleted file mode 100644 index e69de29b..00000000 diff --git a/test/specs/blank/files/blank.json b/test/specs/blank/files/blank.json deleted file mode 100644 index e69de29b..00000000 diff --git a/test/specs/blank/files/blank.png b/test/specs/blank/files/blank.png deleted file mode 100644 index e69de29b..00000000 diff --git a/test/specs/blank/files/blank.txt b/test/specs/blank/files/blank.txt deleted file mode 100644 index e69de29b..00000000 diff --git a/test/specs/blank/files/blank.yaml b/test/specs/blank/files/blank.yaml deleted file mode 100644 index e69de29b..00000000 diff --git a/test/specs/blank/parsed.ts b/test/specs/blank/parsed.ts deleted file mode 100644 index 7c43ecf0..00000000 --- a/test/specs/blank/parsed.ts +++ /dev/null @@ -1,29 +0,0 @@ -export default { - schema: { - yaml: { - $ref: "files/blank.yaml", - }, - json: { - $ref: "files/blank.json", - }, - text: { - $ref: "files/blank.txt", - }, - binary: { - $ref: "files/blank.png", - }, - unknown: { - $ref: "files/blank.foo", - }, - }, - - yaml: undefined, - - json: undefined, - - text: "", - - binary: { type: "Buffer", data: [] }, - - unknown: undefined, -}; diff --git a/test/specs/bundle/bundle.spec.ts b/test/specs/bundle/bundle.spec.ts deleted file mode 100644 index a7de64f8..00000000 --- a/test/specs/bundle/bundle.spec.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { describe, it } from "vitest"; -import { expect } from "vitest"; -import $RefParser from "../../../lib/index.js"; -import path from "../../utils/path"; -import dereferencedSchema from "./bundled"; - -describe("Bundles", () => { - it("should bundle correctly", async () => { - const parser = new $RefParser(); - const schema = path.rel("test/specs/bundle/schemaA.json"); - const bundled = await parser.bundle(schema); - expect(bundled).to.deep.equal(dereferencedSchema); - }); -}); diff --git a/test/specs/bundle/bundled.ts b/test/specs/bundle/bundled.ts deleted file mode 100644 index 31cceef8..00000000 --- a/test/specs/bundle/bundled.ts +++ /dev/null @@ -1,32 +0,0 @@ -export default { - $id: "schemaA/1.0", - $schema: "http://json-schema.org/draft-07/schema#", - type: "object", - properties: { - purchaseRate: { - allOf: [ - { - type: "object", - properties: { - amount: { - type: "number", - format: "float", - }, - }, - }, - { - type: "object", - $ref: "#/properties/fee/properties/modificationFee/properties/amount", - }, - ], - }, - fee: { - type: "object", - properties: { - modificationFee: { - $ref: "#/properties/purchaseRate/allOf/0", - }, - }, - }, - }, -}; diff --git a/test/specs/bundle/schemaA.json b/test/specs/bundle/schemaA.json deleted file mode 100644 index d1a6b0a9..00000000 --- a/test/specs/bundle/schemaA.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "$id": "schemaA/1.0", - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "object", - "$ref": "schemaB.json#/definitions/SupplierPriceElement" -} diff --git a/test/specs/bundle/schemaB.json b/test/specs/bundle/schemaB.json deleted file mode 100644 index 2aaba39c..00000000 --- a/test/specs/bundle/schemaB.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "$id": "schemaC/1.0", - "$schema": "http://json-schema.org/draft-07/schema#", - "definitions": { - "SupplierPriceElement": { - "type": "object", - "properties": { - "fee": { - "$ref": "#/definitions/AllFees" - }, - "purchaseRate": { - "$ref": "#/definitions/InDetailParent" - } - } - }, - "AllFees": { - "type": "object", - "properties": { - "modificationFee": { - "$ref": "#/definitions/MonetaryAmount" - } - } - }, - "MonetaryAmount": { - "type": "object", - "properties": { - "amount": { - "$ref": "#/definitions/Amount" - } - } - }, - "Amount": { - "type": "number", - "format": "float" - }, - "InDetailParent": { - "allOf": [ - { - "$ref": "#/definitions/MonetaryAmount" - }, - { - "type": "object", - "$ref": "#/definitions/Amount" - } - ] - } - } -} diff --git a/test/specs/callbacks.spec.ts b/test/specs/callbacks.spec.ts deleted file mode 100644 index c3398070..00000000 --- a/test/specs/callbacks.spec.ts +++ /dev/null @@ -1,84 +0,0 @@ -import { describe, it } from "vitest"; -import $RefParser from "../../lib/index.js"; -import helper from "../utils/helper.js"; -import path from "../utils/path.js"; -import { ParserError } from "../../lib/util/errors.js"; - -import { expect } from "vitest"; - -describe("Callback & Promise syntax", () => { - const methods = ["parse", "resolve", "dereference", "bundle"] as const; - for (const method of methods) { - describe(method + " method", () => { - it("should call the callback function upon success", testCallbackSuccess(method)); - it("should call the callback function upon failure", testCallbackError(method)); - it("should resolve the Promise upon success", testPromiseSuccess(method)); - it("should reject the Promise upon failure", testPromiseError(method)); - }); - } - - function testCallbackSuccess(method: (typeof methods)[number]) { - return () => - new Promise((resolve, reject) => { - const parser = new $RefParser(); - parser[method](path.rel("test/specs/internal/internal.yaml"), (err: any, result: any) => { - try { - expect(err).to.equal(null); - expect(result).to.be.an("object"); - - if (method === "resolve") { - expect(result).to.equal(parser.$refs); - } else { - expect(result).to.equal(parser.schema); - } - resolve(); - } catch (e) { - reject(e); - } - }); - }); - } - - function testCallbackError(method: (typeof methods)[number]) { - return () => - new Promise((resolve, reject) => { - // @ts-ignore - $RefParser[method](path.rel("test/specs/invalid/invalid.yaml"), (err: any, result: any) => { - try { - expect(err).to.be.an.instanceOf(ParserError); - expect(result).to.equal(undefined); - resolve(); - } catch (e) { - reject(e); - } - }); - }); - } - - function testPromiseSuccess(method: (typeof methods)[number]) { - return function () { - const parser = new $RefParser(); - return parser[method](path.rel("test/specs/internal/internal.yaml")).then((result: any) => { - expect(result).to.be.an("object"); - - if (method === "resolve") { - expect(result).to.equal(parser.$refs); - } else { - expect(result).to.equal(parser.schema); - } - }); - }; - } - - function testPromiseError(method: (typeof methods)[number]) { - return async function () { - try { - // @ts-ignore - await $RefParser[method](path.rel("test/specs/invalid/invalid.yaml")); - helper.shouldNotGetCalled(); - } catch (err: any) { - expect(err).to.be.an.instanceOf(ParserError); - } - }; - } -}); diff --git a/test/specs/circular-extended/bundled.ts b/test/specs/circular-extended/bundled.ts deleted file mode 100644 index edfad057..00000000 --- a/test/specs/circular-extended/bundled.ts +++ /dev/null @@ -1,147 +0,0 @@ -const bundledSchema = { - self: { - definitions: { - thing: { - title: "thing", - $ref: "#/definitions/thing", - description: - "This JSON Reference has additional properties (other than $ref). Normally, this creates a new type that extends the referenced type, but since this reference points to ITSELF, it doesn't do that.\n", - }, - }, - }, - - pet: { - title: "pet", - type: "object", - properties: { - age: { - type: "number", - }, - name: { - type: "string", - }, - species: { - type: "string", - enum: ["cat", "dog", "bird", "fish"], - }, - }, - }, - - ancestor: { - definitions: { - person: { - title: "person", - properties: { - spouse: { - $ref: "#/definitions/person", - description: - 'This JSON Reference has additional properties (other than $ref). This creates a new type that extends "person".\n', - }, - pet: { - $ref: "#/definitions/pet", - description: - 'This JSON Reference has additional properties (other than $ref). This creates a new type that extends "pet".\n', - }, - name: { - type: "string", - }, - }, - }, - pet: null, - }, - }, - - indirect: { - definitions: { - parent: { - title: "parent", - properties: { - name: { - type: "string", - }, - children: { - items: { - $ref: "#/definitions/child", - description: - 'This JSON Reference has additional properties (other than $ref). This creates a new type that extends "child".\n', - }, - type: "array", - }, - }, - }, - child: { - title: "child", - properties: { - parents: { - items: { - $ref: "#/definitions/parent", - description: - 'This JSON Reference has additional properties (other than $ref). This creates a new type that extends "parent".\n', - }, - type: "array", - }, - pet: { - $ref: "#/definitions/pet", - description: - 'This JSON Reference has additional properties (other than $ref). This creates a new type that extends "pet".\n', - }, - name: { - type: "string", - }, - }, - }, - pet: null, - }, - }, - - indirectAncestor: { - definitions: { - pet: null, - parent: { - title: "parent", - properties: { - name: { - type: "string", - }, - child: { - $ref: "#/definitions/child", - description: - 'This JSON Reference has additional properties (other than $ref). This creates a new type that extends "child".\n', - }, - }, - }, - child: { - title: "child", - properties: { - pet: { - $ref: "#/definitions/pet", - description: - 'This JSON Reference has additional properties (other than $ref). This creates a new type that extends "pet".\n', - }, - name: { - type: "string", - }, - children: { - items: { - $ref: "#/definitions/child", - description: - 'This JSON Reference has additional properties (other than $ref). This creates a new type that extends "child".\n', - }, - type: "array", - description: "children", - }, - }, - }, - }, - }, -}; - -// @ts-expect-error TS(2322): Type '{ title: string; type: string; properties: {... Remove this comment to see the full error message -bundledSchema.ancestor.definitions.pet = - // @ts-expect-error TS(2322): Type '{ title: string; type: string; properties: {... Remove this comment to see the full error message - bundledSchema.indirect.definitions.pet = - // @ts-expect-error TS(2322): Type '{ title: string; type: string; properties: {... Remove this comment to see the full error message - bundledSchema.indirectAncestor.definitions.pet = - bundledSchema.pet; - -export default bundledSchema; diff --git a/test/specs/circular-extended/circular-extended-ancestor.yaml b/test/specs/circular-extended/circular-extended-ancestor.yaml deleted file mode 100644 index 1e6b0609..00000000 --- a/test/specs/circular-extended/circular-extended-ancestor.yaml +++ /dev/null @@ -1,6 +0,0 @@ -definitions: - person: - $ref: definitions/person-with-spouse.yaml - - pet: - $ref: definitions/pet.yaml diff --git a/test/specs/circular-extended/circular-extended-indirect-ancestor.yaml b/test/specs/circular-extended/circular-extended-indirect-ancestor.yaml deleted file mode 100644 index ab476d6b..00000000 --- a/test/specs/circular-extended/circular-extended-indirect-ancestor.yaml +++ /dev/null @@ -1,9 +0,0 @@ -definitions: - parent: - $ref: definitions/parent-with-child.yaml - - child: - $ref: definitions/child-with-children.yaml - - pet: - $ref: definitions/pet.yaml diff --git a/test/specs/circular-extended/circular-extended-indirect.yaml b/test/specs/circular-extended/circular-extended-indirect.yaml deleted file mode 100644 index 51bfda63..00000000 --- a/test/specs/circular-extended/circular-extended-indirect.yaml +++ /dev/null @@ -1,9 +0,0 @@ -definitions: - parent: - $ref: definitions/parent-with-children.yaml - - child: - $ref: definitions/child-with-parents.yaml - - pet: - $ref: definitions/pet.yaml diff --git a/test/specs/circular-extended/circular-extended-self.yaml b/test/specs/circular-extended/circular-extended-self.yaml deleted file mode 100644 index a00b8893..00000000 --- a/test/specs/circular-extended/circular-extended-self.yaml +++ /dev/null @@ -1,3 +0,0 @@ -definitions: - thing: - $ref: "definitions/thing.yaml" diff --git a/test/specs/circular-extended/circular-extended.spec.ts b/test/specs/circular-extended/circular-extended.spec.ts deleted file mode 100644 index a8949c66..00000000 --- a/test/specs/circular-extended/circular-extended.spec.ts +++ /dev/null @@ -1,384 +0,0 @@ -import { describe, it } from "vitest"; -import $RefParser from "../../../lib/index.js"; -import helper from "../../utils/helper.js"; -import path from "../../utils/path.js"; -import parsedSchema from "./parsed.js"; -import dereferencedSchema from "./dereferenced.js"; -import bundledSchema from "./bundled.js"; - -import { expect } from "vitest"; - -describe("Schema with circular $refs that extend each other", () => { - describe("$ref to self", () => { - it("should parse successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.parse(path.rel("test/specs/circular-extended/circular-extended-self.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(parsedSchema.self); - expect(parser.$refs.paths()).to.deep.equal([ - path.abs("test/specs/circular-extended/circular-extended-self.yaml"), - ]); - // The "circular" flag should NOT be set - // (it only gets set by `dereference`) - expect(parser.$refs.circular).to.equal(false); - }); - - it( - "should resolve successfully", - helper.testResolve( - path.rel("test/specs/circular-extended/circular-extended-self.yaml"), - path.abs("test/specs/circular-extended/circular-extended-self.yaml"), - parsedSchema.self, - path.abs("test/specs/circular-extended/definitions/thing.yaml"), - parsedSchema.thing, - ), - ); - - it("should dereference successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.dereference(path.rel("test/specs/circular-extended/circular-extended-self.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(dereferencedSchema.self); - // The "circular" flag should be set - expect(parser.$refs.circular).to.equal(true); - }); - - it('should not dereference circular $refs if "options.$refs.circular" is "ignore"', async () => { - const parser = new $RefParser(); - - const schema = await parser.dereference(path.rel("test/specs/circular-extended/circular-extended-self.yaml"), { - dereference: { circular: "ignore" }, - }); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(dereferencedSchema.self); - // The "circular" flag should be set - expect(parser.$refs.circular).to.equal(true); - }); - - it('should throw an error if "options.$refs.circular" is false', async () => { - const parser = new $RefParser(); - - try { - await parser.dereference(path.rel("test/specs/circular-extended/circular-extended-self.yaml"), { - dereference: { circular: false }, - }); - helper.shouldNotGetCalled(); - } catch (err) { - // A ReferenceError should have been thrown - expect(err).to.be.an.instanceOf(ReferenceError); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain("Circular $ref pointer found at "); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain("specs/circular-extended/circular-extended-self.yaml#/definitions/thing"); - - // $Refs.circular should be true - expect(parser.$refs.circular).to.equal(true); - } - }); - - it("should bundle successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.bundle(path.rel("test/specs/circular-extended/circular-extended-self.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(bundledSchema.self); - // The "circular" flag should NOT be set - // (it only gets set by `dereference`) - expect(parser.$refs.circular).to.equal(false); - }); - }); - - describe("$ref to ancestor", () => { - it("should parse successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.parse(path.rel("test/specs/circular-extended/circular-extended-ancestor.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(parsedSchema.ancestor); - expect(parser.$refs.paths()).to.deep.equal([ - path.abs("test/specs/circular-extended/circular-extended-ancestor.yaml"), - ]); - // The "circular" flag should NOT be set - // (it only gets set by `dereference`) - expect(parser.$refs.circular).to.equal(false); - }); - - it( - "should resolve successfully", - helper.testResolve( - path.rel("test/specs/circular-extended/circular-extended-ancestor.yaml"), - path.abs("test/specs/circular-extended/circular-extended-ancestor.yaml"), - parsedSchema.ancestor, - path.abs("test/specs/circular-extended/definitions/person-with-spouse.yaml"), - parsedSchema.personWithSpouse, - path.abs("test/specs/circular-extended/definitions/pet.yaml"), - parsedSchema.pet, - path.abs("test/specs/circular-extended/definitions/animals.yaml"), - parsedSchema.animals, - ), - ); - - it("should dereference successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.dereference(path.rel("test/specs/circular-extended/circular-extended-ancestor.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(dereferencedSchema.ancestor.fullyDereferenced); - // The "circular" flag should be set - expect(parser.$refs.circular).to.equal(true); - // Reference equality - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - expect(schema.definitions.person.properties.spouse.properties).to.equal(schema.definitions.person.properties); - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - expect(schema.definitions.person.properties.pet.properties).to.equal(schema.definitions.pet.properties); - }); - - it('should not dereference circular $refs if "options.$refs.circular" is "ignore"', async () => { - const parser = new $RefParser(); - - const schema = await parser.dereference( - path.rel("test/specs/circular-extended/circular-extended-ancestor.yaml"), - { - dereference: { circular: "ignore" }, - }, - ); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(dereferencedSchema.ancestor.ignoreCircular$Refs); - // The "circular" flag should be set - expect(parser.$refs.circular).to.equal(true); - }); - - it('should throw an error if "options.$refs.circular" is false', async () => { - const parser = new $RefParser(); - - try { - await parser.dereference(path.rel("test/specs/circular-extended/circular-extended-ancestor.yaml"), { - dereference: { circular: false }, - }); - helper.shouldNotGetCalled(); - } catch (err) { - // A ReferenceError should have been thrown - expect(err).to.be.an.instanceOf(ReferenceError); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain("Circular $ref pointer found at "); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain( - "specs/circular-extended/definitions/person-with-spouse.yaml#/properties/spouse", - ); - - // $Refs.circular should be true - expect(parser.$refs.circular).to.equal(true); - } - }); - - it("should bundle successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.bundle(path.rel("test/specs/circular-extended/circular-extended-ancestor.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(bundledSchema.ancestor); - // The "circular" flag should NOT be set - // (it only gets set by `dereference`) - expect(parser.$refs.circular).to.equal(false); - }); - }); - - describe("indirect circular $refs", () => { - it("should parse successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.parse(path.rel("test/specs/circular-extended/circular-extended-indirect.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(parsedSchema.indirect); - expect(parser.$refs.paths()).to.deep.equal([ - path.abs("test/specs/circular-extended/circular-extended-indirect.yaml"), - ]); - // The "circular" flag should NOT be set - // (it only gets set by `dereference`) - expect(parser.$refs.circular).to.equal(false); - }); - - it( - "should resolve successfully", - helper.testResolve( - path.rel("test/specs/circular-extended/circular-extended-indirect.yaml"), - path.abs("test/specs/circular-extended/circular-extended-indirect.yaml"), - parsedSchema.indirect, - path.abs("test/specs/circular-extended/definitions/parent-with-children.yaml"), - parsedSchema.parentWithChildren, - path.abs("test/specs/circular-extended/definitions/child-with-parents.yaml"), - parsedSchema.childWithParents, - path.abs("test/specs/circular-extended/definitions/pet.yaml"), - parsedSchema.pet, - path.abs("test/specs/circular-extended/definitions/animals.yaml"), - parsedSchema.animals, - ), - ); - - it("should dereference successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.dereference(path.rel("test/specs/circular-extended/circular-extended-indirect.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(dereferencedSchema.indirect.fullyDereferenced); - // The "circular" flag should be set - expect(parser.$refs.circular).to.equal(true); - // Reference equality - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - expect(schema.definitions.parent.properties.children.items.properties).to.equal( - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - schema.definitions.child.properties, - ); - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - expect(schema.definitions.child.properties.parents.items.properties).to.equal( - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - schema.definitions.parent.properties, - ); - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - expect(schema.definitions.child.properties.pet.properties).to.equal(schema.definitions.pet.properties); - }); - - it('should not dereference circular $refs if "options.$refs.circular" is "ignore"', async () => { - const parser = new $RefParser(); - - const schema = await parser.dereference( - path.rel("test/specs/circular-extended/circular-extended-indirect.yaml"), - { - dereference: { circular: "ignore" }, - }, - ); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(dereferencedSchema.indirect.ignoreCircular$Refs); - // The "circular" flag should be set - expect(parser.$refs.circular).to.equal(true); - }); - - it('should throw an error if "options.$refs.circular" is false', async () => { - const parser = new $RefParser(); - - try { - await parser.dereference(path.rel("test/specs/circular-extended/circular-extended-indirect.yaml"), { - dereference: { circular: false }, - }); - helper.shouldNotGetCalled(); - } catch (err) { - // A ReferenceError should have been thrown - expect(err).to.be.an.instanceOf(ReferenceError); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain("Circular $ref pointer found at "); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain( - "specs/circular-extended/definitions/child-with-parents.yaml#/properties/parents/items", - ); - - // $Refs.circular should be true - expect(parser.$refs.circular).to.equal(true); - } - }); - - it("should bundle successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.bundle(path.rel("test/specs/circular-extended/circular-extended-indirect.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(bundledSchema.indirect); - // The "circular" flag should NOT be set - // (it only gets set by `dereference`) - expect(parser.$refs.circular).to.equal(false); - }); - }); - - describe("indirect circular and ancestor $refs", () => { - it("should parse successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.parse( - path.rel("test/specs/circular-extended/circular-extended-indirect-ancestor.yaml"), - ); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(parsedSchema.indirectAncestor); - expect(parser.$refs.paths()).to.deep.equal([ - path.abs("test/specs/circular-extended/circular-extended-indirect-ancestor.yaml"), - ]); - // The "circular" flag should NOT be set - // (it only gets set by `dereference`) - expect(parser.$refs.circular).to.equal(false); - }); - - it( - "should resolve successfully", - helper.testResolve( - path.rel("test/specs/circular-extended/circular-extended-indirect-ancestor.yaml"), - path.abs("test/specs/circular-extended/circular-extended-indirect-ancestor.yaml"), - parsedSchema.indirectAncestor, - path.abs("test/specs/circular-extended/definitions/parent-with-child.yaml"), - parsedSchema.parentWithChild, - path.abs("test/specs/circular-extended/definitions/child-with-children.yaml"), - parsedSchema.childWithChildren, - path.abs("test/specs/circular-extended/definitions/pet.yaml"), - parsedSchema.pet, - path.abs("test/specs/circular-extended/definitions/animals.yaml"), - parsedSchema.animals, - ), - ); - - it("should dereference successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.dereference( - path.rel("test/specs/circular-extended/circular-extended-indirect-ancestor.yaml"), - ); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(dereferencedSchema.indirectAncestor.fullyDereferenced); - // The "circular" flag should be set - expect(parser.$refs.circular).to.equal(true); - // Reference equality - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - expect(schema.definitions.parent.properties.child.properties).to.equal(schema.definitions.child.properties); - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - expect(schema.definitions.child.properties.children.items.properties).to.equal( - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - schema.definitions.child.properties, - ); - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - expect(schema.definitions.pet.properties).to.equal(schema.definitions.child.properties.pet.properties); - }); - - it('should not dereference circular $refs if "options.$refs.circular" is "ignore"', async () => { - const parser = new $RefParser(); - - const schema = await parser.dereference( - path.rel("test/specs/circular-extended/circular-extended-indirect-ancestor.yaml"), - { dereference: { circular: "ignore" } }, - ); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(dereferencedSchema.indirectAncestor.ignoreCircular$Refs); - // The "circular" flag should be set - expect(parser.$refs.circular).to.equal(true); - }); - - it('should throw an error if "options.$refs.circular" is false', async () => { - const parser = new $RefParser(); - - try { - await parser.dereference(path.rel("test/specs/circular-extended/circular-extended-indirect-ancestor.yaml"), { - dereference: { circular: false }, - }); - helper.shouldNotGetCalled(); - } catch (err) { - // A ReferenceError should have been thrown - expect(err).to.be.an.instanceOf(ReferenceError); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain("Circular $ref pointer found at "); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain("specs/circular-extended/definitions/child-with-children.yaml#/properties"); - - // $Refs.circular should be true - expect(parser.$refs.circular).to.equal(true); - } - }); - - it("should bundle successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.bundle( - path.rel("test/specs/circular-extended/circular-extended-indirect-ancestor.yaml"), - ); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(bundledSchema.indirectAncestor); - // The "circular" flag should NOT be set - // (it only gets set by `dereference`) - expect(parser.$refs.circular).to.equal(false); - }); - }); -}); diff --git a/test/specs/circular-extended/definitions/animals.yaml b/test/specs/circular-extended/definitions/animals.yaml deleted file mode 100644 index d7f858ae..00000000 --- a/test/specs/circular-extended/definitions/animals.yaml +++ /dev/null @@ -1,25 +0,0 @@ -definitions: - animal: - title: animal - type: object - properties: - name: - type: string - age: - type: number - - cat: - title: cat - $ref: "#/definitions/animal" - - dog: - title: dog - $ref: "#/definitions/animal" - - bird: - title: bird - $ref: "#/definitions/animal" - - fish: - title: fish - $ref: "#/definitions/animal" diff --git a/test/specs/circular-extended/definitions/child-with-children.yaml b/test/specs/circular-extended/definitions/child-with-children.yaml deleted file mode 100644 index c1814846..00000000 --- a/test/specs/circular-extended/definitions/child-with-children.yaml +++ /dev/null @@ -1,17 +0,0 @@ -title: child -properties: - name: - type: string - pet: - $ref: pet.yaml - description: > - This JSON Reference has additional properties (other than $ref). - This creates a new type that extends "pet". - children: - description: children - type: array - items: - $ref: child-with-children.yaml - description: > - This JSON Reference has additional properties (other than $ref). - This creates a new type that extends "child". diff --git a/test/specs/circular-extended/definitions/child-with-parents.yaml b/test/specs/circular-extended/definitions/child-with-parents.yaml deleted file mode 100644 index 3c6ac6b3..00000000 --- a/test/specs/circular-extended/definitions/child-with-parents.yaml +++ /dev/null @@ -1,16 +0,0 @@ -title: child -properties: - name: - type: string - pet: - $ref: pet.yaml - description: > - This JSON Reference has additional properties (other than $ref). - This creates a new type that extends "pet". - parents: - type: array - items: - $ref: parent-with-children.yaml - description: > - This JSON Reference has additional properties (other than $ref). - This creates a new type that extends "parent". diff --git a/test/specs/circular-extended/definitions/parent-with-child.yaml b/test/specs/circular-extended/definitions/parent-with-child.yaml deleted file mode 100644 index ef69fc42..00000000 --- a/test/specs/circular-extended/definitions/parent-with-child.yaml +++ /dev/null @@ -1,9 +0,0 @@ -title: parent -properties: - name: - type: string - child: - $ref: child-with-children.yaml - description: > - This JSON Reference has additional properties (other than $ref). - This creates a new type that extends "child". diff --git a/test/specs/circular-extended/definitions/parent-with-children.yaml b/test/specs/circular-extended/definitions/parent-with-children.yaml deleted file mode 100644 index b71a5366..00000000 --- a/test/specs/circular-extended/definitions/parent-with-children.yaml +++ /dev/null @@ -1,11 +0,0 @@ -title: parent -properties: - name: - type: string - children: - type: array - items: - $ref: child-with-parents.yaml - description: > - This JSON Reference has additional properties (other than $ref). - This creates a new type that extends "child". diff --git a/test/specs/circular-extended/definitions/person-with-spouse.yaml b/test/specs/circular-extended/definitions/person-with-spouse.yaml deleted file mode 100644 index f1a0842b..00000000 --- a/test/specs/circular-extended/definitions/person-with-spouse.yaml +++ /dev/null @@ -1,14 +0,0 @@ -title: person -properties: - name: - type: string - spouse: - $ref: person-with-spouse.yaml - description: > - This JSON Reference has additional properties (other than $ref). - This creates a new type that extends "person". - pet: - $ref: pet.yaml - description: > - This JSON Reference has additional properties (other than $ref). - This creates a new type that extends "pet". diff --git a/test/specs/circular-extended/definitions/pet.yaml b/test/specs/circular-extended/definitions/pet.yaml deleted file mode 100644 index 204f5c95..00000000 --- a/test/specs/circular-extended/definitions/pet.yaml +++ /dev/null @@ -1,15 +0,0 @@ -title: pet -type: - $ref: "animals.yaml#/definitions/cat/type" # <-- deep linking into an extended object -properties: - name: - $ref: "animals.yaml#/definitions/dog/properties/name" # <-- deep linking into an extended object - age: - $ref: "animals.yaml#/definitions/bird/properties/age" # <-- deep linking into an extended object - species: - type: string - enum: - - cat - - dog - - bird - - fish diff --git a/test/specs/circular-extended/definitions/thing.yaml b/test/specs/circular-extended/definitions/thing.yaml deleted file mode 100644 index f0d96b6b..00000000 --- a/test/specs/circular-extended/definitions/thing.yaml +++ /dev/null @@ -1,6 +0,0 @@ -title: thing -$ref: thing.yaml -description: > - This JSON Reference has additional properties (other than $ref). - Normally, this creates a new type that extends the referenced type, - but since this reference points to ITSELF, it doesn't do that. diff --git a/test/specs/circular-extended/dereferenced.ts b/test/specs/circular-extended/dereferenced.ts deleted file mode 100644 index 9e14550c..00000000 --- a/test/specs/circular-extended/dereferenced.ts +++ /dev/null @@ -1,228 +0,0 @@ -const dereferencedSchema = { - self: { - definitions: { - thing: { - title: "thing", - $ref: "#/definitions/thing", - description: - "This JSON Reference has additional properties (other than $ref). Normally, this creates a new type that extends the referenced type, but since this reference points to ITSELF, it doesn't do that.\n", - }, - }, - }, - - pet: { - title: "pet", - type: "object", - properties: { - age: { - type: "number", - }, - name: { - type: "string", - }, - species: { - type: "string", - enum: ["cat", "dog", "bird", "fish"], - }, - }, - }, - - ancestor: { - fullyDereferenced: { - definitions: { - person: { - title: "person", - properties: { - spouse: { - title: "person", - description: - 'This JSON Reference has additional properties (other than $ref). This creates a new type that extends "person".\n', - properties: null, - }, - pet: { - description: - 'This JSON Reference has additional properties (other than $ref). This creates a new type that extends "pet".\n', - title: "pet", - type: "object", - properties: null, - }, - name: { - type: "string", - }, - }, - }, - pet: null, - }, - }, - - ignoreCircular$Refs: { - definitions: { - person: { - $ref: "definitions/person-with-spouse.yaml", - }, - pet: null, - }, - }, - }, - - indirect: { - fullyDereferenced: { - definitions: { - parent: { - title: "parent", - properties: { - name: { - type: "string", - }, - children: { - items: { - title: "child", - description: - 'This JSON Reference has additional properties (other than $ref). This creates a new type that extends "child".\n', - properties: null, - }, - type: "array", - }, - }, - }, - child: { - title: "child", - properties: { - parents: { - items: { - title: "parent", - description: - 'This JSON Reference has additional properties (other than $ref). This creates a new type that extends "parent".\n', - properties: null, - }, - type: "array", - }, - pet: { - description: - 'This JSON Reference has additional properties (other than $ref). This creates a new type that extends "pet".\n', - title: "pet", - type: "object", - properties: null, - }, - name: { - type: "string", - }, - }, - }, - pet: null, - }, - }, - - ignoreCircular$Refs: { - definitions: { - parent: { - $ref: "definitions/parent-with-children.yaml", - }, - child: { - $ref: "definitions/child-with-parents.yaml", - }, - pet: null, - }, - }, - }, - - indirectAncestor: { - fullyDereferenced: { - definitions: { - pet: null, - parent: { - title: "parent", - properties: { - name: { - type: "string", - }, - child: { - description: - 'This JSON Reference has additional properties (other than $ref). This creates a new type that extends "child".\n', - title: "child", - properties: null, - }, - }, - }, - child: { - title: "child", - properties: { - pet: { - description: - 'This JSON Reference has additional properties (other than $ref). This creates a new type that extends "pet".\n', - title: "pet", - type: "object", - properties: null, - }, - name: { - type: "string", - }, - children: { - items: { - description: - 'This JSON Reference has additional properties (other than $ref). This creates a new type that extends "child".\n', - title: "child", - properties: null, - }, - type: "array", - description: "children", - }, - }, - }, - }, - }, - - ignoreCircular$Refs: { - definitions: { - pet: null, - parent: { - $ref: "definitions/parent-with-child.yaml", - }, - child: { - $ref: "definitions/child-with-children.yaml", - }, - }, - }, - }, -}; -// @ts-expect-error TS(2322): Type '{ title: string; type: string; properties: {... Remove this comment to see the full error message -dereferencedSchema.ancestor.fullyDereferenced.definitions.pet = - // @ts-expect-error TS(2322): Type '{ title: string; type: string; properties: {... Remove this comment to see the full error message - dereferencedSchema.ancestor.ignoreCircular$Refs.definitions.pet = - // @ts-expect-error TS(2322): Type '{ title: string; type: string; properties: {... Remove this comment to see the full error message - dereferencedSchema.indirect.fullyDereferenced.definitions.pet = - // @ts-expect-error TS(2322): Type '{ title: string; type: string; properties: {... Remove this comment to see the full error message - dereferencedSchema.indirect.ignoreCircular$Refs.definitions.pet = - // @ts-expect-error TS(2322): Type '{ title: string; type: string; properties: {... Remove this comment to see the full error message - dereferencedSchema.indirectAncestor.fullyDereferenced.definitions.pet = - // @ts-expect-error TS(2322): Type '{ title: string; type: string; properties: {... Remove this comment to see the full error message - dereferencedSchema.indirectAncestor.ignoreCircular$Refs.definitions.pet = - dereferencedSchema.pet; - -dereferencedSchema.ancestor.fullyDereferenced.definitions.person.properties.pet.properties = - dereferencedSchema.indirect.fullyDereferenced.definitions.child.properties.pet.properties = - dereferencedSchema.indirectAncestor.fullyDereferenced.definitions.child.properties.pet.properties = - // @ts-expect-error TS(2531): Object is possibly 'null'. - dereferencedSchema.ancestor.fullyDereferenced.definitions.pet.properties; - -// @ts-expect-error TS(2322): Type '{ spouse: { title: string; description: stri... Remove this comment to see the full error message -dereferencedSchema.ancestor.fullyDereferenced.definitions.person.properties.spouse.properties = - dereferencedSchema.ancestor.fullyDereferenced.definitions.person.properties; - -// @ts-expect-error TS(2322): Type '{ parents: { items: { title: string; descrip... Remove this comment to see the full error message -dereferencedSchema.indirect.fullyDereferenced.definitions.parent.properties.children.items.properties = - dereferencedSchema.indirect.fullyDereferenced.definitions.child.properties; - -// @ts-expect-error TS(2322): Type '{ name: { type: string; }; children: { items... Remove this comment to see the full error message -dereferencedSchema.indirect.fullyDereferenced.definitions.child.properties.parents.items.properties = - dereferencedSchema.indirect.fullyDereferenced.definitions.parent.properties; - -// @ts-expect-error TS(2322): Type '{ pet: { description: string; title: string;... Remove this comment to see the full error message -dereferencedSchema.indirectAncestor.fullyDereferenced.definitions.parent.properties.child.properties = - dereferencedSchema.indirectAncestor.fullyDereferenced.definitions.child.properties; - -// @ts-expect-error TS(2322): Type '{ pet: { description: string; title: string;... Remove this comment to see the full error message -dereferencedSchema.indirectAncestor.fullyDereferenced.definitions.child.properties.children.items.properties = - dereferencedSchema.indirectAncestor.fullyDereferenced.definitions.child.properties; - -export default dereferencedSchema; diff --git a/test/specs/circular-extended/parsed.ts b/test/specs/circular-extended/parsed.ts deleted file mode 100644 index 582d34ad..00000000 --- a/test/specs/circular-extended/parsed.ts +++ /dev/null @@ -1,202 +0,0 @@ -export default { - self: { - definitions: { - thing: { - $ref: "definitions/thing.yaml", - }, - }, - }, - - thing: { - title: "thing", - $ref: "thing.yaml", - description: - "This JSON Reference has additional properties (other than $ref). Normally, this creates a new type that extends the referenced type, but since this reference points to ITSELF, it doesn't do that.\n", - }, - - ancestor: { - definitions: { - person: { - $ref: "definitions/person-with-spouse.yaml", - }, - pet: { - $ref: "definitions/pet.yaml", - }, - }, - }, - - personWithSpouse: { - title: "person", - properties: { - spouse: { - description: - 'This JSON Reference has additional properties (other than $ref). This creates a new type that extends "person".\n', - $ref: "person-with-spouse.yaml", - }, - pet: { - description: - 'This JSON Reference has additional properties (other than $ref). This creates a new type that extends "pet".\n', - $ref: "pet.yaml", - }, - name: { - type: "string", - }, - }, - }, - - animals: { - definitions: { - fish: { - title: "fish", - $ref: "#/definitions/animal", - }, - cat: { - title: "cat", - $ref: "#/definitions/animal", - }, - bird: { - title: "bird", - $ref: "#/definitions/animal", - }, - animal: { - type: "object", - properties: { - age: { - type: "number", - }, - name: { - type: "string", - }, - }, - title: "animal", - }, - dog: { - title: "dog", - $ref: "#/definitions/animal", - }, - }, - }, - - pet: { - title: "pet", - type: { - $ref: "animals.yaml#/definitions/cat/type", - }, - properties: { - age: { - $ref: "animals.yaml#/definitions/bird/properties/age", - }, - name: { - $ref: "animals.yaml#/definitions/dog/properties/name", - }, - species: { - type: "string", - enum: ["cat", "dog", "bird", "fish"], - }, - }, - }, - - indirect: { - definitions: { - parent: { - $ref: "definitions/parent-with-children.yaml", - }, - child: { - $ref: "definitions/child-with-parents.yaml", - }, - pet: { - $ref: "definitions/pet.yaml", - }, - }, - }, - - parentWithChildren: { - title: "parent", - properties: { - name: { - type: "string", - }, - children: { - items: { - description: - 'This JSON Reference has additional properties (other than $ref). This creates a new type that extends "child".\n', - $ref: "child-with-parents.yaml", - }, - type: "array", - }, - }, - }, - - childWithParents: { - title: "child", - properties: { - parents: { - items: { - description: - 'This JSON Reference has additional properties (other than $ref). This creates a new type that extends "parent".\n', - $ref: "parent-with-children.yaml", - }, - type: "array", - }, - pet: { - description: - 'This JSON Reference has additional properties (other than $ref). This creates a new type that extends "pet".\n', - $ref: "pet.yaml", - }, - name: { - type: "string", - }, - }, - }, - - indirectAncestor: { - definitions: { - pet: { - $ref: "definitions/pet.yaml", - }, - parent: { - $ref: "definitions/parent-with-child.yaml", - }, - child: { - $ref: "definitions/child-with-children.yaml", - }, - }, - }, - - parentWithChild: { - title: "parent", - properties: { - name: { - type: "string", - }, - child: { - description: - 'This JSON Reference has additional properties (other than $ref). This creates a new type that extends "child".\n', - $ref: "child-with-children.yaml", - }, - }, - }, - - childWithChildren: { - title: "child", - properties: { - pet: { - description: - 'This JSON Reference has additional properties (other than $ref). This creates a new type that extends "pet".\n', - $ref: "pet.yaml", - }, - name: { - type: "string", - }, - children: { - items: { - description: - 'This JSON Reference has additional properties (other than $ref). This creates a new type that extends "child".\n', - $ref: "child-with-children.yaml", - }, - type: "array", - description: "children", - }, - }, - }, -}; diff --git a/test/specs/circular-external-direct/circular-external-direct-child.yaml b/test/specs/circular-external-direct/circular-external-direct-child.yaml deleted file mode 100644 index e2862a47..00000000 --- a/test/specs/circular-external-direct/circular-external-direct-child.yaml +++ /dev/null @@ -1,2 +0,0 @@ -foo: - $ref: ./circular-external-direct-root.yaml#/foo diff --git a/test/specs/circular-external-direct/circular-external-direct-root.yaml b/test/specs/circular-external-direct/circular-external-direct-root.yaml deleted file mode 100644 index c181a4cc..00000000 --- a/test/specs/circular-external-direct/circular-external-direct-root.yaml +++ /dev/null @@ -1 +0,0 @@ -$ref: ./circular-external-direct-child.yaml#/foo diff --git a/test/specs/circular-external-direct/circular-external-direct.spec.ts b/test/specs/circular-external-direct/circular-external-direct.spec.ts deleted file mode 100644 index 4e724372..00000000 --- a/test/specs/circular-external-direct/circular-external-direct.spec.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { describe, it } from "vitest"; -import { expect } from "vitest"; -import $RefParser from "../../../lib/index.js"; -import path from "../../utils/path.js"; -import parsedSchema from "./parsed.js"; -import dereferencedSchema from "./dereferenced.js"; - -describe("Schema with direct circular (recursive) external $refs", () => { - it("should parse successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.parse( - path.rel("test/specs/circular-external-direct/circular-external-direct-root.yaml"), - ); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(parsedSchema.schema); - expect(parser.$refs.paths()).to.deep.equal([ - path.abs("test/specs/circular-external-direct/circular-external-direct-root.yaml"), - ]); - // The "circular" flag should NOT be set - // (it only gets set by `dereference`) - expect(parser.$refs.circular).to.equal(false); - }); - - it("should dereference successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.dereference( - path.rel("test/specs/circular-external-direct/circular-external-direct-root.yaml"), - ); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(dereferencedSchema); - // The "circular" flag should be set - expect(parser.$refs.circular).to.equal(true); - }); -}); diff --git a/test/specs/circular-external-direct/dereferenced.ts b/test/specs/circular-external-direct/dereferenced.ts deleted file mode 100644 index 7ce003ec..00000000 --- a/test/specs/circular-external-direct/dereferenced.ts +++ /dev/null @@ -1,3 +0,0 @@ -export default { - $ref: "./circular-external-direct-root.yaml#/foo", -}; diff --git a/test/specs/circular-external-direct/parsed.ts b/test/specs/circular-external-direct/parsed.ts deleted file mode 100644 index 77460912..00000000 --- a/test/specs/circular-external-direct/parsed.ts +++ /dev/null @@ -1,5 +0,0 @@ -export default { - schema: { - $ref: "./circular-external-direct-child.yaml#/foo", - }, -}; diff --git a/test/specs/circular-external/bundled.ts b/test/specs/circular-external/bundled.ts deleted file mode 100644 index e11d3ff8..00000000 --- a/test/specs/circular-external/bundled.ts +++ /dev/null @@ -1,65 +0,0 @@ -export default { - definitions: { - pet: { - title: "pet", - type: "object", - properties: { - age: { - type: "number", - }, - name: { - type: "string", - }, - species: { - enum: ["cat", "dog", "bird", "fish"], - type: "string", - }, - }, - }, - thing: { - $ref: "#/definitions/thing", - }, - person: { - title: "person", - type: "object", - properties: { - spouse: { - $ref: "#/definitions/person", - }, - name: { - type: "string", - }, - }, - }, - parent: { - title: "parent", - type: "object", - properties: { - name: { - type: "string", - }, - children: { - items: { - $ref: "#/definitions/child", - }, - type: "array", - }, - }, - }, - child: { - title: "child", - type: "object", - properties: { - parents: { - items: { - $ref: "#/definitions/parent", - }, - type: "array", - }, - name: { - type: "string", - }, - }, - }, - }, -}; diff --git a/test/specs/circular-external/circular-external.spec.ts b/test/specs/circular-external/circular-external.spec.ts deleted file mode 100644 index 0f1b5379..00000000 --- a/test/specs/circular-external/circular-external.spec.ts +++ /dev/null @@ -1,86 +0,0 @@ -import { describe, it } from "vitest"; -import $RefParser from "../../../lib/index.js"; -import helper from "../../utils/helper.js"; -import path from "../../utils/path.js"; -import parsedSchema from "./parsed.js"; -import dereferencedSchema from "./dereferenced.js"; -import bundledSchema from "./bundled.js"; - -import { expect } from "vitest"; - -describe("Schema with circular (recursive) external $refs", () => { - it("should parse successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.parse(path.rel("test/specs/circular-external/circular-external.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(parsedSchema.schema); - expect(parser.$refs.paths()).to.deep.equal([path.abs("test/specs/circular-external/circular-external.yaml")]); - // The "circular" flag should NOT be set - // (it only gets set by `dereference`) - expect(parser.$refs.circular).to.equal(false); - }); - - it( - "should resolve successfully", - helper.testResolve( - path.rel("test/specs/circular-external/circular-external.yaml"), - path.abs("test/specs/circular-external/circular-external.yaml"), - parsedSchema.schema, - path.abs("test/specs/circular-external/definitions/pet.yaml"), - parsedSchema.pet, - path.abs("test/specs/circular-external/definitions/child.yaml"), - parsedSchema.child, - path.abs("test/specs/circular-external/definitions/parent.yaml"), - parsedSchema.parent, - path.abs("test/specs/circular-external/definitions/person.yaml"), - parsedSchema.person, - ), - ); - - it("should dereference successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.dereference(path.rel("test/specs/circular-external/circular-external.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(dereferencedSchema); - // The "circular" flag should be set - expect(parser.$refs.circular).to.equal(true); - // Reference equality - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - expect(schema.definitions.person.properties.spouse).to.equal(schema.definitions.person); - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - expect(schema.definitions.parent.properties.children.items).to.equal(schema.definitions.child); - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - expect(schema.definitions.child.properties.parents.items).to.equal(schema.definitions.parent); - }); - - it('should throw an error if "options.$refs.circular" is false', async () => { - const parser = new $RefParser(); - - try { - await parser.dereference(path.rel("test/specs/circular-external/circular-external.yaml"), { - dereference: { circular: false }, - }); - helper.shouldNotGetCalled(); - } catch (err) { - // A ReferenceError should have been thrown - expect(err).to.be.an.instanceOf(ReferenceError); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain("Circular $ref pointer found at "); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain("specs/circular-external/circular-external.yaml#/definitions/thing"); - - // $Refs.circular should be true - expect(parser.$refs.circular).to.equal(true); - } - }); - - it("should bundle successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.bundle(path.rel("test/specs/circular-external/circular-external.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(bundledSchema); - // The "circular" flag should NOT be set - // (it only gets set by `dereference`) - expect(parser.$refs.circular).to.equal(false); - }); -}); diff --git a/test/specs/circular-external/circular-external.yaml b/test/specs/circular-external/circular-external.yaml deleted file mode 100644 index 0ae1d369..00000000 --- a/test/specs/circular-external/circular-external.yaml +++ /dev/null @@ -1,15 +0,0 @@ -definitions: - pet: - $ref: definitions/pet.yaml # <--- not circular - - thing: - $ref: "circular-external.yaml#/definitions/thing" # <--- circular reference to self - - person: - $ref: definitions/person.yaml # <--- circular reference to ancestor - - parent: - $ref: definitions/parent.yaml # <--- indirect circular reference - - child: - $ref: definitions/child.yaml # <--- indirect circular reference diff --git a/test/specs/circular-external/definitions/child.yaml b/test/specs/circular-external/definitions/child.yaml deleted file mode 100644 index 0030b774..00000000 --- a/test/specs/circular-external/definitions/child.yaml +++ /dev/null @@ -1,9 +0,0 @@ -title: child -type: object -properties: - name: - type: string - parents: - type: array - items: - $ref: parent.yaml # indirect circular reference diff --git a/test/specs/circular-external/definitions/parent.yaml b/test/specs/circular-external/definitions/parent.yaml deleted file mode 100644 index 17d64e75..00000000 --- a/test/specs/circular-external/definitions/parent.yaml +++ /dev/null @@ -1,9 +0,0 @@ -title: parent -type: object -properties: - name: - type: string - children: - type: array - items: - $ref: child.yaml # indirect circular reference diff --git a/test/specs/circular-external/definitions/person.yaml b/test/specs/circular-external/definitions/person.yaml deleted file mode 100644 index 7287489e..00000000 --- a/test/specs/circular-external/definitions/person.yaml +++ /dev/null @@ -1,7 +0,0 @@ -title: person -type: object -properties: - name: - type: string - spouse: - $ref: person.yaml # direct circular reference diff --git a/test/specs/circular-external/definitions/pet.yaml b/test/specs/circular-external/definitions/pet.yaml deleted file mode 100644 index 2e38294e..00000000 --- a/test/specs/circular-external/definitions/pet.yaml +++ /dev/null @@ -1,14 +0,0 @@ -title: pet -type: object -properties: - name: - type: string - age: - type: number - species: - type: string - enum: - - cat - - dog - - bird - - fish diff --git a/test/specs/circular-external/dereferenced.ts b/test/specs/circular-external/dereferenced.ts deleted file mode 100644 index 5bf9eef4..00000000 --- a/test/specs/circular-external/dereferenced.ts +++ /dev/null @@ -1,68 +0,0 @@ -const dereferencedSchema = { - definitions: { - pet: { - title: "pet", - type: "object", - properties: { - age: { - type: "number", - }, - name: { - type: "string", - }, - species: { - enum: ["cat", "dog", "bird", "fish"], - type: "string", - }, - }, - }, - thing: { - $ref: "circular-external.yaml#/definitions/thing", - }, - person: { - title: "person", - type: "object", - properties: { - spouse: null, - name: { - type: "string", - }, - }, - }, - parent: { - title: "parent", - type: "object", - properties: { - name: { - type: "string", - }, - children: { - items: null, - type: "array", - }, - }, - }, - child: { - title: "child", - type: "object", - properties: { - parents: { - items: null, - type: "array", - }, - name: { - type: "string", - }, - }, - }, - }, -}; - -// @ts-expect-error TS(2322): Type '{ title: string; type: string; properties: {... Remove this comment to see the full error message -dereferencedSchema.definitions.person.properties.spouse = dereferencedSchema.definitions.person; -// @ts-expect-error TS(2322): Type '{ title: string; type: string; properties: {... Remove this comment to see the full error message -dereferencedSchema.definitions.parent.properties.children.items = dereferencedSchema.definitions.child; -// @ts-expect-error TS(2322): Type '{ title: string; type: string; properties: {... Remove this comment to see the full error message -dereferencedSchema.definitions.child.properties.parents.items = dereferencedSchema.definitions.parent; - -export default dereferencedSchema; diff --git a/test/specs/circular-external/parsed.ts b/test/specs/circular-external/parsed.ts deleted file mode 100644 index 091ecc63..00000000 --- a/test/specs/circular-external/parsed.ts +++ /dev/null @@ -1,83 +0,0 @@ -export default { - schema: { - definitions: { - pet: { - $ref: "definitions/pet.yaml", - }, - thing: { - $ref: "circular-external.yaml#/definitions/thing", - }, - person: { - $ref: "definitions/person.yaml", - }, - parent: { - $ref: "definitions/parent.yaml", - }, - child: { - $ref: "definitions/child.yaml", - }, - }, - }, - - pet: { - title: "pet", - type: "object", - properties: { - age: { - type: "number", - }, - name: { - type: "string", - }, - species: { - enum: ["cat", "dog", "bird", "fish"], - type: "string", - }, - }, - }, - - child: { - type: "object", - properties: { - parents: { - items: { - $ref: "parent.yaml", - }, - type: "array", - }, - name: { - type: "string", - }, - }, - title: "child", - }, - - parent: { - type: "object", - properties: { - name: { - type: "string", - }, - children: { - items: { - $ref: "child.yaml", - }, - type: "array", - }, - }, - title: "parent", - }, - - person: { - type: "object", - properties: { - spouse: { - $ref: "person.yaml", - }, - name: { - type: "string", - }, - }, - title: "person", - }, -}; diff --git a/test/specs/circular-multi/bundled.ts b/test/specs/circular-multi/bundled.ts deleted file mode 100644 index aec083f5..00000000 --- a/test/specs/circular-multi/bundled.ts +++ /dev/null @@ -1,49 +0,0 @@ -export default { - $schema: "http://json-schema.org/draft-07/schema#", - properties: { - actions: { - type: "object", - properties: { - affirmativeAction: { - $ref: "#/properties/actions/properties/prevAction", - }, - negativeAction: { - $ref: "#/properties/actions/properties/prevAction", - }, - prevAction: { - type: "object", - properties: { - $id: "text_assets", - oneOf: [ - { - $ref: "#/properties/actions/properties/prevAction/properties/definitions/asset", - }, - { - $ref: "#/properties/actions/properties/prevAction/properties/definitions/asset", - }, - ], - definitions: { - switchWrapper: { - type: "object", - $ref: "#/properties/actions/properties/prevAction/properties/definitions/switch", - }, - asset: { - type: "object", - $id: "asset_action", - properties: { - label: { - $ref: "#/properties/actions/properties/prevAction/properties", - }, - }, - }, - switch: { - type: "array", - $ref: "#/properties/actions/properties/prevAction/properties/definitions/asset", - }, - }, - }, - }, - }, - }, - }, -}; diff --git a/test/specs/circular-multi/circular-multi.spec.ts b/test/specs/circular-multi/circular-multi.spec.ts deleted file mode 100644 index 0dc19c00..00000000 --- a/test/specs/circular-multi/circular-multi.spec.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { describe, it } from "vitest"; -import $RefParser from "../../../lib/index.js"; -import path from "../../utils/path.js"; -import bundledSchema from "./bundled.js"; - -import { expect } from "vitest"; - -describe("multiple circular $refs at the same depth in the schema", () => { - it("should bundle successfully", async () => { - const parser = new $RefParser(); - - const schema = await parser.bundle(path.rel("test/specs/circular-multi/definitions/root.json")); - expect(schema).to.deep.equal(parser.schema); - expect(schema).to.deep.equal(bundledSchema); - }); -}); diff --git a/test/specs/circular-multi/definitions/action.json b/test/specs/circular-multi/definitions/action.json deleted file mode 100644 index e018f4ba..00000000 --- a/test/specs/circular-multi/definitions/action.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "$id": "asset_action", - "properties": { - "label": { - "$ref": "text_assets.json" - } - } -} diff --git a/test/specs/circular-multi/definitions/def.json b/test/specs/circular-multi/definitions/def.json deleted file mode 100644 index 9e3b7650..00000000 --- a/test/specs/circular-multi/definitions/def.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "$id": "def", - "definitions": { - "container": { - "properties": { - "actions": { - "type": "object", - "properties": { - "affirmativeAction": { - "$ref": "#/definitions/actions" - }, - "negativeAction": { - "$ref": "#/definitions/actions" - }, - "prevAction": { - "$ref": "#/definitions/actions" - } - } - } - } - }, - "actions": { - "type": "object", - "properties": { - "$ref": "text_assets.json" - } - } - } -} diff --git a/test/specs/circular-multi/definitions/root.json b/test/specs/circular-multi/definitions/root.json deleted file mode 100644 index 93bcfe66..00000000 --- a/test/specs/circular-multi/definitions/root.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$ref": "def.json#/definitions/container" -} diff --git a/test/specs/circular-multi/definitions/text_assets.json b/test/specs/circular-multi/definitions/text_assets.json deleted file mode 100644 index 4b27355d..00000000 --- a/test/specs/circular-multi/definitions/text_assets.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "$id": "text_assets", - "oneOf": [ - { - "$ref": "#/definitions/asset" - }, - { - "$ref": "#/definitions/asset" - } - ], - "definitions": { - "switchWrapper": { - "type": "object", - "$ref": "#/definitions/switch" - }, - "asset": { - "type": "object", - "$ref": "action.json" - }, - "switch": { - "type": "array", - "$ref": "#/definitions/asset" - } - } -} diff --git a/test/specs/circular/circular-ancestor.yaml b/test/specs/circular/circular-ancestor.yaml deleted file mode 100644 index 771f87a7..00000000 --- a/test/specs/circular/circular-ancestor.yaml +++ /dev/null @@ -1,28 +0,0 @@ -definitions: - person: - title: person - properties: - name: - type: string - pet: - $ref: "#/definitions/pet" - spouse: - $ref: "#/definitions/person" # <--- circular reference to ancestor - age: - type: number - - pet: - title: pet - type: object - properties: - name: - type: string - age: - type: number - species: - type: string - enum: - - cat - - dog - - bird - - fish diff --git a/test/specs/circular/circular-indirect-ancestor.yaml b/test/specs/circular/circular-indirect-ancestor.yaml deleted file mode 100644 index 1b8736af..00000000 --- a/test/specs/circular/circular-indirect-ancestor.yaml +++ /dev/null @@ -1,37 +0,0 @@ -definitions: - parent: - title: parent - properties: - name: - type: string - child: - $ref: "#/definitions/child" # <--- indirect circular reference - - child: - title: child - properties: - name: - type: string - pet: - $ref: "#/definitions/pet" - children: - description: children - type: array - items: - $ref: "#/definitions/child" # <--- circular reference to ancestor - - pet: - title: pet - type: object - properties: - name: - type: string - age: - type: number - species: - type: string - enum: - - cat - - dog - - bird - - fish diff --git a/test/specs/circular/circular-indirect.yaml b/test/specs/circular/circular-indirect.yaml deleted file mode 100644 index d70b73d0..00000000 --- a/test/specs/circular/circular-indirect.yaml +++ /dev/null @@ -1,38 +0,0 @@ -definitions: - parent: - title: parent - properties: - name: - type: string - children: - type: array - items: - $ref: "#/definitions/child" # <--- indirect circular reference - - child: - title: child - properties: - name: - type: string - pet: - $ref: "#/definitions/pet" - parents: - type: array - items: - $ref: "#/definitions/parent" # <--- indirect circular reference - - pet: - title: pet - type: object - properties: - name: - type: string - age: - type: number - species: - type: string - enum: - - cat - - dog - - bird - - fish diff --git a/test/specs/circular/circular-self.yaml b/test/specs/circular/circular-self.yaml deleted file mode 100644 index 473bb0e7..00000000 --- a/test/specs/circular/circular-self.yaml +++ /dev/null @@ -1,28 +0,0 @@ -definitions: - child: - title: child - type: object - properties: - name: - type: string - pet: - $ref: "#/definitions/pet" - - thing: - $ref: "#/definitions/thing" # <--- circular reference to self - - pet: - title: pet - type: object - properties: - name: - type: string - age: - type: number - species: - type: string - enum: - - cat - - dog - - bird - - fish diff --git a/test/specs/circular/circular.spec.ts b/test/specs/circular/circular.spec.ts deleted file mode 100644 index 7c416287..00000000 --- a/test/specs/circular/circular.spec.ts +++ /dev/null @@ -1,396 +0,0 @@ -import { describe, it } from "vitest"; -import $RefParser from "../../../lib/index.js"; -import helper from "../../utils/helper.js"; -import path from "../../utils/path.js"; -import parsedSchema from "./parsed.js"; -import dereferencedSchema from "./dereferenced.js"; - -import { expect } from "vitest"; - -describe("Schema with circular (recursive) $refs", () => { - describe("$ref to self", () => { - it("should parse successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.parse(path.rel("test/specs/circular/circular-self.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(parsedSchema.self); - expect(parser.$refs.paths()).to.deep.equal([path.abs("test/specs/circular/circular-self.yaml")]); - // The "circular" flag should NOT be set - // (it only gets set by `dereference`) - expect(parser.$refs.circular).to.equal(false); - }); - - it( - "should resolve successfully", - helper.testResolve( - path.rel("test/specs/circular/circular-self.yaml"), - path.abs("test/specs/circular/circular-self.yaml"), - parsedSchema.self, - ), - ); - - it("should dereference successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.dereference(path.rel("test/specs/circular/circular-self.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(dereferencedSchema.self); - // The "circular" flag should be set - expect(parser.$refs.circular).to.equal(true); - // Reference equality - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - expect(schema.definitions.child.properties.pet).to.equal(schema.definitions.pet); - }); - - it("should double dereference successfully", async () => { - const firstPassSchema = await $RefParser.dereference(path.rel("test/specs/circular/circular-self.yaml")); - const parser = new $RefParser(); - const schema = await parser.dereference(firstPassSchema); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(dereferencedSchema.self); - // The "circular" flag should be set - expect(parser.$refs.circular).to.equal(true); - // Reference equality - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - expect(schema.definitions.child.properties.pet).to.equal(schema.definitions.pet); - }); - - it('should produce the same results if "options.$refs.circular" is "ignore"', async () => { - const parser = new $RefParser(); - - const schema = await parser.dereference(path.rel("test/specs/circular/circular-self.yaml"), { - dereference: { circular: "ignore" }, - }); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(dereferencedSchema.self); - // The "circular" flag should be set - expect(parser.$refs.circular).to.equal(true); - }); - - it('should throw an error if "options.$refs.circular" is false', async () => { - const parser = new $RefParser(); - - try { - await parser.dereference(path.rel("test/specs/circular/circular-self.yaml"), { - dereference: { circular: false }, - }); - helper.shouldNotGetCalled(); - } catch (err) { - // A ReferenceError should have been thrown - expect(err).to.be.an.instanceOf(ReferenceError); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain("Circular $ref pointer found at "); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain("specs/circular/circular-self.yaml#/definitions/thing"); - - // $Refs.circular should be true - expect(parser.$refs.circular).to.equal(true); - } - }); - - it("should bundle successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.bundle(path.rel("test/specs/circular/circular-self.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(parsedSchema.self); - // The "circular" flag should NOT be set - // (it only gets set by `dereference`) - expect(parser.$refs.circular).to.equal(false); - }); - }); - - describe("$ref to ancestor", () => { - it("should parse successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.parse(path.rel("test/specs/circular/circular-ancestor.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(parsedSchema.ancestor); - expect(parser.$refs.paths()).to.deep.equal([path.abs("test/specs/circular/circular-ancestor.yaml")]); - // The "circular" flag should NOT be set - // (it only gets set by `dereference`) - expect(parser.$refs.circular).to.equal(false); - }); - - it( - "should resolve successfully", - helper.testResolve( - path.rel("test/specs/circular/circular-ancestor.yaml"), - path.abs("test/specs/circular/circular-ancestor.yaml"), - - parsedSchema.ancestor, - ), - ); - - it("should dereference successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.dereference(path.rel("test/specs/circular/circular-ancestor.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(dereferencedSchema.ancestor.fullyDereferenced); - // The "circular" flag should be set - expect(parser.$refs.circular).to.equal(true); - // Reference equality - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - expect(schema.definitions.person.properties.spouse).to.equal(schema.definitions.person); - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - expect(schema.definitions.person.properties.pet).to.equal(schema.definitions.pet); - }); - - it("should double dereference successfully", async () => { - const parser = new $RefParser(); - const firstPassSchema = await $RefParser.dereference(path.rel("test/specs/circular/circular-ancestor.yaml")); - const schema = await parser.dereference(firstPassSchema); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(dereferencedSchema.ancestor.fullyDereferenced); - // The "circular" flag should be set - expect(parser.$refs.circular).to.equal(true); - // Reference equality - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - expect(schema.definitions.person.properties.spouse).to.equal(schema.definitions.person); - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - expect(schema.definitions.person.properties.pet).to.equal(schema.definitions.pet); - }); - - it('should not dereference circular $refs if "options.$refs.circular" is "ignore"', async () => { - const parser = new $RefParser(); - - const schema = await parser.dereference(path.rel("test/specs/circular/circular-ancestor.yaml"), { - dereference: { circular: "ignore" }, - }); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(dereferencedSchema.ancestor.ignoreCircular$Refs); - // The "circular" flag should be set - expect(parser.$refs.circular).to.equal(true); - // Reference equality - // @ts-expect-error TS(2339): Property 'definitions' does not exist on type 'voi... Remove this comment to see the full error message - expect(schema.definitions.person.properties.pet).to.equal(schema.definitions.pet); - }); - - it('should throw an error if "options.$refs.circular" is false', async () => { - const parser = new $RefParser(); - - try { - await parser.dereference(path.rel("test/specs/circular/circular-ancestor.yaml"), { - dereference: { circular: false }, - }); - helper.shouldNotGetCalled(); - } catch (err) { - // A ReferenceError should have been thrown - expect(err).to.be.an.instanceOf(ReferenceError); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain("Circular $ref pointer found at "); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain("specs/circular/circular-ancestor.yaml#/definitions/person/properties/spouse"); - - // $Refs.circular should be true - expect(parser.$refs.circular).to.equal(true); - } - }); - - it("should bundle successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.bundle(path.rel("test/specs/circular/circular-ancestor.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(parsedSchema.ancestor); - // The "circular" flag should NOT be set - // (it only gets set by `dereference`) - expect(parser.$refs.circular).to.equal(false); - }); - }); - - describe("indirect circular $refs", () => { - it("should parse successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.parse(path.rel("test/specs/circular/circular-indirect.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(parsedSchema.indirect); - expect(parser.$refs.paths()).to.deep.equal([path.abs("test/specs/circular/circular-indirect.yaml")]); - // The "circular" flag should NOT be set - // (it only gets set by `dereference`) - expect(parser.$refs.circular).to.equal(false); - }); - - it( - "should resolve successfully", - helper.testResolve( - path.rel("test/specs/circular/circular-indirect.yaml"), - path.abs("test/specs/circular/circular-indirect.yaml"), - - parsedSchema.indirect, - ), - ); - - it("should dereference successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.dereference(path.rel("test/specs/circular/circular-indirect.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(dereferencedSchema.indirect.fullyDereferenced); - // The "circular" flag should be set - expect(parser.$refs.circular).to.equal(true); - // Reference equality - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - expect(schema.definitions.parent.properties.children.items).to.equal(schema.definitions.child); - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - expect(schema.definitions.child.properties.parents.items).to.equal(schema.definitions.parent); - }); - - it("should double dereference successfully", async () => { - const parser = new $RefParser(); - const firstPassSchema = await $RefParser.dereference(path.rel("test/specs/circular/circular-indirect.yaml")); - const schema = await parser.dereference(firstPassSchema); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(dereferencedSchema.indirect.fullyDereferenced); - // The "circular" flag should be set - expect(parser.$refs.circular).to.equal(true); - // Reference equality - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - expect(schema.definitions.parent.properties.children.items).to.equal(schema.definitions.child); - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - expect(schema.definitions.child.properties.parents.items).to.equal(schema.definitions.parent); - }); - - it('should not dereference circular $refs if "options.$refs.circular" is "ignore"', async () => { - const parser = new $RefParser(); - - const schema = await parser.dereference(path.rel("test/specs/circular/circular-indirect.yaml"), { - dereference: { circular: "ignore" }, - }); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(dereferencedSchema.indirect.ignoreCircular$Refs); - // The "circular" flag should be set - expect(parser.$refs.circular).to.equal(true); - // Reference equality - // @ts-expect-error TS(2339): Property 'definitions' does not exist on type 'voi... Remove this comment to see the full error message - expect(schema.definitions.child.properties.pet).to.equal(schema.definitions.pet); - }); - - it('should throw an error if "options.$refs.circular" is false', async () => { - const parser = new $RefParser(); - - try { - await parser.dereference(path.rel("test/specs/circular/circular-indirect.yaml"), { - dereference: { circular: false }, - }); - helper.shouldNotGetCalled(); - } catch (err) { - // A ReferenceError should have been thrown - expect(err).to.be.an.instanceOf(ReferenceError); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain("Circular $ref pointer found at "); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain( - "specs/circular/circular-indirect.yaml#/definitions/child/properties/parents/items", - ); - - // $Refs.circular should be true - expect(parser.$refs.circular).to.equal(true); - } - }); - - it("should bundle successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.bundle(path.rel("test/specs/circular/circular-indirect.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(parsedSchema.indirect); - // The "circular" flag should NOT be set - // (it only gets set by `dereference`) - expect(parser.$refs.circular).to.equal(false); - }); - }); - - describe("indirect circular and ancestor $refs", () => { - it("should parse successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.parse(path.rel("test/specs/circular/circular-indirect-ancestor.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(parsedSchema.indirectAncestor); - expect(parser.$refs.paths()).to.deep.equal([path.abs("test/specs/circular/circular-indirect-ancestor.yaml")]); - // The "circular" flag should NOT be set - // (it only gets set by `dereference`) - expect(parser.$refs.circular).to.equal(false); - }); - - it( - "should resolve successfully", - helper.testResolve( - path.rel("test/specs/circular/circular-indirect-ancestor.yaml"), - path.abs("test/specs/circular/circular-indirect-ancestor.yaml"), - - parsedSchema.indirectAncestor, - ), - ); - - it("should dereference successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.dereference(path.rel("test/specs/circular/circular-indirect-ancestor.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(dereferencedSchema.indirectAncestor.fullyDereferenced); - // The "circular" flag should be set - expect(parser.$refs.circular).to.equal(true); - // Reference equality - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - expect(schema.definitions.parent.properties.child).to.equal(schema.definitions.child); - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - expect(schema.definitions.child.properties.children.items).to.equal(schema.definitions.child); - }); - - it("should double dereference successfully", async () => { - const parser = new $RefParser(); - const firstPassSchema = await parser.dereference(path.rel("test/specs/circular/circular-indirect-ancestor.yaml")); - const schema = await parser.dereference(firstPassSchema); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(dereferencedSchema.indirectAncestor.fullyDereferenced); - // The "circular" flag should be set - expect(parser.$refs.circular).to.equal(true); - // Reference equality - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - expect(schema.definitions.parent.properties.child).to.equal(schema.definitions.child); - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - expect(schema.definitions.child.properties.children.items).to.equal(schema.definitions.child); - }); - - it('should not dereference circular $refs if "options.$refs.circular" is "ignore"', async () => { - const parser = new $RefParser(); - - const schema = await parser.dereference(path.rel("test/specs/circular/circular-indirect-ancestor.yaml"), { - dereference: { circular: "ignore" }, - }); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(dereferencedSchema.indirectAncestor.ignoreCircular$Refs); - // The "circular" flag should be set - expect(parser.$refs.circular).to.equal(true); - // Reference equality - // @ts-expect-error TS(2339): Property 'definitions' does not exist on type 'voi... Remove this comment to see the full error message - expect(schema.definitions.child.properties.pet).to.equal(schema.definitions.pet); - }); - - it('should throw an error if "options.$refs.circular" is false', async () => { - const parser = new $RefParser(); - - try { - await parser.dereference(path.rel("test/specs/circular/circular-indirect-ancestor.yaml"), { - dereference: { circular: false }, - }); - helper.shouldNotGetCalled(); - } catch (err) { - // A ReferenceError should have been thrown - expect(err).to.be.an.instanceOf(ReferenceError); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain("Circular $ref pointer found at "); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain("specs/circular/circular-indirect-ancestor.yaml#/definitions/child/properties"); - - // $Refs.circular should be true - expect(parser.$refs.circular).to.equal(true); - } - }); - - it("should bundle successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.bundle(path.rel("test/specs/circular/circular-indirect-ancestor.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(parsedSchema.indirectAncestor); - // The "circular" flag should NOT be set - // (it only gets set by `dereference`) - expect(parser.$refs.circular).to.equal(false); - }); - }); -}); diff --git a/test/specs/circular/dereferenced.ts b/test/specs/circular/dereferenced.ts deleted file mode 100644 index f2ec9ba2..00000000 --- a/test/specs/circular/dereferenced.ts +++ /dev/null @@ -1,360 +0,0 @@ -const dereferencedSchema = { - self: { - definitions: { - pet: { - type: "object", - properties: { - age: { - type: "number", - }, - name: { - type: "string", - }, - species: { - enum: ["cat", "dog", "bird", "fish"], - type: "string", - }, - }, - title: "pet", - }, - thing: { - $ref: "#/definitions/thing", - }, - child: { - type: "object", - properties: { - pet: { - type: "object", - properties: { - age: { - type: "number", - }, - name: { - type: "string", - }, - species: { - enum: ["cat", "dog", "bird", "fish"], - type: "string", - }, - }, - title: "pet", - }, - name: { - type: "string", - }, - }, - title: "child", - }, - }, - }, - - ancestor: { - fullyDereferenced: { - definitions: { - person: { - title: "person", - properties: { - spouse: null, - pet: null, - name: { - type: "string", - }, - age: { - type: "number", - }, - }, - }, - pet: { - type: "object", - properties: { - age: { - type: "number", - }, - name: { - type: "string", - }, - species: { - enum: ["cat", "dog", "bird", "fish"], - type: "string", - }, - }, - title: "pet", - }, - }, - }, - - ignoreCircular$Refs: { - definitions: { - person: { - title: "person", - properties: { - spouse: { - $ref: "#/definitions/person", - }, - pet: null, - name: { - type: "string", - }, - age: { - type: "number", - }, - }, - }, - pet: { - type: "object", - properties: { - age: { - type: "number", - }, - name: { - type: "string", - }, - species: { - enum: ["cat", "dog", "bird", "fish"], - type: "string", - }, - }, - title: "pet", - }, - }, - }, - }, - - indirect: { - fullyDereferenced: { - definitions: { - parent: { - title: "parent", - properties: { - name: { - type: "string", - }, - children: { - items: null, - type: "array", - }, - }, - }, - child: { - title: "child", - properties: { - parents: { - items: null, - type: "array", - }, - pet: null, - name: { - type: "string", - }, - }, - }, - pet: { - type: "object", - properties: { - age: { - type: "number", - }, - name: { - type: "string", - }, - species: { - enum: ["cat", "dog", "bird", "fish"], - type: "string", - }, - }, - title: "pet", - }, - }, - }, - - ignoreCircular$Refs: { - definitions: { - parent: { - title: "parent", - properties: { - name: { - type: "string", - }, - children: { - items: { - $ref: "#/definitions/child", - }, - type: "array", - }, - }, - }, - child: { - title: "child", - properties: { - parents: { - items: { - $ref: "#/definitions/parent", - }, - type: "array", - }, - pet: null, - name: { - type: "string", - }, - }, - }, - pet: { - type: "object", - properties: { - age: { - type: "number", - }, - name: { - type: "string", - }, - species: { - enum: ["cat", "dog", "bird", "fish"], - type: "string", - }, - }, - title: "pet", - }, - }, - }, - }, - - indirectAncestor: { - fullyDereferenced: { - definitions: { - parent: { - title: "parent", - properties: { - name: { - type: "string", - }, - child: null, - }, - }, - child: { - title: "child", - properties: { - name: { - type: "string", - }, - pet: null, - children: { - items: null, - type: "array", - description: "children", - }, - }, - }, - pet: { - type: "object", - properties: { - age: { - type: "number", - }, - name: { - type: "string", - }, - species: { - enum: ["cat", "dog", "bird", "fish"], - type: "string", - }, - }, - title: "pet", - }, - }, - }, - - ignoreCircular$Refs: { - definitions: { - parent: { - title: "parent", - properties: { - name: { - type: "string", - }, - child: { - $ref: "#/definitions/child", - }, - }, - }, - child: { - title: "child", - properties: { - name: { - type: "string", - }, - pet: null, - children: { - items: { - $ref: "#/definitions/child", - }, - type: "array", - description: "children", - }, - }, - }, - pet: { - type: "object", - properties: { - age: { - type: "number", - }, - name: { - type: "string", - }, - species: { - enum: ["cat", "dog", "bird", "fish"], - type: "string", - }, - }, - title: "pet", - }, - }, - }, - }, -}; - -// @ts-expect-error TS(2322): Type '{ title: string; properties: { spouse: null;... Remove this comment to see the full error message -dereferencedSchema.ancestor.fullyDereferenced.definitions.person.properties.spouse = - dereferencedSchema.ancestor.fullyDereferenced.definitions.person; - -// @ts-expect-error TS(2322): Type '{ type: string; properties: { age: { type: s... Remove this comment to see the full error message -dereferencedSchema.ancestor.fullyDereferenced.definitions.person.properties.pet = - dereferencedSchema.ancestor.fullyDereferenced.definitions.pet; - -// @ts-expect-error TS(2322): Type '{ type: string; properties: { age: { type: s... Remove this comment to see the full error message -dereferencedSchema.ancestor.ignoreCircular$Refs.definitions.person.properties.pet = - dereferencedSchema.ancestor.ignoreCircular$Refs.definitions.pet; - -// @ts-expect-error TS(2322): Type '{ title: string; properties: { parents: { it... Remove this comment to see the full error message -dereferencedSchema.indirect.fullyDereferenced.definitions.parent.properties.children.items = - dereferencedSchema.indirect.fullyDereferenced.definitions.child; - -// @ts-expect-error TS(2322): Type '{ title: string; properties: { name: { type:... Remove this comment to see the full error message -dereferencedSchema.indirect.fullyDereferenced.definitions.child.properties.parents.items = - dereferencedSchema.indirect.fullyDereferenced.definitions.parent; - -// @ts-expect-error TS(2322): Type '{ type: string; properties: { age: { type: s... Remove this comment to see the full error message -dereferencedSchema.indirect.fullyDereferenced.definitions.child.properties.pet = - dereferencedSchema.indirect.fullyDereferenced.definitions.pet; - -// @ts-expect-error TS(2322): Type '{ type: string; properties: { age: { type: s... Remove this comment to see the full error message -dereferencedSchema.indirect.ignoreCircular$Refs.definitions.child.properties.pet = - dereferencedSchema.indirect.ignoreCircular$Refs.definitions.pet; - -// @ts-expect-error TS(2322): Type '{ title: string; properties: { name: { type:... Remove this comment to see the full error message -dereferencedSchema.indirectAncestor.fullyDereferenced.definitions.parent.properties.child = - dereferencedSchema.indirectAncestor.fullyDereferenced.definitions.child; - -// @ts-expect-error TS(2322): Type '{ title: string; properties: { name: { type:... Remove this comment to see the full error message -dereferencedSchema.indirectAncestor.fullyDereferenced.definitions.child.properties.children.items = - dereferencedSchema.indirectAncestor.fullyDereferenced.definitions.child; - -// @ts-expect-error TS(2322): Type '{ type: string; properties: { age: { type: s... Remove this comment to see the full error message -dereferencedSchema.indirectAncestor.fullyDereferenced.definitions.child.properties.pet = - dereferencedSchema.indirectAncestor.fullyDereferenced.definitions.pet; - -// @ts-expect-error TS(2322): Type '{ type: string; properties: { age: { type: s... Remove this comment to see the full error message -dereferencedSchema.indirectAncestor.ignoreCircular$Refs.definitions.child.properties.pet = - dereferencedSchema.indirectAncestor.ignoreCircular$Refs.definitions.pet; - -export default dereferencedSchema; diff --git a/test/specs/circular/parsed.ts b/test/specs/circular/parsed.ts deleted file mode 100644 index a2a68de8..00000000 --- a/test/specs/circular/parsed.ts +++ /dev/null @@ -1,177 +0,0 @@ -export default { - self: { - definitions: { - pet: { - type: "object", - properties: { - age: { - type: "number", - }, - name: { - type: "string", - }, - species: { - enum: ["cat", "dog", "bird", "fish"], - type: "string", - }, - }, - title: "pet", - }, - thing: { - $ref: "#/definitions/thing", - }, - child: { - type: "object", - properties: { - pet: { - $ref: "#/definitions/pet", - }, - name: { - type: "string", - }, - }, - title: "child", - }, - }, - }, - - ancestor: { - definitions: { - person: { - title: "person", - properties: { - spouse: { - $ref: "#/definitions/person", - }, - pet: { - $ref: "#/definitions/pet", - }, - name: { - type: "string", - }, - age: { - type: "number", - }, - }, - }, - pet: { - type: "object", - properties: { - age: { - type: "number", - }, - name: { - type: "string", - }, - species: { - enum: ["cat", "dog", "bird", "fish"], - type: "string", - }, - }, - title: "pet", - }, - }, - }, - - indirect: { - definitions: { - parent: { - title: "parent", - properties: { - name: { - type: "string", - }, - children: { - items: { - $ref: "#/definitions/child", - }, - type: "array", - }, - }, - }, - child: { - title: "child", - properties: { - parents: { - items: { - $ref: "#/definitions/parent", - }, - type: "array", - }, - pet: { - $ref: "#/definitions/pet", - }, - name: { - type: "string", - }, - }, - }, - pet: { - type: "object", - properties: { - age: { - type: "number", - }, - name: { - type: "string", - }, - species: { - enum: ["cat", "dog", "bird", "fish"], - type: "string", - }, - }, - title: "pet", - }, - }, - }, - - indirectAncestor: { - definitions: { - parent: { - title: "parent", - properties: { - name: { - type: "string", - }, - child: { - $ref: "#/definitions/child", - }, - }, - }, - child: { - title: "child", - properties: { - name: { - type: "string", - }, - pet: { - $ref: "#/definitions/pet", - }, - children: { - items: { - $ref: "#/definitions/child", - }, - type: "array", - description: "children", - }, - }, - }, - pet: { - title: "pet", - type: "object", - properties: { - age: { - type: "number", - }, - name: { - type: "string", - }, - species: { - enum: ["cat", "dog", "bird", "fish"], - type: "string", - }, - }, - }, - }, - }, -}; diff --git a/test/specs/date-strings/date-strings.spec.ts b/test/specs/date-strings/date-strings.spec.ts deleted file mode 100644 index 178680ed..00000000 --- a/test/specs/date-strings/date-strings.spec.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { describe, it } from "vitest"; -import $RefParser from "../../../lib/index.js"; -import helper from "../../utils/helper.js"; -import path from "../../utils/path.js"; -import parsedSchema from "./parsed.js"; - -import { expect } from "vitest"; - -describe("Schema with date strings", () => { - it("should parse successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.parse(path.rel("test/specs/date-strings/date-strings.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(parsedSchema.schema); - expect(parser.$refs.paths()).to.deep.equal([path.abs("test/specs/date-strings/date-strings.yaml")]); - }); - - it( - "should resolve successfully", - helper.testResolve( - path.rel("test/specs/date-strings/date-strings.yaml"), - path.abs("test/specs/date-strings/date-strings.yaml"), - parsedSchema.schema, - ), - ); -}); diff --git a/test/specs/date-strings/date-strings.yaml b/test/specs/date-strings/date-strings.yaml deleted file mode 100644 index 9137a651..00000000 --- a/test/specs/date-strings/date-strings.yaml +++ /dev/null @@ -1,6 +0,0 @@ -title: Date Strings -type: object -properties: - name: - description: 2015-04-22T10:03:19.323-07:00 - type: string diff --git a/test/specs/date-strings/parsed.ts b/test/specs/date-strings/parsed.ts deleted file mode 100644 index dc794739..00000000 --- a/test/specs/date-strings/parsed.ts +++ /dev/null @@ -1,12 +0,0 @@ -export default { - schema: { - title: "Date Strings", - type: "object", - properties: { - name: { - description: "2015-04-22T10:03:19.323-07:00", - type: "string", - }, - }, - }, -}; diff --git a/test/specs/deep-circular/bundled.ts b/test/specs/deep-circular/bundled.ts deleted file mode 100644 index b2af0547..00000000 --- a/test/specs/deep-circular/bundled.ts +++ /dev/null @@ -1,326 +0,0 @@ -export default { - title: "Deep Schema", - type: "object", - definitions: { - name: { - title: "name", - required: ["first", "last"], - type: "object", - properties: { - middle: { - minLength: { - $ref: "#/definitions/name/properties/last/minLength", - }, - type: { - $ref: "#/definitions/name/properties/last/type", - }, - }, - prefix: { - minLength: 3, - $ref: "#/definitions/name/properties/last", - }, - last: { - minLength: 1, - type: "string", - title: "requiredString", - }, - suffix: { - $ref: "#/definitions/name/properties/prefix", - type: "string", - maxLength: 3, - }, - first: { - $ref: "#/definitions/name/properties/last", - }, - }, - }, - }, - properties: { - level1: { - required: ["name"], - type: "object", - properties: { - level2: { - required: ["name"], - type: "object", - properties: { - level3: { - required: ["name"], - type: "object", - properties: { - level4: { - required: ["name"], - type: "object", - properties: { - name: { - $ref: "#/definitions/name", - }, - level5: { - required: ["name"], - type: "object", - properties: { - name: { - $ref: "#/definitions/name", - }, - level6: { - required: ["name"], - type: "object", - properties: { - name: { - $ref: "#/definitions/name", - }, - level7: { - required: ["name"], - type: "object", - properties: { - level8: { - required: ["name"], - type: "object", - properties: { - level9: { - required: ["name"], - type: "object", - properties: { - level10: { - required: ["name"], - type: "object", - properties: { - level11: { - required: ["name"], - type: "object", - properties: { - level12: { - required: ["name"], - type: "object", - properties: { - level13: { - required: ["name"], - type: "object", - properties: { - name: { - $ref: "#/definitions/name", - }, - level14: { - required: ["name"], - type: "object", - properties: { - name: { - $ref: "#/definitions/name", - }, - level15: { - required: ["name"], - type: "object", - properties: { - level16: { - required: ["name"], - type: "object", - properties: { - name: { - $ref: "#/definitions/name", - }, - level17: { - required: ["name"], - type: "object", - properties: { - level18: { - required: ["name"], - type: "object", - properties: { - level19: { - required: ["name"], - type: "object", - properties: { - level20: { - required: ["name"], - type: "object", - properties: { - level21: { - required: ["name"], - type: "object", - properties: { - level22: { - required: ["name"], - type: "object", - properties: { - level23: { - required: ["name"], - type: "object", - properties: { - name: { - $ref: "#/definitions/name", - }, - level24: { - required: ["name"], - type: "object", - properties: { - name: { - $ref: "#/definitions/name", - }, - level25: { - required: [ - "name", - ], - type: "object", - properties: { - name: { - $ref: "#/definitions/name", - }, - level26: { - required: [ - "name", - ], - type: "object", - properties: { - level27: { - required: - [ - "name", - ], - type: "object", - properties: - { - level28: - { - required: - [ - "name", - ], - type: "object", - properties: - { - level29: - { - required: - [ - "name", - ], - type: "object", - properties: - { - level30: - { - $ref: "#", - }, - name: { - $ref: "#/definitions/name", - }, - }, - }, - name: { - $ref: "#/definitions/name", - }, - }, - }, - name: { - $ref: "#/definitions/name", - }, - }, - }, - name: { - $ref: "#/definitions/name", - }, - }, - }, - }, - }, - }, - }, - }, - }, - name: { - $ref: "#/definitions/name", - }, - }, - }, - name: { - $ref: "#/definitions/name", - }, - }, - }, - name: { - $ref: "#/definitions/name", - }, - }, - }, - name: { - $ref: "#/definitions/name", - }, - }, - }, - name: { - $ref: "#/definitions/name", - }, - }, - }, - name: { - $ref: "#/definitions/name", - }, - }, - }, - }, - }, - name: { - $ref: "#/definitions/name", - }, - }, - }, - }, - }, - }, - }, - name: { - $ref: "#/definitions/name", - }, - }, - }, - name: { - $ref: "#/definitions/name", - }, - }, - }, - name: { - $ref: "#/definitions/name", - }, - }, - }, - name: { - $ref: "#/definitions/name", - }, - }, - }, - name: { - $ref: "#/definitions/name", - }, - }, - }, - name: { - $ref: "#/definitions/name", - }, - }, - }, - }, - }, - }, - }, - }, - }, - name: { - $ref: "#/definitions/name", - }, - }, - }, - name: { - $ref: "#/definitions/name", - }, - }, - }, - name: { - $ref: "#/definitions/name", - }, - }, - }, - name: { - $ref: "#/definitions/name", - }, - }, -}; diff --git a/test/specs/deep-circular/deep-circular.spec.ts b/test/specs/deep-circular/deep-circular.spec.ts deleted file mode 100644 index ec432869..00000000 --- a/test/specs/deep-circular/deep-circular.spec.ts +++ /dev/null @@ -1,96 +0,0 @@ -import { describe, it } from "vitest"; -import $RefParser from "../../../lib/index.js"; -import helper from "../../utils/helper.js"; -import path from "../../utils/path.js"; -import parsedSchema from "./parsed.js"; -import dereferencedSchema from "./dereferenced.js"; -import bundledSchema from "./bundled.js"; - -import { expect } from "vitest"; - -describe("Schema with deeply-nested circular $refs", () => { - it("should parse successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.parse(path.rel("test/specs/deep-circular/deep-circular.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(parsedSchema.schema); - expect(parser.$refs.paths()).to.deep.equal([path.abs("test/specs/deep-circular/deep-circular.yaml")]); - // The "circular" flag should NOT be set - // (it only gets set by `dereference`) - expect(parser.$refs.circular).to.equal(false); - }); - - it( - "should resolve successfully", - helper.testResolve( - path.rel("test/specs/deep-circular/deep-circular.yaml"), - path.abs("test/specs/deep-circular/deep-circular.yaml"), - parsedSchema.schema, - path.abs("test/specs/deep-circular/definitions/name.yaml"), - parsedSchema.name, - path.abs("test/specs/deep-circular/definitions/required-string.yaml"), - parsedSchema.requiredString, - ), - ); - - it("should dereference successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.dereference(path.rel("test/specs/deep-circular/deep-circular.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(dereferencedSchema); - // The "circular" flag should be set - expect(parser.$refs.circular).to.equal(true); - // Reference equality - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - expect(schema.definitions.name) - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - .to.equal(schema.properties.name) - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - .to.equal(schema.properties.level1.properties.name) - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - .to.equal(schema.properties.level1.properties.level2.properties.name) - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - .to.equal(schema.properties.level1.properties.level2.properties.level3.properties.name) - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - .to.equal(schema.properties.level1.properties.level2.properties.level3.properties.level4.properties.name); - }); - - it('should throw an error if "options.$refs.circular" is false', async () => { - const parser = new $RefParser(); - - try { - await parser.dereference(path.rel("test/specs/deep-circular/deep-circular.yaml"), { - dereference: { circular: false }, - }); - helper.shouldNotGetCalled(); - } catch (err) { - // A ReferenceError should have been thrown - expect(err).to.be.an.instanceOf(ReferenceError); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain("Circular $ref pointer found at "); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain( - "specs/deep-circular/deep-circular.yaml#/properties/level1/properties/level2/properties/" + - "level3/properties/level4/properties/level5/properties/level6/properties/level7/properties/" + - "level8/properties/level9/properties/level10/properties/level11/properties/level12/properties/" + - "level13/properties/level14/properties/level15/properties/level16/properties/level17/properties/" + - "level18/properties/level19/properties/level20/properties/level21/properties/level22/properties/" + - "level23/properties/level24/properties/level25/properties/level26/properties/level27/properties/" + - "level28/properties/level29/properties/level30", - ); - - // $Refs.circular should be true - expect(parser.$refs.circular).to.equal(true); - } - }); - - it("should bundle successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.bundle(path.rel("test/specs/deep-circular/deep-circular.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(bundledSchema); - // The "circular" flag should NOT be set - // (it only gets set by `dereference`) - expect(parser.$refs.circular).to.equal(false); - }); -}); diff --git a/test/specs/deep-circular/deep-circular.yaml b/test/specs/deep-circular/deep-circular.yaml deleted file mode 100644 index ce4c3406..00000000 --- a/test/specs/deep-circular/deep-circular.yaml +++ /dev/null @@ -1,213 +0,0 @@ -title: Deep Schema -type: object -properties: - name: - $ref: "#/definitions/name" - level1: - type: object - required: - - name - properties: - name: - $ref: definitions/name.yaml - level2: - type: object - required: - - name - properties: - name: - $ref: definitions/name.yaml - level3: - type: object - required: - - name - properties: - name: - $ref: "#/definitions/name" - level4: - type: object - required: - - name - properties: - name: - $ref: definitions/name.yaml - level5: - type: object - required: - - name - properties: - name: - $ref: definitions/name.yaml - level6: - type: object - required: - - name - properties: - name: - $ref: "#/definitions/name" - level7: - type: object - required: - - name - properties: - name: - $ref: definitions/name.yaml - level8: - type: object - required: - - name - properties: - name: - $ref: definitions/name.yaml - level9: - type: object - required: - - name - properties: - name: - $ref: definitions/name.yaml - level10: - type: object - required: - - name - properties: - name: - $ref: definitions/name.yaml - level11: - type: object - required: - - name - properties: - name: - $ref: definitions/name.yaml - level12: - type: object - required: - - name - properties: - name: - $ref: "#/definitions/name" - level13: - type: object - required: - - name - properties: - name: - $ref: "#/definitions/name" - level14: - type: object - required: - - name - properties: - name: - $ref: definitions/name.yaml - level15: - type: object - required: - - name - properties: - name: - $ref: definitions/name.yaml - level16: - type: object - required: - - name - properties: - name: - $ref: definitions/name.yaml - level17: - type: object - required: - - name - properties: - name: - $ref: definitions/name.yaml - level18: - type: object - required: - - name - properties: - name: - $ref: definitions/name.yaml - level19: - type: object - required: - - name - properties: - name: - $ref: definitions/name.yaml - level20: - type: object - required: - - name - properties: - name: - $ref: definitions/name.yaml - level21: - type: object - required: - - name - properties: - name: - $ref: definitions/name.yaml - level22: - type: object - required: - - name - properties: - name: - $ref: definitions/name.yaml - level23: - type: object - required: - - name - properties: - name: - $ref: definitions/name.yaml - level24: - type: object - required: - - name - properties: - name: - $ref: definitions/name.yaml - level25: - type: object - required: - - name - properties: - name: - $ref: definitions/name.yaml - level26: - type: object - required: - - name - properties: - name: - $ref: "#/definitions/name" - level27: - type: object - required: - - name - properties: - name: - $ref: definitions/name.yaml - level28: - type: object - required: - - name - properties: - name: - $ref: definitions/name.yaml - level29: - type: object - required: - - name - properties: - name: - $ref: definitions/name.yaml - level30: - $ref: "#" -definitions: - name: - $ref: definitions/name.yaml diff --git a/test/specs/deep-circular/definitions/name.yaml b/test/specs/deep-circular/definitions/name.yaml deleted file mode 100644 index 02eeba43..00000000 --- a/test/specs/deep-circular/definitions/name.yaml +++ /dev/null @@ -1,22 +0,0 @@ -title: name -type: object -required: - - first - - last -properties: - first: - $ref: ../definitions/required-string.yaml - last: - $ref: ./required-string.yaml - middle: - type: - $ref: "#/properties/first/type" - minLength: - $ref: "#/properties/first/minLength" - prefix: - $ref: "#/properties/last" - minLength: 3 - suffix: - type: string - $ref: "#/properties/prefix" - maxLength: 3 diff --git a/test/specs/deep-circular/definitions/required-string.yaml b/test/specs/deep-circular/definitions/required-string.yaml deleted file mode 100644 index 3970e6ba..00000000 --- a/test/specs/deep-circular/definitions/required-string.yaml +++ /dev/null @@ -1,3 +0,0 @@ -title: requiredString -type: string -minLength: 1 diff --git a/test/specs/deep-circular/dereferenced.ts b/test/specs/deep-circular/dereferenced.ts deleted file mode 100644 index 667146c1..00000000 --- a/test/specs/deep-circular/dereferenced.ts +++ /dev/null @@ -1,270 +0,0 @@ -const name = { - required: ["first", "last"], - type: "object", - properties: { - middle: { - minLength: 1, - type: "string", - }, - prefix: { - minLength: 3, - type: "string", - title: "requiredString", - }, - last: { - minLength: 1, - type: "string", - title: "requiredString", - }, - suffix: { - minLength: 3, - maxLength: 3, - type: "string", - title: "requiredString", - }, - first: { - minLength: 1, - type: "string", - title: "requiredString", - }, - }, - title: "name", -}; - -const dereferencedSchema = { - title: "Deep Schema", - type: "object", - definitions: { - name, - }, - properties: { - level1: { - required: ["name"], - type: "object", - properties: { - level2: { - required: ["name"], - type: "object", - properties: { - level3: { - required: ["name"], - type: "object", - properties: { - level4: { - required: ["name"], - type: "object", - properties: { - name, - level5: { - required: ["name"], - type: "object", - properties: { - name, - level6: { - required: ["name"], - type: "object", - properties: { - name, - level7: { - required: ["name"], - type: "object", - properties: { - level8: { - required: ["name"], - type: "object", - properties: { - level9: { - required: ["name"], - type: "object", - properties: { - level10: { - required: ["name"], - type: "object", - properties: { - level11: { - required: ["name"], - type: "object", - properties: { - level12: { - required: ["name"], - type: "object", - properties: { - level13: { - required: ["name"], - type: "object", - properties: { - name, - level14: { - required: ["name"], - type: "object", - properties: { - name, - level15: { - required: ["name"], - type: "object", - properties: { - level16: { - required: ["name"], - type: "object", - properties: { - name, - level17: { - required: ["name"], - type: "object", - properties: { - level18: { - required: ["name"], - type: "object", - properties: { - level19: { - required: ["name"], - type: "object", - properties: { - level20: { - required: ["name"], - type: "object", - properties: { - level21: { - required: ["name"], - type: "object", - properties: { - level22: { - required: ["name"], - type: "object", - properties: { - level23: { - required: ["name"], - type: "object", - properties: { - name, - level24: { - required: ["name"], - type: "object", - properties: { - name, - level25: { - required: [ - "name", - ], - type: "object", - properties: { - name, - level26: { - required: [ - "name", - ], - type: "object", - properties: { - level27: { - required: - [ - "name", - ], - type: "object", - properties: - { - level28: - { - required: - [ - "name", - ], - type: "object", - properties: - { - level29: - { - required: - [ - "name", - ], - type: "object", - properties: - { - name, - }, - }, - name, - }, - }, - name, - }, - }, - name, - }, - }, - }, - }, - }, - }, - }, - }, - name, - }, - }, - name, - }, - }, - name, - }, - }, - name, - }, - }, - name, - }, - }, - name, - }, - }, - }, - }, - name, - }, - }, - }, - }, - }, - }, - name, - }, - }, - name, - }, - }, - name, - }, - }, - name, - }, - }, - name, - }, - }, - name, - }, - }, - }, - }, - }, - }, - }, - }, - name, - }, - }, - name, - }, - }, - name, - }, - }, - name, - }, -}; - -// @ts-expect-error TS(2339): Property 'level30' does not exist on type '{ name:... Remove this comment to see the full error message -dereferencedSchema.properties.level1.properties.level2.properties.level3.properties.level4.properties.level5.properties.level6.properties.level7.properties.level8.properties.level9.properties.level10.properties.level11.properties.level12.properties.level13.properties.level14.properties.level15.properties.level16.properties.level17.properties.level18.properties.level19.properties.level20.properties.level21.properties.level22.properties.level23.properties.level24.properties.level25.properties.level26.properties.level27.properties.level28.properties.level29.properties.level30 = - dereferencedSchema; - -export default dereferencedSchema; diff --git a/test/specs/deep-circular/parsed.ts b/test/specs/deep-circular/parsed.ts deleted file mode 100644 index eac6c21e..00000000 --- a/test/specs/deep-circular/parsed.ts +++ /dev/null @@ -1,338 +0,0 @@ -export default { - schema: { - title: "Deep Schema", - definitions: { - name: { - $ref: "definitions/name.yaml", - }, - }, - type: "object", - properties: { - level1: { - required: ["name"], - type: "object", - properties: { - level2: { - required: ["name"], - type: "object", - properties: { - level3: { - required: ["name"], - type: "object", - properties: { - level4: { - required: ["name"], - type: "object", - properties: { - name: { - $ref: "definitions/name.yaml", - }, - level5: { - required: ["name"], - type: "object", - properties: { - name: { - $ref: "definitions/name.yaml", - }, - level6: { - required: ["name"], - type: "object", - properties: { - name: { - $ref: "#/definitions/name", - }, - level7: { - required: ["name"], - type: "object", - properties: { - level8: { - required: ["name"], - type: "object", - properties: { - level9: { - required: ["name"], - type: "object", - properties: { - level10: { - required: ["name"], - type: "object", - properties: { - level11: { - required: ["name"], - type: "object", - properties: { - level12: { - required: ["name"], - type: "object", - properties: { - level13: { - required: ["name"], - type: "object", - properties: { - name: { - $ref: "#/definitions/name", - }, - level14: { - required: ["name"], - type: "object", - properties: { - name: { - $ref: "definitions/name.yaml", - }, - level15: { - required: ["name"], - type: "object", - properties: { - level16: { - required: ["name"], - type: "object", - properties: { - name: { - $ref: "definitions/name.yaml", - }, - level17: { - required: ["name"], - type: "object", - properties: { - level18: { - required: ["name"], - type: "object", - properties: { - level19: { - required: ["name"], - type: "object", - properties: { - level20: { - required: ["name"], - type: "object", - properties: { - level21: { - required: ["name"], - type: "object", - properties: { - level22: { - required: ["name"], - type: "object", - properties: { - level23: { - required: ["name"], - type: "object", - properties: { - name: { - $ref: "definitions/name.yaml", - }, - level24: { - required: ["name"], - type: "object", - properties: { - name: { - $ref: "definitions/name.yaml", - }, - level25: { - required: [ - "name", - ], - type: "object", - properties: { - name: { - $ref: "definitions/name.yaml", - }, - level26: { - required: [ - "name", - ], - type: "object", - properties: - { - level27: - { - required: - [ - "name", - ], - type: "object", - properties: - { - level28: - { - required: - [ - "name", - ], - type: "object", - properties: - { - level29: - { - required: - [ - "name", - ], - type: "object", - properties: - { - level30: - { - $ref: "#", - }, - name: { - $ref: "definitions/name.yaml", - }, - }, - }, - name: { - $ref: "definitions/name.yaml", - }, - }, - }, - name: { - $ref: "definitions/name.yaml", - }, - }, - }, - name: { - $ref: "#/definitions/name", - }, - }, - }, - }, - }, - }, - }, - }, - }, - name: { - $ref: "definitions/name.yaml", - }, - }, - }, - name: { - $ref: "definitions/name.yaml", - }, - }, - }, - name: { - $ref: "definitions/name.yaml", - }, - }, - }, - name: { - $ref: "definitions/name.yaml", - }, - }, - }, - name: { - $ref: "definitions/name.yaml", - }, - }, - }, - name: { - $ref: "definitions/name.yaml", - }, - }, - }, - }, - }, - name: { - $ref: "definitions/name.yaml", - }, - }, - }, - }, - }, - }, - }, - name: { - $ref: "#/definitions/name", - }, - }, - }, - name: { - $ref: "definitions/name.yaml", - }, - }, - }, - name: { - $ref: "definitions/name.yaml", - }, - }, - }, - name: { - $ref: "definitions/name.yaml", - }, - }, - }, - name: { - $ref: "definitions/name.yaml", - }, - }, - }, - name: { - $ref: "definitions/name.yaml", - }, - }, - }, - }, - }, - }, - }, - }, - }, - name: { - $ref: "#/definitions/name", - }, - }, - }, - name: { - $ref: "definitions/name.yaml", - }, - }, - }, - name: { - $ref: "definitions/name.yaml", - }, - }, - }, - name: { - $ref: "#/definitions/name", - }, - }, - }, - - name: { - required: ["first", "last"], - type: "object", - properties: { - middle: { - minLength: { - $ref: "#/properties/first/minLength", - }, - type: { - $ref: "#/properties/first/type", - }, - }, - prefix: { - minLength: 3, - $ref: "#/properties/last", - }, - last: { - $ref: "./required-string.yaml", - }, - suffix: { - $ref: "#/properties/prefix", - type: "string", - maxLength: 3, - }, - first: { - $ref: "../definitions/required-string.yaml", - }, - }, - title: "name", - }, - - requiredString: { - minLength: 1, - type: "string", - title: "requiredString", - }, -}; diff --git a/test/specs/deep-external/bundled.ts b/test/specs/deep-external/bundled.ts deleted file mode 100644 index 01d622d7..00000000 --- a/test/specs/deep-external/bundled.ts +++ /dev/null @@ -1,79 +0,0 @@ -export default { - info: { - title: "Main", - }, - paths: { - "/test/add-test": { - post: { - requestBody: { - content: { - "application/json": { - schema: { - $ref: "#/components/schemas/Test1", - }, - }, - }, - }, - responses: { - 204: { - description: "No Content", - }, - }, - }, - }, - }, - components: { - schemas: { - "Common.Test3": { - properties: { - test5: { - items: { - properties: { - test5A: { - properties: { - test6: { - items: { - properties: { - type: { - enum: ["VALUE1", "VALUE2", "VALUE3"], - }, - value: { - format: "double", - type: "number", - }, - }, - }, - }, - }, - }, - test5B: { - properties: { - test6: { - items: { - $ref: "#/components/schemas/Common.Test3/properties/test5/items/properties/test5A/properties/test6/items", - }, - }, - }, - }, - }, - }, - }, - }, - }, - Test1: { - properties: { - test2: { - $ref: "#/components/schemas/Test2", - }, - }, - }, - Test2: { - properties: { - test3: { - $ref: "#/components/schemas/Common.Test3", - }, - }, - }, - }, - }, -}; diff --git a/test/specs/deep-external/deep.spec.ts b/test/specs/deep-external/deep.spec.ts deleted file mode 100644 index e29052da..00000000 --- a/test/specs/deep-external/deep.spec.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { describe, it } from "vitest"; -import $RefParser from "../../../lib/index.js"; -import path from "../../utils/path.js"; -import bundledSchema from "./bundled.js"; - -import { expect } from "vitest"; - -describe("Schema with deeply-nested external $refs", () => { - it("should bundle successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.bundle(path.rel("test/specs/deep-external/definitions/Main-spec.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(bundledSchema); - }); -}); diff --git a/test/specs/deep-external/definitions/Main-spec.yaml b/test/specs/deep-external/definitions/Main-spec.yaml deleted file mode 100644 index 13886934..00000000 --- a/test/specs/deep-external/definitions/Main-spec.yaml +++ /dev/null @@ -1,26 +0,0 @@ -info: - title: Main -paths: - /test/add-test: - post: - requestBody: - content: - application/json: - schema: - $ref: "#/components/schemas/Test1" - responses: - "204": - description: No Content - -components: - schemas: - Test1: - properties: - test2: - $ref: "#/components/schemas/Test2" - Test2: - properties: - test3: - $ref: "#/components/schemas/Common.Test3" - Common.Test3: - $ref: "../definitions/Shared.yaml#/components/schemas/Test4" diff --git a/test/specs/deep-external/definitions/Shared.yaml b/test/specs/deep-external/definitions/Shared.yaml deleted file mode 100644 index c0b265cc..00000000 --- a/test/specs/deep-external/definitions/Shared.yaml +++ /dev/null @@ -1,43 +0,0 @@ -info: - title: Shared - -components: - schemas: - Test4: - properties: - test5: - items: - $ref: "#/components/schemas/Test5" - - Test5: - properties: - test5A: - $ref: "#/components/schemas/Test5A" - test5B: - $ref: "#/components/schemas/Test5B" - - Test5A: - properties: - test6: - items: - $ref: "#/components/schemas/Test6" - - Test5B: - properties: - test6: - items: - $ref: "#/components/schemas/Test6" - - Test6: - properties: - type: - $ref: "#/components/schemas/Test7Type" - value: - format: double - type: number - - Test7Type: - enum: - - VALUE1 - - VALUE2 - - VALUE3 diff --git a/test/specs/deep-internal/Full-spec.yaml b/test/specs/deep-internal/Full-spec.yaml deleted file mode 100644 index 46a74aef..00000000 --- a/test/specs/deep-internal/Full-spec.yaml +++ /dev/null @@ -1,67 +0,0 @@ -info: - title: Main -paths: - /test/add-test: - post: - requestBody: - content: - application/json: - schema: - $ref: "#/components/schemas/Test1" - responses: - "204": - description: No Content - -components: - schemas: - Test1: - properties: - test2: - $ref: "#/components/schemas/Test2" - - Test2: - properties: - test3: - $ref: "#/components/schemas/Common.Test3" - - Common.Test3: - $ref: "#/components/schemas/Test4" - - Test4: - properties: - test5: - items: - $ref: "#/components/schemas/Test5" - - Test5: - properties: - test5A: - $ref: "#/components/schemas/Test5A" - test5B: - $ref: "#/components/schemas/Test5B" - - Test5A: - properties: - test6: - items: - $ref: "#/components/schemas/Test6" - - Test5B: - properties: - test6: - items: - $ref: "#/components/schemas/Test6" - - Test6: - properties: - type: - $ref: "#/components/schemas/Test7Type" - value: - format: double - type: number - - Test7Type: - enum: - - VALUE1 - - VALUE2 - - VALUE3 diff --git a/test/specs/deep-internal/bundled.ts b/test/specs/deep-internal/bundled.ts deleted file mode 100644 index 43bdaa4d..00000000 --- a/test/specs/deep-internal/bundled.ts +++ /dev/null @@ -1,97 +0,0 @@ -export default { - info: { - title: "Main", - }, - paths: { - "/test/add-test": { - post: { - requestBody: { - content: { - "application/json": { - schema: { - $ref: "#/components/schemas/Test1", - }, - }, - }, - }, - responses: { - 204: { - description: "No Content", - }, - }, - }, - }, - }, - components: { - schemas: { - "Common.Test3": { - $ref: "#/components/schemas/Test4", - }, - Test1: { - properties: { - test2: { - $ref: "#/components/schemas/Test2", - }, - }, - }, - Test2: { - properties: { - test3: { - $ref: "#/components/schemas/Test4", - }, - }, - }, - Test4: { - properties: { - test5: { - items: { - $ref: "#/components/schemas/Test5", - }, - }, - }, - }, - Test5: { - properties: { - test5A: { - $ref: "#/components/schemas/Test5A", - }, - test5B: { - $ref: "#/components/schemas/Test5B", - }, - }, - }, - Test5A: { - properties: { - test6: { - items: { - $ref: "#/components/schemas/Test6", - }, - }, - }, - }, - Test5B: { - properties: { - test6: { - items: { - $ref: "#/components/schemas/Test6", - }, - }, - }, - }, - Test6: { - properties: { - type: { - $ref: "#/components/schemas/Test7Type", - }, - value: { - format: "double", - type: "number", - }, - }, - }, - Test7Type: { - enum: ["VALUE1", "VALUE2", "VALUE3"], - }, - }, - }, -}; diff --git a/test/specs/deep-internal/deep.spec.ts b/test/specs/deep-internal/deep.spec.ts deleted file mode 100644 index d30cac1d..00000000 --- a/test/specs/deep-internal/deep.spec.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { describe, it } from "vitest"; -import $RefParser from "../../../lib/index.js"; -import path from "../../utils/path.js"; -import bundledSchema from "./bundled.js"; - -import { expect } from "vitest"; - -describe("Schema with deeply-nested internal $refs", () => { - it("should bundle successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.bundle(path.rel("test/specs/deep-internal/Full-spec.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(bundledSchema); - }); -}); diff --git a/test/specs/deep/bundled.ts b/test/specs/deep/bundled.ts deleted file mode 100644 index d83845bd..00000000 --- a/test/specs/deep/bundled.ts +++ /dev/null @@ -1,378 +0,0 @@ -export default { - type: "object", - properties: { - "level 1": { - required: ["name"], - type: "object", - properties: { - "level 2": { - required: ["name"], - type: "object", - properties: { - "level 3": { - required: ["name"], - type: "object", - properties: { - "level 4": { - required: ["name"], - type: "object", - properties: { - name: { - type: { - $ref: "#/properties/name/type", - }, - }, - "level 5": { - required: ["name"], - type: "object", - properties: { - name: { - type: { - $ref: "#/properties/name/type", - }, - }, - "level 6": { - required: ["name"], - type: "object", - properties: { - name: { - type: { - $ref: "#/properties/name/type", - }, - }, - "level 7": { - required: ["name"], - type: "object", - properties: { - "level 8": { - required: ["name"], - type: "object", - properties: { - "level 9": { - required: ["name"], - type: "object", - properties: { - "level 10": { - required: ["name"], - type: "object", - properties: { - "level 11": { - required: ["name"], - type: "object", - properties: { - "level 12": { - required: ["name"], - type: "object", - properties: { - "level 13": { - required: ["name"], - type: "object", - properties: { - name: { - type: { - $ref: "#/properties/name/type", - }, - }, - "level 14": { - required: ["name"], - type: "object", - properties: { - name: { - type: { - $ref: "#/properties/name/type", - }, - }, - "level 15": { - required: ["name"], - type: "object", - properties: { - "level 16": { - required: ["name"], - type: "object", - properties: { - name: { - type: { - $ref: "#/properties/name/type", - }, - }, - "level 17": { - required: ["name"], - type: "object", - properties: { - "level 18": { - required: ["name"], - type: "object", - properties: { - "level 19": { - required: ["name"], - type: "object", - properties: { - "level 20": { - required: ["name"], - type: "object", - properties: { - "level 21": { - required: ["name"], - type: "object", - properties: { - "level 22": { - required: ["name"], - type: "object", - properties: { - "level 23": { - required: ["name"], - type: "object", - properties: { - name: { - type: { - $ref: "#/properties/name/type", - }, - }, - "level 24": { - required: ["name"], - type: "object", - properties: { - name: { - type: { - $ref: "#/properties/name/type", - }, - }, - "level 25": { - required: [ - "name", - ], - type: "object", - properties: { - name: { - type: { - $ref: "#/properties/name/type", - }, - }, - "level 26": { - required: [ - "name", - ], - type: "object", - properties: { - "level 27": - { - required: - [ - "name", - ], - type: "object", - properties: - { - "level 28": - { - required: - [ - "name", - ], - type: "object", - properties: - { - "level 29": - { - required: - [ - "name", - ], - type: "object", - properties: - { - name: { - type: { - $ref: "#/properties/name/type", - }, - }, - }, - }, - name: { - type: { - $ref: "#/properties/name/type", - }, - }, - }, - }, - name: { - type: { - $ref: "#/properties/name/type", - }, - }, - }, - }, - name: { - type: { - $ref: "#/properties/name/type", - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - name: { - type: { - $ref: "#/properties/name/type", - }, - }, - }, - }, - name: { - type: { - $ref: "#/properties/name/type", - }, - }, - }, - }, - name: { - type: { - $ref: "#/properties/name/type", - }, - }, - }, - }, - name: { - type: { - $ref: "#/properties/name/type", - }, - }, - }, - }, - name: { - type: { - $ref: "#/properties/name/type", - }, - }, - }, - }, - name: { - type: { - $ref: "#/properties/name/type", - }, - }, - }, - }, - }, - }, - name: { - type: { - $ref: "#/properties/name/type", - }, - }, - }, - }, - }, - }, - }, - }, - name: { - type: { - $ref: "#/properties/name/type", - }, - }, - }, - }, - name: { - type: { - $ref: "#/properties/name/type", - }, - }, - }, - }, - name: { - type: { - $ref: "#/properties/name/type", - }, - }, - }, - }, - name: { - type: { - $ref: "#/properties/name/type", - }, - }, - }, - }, - name: { - type: { - $ref: "#/properties/name/type", - }, - }, - }, - }, - name: { - type: { - $ref: "#/properties/name/type", - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - name: { - type: { - $ref: "#/properties/name/type", - }, - }, - }, - }, - name: { - type: { - $ref: "#/properties/name/type", - }, - }, - }, - }, - name: { - type: { - $ref: "#/properties/name/type", - }, - }, - }, - }, - name: { - type: { - required: ["first", "last"], - type: "object", - properties: { - middle: { - minLength: { - $ref: "#/properties/name/type/properties/last/minLength", - }, - type: { - $ref: "#/properties/name/type/properties/last/type", - }, - }, - prefix: { - minLength: 3, - $ref: "#/properties/name/type/properties/last", - }, - last: { - minLength: 1, - type: "string", - title: "requiredString", - }, - suffix: { - $ref: "#/properties/name/type/properties/prefix", - type: "string", - maxLength: 3, - }, - first: { - $ref: "#/properties/name/type/properties/last", - }, - }, - title: "name", - }, - }, - }, - title: "Deep Schema", -}; diff --git a/test/specs/deep/deep.spec.ts b/test/specs/deep/deep.spec.ts deleted file mode 100644 index 509768e1..00000000 --- a/test/specs/deep/deep.spec.ts +++ /dev/null @@ -1,62 +0,0 @@ -import { describe, it } from "vitest"; -import $RefParser from "../../../lib/index.js"; -import helper from "../../utils/helper.js"; -import path from "../../utils/path.js"; -import parsedSchema from "./parsed.js"; -import dereferencedSchema from "./dereferenced.js"; -import bundledSchema from "./bundled.js"; - -import { expect } from "vitest"; - -describe("Schema with deeply-nested $refs", () => { - it("should parse successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.parse(path.rel("test/specs/deep/deep.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(parsedSchema.schema); - expect(parser.$refs.paths()).to.deep.equal([path.abs("test/specs/deep/deep.yaml")]); - }); - - it( - "should resolve successfully", - helper.testResolve( - path.rel("test/specs/deep/deep.yaml"), - path.abs("test/specs/deep/deep.yaml"), - parsedSchema.schema, - path.abs("test/specs/deep/definitions/name.yaml"), - parsedSchema.name, - path.abs("test/specs/deep/definitions/required-string.yaml"), - parsedSchema.requiredString, - ), - ); - - it("should dereference successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.dereference(path.rel("test/specs/deep/deep.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(dereferencedSchema); - // Reference equality - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - expect(schema.properties.name.type) - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - .to.equal(schema.properties["level 1"].properties.name.type) - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - .to.equal(schema.properties["level 1"].properties["level 2"].properties.name.type) - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - .to.equal(schema.properties["level 1"].properties["level 2"].properties["level 3"].properties.name.type) - .to.equal( - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - schema.properties["level 1"].properties["level 2"].properties["level 3"].properties["level 4"].properties.name - .type, - ); - // The "circular" flag should NOT be set - expect(parser.$refs.circular).to.equal(false); - }); - - it("should bundle successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.bundle(path.rel("test/specs/deep/deep.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(bundledSchema); - }); -}); diff --git a/test/specs/deep/deep.yaml b/test/specs/deep/deep.yaml deleted file mode 100644 index c201bd1e..00000000 --- a/test/specs/deep/deep.yaml +++ /dev/null @@ -1,238 +0,0 @@ -title: Deep Schema -type: object -properties: - name: - type: - $ref: definitions/name.yaml - level 1: - type: object - required: - - name - properties: - name: - type: - $ref: definitions/name.yaml - level 2: - type: object - required: - - name - properties: - name: - type: - $ref: definitions/name.yaml - level 3: - type: object - required: - - name - properties: - name: - type: - $ref: definitions/name.yaml - level 4: - type: object - required: - - name - properties: - name: - type: - $ref: definitions/name.yaml - level 5: - type: object - required: - - name - properties: - name: - type: - $ref: definitions/name.yaml - level 6: - type: object - required: - - name - properties: - name: - type: - $ref: definitions/name.yaml - level 7: - type: object - required: - - name - properties: - name: - type: - $ref: definitions/name.yaml - level 8: - type: object - required: - - name - properties: - name: - type: - $ref: definitions/name.yaml - level 9: - type: object - required: - - name - properties: - name: - type: - $ref: definitions/name.yaml - level 10: - type: object - required: - - name - properties: - name: - type: - $ref: definitions/name.yaml - level 11: - type: object - required: - - name - properties: - name: - type: - $ref: definitions/name.yaml - level 12: - type: object - required: - - name - properties: - name: - type: - $ref: definitions/name.yaml - level 13: - type: object - required: - - name - properties: - name: - type: - $ref: definitions/name.yaml - level 14: - type: object - required: - - name - properties: - name: - type: - $ref: definitions/name.yaml - level 15: - type: object - required: - - name - properties: - name: - type: - $ref: definitions/name.yaml - level 16: - type: object - required: - - name - properties: - name: - type: - $ref: definitions/name.yaml - level 17: - type: object - required: - - name - properties: - name: - type: - $ref: definitions/name.yaml - level 18: - type: object - required: - - name - properties: - name: - type: - $ref: definitions/name.yaml - level 19: - type: object - required: - - name - properties: - name: - type: - $ref: definitions/name.yaml - level 20: - type: object - required: - - name - properties: - name: - type: - $ref: definitions/name.yaml - level 21: - type: object - required: - - name - properties: - name: - type: - $ref: definitions/name.yaml - level 22: - type: object - required: - - name - properties: - name: - type: - $ref: definitions/name.yaml - level 23: - type: object - required: - - name - properties: - name: - type: - $ref: definitions/name.yaml - level 24: - type: object - required: - - name - properties: - name: - type: - $ref: definitions/name.yaml - level 25: - type: object - required: - - name - properties: - name: - type: - $ref: definitions/name.yaml - level 26: - type: object - required: - - name - properties: - name: - type: - $ref: definitions/name.yaml - level 27: - type: object - required: - - name - properties: - name: - type: - $ref: definitions/name.yaml - level 28: - type: object - required: - - name - properties: - name: - type: - $ref: definitions/name.yaml - level 29: - type: object - required: - - name - properties: - name: - type: - $ref: definitions/name.yaml diff --git a/test/specs/deep/definitions/name.yaml b/test/specs/deep/definitions/name.yaml deleted file mode 100644 index 02eeba43..00000000 --- a/test/specs/deep/definitions/name.yaml +++ /dev/null @@ -1,22 +0,0 @@ -title: name -type: object -required: - - first - - last -properties: - first: - $ref: ../definitions/required-string.yaml - last: - $ref: ./required-string.yaml - middle: - type: - $ref: "#/properties/first/type" - minLength: - $ref: "#/properties/first/minLength" - prefix: - $ref: "#/properties/last" - minLength: 3 - suffix: - type: string - $ref: "#/properties/prefix" - maxLength: 3 diff --git a/test/specs/deep/definitions/required-string.yaml b/test/specs/deep/definitions/required-string.yaml deleted file mode 100644 index 3970e6ba..00000000 --- a/test/specs/deep/definitions/required-string.yaml +++ /dev/null @@ -1,3 +0,0 @@ -title: requiredString -type: string -minLength: 1 diff --git a/test/specs/deep/dereferenced.ts b/test/specs/deep/dereferenced.ts deleted file mode 100644 index a389e226..00000000 --- a/test/specs/deep/dereferenced.ts +++ /dev/null @@ -1,322 +0,0 @@ -const name = { - required: ["first", "last"], - type: "object", - properties: { - middle: { - minLength: 1, - type: "string", - }, - prefix: { - minLength: 3, - type: "string", - title: "requiredString", - }, - last: { - minLength: 1, - type: "string", - title: "requiredString", - }, - suffix: { - minLength: 3, - maxLength: 3, - type: "string", - title: "requiredString", - }, - first: { - minLength: 1, - type: "string", - title: "requiredString", - }, - }, - title: "name", -}; - -export default { - type: "object", - properties: { - "level 1": { - required: ["name"], - type: "object", - properties: { - "level 2": { - required: ["name"], - type: "object", - properties: { - "level 3": { - required: ["name"], - type: "object", - properties: { - "level 4": { - required: ["name"], - type: "object", - properties: { - name: { - type: name, - }, - "level 5": { - required: ["name"], - type: "object", - properties: { - name: { - type: name, - }, - "level 6": { - required: ["name"], - type: "object", - properties: { - name: { - type: name, - }, - "level 7": { - required: ["name"], - type: "object", - properties: { - "level 8": { - required: ["name"], - type: "object", - properties: { - "level 9": { - required: ["name"], - type: "object", - properties: { - "level 10": { - required: ["name"], - type: "object", - properties: { - "level 11": { - required: ["name"], - type: "object", - properties: { - "level 12": { - required: ["name"], - type: "object", - properties: { - "level 13": { - required: ["name"], - type: "object", - properties: { - name: { - type: name, - }, - "level 14": { - required: ["name"], - type: "object", - properties: { - name: { - type: name, - }, - "level 15": { - required: ["name"], - type: "object", - properties: { - "level 16": { - required: ["name"], - type: "object", - properties: { - name: { - type: name, - }, - "level 17": { - required: ["name"], - type: "object", - properties: { - "level 18": { - required: ["name"], - type: "object", - properties: { - "level 19": { - required: ["name"], - type: "object", - properties: { - "level 20": { - required: ["name"], - type: "object", - properties: { - "level 21": { - required: ["name"], - type: "object", - properties: { - "level 22": { - required: ["name"], - type: "object", - properties: { - "level 23": { - required: ["name"], - type: "object", - properties: { - name: { - type: name, - }, - "level 24": { - required: ["name"], - type: "object", - properties: { - name: { - type: name, - }, - "level 25": { - required: [ - "name", - ], - type: "object", - properties: { - name: { - type: name, - }, - "level 26": { - required: [ - "name", - ], - type: "object", - properties: { - "level 27": - { - required: - [ - "name", - ], - type: "object", - properties: - { - "level 28": - { - required: - [ - "name", - ], - type: "object", - properties: - { - "level 29": - { - required: - [ - "name", - ], - type: "object", - properties: - { - name: { - type: name, - }, - }, - }, - name: { - type: name, - }, - }, - }, - name: { - type: name, - }, - }, - }, - name: { - type: name, - }, - }, - }, - }, - }, - }, - }, - }, - }, - name: { - type: name, - }, - }, - }, - name: { - type: name, - }, - }, - }, - name: { - type: name, - }, - }, - }, - name: { - type: name, - }, - }, - }, - name: { - type: name, - }, - }, - }, - name: { - type: name, - }, - }, - }, - }, - }, - name: { - type: name, - }, - }, - }, - }, - }, - }, - }, - name: { - type: name, - }, - }, - }, - name: { - type: name, - }, - }, - }, - name: { - type: name, - }, - }, - }, - name: { - type: name, - }, - }, - }, - name: { - type: name, - }, - }, - }, - name: { - type: name, - }, - }, - }, - }, - }, - }, - }, - }, - }, - name: { - type: name, - }, - }, - }, - name: { - type: name, - }, - }, - }, - name: { - type: name, - }, - }, - }, - name: { - type: name, - }, - }, - title: "Deep Schema", -}; diff --git a/test/specs/deep/parsed.ts b/test/specs/deep/parsed.ts deleted file mode 100644 index 7aa54c77..00000000 --- a/test/specs/deep/parsed.ts +++ /dev/null @@ -1,389 +0,0 @@ -export default { - schema: { - type: "object", - properties: { - "level 1": { - required: ["name"], - type: "object", - properties: { - "level 2": { - required: ["name"], - type: "object", - properties: { - "level 3": { - required: ["name"], - type: "object", - properties: { - "level 4": { - required: ["name"], - type: "object", - properties: { - name: { - type: { - $ref: "definitions/name.yaml", - }, - }, - "level 5": { - required: ["name"], - type: "object", - properties: { - name: { - type: { - $ref: "definitions/name.yaml", - }, - }, - "level 6": { - required: ["name"], - type: "object", - properties: { - name: { - type: { - $ref: "definitions/name.yaml", - }, - }, - "level 7": { - required: ["name"], - type: "object", - properties: { - "level 8": { - required: ["name"], - type: "object", - properties: { - "level 9": { - required: ["name"], - type: "object", - properties: { - "level 10": { - required: ["name"], - type: "object", - properties: { - "level 11": { - required: ["name"], - type: "object", - properties: { - "level 12": { - required: ["name"], - type: "object", - properties: { - "level 13": { - required: ["name"], - type: "object", - properties: { - name: { - type: { - $ref: "definitions/name.yaml", - }, - }, - "level 14": { - required: ["name"], - type: "object", - properties: { - name: { - type: { - $ref: "definitions/name.yaml", - }, - }, - "level 15": { - required: ["name"], - type: "object", - properties: { - "level 16": { - required: ["name"], - type: "object", - properties: { - name: { - type: { - $ref: "definitions/name.yaml", - }, - }, - "level 17": { - required: ["name"], - type: "object", - properties: { - "level 18": { - required: ["name"], - type: "object", - properties: { - "level 19": { - required: ["name"], - type: "object", - properties: { - "level 20": { - required: ["name"], - type: "object", - properties: { - "level 21": { - required: ["name"], - type: "object", - properties: { - "level 22": { - required: ["name"], - type: "object", - properties: { - "level 23": { - required: ["name"], - type: "object", - properties: { - name: { - type: { - $ref: "definitions/name.yaml", - }, - }, - "level 24": { - required: ["name"], - type: "object", - properties: { - name: { - type: { - $ref: "definitions/name.yaml", - }, - }, - "level 25": { - required: [ - "name", - ], - type: "object", - properties: { - name: { - type: { - $ref: "definitions/name.yaml", - }, - }, - "level 26": { - required: [ - "name", - ], - type: "object", - properties: - { - "level 27": - { - required: - [ - "name", - ], - type: "object", - properties: - { - "level 28": - { - required: - [ - "name", - ], - type: "object", - properties: - { - "level 29": - { - required: - [ - "name", - ], - type: "object", - properties: - { - name: { - type: { - $ref: "definitions/name.yaml", - }, - }, - }, - }, - name: { - type: { - $ref: "definitions/name.yaml", - }, - }, - }, - }, - name: { - type: { - $ref: "definitions/name.yaml", - }, - }, - }, - }, - name: { - type: { - $ref: "definitions/name.yaml", - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - name: { - type: { - $ref: "definitions/name.yaml", - }, - }, - }, - }, - name: { - type: { - $ref: "definitions/name.yaml", - }, - }, - }, - }, - name: { - type: { - $ref: "definitions/name.yaml", - }, - }, - }, - }, - name: { - type: { - $ref: "definitions/name.yaml", - }, - }, - }, - }, - name: { - type: { - $ref: "definitions/name.yaml", - }, - }, - }, - }, - name: { - type: { - $ref: "definitions/name.yaml", - }, - }, - }, - }, - }, - }, - name: { - type: { - $ref: "definitions/name.yaml", - }, - }, - }, - }, - }, - }, - }, - }, - name: { - type: { - $ref: "definitions/name.yaml", - }, - }, - }, - }, - name: { - type: { - $ref: "definitions/name.yaml", - }, - }, - }, - }, - name: { - type: { - $ref: "definitions/name.yaml", - }, - }, - }, - }, - name: { - type: { - $ref: "definitions/name.yaml", - }, - }, - }, - }, - name: { - type: { - $ref: "definitions/name.yaml", - }, - }, - }, - }, - name: { - type: { - $ref: "definitions/name.yaml", - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - name: { - type: { - $ref: "definitions/name.yaml", - }, - }, - }, - }, - name: { - type: { - $ref: "definitions/name.yaml", - }, - }, - }, - }, - name: { - type: { - $ref: "definitions/name.yaml", - }, - }, - }, - }, - name: { - type: { - $ref: "definitions/name.yaml", - }, - }, - }, - title: "Deep Schema", - }, - - name: { - required: ["first", "last"], - type: "object", - properties: { - middle: { - minLength: { - $ref: "#/properties/first/minLength", - }, - type: { - $ref: "#/properties/first/type", - }, - }, - prefix: { - minLength: 3, - $ref: "#/properties/last", - }, - last: { - $ref: "./required-string.yaml", - }, - suffix: { - $ref: "#/properties/prefix", - type: "string", - maxLength: 3, - }, - first: { - $ref: "../definitions/required-string.yaml", - }, - }, - title: "name", - }, - - requiredString: { - minLength: 1, - type: "string", - title: "requiredString", - }, -}; diff --git a/test/specs/dereference-callback/dereference-callback.spec.ts b/test/specs/dereference-callback/dereference-callback.spec.ts deleted file mode 100644 index 03d26522..00000000 --- a/test/specs/dereference-callback/dereference-callback.spec.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { describe, it } from "vitest"; -import $RefParser from "../../../lib/index.js"; -import pathUtils from "../../utils/path.js"; - -import { expect } from "vitest"; -import type { Options } from "../../../lib/options"; - -describe("Schema with a $ref", () => { - it("should call onDereference", async () => { - const parser = new $RefParser(); - const calls: any = []; - const schema = pathUtils.rel("test/specs/dereference-callback/dereference-callback.yaml"); - const options = { - dereference: { - onDereference(path, value, parent, parentPropName) { - calls.push({ path, value, parent, parentPropName }); - }, - }, - } as Options; - await parser.dereference(schema, options); - - expect(calls).to.deep.equal([ - { - path: "#/definitions/b", - value: { $ref: "#/definitions/b" }, - parent: { - a: { - $ref: "#/definitions/b", - }, - b: { - $ref: "#/definitions/b", - }, - }, - parentPropName: "a", - }, - { - path: "#/definitions/a", - value: { $ref: "#/definitions/b" }, - parent: { - c: { - type: "string", - }, - d: { - $ref: "#/definitions/b", - }, - }, - parentPropName: "d", - }, - ]); - }); -}); diff --git a/test/specs/dereference-callback/dereference-callback.yaml b/test/specs/dereference-callback/dereference-callback.yaml deleted file mode 100644 index f9c40dd9..00000000 --- a/test/specs/dereference-callback/dereference-callback.yaml +++ /dev/null @@ -1,12 +0,0 @@ -title: test -type: object -definitions: - a: - $ref: "#/definitions/b" - b: - $ref: "#/definitions/a" -properties: - c: - type: string - d: - $ref: "#/definitions/a" diff --git a/test/specs/empty/empty.json b/test/specs/empty/empty.json deleted file mode 100644 index 0967ef42..00000000 --- a/test/specs/empty/empty.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/test/specs/empty/empty.spec.ts b/test/specs/empty/empty.spec.ts deleted file mode 100644 index 9d932528..00000000 --- a/test/specs/empty/empty.spec.ts +++ /dev/null @@ -1,57 +0,0 @@ -import { describe, it } from "vitest"; -import $RefParser from "../../../lib/index.js"; -import helper from "../../utils/helper.js"; -import path from "../../utils/path.js"; - -import { expect } from "vitest"; - -describe("Empty schema", () => { - it("should parse successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.parse(path.rel("test/specs/empty/empty.json")); - expect(schema).to.be.an("object"); - expect(schema).to.be.empty; // eslint-disable-line no-unused-expressions - expect(parser.schema).to.equal(schema); - expect(parser.$refs.paths()).to.deep.equal([path.abs("test/specs/empty/empty.json")]); - }); - - it( - "should resolve successfully", - helper.testResolve(path.rel("test/specs/empty/empty.json"), path.abs("test/specs/empty/empty.json"), {}), - ); - - it("should dereference successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.dereference(path.rel("test/specs/empty/empty.json")); - expect(schema).to.be.an("object"); - expect(schema).to.be.empty; // eslint-disable-line no-unused-expressions - expect(parser.schema).to.equal(schema); - expect(parser.$refs.paths()).to.deep.equal([path.abs("test/specs/empty/empty.json")]); - // The "circular" flag should NOT be set - expect(parser.$refs.circular).to.equal(false); - }); - - it("should bundle successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.bundle(path.rel("test/specs/empty/empty.json")); - expect(schema).to.be.an("object"); - expect(schema).to.be.empty; // eslint-disable-line no-unused-expressions - expect(parser.schema).to.equal(schema); - expect(parser.$refs.paths()).to.deep.equal([path.abs("test/specs/empty/empty.json")]); - }); - - it('should throw an error if "parse.json.allowEmpty" is disabled', async () => { - try { - await $RefParser.parse(path.rel("test/specs/empty/empty.json"), { parse: { json: { allowEmpty: false } } }); - helper.shouldNotGetCalled(); - } catch (err) { - expect(err).to.be.an.instanceOf(SyntaxError); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain("Error parsing "); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain('empty/empty.json"'); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain("Parsed value is empty"); - } - }); -}); diff --git a/test/specs/error-source/broken-external.json b/test/specs/error-source/broken-external.json deleted file mode 100644 index 0dd10d2e..00000000 --- a/test/specs/error-source/broken-external.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "components": { - "messages": { - "testMessage": { - "payload": { - "$ref": "#/components/schemas/testSchema" - } - } - }, - "schemas": { - "testSchema": { - "type": "object", - "properties": { - "name": { - "type": "string" - }, - "test": { - "$ref": "non-existing.json" - } - } - } - } - } -} diff --git a/test/specs/error-source/error-source.spec.ts b/test/specs/error-source/error-source.spec.ts deleted file mode 100644 index 3db8c576..00000000 --- a/test/specs/error-source/error-source.spec.ts +++ /dev/null @@ -1,83 +0,0 @@ -import { describe, it } from "vitest"; - -import { expect } from "vitest"; -import $RefParser from "../../../lib/index.js"; -import helper from "../../utils/helper.js"; -import path from "../../utils/path.js"; -import { InvalidPointerError, ResolverError, MissingPointerError } from "../../../lib/util/errors.js"; - -describe("Report correct error source and path for", () => { - it("schema with broken reference", async () => { - const parser = new $RefParser(); - try { - await parser.dereference({ foo: { bar: { $ref: "I do not exist" } } }, { continueOnError: true }); - helper.shouldNotGetCalled(); - } catch (err: any) { - expect(err.errors).to.containSubset([ - { - name: ResolverError.name, - source: (source: any) => typeof source === "string", - path: ["foo", "bar"], - message: (message: any) => typeof message === "string", - }, - ]); - } - }); - - it("schema with a local reference pointing at property with broken external reference", async () => { - const parser = new $RefParser(); - try { - await parser.dereference(path.abs("test/specs/error-source/broken-external.json"), { continueOnError: true }); - helper.shouldNotGetCalled(); - } catch (err: any) { - expect(err.errors).to.containSubset([ - { - name: ResolverError.name, - source: path.unixify(path.abs("test/specs/error-source/broken-external.json")), - path: ["components", "schemas", "testSchema", "properties", "test"], - message: (message: any) => typeof message === "string", - }, - ]); - } - }); - - it("schema with a missing local pointer and reference pointing at external file with broken external", async () => { - const parser = new $RefParser(); - try { - await parser.dereference(path.abs("test/specs/error-source/invalid-external.json"), { continueOnError: true }); - helper.shouldNotGetCalled(); - } catch (err: any) { - expect(err.errors).to.containSubset([ - { - name: MissingPointerError.name, - source: path.unixify(path.abs("test/specs/error-source/invalid-external.json")), - path: ["foo", "bar"], - message: (message: any) => typeof message === "string", - }, - { - name: ResolverError.name, - source: path.unixify(path.abs("test/specs/error-source/broken-external.json")), - path: ["components", "schemas", "testSchema", "properties", "test"], - message: (message: any) => typeof message === "string", - }, - ]); - } - }); - - it("schema with an invalid pointer", async () => { - const parser = new $RefParser(); - try { - await parser.dereference(path.abs("test/specs/error-source/invalid-pointer.json"), { continueOnError: true }); - helper.shouldNotGetCalled(); - } catch (err: any) { - expect(err.errors).to.containSubset([ - { - name: InvalidPointerError.name, - source: path.unixify(path.abs("test/specs/error-source/invalid-pointer.json")), - path: ["foo", "baz"], - message: (message: any) => typeof message === "string", - }, - ]); - } - }); -}); diff --git a/test/specs/error-source/invalid-external.json b/test/specs/error-source/invalid-external.json deleted file mode 100644 index d2f600d2..00000000 --- a/test/specs/error-source/invalid-external.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "foo": { - "baz": { - "$ref": "./broken-external.json#/components/messages/testMessage/payload" - }, - "bar": { - "$ref": "#/foo/baz-2" - }, - "bazinga": { - "$ref": "/#foo/baz-2" - } - } -} diff --git a/test/specs/error-source/invalid-pointer.json b/test/specs/error-source/invalid-pointer.json deleted file mode 100644 index 5017acfe..00000000 --- a/test/specs/error-source/invalid-pointer.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "foo": { - "baz": { - "$ref": "/#foo/baz-2" - } - } -} diff --git a/test/specs/exports.spec.ts b/test/specs/exports.spec.ts deleted file mode 100644 index e37ec52e..00000000 --- a/test/specs/exports.spec.ts +++ /dev/null @@ -1,76 +0,0 @@ -import { describe, it } from "vitest"; -import defaultExport from "../../lib/index.js"; -import { default as namedDefaultExport } from "../../lib/index.js"; -import { - JSONParserError, - InvalidPointerError, - MissingPointerError, - ResolverError, - ParserError, - UnmatchedParserError, - UnmatchedResolverError, -} from "../../lib/index.js"; - -import { expect } from "vitest"; - -describe("json-schema-ref-parser package exports", () => { - function is$RefParser(parser: any) { - expect(parser).to.be.a("function").with.property("name", "$RefParser"); - expect(parser.parse).to.be.a("function").with.property("name", "parse"); - expect(parser.prototype.parse).to.be.a("function").with.property("name", "parse"); - expect(parser.resolve).to.be.a("function").with.property("name", "resolve"); - expect(parser.prototype.resolve).to.be.a("function").with.property("name", "resolve"); - expect(parser.dereference).to.be.a("function").with.property("name", "dereference"); - expect(parser.prototype.dereference).to.be.a("function").with.property("name", "dereference"); - expect(parser.bundle).to.be.a("function").with.property("name", "bundle"); - expect(parser.prototype.bundle).to.be.a("function").with.property("name", "bundle"); - return true; - } - - // it("should export the $RefParser class as the default CommonJS export", async () => { - // expect(commonJSExport).to.satisfy(is$RefParser); - // }); - - it("should export the $RefParser class as the default ESM export", async () => { - expect(defaultExport).to.satisfy(is$RefParser); - }); - - it("should export the $RefParser class as the named default ESM export", async () => { - expect(namedDefaultExport).to.satisfy(is$RefParser); - }); - - it("should export the JSONParserError class as a named ESM export", async () => { - expect(JSONParserError).to.be.a("function"); - expect(JSONParserError.name).to.equal("JSONParserError"); - }); - - it("should export the InvalidPointerError class as a named ESM export", async () => { - expect(InvalidPointerError).to.be.a("function"); - expect(InvalidPointerError.name).to.equal("InvalidPointerError"); - }); - - it("should export the MissingPointerError class as a named ESM export", async () => { - expect(MissingPointerError).to.be.a("function"); - expect(MissingPointerError.name).to.equal("MissingPointerError"); - }); - - it("should export the ResolverError class as a named ESM export", async () => { - expect(ResolverError).to.be.a("function"); - expect(ResolverError.name).to.equal("ResolverError"); - }); - - it("should export the ParserError class as a named ESM export", async () => { - expect(ParserError).to.be.a("function"); - expect(ParserError.name).to.equal("ParserError"); - }); - - it("should export the UnmatchedParserError class as a named ESM export", async () => { - expect(UnmatchedParserError).to.be.a("function"); - expect(UnmatchedParserError.name).to.equal("UnmatchedParserError"); - }); - - it("should export the UnmatchedResolverError class as a named ESM export", async () => { - expect(UnmatchedResolverError).to.be.a("function"); - expect(UnmatchedResolverError.name).to.equal("UnmatchedResolverError"); - }); -}); diff --git a/test/specs/external-from-internal/bundled.ts b/test/specs/external-from-internal/bundled.ts deleted file mode 100644 index cd89f4c7..00000000 --- a/test/specs/external-from-internal/bundled.ts +++ /dev/null @@ -1,24 +0,0 @@ -export default { - internal1: { - $ref: "#/external1", - }, - internal2: { - $ref: "#/external1", - }, - internal3: { - $ref: "#/external2", - }, - internal4: { - $ref: "#/external2", - }, - external1: { - test: { - type: "string", - }, - }, - external2: { - test: { - $ref: "#/external1/test", // <-- It should point to the most direct reference - }, - }, -}; diff --git a/test/specs/external-from-internal/definitions.yaml b/test/specs/external-from-internal/definitions.yaml deleted file mode 100644 index c123cf5f..00000000 --- a/test/specs/external-from-internal/definitions.yaml +++ /dev/null @@ -1,2 +0,0 @@ -thing: - type: string diff --git a/test/specs/external-from-internal/dereferenced.ts b/test/specs/external-from-internal/dereferenced.ts deleted file mode 100644 index eb9ed69d..00000000 --- a/test/specs/external-from-internal/dereferenced.ts +++ /dev/null @@ -1,32 +0,0 @@ -export default { - internal1: { - test: { - type: "string", - }, - }, - internal2: { - test: { - type: "string", - }, - }, - internal3: { - test: { - type: "string", - }, - }, - internal4: { - test: { - type: "string", - }, - }, - external1: { - test: { - type: "string", - }, - }, - external2: { - test: { - type: "string", - }, - }, -}; diff --git a/test/specs/external-from-internal/external-from-internal.spec.ts b/test/specs/external-from-internal/external-from-internal.spec.ts deleted file mode 100644 index 1ea300a6..00000000 --- a/test/specs/external-from-internal/external-from-internal.spec.ts +++ /dev/null @@ -1,115 +0,0 @@ -import { describe, it } from "vitest"; -import $RefParser from "../../../lib/index.js"; -import helper from "../../utils/helper.js"; -import path from "../../utils/path.js"; -import parsedSchema from "./parsed.js"; -import dereferencedSchema from "./dereferenced.js"; -import bundledSchema from "./bundled.js"; - -import { expect } from "vitest"; - -/** - * This test is from PR #62 - * https://github.com/APIDevTools/json-schema-ref-parser/pull/62 - */ -describe("Schema with two external refs to the same value and internal ref before", () => { - it("should parse successfully from an absolute path", async () => { - const parser = new $RefParser(); - const schema = await parser.parse(path.abs("test/specs/external-from-internal/external-from-internal.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(parsedSchema.schema); - expect(parser.$refs.paths()).to.deep.equal([ - path.abs("test/specs/external-from-internal/external-from-internal.yaml"), - ]); - }); - - it("should parse successfully from a relative path", async () => { - const parser = new $RefParser(); - const schema = await parser.parse(path.rel("test/specs/external-from-internal/external-from-internal.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(parsedSchema.schema); - expect(parser.$refs.paths()).to.deep.equal([ - path.abs("test/specs/external-from-internal/external-from-internal.yaml"), - ]); - }); - - it("should parse successfully from a url", async () => { - const parser = new $RefParser(); - const schema = await parser.parse(path.url("test/specs/external-from-internal/external-from-internal.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(parsedSchema.schema); - expect(parser.$refs.paths()).to.deep.equal([ - path.url("test/specs/external-from-internal/external-from-internal.yaml"), - ]); - }); - - it( - "should resolve successfully from an absolute path", - helper.testResolve( - path.abs("test/specs/external-from-internal/external-from-internal.yaml"), - path.abs("test/specs/external-from-internal/external-from-internal.yaml"), - parsedSchema.schema, - path.abs("test/specs/external-from-internal/definitions.yaml"), - parsedSchema.definitions, - ), - ); - - it( - "should resolve successfully from a relative path", - helper.testResolve( - path.rel("test/specs/external-from-internal/external-from-internal.yaml"), - path.abs("test/specs/external-from-internal/external-from-internal.yaml"), - parsedSchema.schema, - path.abs("test/specs/external-from-internal/definitions.yaml"), - parsedSchema.definitions, - ), - ); - - it( - "should resolve successfully from a url", - helper.testResolve( - path.url("test/specs/external-from-internal/external-from-internal.yaml"), - path.url("test/specs/external-from-internal/external-from-internal.yaml"), - parsedSchema.schema, - path.url("test/specs/external-from-internal/definitions.yaml"), - parsedSchema.definitions, - ), - ); - - it("should dereference successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.dereference(path.rel("test/specs/external-from-internal/external-from-internal.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(dereferencedSchema); - // Reference equality - // @ts-expect-error TS(2339): Property 'internal1' does not exist on type 'JSONS... Remove this comment to see the full error message - expect(schema.internal1).to.equal(schema.internal2); - // @ts-expect-error TS(2339): Property 'internal2' does not exist on type 'JSONS... Remove this comment to see the full error message - expect(schema.internal2).to.equal(schema.external1); - // @ts-expect-error TS(2339): Property 'internal3' does not exist on type 'JSONS... Remove this comment to see the full error message - expect(schema.internal3).to.equal(schema.internal4); - // @ts-expect-error TS(2339): Property 'internal4' does not exist on type 'JSONS... Remove this comment to see the full error message - expect(schema.internal4).to.equal(schema.external2); - // @ts-expect-error TS(2339): Property 'internal1' does not exist on type 'JSONS... Remove this comment to see the full error message - expect(schema.internal1.test) - // @ts-expect-error TS(2339): Property 'internal2' does not exist on type 'JSONS... Remove this comment to see the full error message - .to.equal(schema.internal2.test) - // @ts-expect-error TS(2339): Property 'internal3' does not exist on type 'JSONS... Remove this comment to see the full error message - .to.equal(schema.internal3.test) - // @ts-expect-error TS(2339): Property 'internal4' does not exist on type 'JSONS... Remove this comment to see the full error message - .to.equal(schema.internal4.test) - // @ts-expect-error TS(2339): Property 'external1' does not exist on type 'JSONS... Remove this comment to see the full error message - .to.equal(schema.external1.test) - // @ts-expect-error TS(2339): Property 'external2' does not exist on type 'JSONS... Remove this comment to see the full error message - .to.equal(schema.external2.test); - // The "circular" flag should NOT be set - expect(parser.$refs.circular).to.equal(false); - }); - - it("should bundle successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.bundle(path.rel("test/specs/external-from-internal/external-from-internal.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(bundledSchema); - }); -}); diff --git a/test/specs/external-from-internal/external-from-internal.yaml b/test/specs/external-from-internal/external-from-internal.yaml deleted file mode 100644 index 6ae56892..00000000 --- a/test/specs/external-from-internal/external-from-internal.yaml +++ /dev/null @@ -1,14 +0,0 @@ -internal1: - $ref: "#/internal2" -internal2: - $ref: "#/external1" -internal3: - $ref: "#/internal4" -internal4: - $ref: "#/external2" -external1: - test: - $ref: "definitions.yaml#/thing" -external2: - test: - $ref: "definitions.yaml#/thing" diff --git a/test/specs/external-from-internal/parsed.ts b/test/specs/external-from-internal/parsed.ts deleted file mode 100644 index 44419f83..00000000 --- a/test/specs/external-from-internal/parsed.ts +++ /dev/null @@ -1,32 +0,0 @@ -export default { - schema: { - internal1: { - $ref: "#/internal2", - }, - internal2: { - $ref: "#/external1", - }, - internal3: { - $ref: "#/internal4", - }, - internal4: { - $ref: "#/external2", - }, - external1: { - test: { - $ref: "definitions.yaml#/thing", - }, - }, - external2: { - test: { - $ref: "definitions.yaml#/thing", - }, - }, - }, - - definitions: { - thing: { - type: "string", - }, - }, -}; diff --git a/test/specs/external-multiple/bundled.ts b/test/specs/external-multiple/bundled.ts deleted file mode 100644 index 60b17f9b..00000000 --- a/test/specs/external-multiple/bundled.ts +++ /dev/null @@ -1,27 +0,0 @@ -export default { - type: "object", - required: ["user", "token"], - properties: { - token: { - type: "string", - }, - user: { - type: "object", - required: ["name"], - properties: { - name: { - type: "string", - }, - }, - example: { - name: "Homer", - }, - }, - }, - example: { - token: "11111111", - user: { - $ref: "#/properties/user/example", - }, - }, -}; diff --git a/test/specs/external-multiple/definitions.yaml b/test/specs/external-multiple/definitions.yaml deleted file mode 100644 index 9ccfa790..00000000 --- a/test/specs/external-multiple/definitions.yaml +++ /dev/null @@ -1,8 +0,0 @@ -User: - type: object - required: [name] - properties: - name: - type: string - example: - name: "Homer" diff --git a/test/specs/external-multiple/dereferenced.ts b/test/specs/external-multiple/dereferenced.ts deleted file mode 100644 index 1d517a7c..00000000 --- a/test/specs/external-multiple/dereferenced.ts +++ /dev/null @@ -1,27 +0,0 @@ -export default { - type: "object", - required: ["user", "token"], - properties: { - token: { - type: "string", - }, - user: { - type: "object", - required: ["name"], - properties: { - name: { - type: "string", - }, - }, - example: { - name: "Homer", - }, - }, - }, - example: { - token: "11111111", - user: { - name: "Homer", - }, - }, -}; diff --git a/test/specs/external-multiple/external-multiple.spec.ts b/test/specs/external-multiple/external-multiple.spec.ts deleted file mode 100644 index e6fcd692..00000000 --- a/test/specs/external-multiple/external-multiple.spec.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { describe, it } from "vitest"; -import $RefParser from "../../../lib/index.js"; -import helper from "../../utils/helper.js"; -import path from "../../utils/path.js"; -import parsedSchema from "./parsed.js"; -import dereferencedSchema from "./dereferenced.js"; -import bundledSchema from "./bundled.js"; - -import { expect } from "vitest"; - -describe("Schema with multiple external $refs to different parts of a file", () => { - it("should parse successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.parse(path.abs("test/specs/external-multiple/external-multiple.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(parsedSchema.schema); - expect(parser.$refs.paths()).to.deep.equal([path.abs("test/specs/external-multiple/external-multiple.yaml")]); - }); - - it( - "should resolve successfully", - helper.testResolve( - path.rel("test/specs/external-multiple/external-multiple.yaml"), - path.abs("test/specs/external-multiple/external-multiple.yaml"), - parsedSchema.schema, - path.abs("test/specs/external-multiple/definitions.yaml"), - parsedSchema.definitions, - ), - ); - - it("should dereference successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.dereference(path.rel("test/specs/external-multiple/external-multiple.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(dereferencedSchema); - // Reference equality - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - expect(schema.properties.user.example).to.equal(schema.example.user); - // The "circular" flag should NOT be set - expect(parser.$refs.circular).to.equal(false); - }); - - it("should bundle successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.bundle(path.rel("test/specs/external-multiple/external-multiple.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(bundledSchema); - }); -}); diff --git a/test/specs/external-multiple/external-multiple.yaml b/test/specs/external-multiple/external-multiple.yaml deleted file mode 100644 index 5db3a226..00000000 --- a/test/specs/external-multiple/external-multiple.yaml +++ /dev/null @@ -1,11 +0,0 @@ -type: object -required: [user, token] -properties: - token: - type: string - user: - $ref: "definitions.yaml#/User" -example: - token: "11111111" - user: - $ref: "definitions.yaml#/User/example" diff --git a/test/specs/external-multiple/parsed.ts b/test/specs/external-multiple/parsed.ts deleted file mode 100644 index d308586f..00000000 --- a/test/specs/external-multiple/parsed.ts +++ /dev/null @@ -1,35 +0,0 @@ -export default { - schema: { - type: "object", - required: ["user", "token"], - properties: { - token: { - type: "string", - }, - user: { - $ref: "definitions.yaml#/User", - }, - }, - example: { - token: "11111111", - user: { - $ref: "definitions.yaml#/User/example", - }, - }, - }, - - definitions: { - User: { - type: "object", - required: ["name"], - properties: { - name: { - type: "string", - }, - }, - example: { - name: "Homer", - }, - }, - }, -}; diff --git a/test/specs/external-partial/bundled.ts b/test/specs/external-partial/bundled.ts deleted file mode 100644 index 19cbcf59..00000000 --- a/test/specs/external-partial/bundled.ts +++ /dev/null @@ -1,47 +0,0 @@ -export default { - title: "Person", - type: "object", - required: ["name"], - properties: { - name: { - title: "name", - type: "object", - required: ["first", "last"], - properties: { - first: { - $ref: "#/properties/name/properties/last", - }, - last: { - title: "required string", - type: "string", - minLength: 1, - }, - middle: { - type: { - $ref: "#/properties/name/properties/last/type", - }, - minLength: { - $ref: "#/properties/name/properties/last/minLength", - }, - }, - prefix: { - $ref: "#/properties/name/properties/last", - minLength: 3, - }, - suffix: { - $ref: "#/properties/name/properties/prefix", - type: "string", - maxLength: 3, - }, - }, - }, - age: { - type: "integer", - minimum: 0, - }, - gender: { - type: "string", - enum: ["male", "female"], - }, - }, -}; diff --git a/test/specs/external-partial/definitions/definitions.json b/test/specs/external-partial/definitions/definitions.json deleted file mode 100644 index 18a90e7a..00000000 --- a/test/specs/external-partial/definitions/definitions.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "required string": { - "$ref": "required-string.yaml" - }, - "string": { - "$ref": "#/required%20string/type" - }, - "name": { - "$ref": "../definitions/name.yaml" - }, - "age": { - "type": "integer", - "minimum": 0 - }, - "gender": { - "type": "string", - "enum": ["male", "female"] - } -} diff --git a/test/specs/external-partial/definitions/name.yaml b/test/specs/external-partial/definitions/name.yaml deleted file mode 100644 index 343e6fc5..00000000 --- a/test/specs/external-partial/definitions/name.yaml +++ /dev/null @@ -1,22 +0,0 @@ -title: name -type: object -required: - - first - - last -properties: - first: - $ref: ../definitions/definitions.json#/required string - last: - $ref: ./required-string.yaml - middle: - type: - $ref: "definitions.json#/name/properties/first/type" - minLength: - $ref: "definitions.json#/name/properties/first/minLength" - prefix: - $ref: "../definitions/definitions.json#/name/properties/last" - minLength: 3 - suffix: - type: string - $ref: "definitions.json#/name/properties/prefix" - maxLength: 3 diff --git a/test/specs/external-partial/definitions/required-string.yaml b/test/specs/external-partial/definitions/required-string.yaml deleted file mode 100644 index 7e538a3c..00000000 --- a/test/specs/external-partial/definitions/required-string.yaml +++ /dev/null @@ -1,3 +0,0 @@ -title: required string -type: string -minLength: 1 diff --git a/test/specs/external-partial/dereferenced.ts b/test/specs/external-partial/dereferenced.ts deleted file mode 100644 index 13a0b95b..00000000 --- a/test/specs/external-partial/dereferenced.ts +++ /dev/null @@ -1,47 +0,0 @@ -export default { - title: "Person", - type: "object", - required: ["name"], - properties: { - name: { - title: "name", - type: "object", - required: ["first", "last"], - properties: { - first: { - title: "required string", - type: "string", - minLength: 1, - }, - last: { - title: "required string", - type: "string", - minLength: 1, - }, - middle: { - type: "string", - minLength: 1, - }, - prefix: { - title: "required string", - type: "string", - minLength: 3, - }, - suffix: { - title: "required string", - type: "string", - minLength: 3, - maxLength: 3, - }, - }, - }, - age: { - type: "integer", - minimum: 0, - }, - gender: { - type: "string", - enum: ["male", "female"], - }, - }, -}; diff --git a/test/specs/external-partial/external-partial.spec.ts b/test/specs/external-partial/external-partial.spec.ts deleted file mode 100644 index 854f0dcf..00000000 --- a/test/specs/external-partial/external-partial.spec.ts +++ /dev/null @@ -1,53 +0,0 @@ -import { describe, it } from "vitest"; -import $RefParser from "../../../lib/index.js"; -import helper from "../../utils/helper.js"; -import path from "../../utils/path.js"; -import parsedSchema from "./parsed.js"; -import dereferencedSchema from "./dereferenced.js"; -import bundledSchema from "./bundled.js"; - -import { expect } from "vitest"; - -describe("Schema with $refs to parts of external files", () => { - it("should parse successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.parse(path.rel("test/specs/external-partial/external-partial.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(parsedSchema.schema); - expect(parser.$refs.paths()).to.deep.equal([path.abs("test/specs/external-partial/external-partial.yaml")]); - }); - - it( - "should resolve successfully", - helper.testResolve( - path.rel("test/specs/external-partial/external-partial.yaml"), - path.abs("test/specs/external-partial/external-partial.yaml"), - parsedSchema.schema, - path.abs("test/specs/external-partial/definitions/definitions.json"), - parsedSchema.definitions, - path.abs("test/specs/external-partial/definitions/name.yaml"), - parsedSchema.name, - path.abs("test/specs/external-partial/definitions/required-string.yaml"), - parsedSchema.requiredString, - ), - ); - - it("should dereference successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.dereference(path.rel("test/specs/external-partial/external-partial.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(dereferencedSchema); - // Reference equality - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - expect(schema.properties.name.properties.first).to.equal(schema.properties.name.properties.last); - // The "circular" flag should NOT be set - expect(parser.$refs.circular).to.equal(false); - }); - - it("should bundle successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.bundle(path.rel("test/specs/external-partial/external-partial.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(bundledSchema); - }); -}); diff --git a/test/specs/external-partial/external-partial.yaml b/test/specs/external-partial/external-partial.yaml deleted file mode 100644 index 22a0ec00..00000000 --- a/test/specs/external-partial/external-partial.yaml +++ /dev/null @@ -1,11 +0,0 @@ -title: Person -type: object -required: - - name -properties: - name: - $ref: "definitions/definitions.json#/name" - age: - $ref: "definitions/definitions.json#/age" - gender: - $ref: "definitions/definitions.json#/gender" diff --git a/test/specs/external-partial/parsed.ts b/test/specs/external-partial/parsed.ts deleted file mode 100644 index cde54891..00000000 --- a/test/specs/external-partial/parsed.ts +++ /dev/null @@ -1,75 +0,0 @@ -export default { - schema: { - required: ["name"], - type: "object", - properties: { - gender: { - $ref: "definitions/definitions.json#/gender", - }, - age: { - $ref: "definitions/definitions.json#/age", - }, - name: { - $ref: "definitions/definitions.json#/name", - }, - }, - title: "Person", - }, - - definitions: { - "required string": { - $ref: "required-string.yaml", - }, - string: { - $ref: "#/required%20string/type", - }, - name: { - $ref: "../definitions/name.yaml", - }, - age: { - type: "integer", - minimum: 0, - }, - gender: { - type: "string", - enum: ["male", "female"], - }, - }, - - name: { - required: ["first", "last"], - type: "object", - properties: { - middle: { - minLength: { - $ref: "definitions.json#/name/properties/first/minLength", - }, - type: { - $ref: "definitions.json#/name/properties/first/type", - }, - }, - prefix: { - minLength: 3, - $ref: "../definitions/definitions.json#/name/properties/last", - }, - last: { - $ref: "./required-string.yaml", - }, - suffix: { - $ref: "definitions.json#/name/properties/prefix", - type: "string", - maxLength: 3, - }, - first: { - $ref: "../definitions/definitions.json#/required string", - }, - }, - title: "name", - }, - - requiredString: { - minLength: 1, - type: "string", - title: "required string", - }, -}; diff --git a/test/specs/external/bundled.ts b/test/specs/external/bundled.ts deleted file mode 100644 index 950730a1..00000000 --- a/test/specs/external/bundled.ts +++ /dev/null @@ -1,58 +0,0 @@ -export default { - title: "Person", - type: "object", - required: ["name"], - properties: { - name: { - $ref: "#/definitions/name", - }, - age: { - type: "integer", - minimum: 0, - }, - gender: { - type: "string", - enum: ["male", "female"], - }, - }, - definitions: { - "required string": { - title: "required string", - type: "string", - minLength: 1, - }, - string: { - $ref: "#/definitions/required%20string/type", - }, - name: { - title: "name", - type: "object", - required: ["first", "last"], - properties: { - first: { - $ref: "#/definitions/required%20string", - }, - last: { - $ref: "#/definitions/required%20string", - }, - middle: { - type: { - $ref: "#/definitions/required%20string/type", - }, - minLength: { - $ref: "#/definitions/required%20string/minLength", - }, - }, - prefix: { - $ref: "#/definitions/required%20string", - minLength: 3, - }, - suffix: { - $ref: "#/definitions/name/properties/prefix", - type: "string", - maxLength: 3, - }, - }, - }, - }, -}; diff --git a/test/specs/external/definitions/definitions.json b/test/specs/external/definitions/definitions.json deleted file mode 100644 index 9c1cd400..00000000 --- a/test/specs/external/definitions/definitions.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "required string": { - "$ref": "required-string.yaml" - }, - "string": { - "$ref": "#/required%20string/type" - }, - "name": { - "$ref": "../definitions/name.yaml" - } -} diff --git a/test/specs/external/definitions/name.yaml b/test/specs/external/definitions/name.yaml deleted file mode 100644 index 1210ac45..00000000 --- a/test/specs/external/definitions/name.yaml +++ /dev/null @@ -1,22 +0,0 @@ -title: name -type: object -required: - - first - - last -properties: - first: - $ref: ../definitions/definitions.json#/required string - last: - $ref: ./required-string.yaml - middle: - type: - $ref: "#/properties/first/type" - minLength: - $ref: "#/properties/first/minLength" - prefix: - $ref: "#/properties/last" - minLength: 3 - suffix: - type: string - $ref: "#/properties/prefix" - maxLength: 3 diff --git a/test/specs/external/definitions/required-string.yaml b/test/specs/external/definitions/required-string.yaml deleted file mode 100644 index 7e538a3c..00000000 --- a/test/specs/external/definitions/required-string.yaml +++ /dev/null @@ -1,3 +0,0 @@ -title: required string -type: string -minLength: 1 diff --git a/test/specs/external/dereferenced.ts b/test/specs/external/dereferenced.ts deleted file mode 100644 index 08a960f7..00000000 --- a/test/specs/external/dereferenced.ts +++ /dev/null @@ -1,87 +0,0 @@ -export default { - title: "Person", - type: "object", - required: ["name"], - properties: { - name: { - title: "name", - type: "object", - required: ["first", "last"], - properties: { - first: { - title: "required string", - type: "string", - minLength: 1, - }, - last: { - title: "required string", - type: "string", - minLength: 1, - }, - middle: { - type: "string", - minLength: 1, - }, - prefix: { - title: "required string", - type: "string", - minLength: 3, - }, - suffix: { - title: "required string", - type: "string", - minLength: 3, - maxLength: 3, - }, - }, - }, - age: { - type: "integer", - minimum: 0, - }, - gender: { - type: "string", - enum: ["male", "female"], - }, - }, - definitions: { - "required string": { - title: "required string", - type: "string", - minLength: 1, - }, - string: "string", - name: { - title: "name", - type: "object", - required: ["first", "last"], - properties: { - first: { - title: "required string", - type: "string", - minLength: 1, - }, - last: { - title: "required string", - type: "string", - minLength: 1, - }, - middle: { - type: "string", - minLength: 1, - }, - prefix: { - title: "required string", - type: "string", - minLength: 3, - }, - suffix: { - title: "required string", - type: "string", - minLength: 3, - maxLength: 3, - }, - }, - }, - }, -}; diff --git a/test/specs/external/external.spec.ts b/test/specs/external/external.spec.ts deleted file mode 100644 index 172b300d..00000000 --- a/test/specs/external/external.spec.ts +++ /dev/null @@ -1,109 +0,0 @@ -import { describe, it } from "vitest"; -import $RefParser from "../../../lib/index.js"; -import helper from "../../utils/helper.js"; -import path from "../../utils/path.js"; -import parsedSchema from "./parsed.js"; -import dereferencedSchema from "./dereferenced.js"; -import bundledSchema from "./bundled.js"; - -import { expect } from "vitest"; - -describe("Schema with external $refs", () => { - it("should parse successfully from an absolute path", async () => { - const parser = new $RefParser(); - const schema = await parser.parse(path.abs("test/specs/external/external.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(parsedSchema.schema); - expect(parser.$refs.paths()).to.deep.equal([path.abs("test/specs/external/external.yaml")]); - }); - - it("should parse successfully from a relative path", async () => { - const parser = new $RefParser(); - const schema = await parser.parse(path.rel("test/specs/external/external.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(parsedSchema.schema); - expect(parser.$refs.paths()).to.deep.equal([path.abs("test/specs/external/external.yaml")]); - }); - - it("should parse successfully from a url", async () => { - const parser = new $RefParser(); - const schema = await parser.parse(path.url("test/specs/external/external.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(parsedSchema.schema); - expect(parser.$refs.paths()).to.deep.equal([path.url("test/specs/external/external.yaml")]); - }); - - it( - "should resolve successfully from an absolute path", - helper.testResolve( - path.abs("test/specs/external/external.yaml"), - path.abs("test/specs/external/external.yaml"), - parsedSchema.schema, - path.abs("test/specs/external/definitions/definitions.json"), - parsedSchema.definitions, - path.abs("test/specs/external/definitions/name.yaml"), - parsedSchema.name, - path.abs("test/specs/external/definitions/required-string.yaml"), - parsedSchema.requiredString, - ), - ); - - it( - "should resolve successfully from a relative path", - helper.testResolve( - path.rel("test/specs/external/external.yaml"), - path.abs("test/specs/external/external.yaml"), - parsedSchema.schema, - path.abs("test/specs/external/definitions/definitions.json"), - parsedSchema.definitions, - path.abs("test/specs/external/definitions/name.yaml"), - parsedSchema.name, - path.abs("test/specs/external/definitions/required-string.yaml"), - parsedSchema.requiredString, - ), - ); - - it( - "should resolve successfully from a url", - helper.testResolve( - path.url("test/specs/external/external.yaml"), - path.url("test/specs/external/external.yaml"), - parsedSchema.schema, - path.url("test/specs/external/definitions/definitions.json"), - parsedSchema.definitions, - path.url("test/specs/external/definitions/name.yaml"), - parsedSchema.name, - path.url("test/specs/external/definitions/required-string.yaml"), - parsedSchema.requiredString, - ), - ); - - it("should dereference successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.dereference(path.rel("test/specs/external/external.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(dereferencedSchema); - // Reference equality - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - expect(schema.properties.name).to.equal(schema.definitions.name); - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - expect(schema.definitions["required string"]) - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - .to.equal(schema.definitions.name.properties.first) - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - .to.equal(schema.definitions.name.properties.last) - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - .to.equal(schema.properties.name.properties.first) - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - .to.equal(schema.properties.name.properties.last); - // The "circular" flag should NOT be set - expect(parser.$refs.circular).to.equal(false); - }); - - it("should bundle successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.bundle(path.rel("test/specs/external/external.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(bundledSchema); - }); -}); diff --git a/test/specs/external/external.yaml b/test/specs/external/external.yaml deleted file mode 100644 index 89464c9d..00000000 --- a/test/specs/external/external.yaml +++ /dev/null @@ -1,17 +0,0 @@ -title: Person -type: object -required: - - name -properties: - name: - $ref: "#/definitions/name" - age: - type: integer - minimum: 0 - gender: - type: string - enum: - - male - - female -definitions: - $ref: definitions/definitions.json diff --git a/test/specs/external/parsed.ts b/test/specs/external/parsed.ts deleted file mode 100644 index 982658ff..00000000 --- a/test/specs/external/parsed.ts +++ /dev/null @@ -1,72 +0,0 @@ -export default { - schema: { - definitions: { - $ref: "definitions/definitions.json", - }, - required: ["name"], - type: "object", - properties: { - gender: { - enum: ["male", "female"], - type: "string", - }, - age: { - minimum: 0, - type: "integer", - }, - name: { - $ref: "#/definitions/name", - }, - }, - title: "Person", - }, - - definitions: { - "required string": { - $ref: "required-string.yaml", - }, - string: { - $ref: "#/required%20string/type", - }, - name: { - $ref: "../definitions/name.yaml", - }, - }, - - name: { - required: ["first", "last"], - type: "object", - properties: { - middle: { - minLength: { - $ref: "#/properties/first/minLength", - }, - type: { - $ref: "#/properties/first/type", - }, - }, - prefix: { - minLength: 3, - $ref: "#/properties/last", - }, - last: { - $ref: "./required-string.yaml", - }, - suffix: { - $ref: "#/properties/prefix", - type: "string", - maxLength: 3, - }, - first: { - $ref: "../definitions/definitions.json#/required string", - }, - }, - title: "name", - }, - - requiredString: { - minLength: 1, - type: "string", - title: "required string", - }, -}; diff --git a/test/specs/http.spec.ts b/test/specs/http.spec.ts deleted file mode 100644 index c9e7cc3e..00000000 --- a/test/specs/http.spec.ts +++ /dev/null @@ -1,202 +0,0 @@ -/// -import { describe, it, beforeEach } from "vitest"; -import $RefParser from "../../lib/index.js"; - -import { expect } from "vitest"; - -const isWindows = /^win/.test(globalThis.process ? globalThis.process.platform : ""); -const isBrowser = typeof window !== "undefined"; -describe("HTTP options", () => { - describe.skip("http.headers", () => { - it("should override default HTTP headers", async () => { - if (isWindows || isBrowser) { - return; - } - - const parser = new $RefParser(); - - const schema = await parser.parse("https://httpbin.org/headers", { - resolve: { - http: { - headers: { - accept: "application/json", - }, - }, - }, - }); - - // @ts-expect-error TS(2339): Property 'headers' does not exist on type 'void & ... Remove this comment to see the full error message - expect(schema.headers).to.have.property("Accept", "application/json"); - }); - - // Old versions of IE don't allow setting custom headers - it("should set custom HTTP headers", async () => { - if (isWindows) { - return; - } - - const parser = new $RefParser(); - - const schema = await parser.parse("https://httpbin.org/headers", { - resolve: { - http: { - headers: { - "my-custom-header": "hello, world", - }, - }, - }, - }); - - // @ts-expect-error TS(2339): Property 'headers' does not exist on type 'void & ... Remove this comment to see the full error message - expect(schema.headers).to.have.property("My-Custom-Header", "hello, world"); - }); - }); - - // 2020-07-08 - The HTTPBin redirect endpoints are suddenly returning 404 errors. Not sure why 🤷‍♂️ - // TODO: Re-enable these tests once HTTPBin is working again - describe.skip("http.redirect", () => { - beforeEach(function (this: any) { - // Increase the timeout for these tests, to allow for multiple redirects - this.currentTest.timeout(30000); - this.currentTest.slow(3000); - }); - - it("should follow 5 redirects by default", async () => { - const parser = new $RefParser(); - - const schema = await parser.parse("https://httpbin.org/redirect/5"); - // @ts-expect-error TS(2339): Property 'url' does not exist on type 'JSONSchema'... Remove this comment to see the full error message - expect(schema.url).to.equal("https://httpbin.org/get"); - }); - - it("should not follow 6 redirects by default", async () => { - try { - const parser = new $RefParser(); - const schema = await parser.parse("https://httpbin.org/redirect/6"); - - if (typeof window === "undefined") { - throw new Error("All 6 redirects were followed. That should NOT have happened!"); - } else { - // Some web browsers will automatically follow redirects. - // Nothing we can do about that. - // @ts-expect-error TS(2339): Property 'url' does not exist on type 'JSONSchema'... Remove this comment to see the full error message - expect(schema.url).to.equal("https://httpbin.org/get"); - } - } catch (err) { - expect(err).to.be.an.instanceOf(Error); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain("Error downloading https://httpbin.org/redirect/6"); - if (typeof window === "undefined") { - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.equal( - "Error downloading https://httpbin.org/redirect/6. \n" + - "Too many redirects: \n" + - " https://httpbin.org/redirect/6 \n" + - " https://httpbin.org/relative-redirect/5 \n" + - " https://httpbin.org/relative-redirect/4 \n" + - " https://httpbin.org/relative-redirect/3 \n" + - " https://httpbin.org/relative-redirect/2 \n" + - " https://httpbin.org/relative-redirect/1", - ); - } - } - }); - - it("should follow 10 redirects if http.redirects = 10", async () => { - const parser = new $RefParser(); - - const schema = await parser.parse("https://httpbin.org/redirect/10", { - resolve: { http: { redirects: 10 } }, - }); - - // @ts-expect-error TS(2339): Property 'url' does not exist on type 'void & Prom... Remove this comment to see the full error message - expect(schema.url).to.equal("https://httpbin.org/get"); - }); - - it("should not follow any redirects if http.redirects = 0", async () => { - try { - const parser = new $RefParser(); - - const schema = await parser.parse("https://httpbin.org/redirect/1", { - resolve: { http: { redirects: 0 } }, - }); - - if (typeof window === "undefined") { - throw new Error("The redirect was followed. That should NOT have happened!"); - } else { - // Some web browsers will automatically follow redirects. - // Nothing we can do about that. - // @ts-expect-error TS(2339): Property 'url' does not exist on type 'void & Prom... Remove this comment to see the full error message - expect(schema.url).to.equal("https://httpbin.org/get"); - } - } catch (err) { - expect(err).to.be.an.instanceOf(Error); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain("Error downloading https://httpbin.org/redirect/1"); - if (typeof window === "undefined") { - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.equal( - "Error downloading https://httpbin.org/redirect/1. \n" + - "Too many redirects: \n" + - " https://httpbin.org/redirect/1", - ); - } - } - }); - }); - - if (!isWindows) { - describe("http.withCredentials", () => { - it('should work by default with CORS "Access-Control-Allow-Origin: *"', async () => { - const parser = new $RefParser(); - - // Swagger.io has CORS enabled, with "Access-Control-Allow-Origin" set to a wildcard ("*"). - // This should work by-default. - const schema = await parser.parse("https://petstore.swagger.io/v2/swagger.json"); - - expect(schema).to.be.an("object"); - expect(schema).not.to.be.empty; // eslint-disable-line no-unused-expressions - expect(parser.schema).to.equal(schema); - }); - - it("should download successfully with http.withCredentials = false (default)", async () => { - const parser = new $RefParser(); - - // Swagger.io has CORS enabled, with "Access-Control-Allow-Origin" set to a wildcard ("*"). - // So, withCredentials MUST be false (this is the default, but we're testing it explicitly here) - - const schema = await parser.parse("https://petstore.swagger.io/v2/swagger.json", { - resolve: { http: { withCredentials: false } }, - }); - - expect(schema).to.be.an("object"); - expect(schema).not.to.be.empty; // eslint-disable-line no-unused-expressions - expect(parser.schema).to.equal(schema); - }); - - if (isBrowser) { - it("should throw error in browser if http.withCredentials = true", async () => { - try { - const parser = new $RefParser(); - - // Swagger.io has CORS enabled, with "Access-Control-Allow-Origin" set to a wildcard ("*"). - // So, withCredentials MUST be false (this is the default, but we're testing it explicitly here) - - const schema = await parser.parse("https://petstore.swagger.io/v2/swagger.json", { - resolve: { http: { withCredentials: true } }, - }); - - // The request succeeded, which means this browser doesn't support CORS. - expect(schema).to.be.an("object"); - expect(schema).not.to.be.empty; // eslint-disable-line no-unused-expressions - expect(parser.schema).to.equal(schema); - } catch (err) { - // The request failed, which is expected - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain("Error downloading https://petstore.swagger.io/v2/swagger.json"); - } - }); - } - }); - } -}); diff --git a/test/specs/internal-root-ref/bundled.ts b/test/specs/internal-root-ref/bundled.ts deleted file mode 100644 index 6e9ff7dc..00000000 --- a/test/specs/internal-root-ref/bundled.ts +++ /dev/null @@ -1,14 +0,0 @@ -export default { - $ref: "#/definitions/user", - definitions: { - user: { - properties: { - userId: { - type: "integer", - }, - }, - required: ["userId"], - type: "object", - }, - }, -}; diff --git a/test/specs/internal-root-ref/dereferenced.ts b/test/specs/internal-root-ref/dereferenced.ts deleted file mode 100644 index f8792463..00000000 --- a/test/specs/internal-root-ref/dereferenced.ts +++ /dev/null @@ -1,20 +0,0 @@ -export default { - definitions: { - user: { - type: "object", - properties: { - userId: { - type: "integer", - }, - }, - required: ["userId"], - }, - }, - type: "object", - properties: { - userId: { - type: "integer", - }, - }, - required: ["userId"], -}; diff --git a/test/specs/internal-root-ref/internal-root-ref.spec.ts b/test/specs/internal-root-ref/internal-root-ref.spec.ts deleted file mode 100644 index a31e542f..00000000 --- a/test/specs/internal-root-ref/internal-root-ref.spec.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { describe, it } from "vitest"; -import $RefParser from "../../../lib/index.js"; -import helper from "../../utils/helper.js"; -import path from "../../utils/path.js"; -import parsedSchema from "./parsed.js"; -import dereferencedSchema from "./dereferenced.js"; -import bundledSchema from "./bundled.js"; - -import { expect } from "vitest"; - -describe("Schema with $ref at root level", () => { - it("should parse successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.parse(path.rel("test/specs/internal-root-ref/internal-root-ref.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(parsedSchema); - expect(parser.$refs.paths()).to.deep.equal([path.abs("test/specs/internal-root-ref/internal-root-ref.yaml")]); - }); - - it( - "should resolve successfully", - helper.testResolve( - path.rel("test/specs/internal-root-ref/internal-root-ref.yaml"), - path.abs("test/specs/internal-root-ref/internal-root-ref.yaml"), - parsedSchema, - ), - ); - - it("should dereference successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.dereference(path.rel("test/specs/internal-root-ref/internal-root-ref.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(dereferencedSchema); - // Reference equality - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - expect(schema.properties.userId).to.deep.equal(schema.definitions.user.properties.userId); - expect(parser.$refs.circular).to.equal(false); - }); - - it("should bundle successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.bundle(path.rel("test/specs/internal-root-ref/internal-root-ref.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(bundledSchema); - }); -}); diff --git a/test/specs/internal-root-ref/internal-root-ref.yaml b/test/specs/internal-root-ref/internal-root-ref.yaml deleted file mode 100644 index 3b41be66..00000000 --- a/test/specs/internal-root-ref/internal-root-ref.yaml +++ /dev/null @@ -1,9 +0,0 @@ -$ref: "#/definitions/user" -definitions: - user: - type: object - properties: - userId: - type: integer - required: - - userId diff --git a/test/specs/internal-root-ref/parsed.ts b/test/specs/internal-root-ref/parsed.ts deleted file mode 100644 index 6e9ff7dc..00000000 --- a/test/specs/internal-root-ref/parsed.ts +++ /dev/null @@ -1,14 +0,0 @@ -export default { - $ref: "#/definitions/user", - definitions: { - user: { - properties: { - userId: { - type: "integer", - }, - }, - required: ["userId"], - type: "object", - }, - }, -}; diff --git a/test/specs/internal/bundled.ts b/test/specs/internal/bundled.ts deleted file mode 100644 index 6fe2c3aa..00000000 --- a/test/specs/internal/bundled.ts +++ /dev/null @@ -1,60 +0,0 @@ -export default { - definitions: { - fragment: { - $id: "#fragment", - }, - requiredString: { - title: "requiredString", - minLength: 1, - type: "string", - }, - name: { - required: ["first", "last"], - type: "object", - properties: { - first: { - $ref: "#/definitions/requiredString", - }, - last: { - $ref: "#/definitions/requiredString", - }, - middle: { - type: { - $ref: "#/definitions/requiredString/type", - }, - minLength: { - $ref: "#/definitions/requiredString/minLength", - }, - }, - prefix: { - $ref: "#/definitions/requiredString", - minLength: 3, - }, - suffix: { - type: "string", - $ref: "#/definitions/name/properties/prefix", - maxLength: 3, - }, - }, - }, - }, - required: ["name"], - type: "object", - properties: { - fragment: { - $ref: "#fragment", - }, - gender: { - enum: ["male", "female"], - type: "string", - }, - age: { - minimum: 0, - type: "integer", - }, - name: { - $ref: "#/definitions/name", - }, - }, - title: "Person", -}; diff --git a/test/specs/internal/dereferenced.ts b/test/specs/internal/dereferenced.ts deleted file mode 100644 index 6ac835d0..00000000 --- a/test/specs/internal/dereferenced.ts +++ /dev/null @@ -1,90 +0,0 @@ -export default { - definitions: { - fragment: { - $id: "#fragment", - }, - requiredString: { - title: "requiredString", - minLength: 1, - type: "string", - }, - name: { - required: ["first", "last"], - type: "object", - properties: { - first: { - title: "requiredString", - type: "string", - minLength: 1, - }, - last: { - title: "requiredString", - type: "string", - minLength: 1, - }, - middle: { - type: "string", - minLength: 1, - }, - prefix: { - title: "requiredString", - type: "string", - minLength: 3, - }, - suffix: { - title: "requiredString", - type: "string", - minLength: 3, - maxLength: 3, - }, - }, - }, - }, - required: ["name"], - type: "object", - properties: { - fragment: { - $ref: "#fragment", - }, - gender: { - enum: ["male", "female"], - type: "string", - }, - age: { - minimum: 0, - type: "integer", - }, - name: { - required: ["first", "last"], - type: "object", - properties: { - first: { - title: "requiredString", - type: "string", - minLength: 1, - }, - last: { - title: "requiredString", - type: "string", - minLength: 1, - }, - middle: { - type: "string", - minLength: 1, - }, - prefix: { - title: "requiredString", - type: "string", - minLength: 3, - }, - suffix: { - title: "requiredString", - type: "string", - minLength: 3, - maxLength: 3, - }, - }, - }, - }, - title: "Person", -}; diff --git a/test/specs/internal/internal.spec.ts b/test/specs/internal/internal.spec.ts deleted file mode 100644 index 0cf29f01..00000000 --- a/test/specs/internal/internal.spec.ts +++ /dev/null @@ -1,57 +0,0 @@ -import { describe, it } from "vitest"; -import $RefParser from "../../../lib/index.js"; -import helper from "../../utils/helper.js"; -import path from "../../utils/path.js"; -import parsedSchema from "./parsed.js"; -import dereferencedSchema from "./dereferenced.js"; -import bundledSchema from "./bundled.js"; - -import { expect } from "vitest"; - -describe("Schema with internal $refs", () => { - it("should parse successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.parse(path.rel("test/specs/internal/internal.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(parsedSchema); - expect(parser.$refs.paths()).to.deep.equal([path.abs("test/specs/internal/internal.yaml")]); - }); - - it( - "should resolve successfully", - helper.testResolve( - path.rel("test/specs/internal/internal.yaml"), - path.abs("test/specs/internal/internal.yaml"), - parsedSchema, - ), - ); - - it("should dereference successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.dereference(path.rel("test/specs/internal/internal.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(dereferencedSchema); - // Reference equality - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - expect(schema.properties.name).to.equal(schema.definitions.name); - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - expect(schema.definitions.requiredString) - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - .to.equal(schema.definitions.name.properties.first) - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - .to.equal(schema.definitions.name.properties.last) - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - .to.equal(schema.properties.name.properties.first) - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - .to.equal(schema.properties.name.properties.last); - // The "circular" flag should NOT be set - expect(parser.$refs.circular).to.equal(false); - }); - - it("should bundle successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.bundle(path.rel("test/specs/internal/internal.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(bundledSchema); - }); -}); diff --git a/test/specs/internal/internal.yaml b/test/specs/internal/internal.yaml deleted file mode 100644 index d679a6b3..00000000 --- a/test/specs/internal/internal.yaml +++ /dev/null @@ -1,46 +0,0 @@ -title: Person -type: object -definitions: - name: - type: object - required: - - first - - last - properties: - first: - $ref: "#/definitions/requiredString" - last: - $ref: "#/definitions/name/properties/first" - middle: - type: - $ref: "#/definitions/name/properties/first/type" - minLength: - $ref: "#/definitions/name/properties/last/minLength" - prefix: - $ref: "#/definitions/name/properties/last" - minLength: 3 - suffix: - type: string - $ref: "#/definitions/name/properties/prefix" - maxLength: 3 - requiredString: - title: requiredString - type: string - minLength: 1 - fragment: - $id: "#fragment" -required: - - name -properties: - name: - $ref: "#/definitions/name" - age: - type: integer - minimum: 0 - gender: - type: string - enum: - - male - - female - fragment: - $ref: "#fragment" diff --git a/test/specs/internal/parsed.ts b/test/specs/internal/parsed.ts deleted file mode 100644 index b3cfb6fc..00000000 --- a/test/specs/internal/parsed.ts +++ /dev/null @@ -1,60 +0,0 @@ -export default { - definitions: { - fragment: { - $id: "#fragment", - }, - requiredString: { - title: "requiredString", - minLength: 1, - type: "string", - }, - name: { - required: ["first", "last"], - type: "object", - properties: { - first: { - $ref: "#/definitions/requiredString", - }, - last: { - $ref: "#/definitions/name/properties/first", - }, - middle: { - type: { - $ref: "#/definitions/name/properties/first/type", - }, - minLength: { - $ref: "#/definitions/name/properties/last/minLength", - }, - }, - prefix: { - $ref: "#/definitions/name/properties/last", - minLength: 3, - }, - suffix: { - type: "string", - $ref: "#/definitions/name/properties/prefix", - maxLength: 3, - }, - }, - }, - }, - required: ["name"], - type: "object", - properties: { - fragment: { - $ref: "#fragment", - }, - gender: { - enum: ["male", "female"], - type: "string", - }, - age: { - minimum: 0, - type: "integer", - }, - name: { - $ref: "#/definitions/name", - }, - }, - title: "Person", -}; diff --git a/test/specs/invalid-pointers/invalid-pointers.ts b/test/specs/invalid-pointers/invalid-pointers.ts deleted file mode 100644 index 5ec2bd8b..00000000 --- a/test/specs/invalid-pointers/invalid-pointers.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { expect, describe, it } from "vitest"; -import $RefParser from "../../../lib"; -import helper from "../../utils/helper"; -import path from "../../utils/path"; -import { InvalidPointerError, JSONParserErrorGroup } from "../../../lib/util/errors"; - -describe("Schema with invalid pointers", () => { - it("should throw an error for an invalid pointer", async () => { - try { - await $RefParser.dereference(path.rel("test/specs/invalid-pointers/invalid.json")); - helper.shouldNotGetCalled(); - } catch (err) { - expect(err).to.be.an.instanceOf(InvalidPointerError); - expect((err as InvalidPointerError).message).to.contain( - 'Invalid $ref pointer "f". Pointers must begin with "#/"', - ); - } - }); - - it("should throw a grouped error for an invalid pointer if continueOnError is true", async () => { - const parser = new $RefParser(); - try { - // { continueOnError: true } - await parser.dereference(path.rel("test/specs/invalid-pointers/invalid.json")); - helper.shouldNotGetCalled(); - } catch (e) { - const err = e as JSONParserErrorGroup; - expect(err).to.be.instanceof(JSONParserErrorGroup); - expect(err.files).to.equal(parser); - expect(err.message).to.equal( - `1 error occurred while reading '${path.abs("test/specs/invalid-pointers/invalid.json")}'`, - ); - expect(err.errors).to.containSubset([ - { - name: InvalidPointerError.name, - message: 'Invalid $ref pointer "f". Pointers must begin with "#/"', - path: ["foo"], - source: path.unixify(path.abs("test/specs/invalid-pointers/invalid.json")), - }, - ]); - } - }); -}); diff --git a/test/specs/invalid-pointers/invalid.json b/test/specs/invalid-pointers/invalid.json deleted file mode 100644 index fd0d8ea3..00000000 --- a/test/specs/invalid-pointers/invalid.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "foo": { - "$ref": "./invalid.json#f" - } -} diff --git a/test/specs/invalid/invalid.json b/test/specs/invalid/invalid.json deleted file mode 100644 index 98232c64..00000000 --- a/test/specs/invalid/invalid.json +++ /dev/null @@ -1 +0,0 @@ -{ diff --git a/test/specs/invalid/invalid.spec.ts b/test/specs/invalid/invalid.spec.ts deleted file mode 100644 index ec64ded6..00000000 --- a/test/specs/invalid/invalid.spec.ts +++ /dev/null @@ -1,404 +0,0 @@ -import { describe, it } from "vitest"; -import { expect } from "vitest"; -import $RefParser from "../../../lib/index.js"; -import helper from "../../utils/helper.js"; -import path from "../../utils/path.js"; -import { JSONParserErrorGroup, ParserError, ResolverError } from "../../../lib/util/errors.js"; - -// @ts-expect-error TS(2345): Argument of type 'string | undefined' is not assig... Remove this comment to see the full error message -const isWindows = /^win/.test(globalThis.process ? globalThis.process.platform : undefined); -const getPathFromOs = (filePath: any) => (isWindows ? filePath.replace(/\\/g, "/") : filePath); - -describe("Invalid syntax", () => { - describe("in main file", () => { - it("should throw an error for an invalid file path", async () => { - try { - await $RefParser.dereference("this file does not exist"); - helper.shouldNotGetCalled(); - } catch (err) { - expect(err).to.be.an.instanceOf(ResolverError); - if (typeof window === "undefined") { - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.ioErrorCode).to.equal("ENOENT"); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain("Error opening file "); - } - } - }); - - it("should throw an error for an invalid YAML file", async () => { - try { - await $RefParser.dereference(path.rel("test/specs/invalid/invalid.yaml")); - helper.shouldNotGetCalled(); - } catch (err) { - expect(err).to.be.an.instanceOf(ParserError); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain("Error parsing "); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain("invalid/invalid.yaml"); - } - }); - - it("should throw an error for an invalid JSON file", async () => { - try { - await $RefParser.dereference(path.rel("test/specs/invalid/invalid.json")); - helper.shouldNotGetCalled(); - } catch (err) { - expect(err).to.be.an.instanceOf(ParserError); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain("Error parsing "); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain("invalid/invalid.json"); - } - }); - - it("should throw an error for an invalid JSON file with YAML disabled", async () => { - try { - await $RefParser.dereference(path.rel("test/specs/invalid/invalid.json"), { parse: { yaml: false } }); - helper.shouldNotGetCalled(); - } catch (err) { - expect(err).to.be.an.instanceOf(ParserError); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain("Error parsing "); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain("invalid/invalid.json"); - } - }); - - it("should throw an error for an invalid YAML file with JSON and YAML disabled", async () => { - try { - await $RefParser.dereference(path.rel("test/specs/invalid/invalid.yaml"), { - parse: { yaml: false, json: false }, - }); - helper.shouldNotGetCalled(); - } catch (err) { - expect(err).to.be.an.instanceOf(SyntaxError); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain('invalid/invalid.yaml" is not a valid JSON Schema'); - } - }); - - describe("when continueOnError is true", () => { - it("should throw a grouped error for an invalid file path", async () => { - const parser = new $RefParser(); - try { - await parser.dereference("this file does not exist", { continueOnError: true }); - helper.shouldNotGetCalled(); - } catch (err) { - expect(err).to.be.instanceof(JSONParserErrorGroup); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.files).to.equal(parser); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.have.string("1 error occurred while reading '"); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.have.string("this file does not exist'"); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.errors.length).to.equal(1); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.errors).to.containSubset([ - { - name: ResolverError.name, - message: (message: any) => message.startsWith("Error opening file") || message.endsWith("HTTP ERROR 404"), - path: [], - source: (message: any) => - message.endsWith("this file does not exist") || message.startsWith("http://localhost"), - }, - ]); - } - }); - - it("should throw a grouped error for an invalid YAML file", async () => { - const parser = new $RefParser(); - try { - await parser.dereference(path.rel("test/specs/invalid/invalid.yaml"), { continueOnError: true }); - helper.shouldNotGetCalled(); - } catch (err) { - expect(err).to.be.instanceof(JSONParserErrorGroup); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.files).to.equal(parser); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(getPathFromOs(err.message)).to.equal( - `1 error occurred while reading '${path.abs("test/specs/invalid/invalid.yaml")}'`, - ); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.errors.length).to.equal(1); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.errors).to.containSubset([ - { - name: ParserError.name, - message: (message: any) => - message.includes( - "invalid.yaml: incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line (1:1)", - ), - path: [], - source: (message: any) => message.endsWith("test/specs/invalid/invalid.yaml"), - }, - ]); - } - }); - - it("should throw a grouped error for an invalid JSON file", async () => { - const parser = new $RefParser(); - try { - await parser.dereference(path.rel("test/specs/invalid/invalid.json"), { continueOnError: true }); - helper.shouldNotGetCalled(); - } catch (err) { - expect(err).to.be.instanceof(JSONParserErrorGroup); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.files).to.equal(parser); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(getPathFromOs(err.message)).to.equal( - `1 error occurred while reading '${path.abs("test/specs/invalid/invalid.json")}'`, - ); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.errors.length).to.equal(1); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.errors).to.containSubset([ - { - name: ParserError.name, - message: (message: any) => - message.includes("invalid.json: unexpected end of the stream within a flow collection (2:1)"), - path: [], - source: (message: any) => message.endsWith("test/specs/invalid/invalid.json"), - }, - ]); - } - }); - - it("should throw a grouped error for an invalid JSON file with YAML disabled", async () => { - const parser = new $RefParser(); - try { - await parser.dereference(path.rel("test/specs/invalid/invalid.json"), { - continueOnError: true, - parse: { yaml: false }, - }); - helper.shouldNotGetCalled(); - } catch (err) { - expect(err).to.be.instanceof(JSONParserErrorGroup); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.files).to.equal(parser); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(getPathFromOs(err.message)).to.equal( - `1 error occurred while reading '${path.abs("test/specs/invalid/invalid.json")}'`, - ); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.errors.length).to.equal(1); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.errors).to.containSubset([ - { - name: ParserError.name, - message: (message: any) => - message.includes("invalid.json: Unexpected end of JSON input") || - message.includes("invalid.json: Expected property name or '}' in JSON") || - message.includes("invalid.json: JSON.parse: end of data while reading object contents") || // Firefox - message.includes("invalid.json: JSON Parse error: Expected '}'") || // Safari - message.includes("invalid.json: JSON.parse Error: Invalid character") || // Edge - message.includes("invalid.json: Syntax error") || // IE - message.includes("invalid.json: Expected property name or '}' in JSON"), // Chrome - path: [], - source: (message: any) => message.endsWith("test/specs/invalid/invalid.json"), - }, - ]); - } - }); - - it("should not throw an error for an invalid YAML file with JSON and YAML disabled", async () => { - const parser = new $RefParser(); - - const result = await parser.dereference(path.rel("test/specs/invalid/invalid.yaml"), { - continueOnError: true, - parse: { yaml: false, json: false }, - }); - expect(result).to.equal(null); - }); - }); - }); - - describe("in referenced files", () => { - it("should throw an error for an invalid YAML file", async () => { - try { - await $RefParser.dereference({ foo: { $ref: path.rel("test/specs/invalid/invalid.yaml") } }); - helper.shouldNotGetCalled(); - } catch (err) { - expect(err).to.be.an.instanceOf(ParserError); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain("Error parsing "); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain("invalid/invalid.yaml"); - } - }); - - it("should throw an error for an invalid JSON file", async () => { - try { - await $RefParser.dereference({ foo: { $ref: path.rel("test/specs/invalid/invalid.json") } }); - helper.shouldNotGetCalled(); - } catch (err) { - expect(err).to.be.an.instanceOf(ParserError); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain("Error parsing "); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain("invalid/invalid.json"); - } - }); - - it("should throw an error for an invalid JSON file with YAML disabled", async () => { - try { - await $RefParser.dereference( - { foo: { $ref: path.rel("test/specs/invalid/invalid.json") } }, - { - parse: { yaml: false }, - }, - ); - helper.shouldNotGetCalled(); - } catch (err) { - expect(err).to.be.an.instanceOf(ParserError); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain("Error parsing "); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain("invalid/invalid.json"); - } - }); - - it("should throw a grouped error for an invalid YAML file with JSON and YAML disabled", async () => { - const schema = await $RefParser.dereference( - { foo: { $ref: path.rel("test/specs/invalid/invalid.yaml") } }, - { - parse: { yaml: false, json: false }, - }, - ); - - // Because the JSON and YAML parsers were disabled, the invalid YAML file got parsed as plain text - expect(schema).to.deep.equal({ - foo: ":\n", - }); - }); - - describe("when continueOnError is true", () => { - it("should throw a grouped error for an invalid file path", async () => { - try { - const parser = new $RefParser(); - - await parser.dereference({ foo: { $ref: "this file does not exist" } }, { continueOnError: true }); - helper.shouldNotGetCalled(); - } catch (err) { - expect(err).to.be.instanceof(JSONParserErrorGroup); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.files.$refs._root$Ref.value).to.deep.equal({ foo: null }); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.errors.length).to.equal(1); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.errors).to.containSubset([ - { - name: ResolverError.name, - message: (message: any) => message.startsWith("Error opening file") || message.endsWith("HTTP ERROR 404"), - path: ["foo"], - // source: message => message.endsWith("/test/") || message.startsWith("http://localhost"), - }, - ]); - } - }); - - it("should throw a grouped error for an invalid YAML file", async () => { - try { - const parser = new $RefParser(); - - await parser.dereference( - { foo: { $ref: path.rel("test/specs/invalid/invalid.yaml") } }, - { continueOnError: true }, - ); - helper.shouldNotGetCalled(); - } catch (err) { - expect(err).to.be.instanceof(JSONParserErrorGroup); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.files.$refs._root$Ref.value).to.deep.equal({ foo: null }); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.errors.length).to.equal(1); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.errors).to.containSubset([ - { - name: ParserError.name, - message: (message: any) => - message.includes( - "invalid.yaml: incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line (1:1)", - ), - path: ["foo"], - // source: message => message.endsWith("/test/") || message.startsWith("http://localhost"), - }, - ]); - } - }); - - it("should throw a grouped error for an invalid JSON file", async () => { - try { - const parser = new $RefParser(); - - await parser.dereference( - { foo: { $ref: path.rel("test/specs/invalid/invalid.json") } }, - { continueOnError: true }, - ); - helper.shouldNotGetCalled(); - } catch (err) { - expect(err).to.be.instanceof(JSONParserErrorGroup); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.files.$refs._root$Ref.value).to.deep.equal({ foo: null }); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.errors.length).to.equal(1); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.errors).to.containSubset([ - { - name: ParserError.name, - message: (message: any) => - message.includes("invalid.json: unexpected end of the stream within a flow collection (2:1)"), - path: ["foo"], - // source: message => message.endsWith("/test/") || message.startsWith("http://localhost"), - }, - ]); - } - }); - - it("should throw a grouped error for an invalid JSON file with YAML disabled", async () => { - try { - const parser = new $RefParser(); - - await parser.dereference( - { foo: { $ref: path.rel("test/specs/invalid/invalid.json") } }, - { continueOnError: true, parse: { yaml: false } }, - ); - helper.shouldNotGetCalled(); - } catch (err) { - expect(err).to.be.instanceof(JSONParserErrorGroup); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.files.$refs._root$Ref.value).to.deep.equal({ foo: null }); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.errors.length).to.equal(1); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.errors).to.containSubset([ - { - name: ParserError.name, - message: (message: any) => - message.includes("invalid.json: Unexpected end of JSON input") || - message.includes("invalid.json: Expected property name or '}' in JSON") || - message.includes("invalid.json: JSON.parse: end of data while reading object contents") || // Firefox - message.includes("invalid.json: JSON Parse error: Expected '}'") || // Safari - message.includes("invalid.json: JSON.parse Error: Invalid character") || // Edge - message.includes("invalid.json: Syntax error") || // IE - message.includes("invalid.json: Expected property name or '}' in JSON"), // Chrome - path: ["foo"], - // source: message => message.endsWith("/test/") || message.startsWith("http://localhost"), - }, - ]); - } - }); - - it("should not throw an error for an invalid YAML file with JSON and YAML disabled", async () => { - const parser = new $RefParser(); - - const result = await parser.dereference( - { foo: { $ref: path.rel("test/specs/invalid/invalid.yaml") } }, - { continueOnError: true, parse: { yaml: false, json: false } }, - ); - expect(result).to.deep.equal({ foo: ":\n" }); - }); - }); - }); -}); diff --git a/test/specs/invalid/invalid.yaml b/test/specs/invalid/invalid.yaml deleted file mode 100644 index 397db75f..00000000 --- a/test/specs/invalid/invalid.yaml +++ /dev/null @@ -1 +0,0 @@ -: diff --git a/test/specs/missing-pointers/external-from-internal.yaml b/test/specs/missing-pointers/external-from-internal.yaml deleted file mode 100644 index 855fd49f..00000000 --- a/test/specs/missing-pointers/external-from-internal.yaml +++ /dev/null @@ -1,4 +0,0 @@ -internal1: - $ref: "#/internal2" -internal2: - $ref: "#/external" diff --git a/test/specs/missing-pointers/missing-pointers.spec.ts b/test/specs/missing-pointers/missing-pointers.spec.ts deleted file mode 100644 index f3bc5156..00000000 --- a/test/specs/missing-pointers/missing-pointers.spec.ts +++ /dev/null @@ -1,94 +0,0 @@ -import { describe, it } from "vitest"; -import { expect } from "vitest"; -import $RefParser from "../../../lib/index.js"; -import { JSONParserErrorGroup, MissingPointerError } from "../../../lib/util/errors.js"; -import helper from "../../utils/helper.js"; -import path from "../../utils/path.js"; - -describe("Schema with missing pointers", () => { - it("should throw an error for missing pointer", async () => { - try { - await $RefParser.dereference({ foo: { $ref: "#/baz" } }); - helper.shouldNotGetCalled(); - } catch (err) { - expect(err).to.be.an.instanceOf(MissingPointerError); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain('Token "baz" does not exist.'); - } - }); - - it("should throw an error for missing pointer in external file", async () => { - try { - await $RefParser.dereference({ - foo: { $ref: path.abs("test/specs/missing-pointers/external-from-internal.yaml") }, - }); - helper.shouldNotGetCalled(); - } catch (err) { - expect(err).to.be.an.instanceOf(MissingPointerError); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain('Missing $ref pointer "#/external". Token "external" does not exist.'); - } - }); - - describe("when continueOnError is true", () => { - it("should throw a grouped error for missing pointer", async () => { - const parser = new $RefParser(); - try { - await parser.dereference({ foo: { $ref: "#/baz" } }, { continueOnError: true }); - helper.shouldNotGetCalled(); - } catch (err) { - expect(err).to.be.instanceof(JSONParserErrorGroup); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.files).to.equal(parser); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.files.$refs._root$Ref.value).to.deep.equal({ foo: null }); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.have.string("1 error occurred while reading '"); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.errors).to.containSubset([ - { - name: MissingPointerError.name, - message: 'Missing $ref pointer "#/baz". Token "baz" does not exist.', - path: ["foo"], - // source: message => message.endsWith("/test/") || message.startsWith("http://localhost"), - }, - ]); - } - }); - - it("should throw an error for missing pointer in external file", async () => { - const parser = new $RefParser(); - try { - await parser.dereference( - { foo: { $ref: path.abs("test/specs/missing-pointers/external-from-internal.yaml") } }, - { continueOnError: true }, - ); - helper.shouldNotGetCalled(); - } catch (err) { - expect(err).to.be.instanceof(JSONParserErrorGroup); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.files).to.equal(parser); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.files.$refs._root$Ref.value).to.deep.equal({ - foo: { - internal1: null, - internal2: null, - }, - }); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.have.string("1 error occurred while reading '"); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.errors).to.containSubset([ - { - name: MissingPointerError.name, - message: 'Missing $ref pointer "#/external". Token "external" does not exist.', - path: ["internal2"], - source: (message: any) => - message.endsWith("missing-pointers/external-from-internal.yaml") || - message.startsWith("http://localhost"), - }, - ]); - } - }); - }); -}); diff --git a/test/specs/nested-pointers/external-from-internal.yaml b/test/specs/nested-pointers/external-from-internal.yaml deleted file mode 100644 index 855fd49f..00000000 --- a/test/specs/nested-pointers/external-from-internal.yaml +++ /dev/null @@ -1,4 +0,0 @@ -internal1: - $ref: "#/internal2" -internal2: - $ref: "#/external" diff --git a/test/specs/nested-pointers/missing-pointers.spec.ts b/test/specs/nested-pointers/missing-pointers.spec.ts deleted file mode 100644 index 5a811d29..00000000 --- a/test/specs/nested-pointers/missing-pointers.spec.ts +++ /dev/null @@ -1,112 +0,0 @@ -import { describe, it } from "vitest"; -import { expect } from "vitest"; -import $RefParser from "../../../lib/index.js"; -const schema = { - type: "object", - allOf: [ - { - description: "REMOVED for better readbility", - }, - { - type: "object", - properties: { - payload: { - type: "array", - items: { - allOf: [ - { - description: "REMOVED for better readbility", - }, - { - type: "object", - properties: { - reservationActionMetaData: { - allOf: [ - { - allOf: [ - { - type: "object", - properties: { - supplierPriceElements: { - allOf: [ - { - description: "REMOVED for better readbility", - }, - { - type: "object", - properties: { - purchaseRate: { - allOf: [ - { - type: "object", - required: ["amount"], - properties: { - amount: { - type: "number", - }, - }, - }, - { - type: "object", - properties: { - inDetail: { - type: "object", - properties: { - perDate: { - type: "array", - items: { - type: "object", - properties: { - amount: { - $ref: "#/allOf/1/properties/payload/items/allOf/1/properties/reservationActionMetaData/allOf/0/allOf/0/properties/supplierPriceElements/allOf/1/properties/fee/properties/modificationFee/properties/amount", - }, - }, - }, - }, - }, - }, - }, - }, - ], - }, - fee: { - type: "object", - properties: { - modificationFee: { - $ref: "#/allOf/1/properties/payload/items/allOf/1/properties/reservationActionMetaData/allOf/0/allOf/0/properties/supplierPriceElements/allOf/1/properties/purchaseRate/allOf/0", - }, - }, - }, - }, - }, - ], - }, - }, - }, - { - description: "REMOVED for better readbility", - }, - ], - }, - { - description: "REMOVED for better readbility", - }, - ], - }, - }, - }, - ], - }, - }, - }, - }, - ], -}; - -describe("Schema with nested pointers", () => { - it("should throw an error for missing pointer", async () => { - // todo - get original schema from #338 - const bundle = await $RefParser.bundle(schema); - expect(bundle).to.equal(schema); - }); -}); diff --git a/test/specs/nested-pointers/schema.json b/test/specs/nested-pointers/schema.json deleted file mode 100644 index 518f936a..00000000 --- a/test/specs/nested-pointers/schema.json +++ /dev/null @@ -1,101 +0,0 @@ -{ - "type": "object", - "allOf": [ - { - "description": "REMOVED for better readbility" - }, - { - "type": "object", - "properties": { - "payload": { - "type": "array", - "items": { - "allOf": [ - { - "description": "REMOVED for better readbility" - }, - { - "type": "object", - "properties": { - "reservationActionMetaData": { - "allOf": [ - { - "allOf": [ - { - "type": "object", - "properties": { - "supplierPriceElements": { - "allOf": [ - { - "description": "REMOVED for better readbility" - }, - { - "type": "object", - "properties": { - "purchaseRate": { - "allOf": [ - { - "type": "object", - "required": ["amount"], - "properties": { - "amount": { - "type": "number" - } - } - }, - { - "type": "object", - "properties": { - "inDetail": { - "type": "object", - "properties": { - "perDate": { - "type": "array", - "items": { - "type": "object", - "properties": { - "amount": { - "$ref": "#/allOf/1/properties/payload/items/allOf/1/properties/reservationActionMetaData/allOf/0/allOf/0/properties/supplierPriceElements/allOf/1/properties/fee/properties/modificationFee/properties/amount" - } - } - } - } - } - } - } - } - ] - }, - "fee": { - "type": "object", - "properties": { - "modificationFee": { - "$ref": "#/allOf/1/properties/payload/items/allOf/1/properties/reservationActionMetaData/allOf/0/allOf/0/properties/supplierPriceElements/allOf/1/properties/purchaseRate/allOf/0" - } - } - } - } - } - ] - } - } - }, - { - "description": "REMOVED for better readbility" - } - ] - }, - { - "description": "REMOVED for better readbility" - } - ] - } - } - } - ] - } - } - } - } - ] -} diff --git a/test/specs/no-refs/no-refs.spec.ts b/test/specs/no-refs/no-refs.spec.ts deleted file mode 100644 index f27eef2e..00000000 --- a/test/specs/no-refs/no-refs.spec.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { describe, it } from "vitest"; -import $RefParser from "../../../lib/index.js"; -import helper from "../../utils/helper.js"; -import path from "../../utils/path.js"; -import parsedSchema from "./parsed.js"; - -import { expect } from "vitest"; - -describe("Schema without any $refs", () => { - it("should parse successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.parse(path.rel("test/specs/no-refs/no-refs.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(parsedSchema); - expect(parser.$refs.paths()).to.deep.equal([path.abs("test/specs/no-refs/no-refs.yaml")]); - }); - - it( - "should resolve successfully", - helper.testResolve( - path.rel("test/specs/no-refs/no-refs.yaml"), - path.abs("test/specs/no-refs/no-refs.yaml"), - parsedSchema, - ), - ); - - it("should dereference successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.dereference(path.rel("test/specs/no-refs/no-refs.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(parsedSchema); - // The "circular" flag should NOT be set - expect(parser.$refs.circular).to.equal(false); - }); - - it("should bundle successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.bundle(path.rel("test/specs/no-refs/no-refs.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(parsedSchema); - }); -}); diff --git a/test/specs/no-refs/no-refs.yaml b/test/specs/no-refs/no-refs.yaml deleted file mode 100644 index bb77b1ec..00000000 --- a/test/specs/no-refs/no-refs.yaml +++ /dev/null @@ -1,27 +0,0 @@ -title: Person -type: object -required: - - name -properties: - name: - type: object - required: - - first - - last - properties: - first: - type: string - minLength: 1 - middle: - type: string - last: - type: string - minLength: 1 - age: - type: integer - minimum: 0 - gender: - type: string - enum: - - male - - female diff --git a/test/specs/no-refs/parsed.ts b/test/specs/no-refs/parsed.ts deleted file mode 100644 index a99d2b76..00000000 --- a/test/specs/no-refs/parsed.ts +++ /dev/null @@ -1,32 +0,0 @@ -export default { - required: ["name"], - type: "object", - properties: { - gender: { - enum: ["male", "female"], - type: "string", - }, - age: { - minimum: 0, - type: "integer", - }, - name: { - required: ["first", "last"], - type: "object", - properties: { - middle: { - type: "string", - }, - last: { - minLength: 1, - type: "string", - }, - first: { - minLength: 1, - type: "string", - }, - }, - }, - }, - title: "Person", -}; diff --git a/test/specs/null-ref/null.spec.ts b/test/specs/null-ref/null.spec.ts deleted file mode 100644 index fb662e80..00000000 --- a/test/specs/null-ref/null.spec.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { describe, it } from "vitest"; -import { expect } from "vitest"; -import $RefParser from "../../../lib/index.js"; -import path from "../../utils/path"; -import parsedSchema from "./null"; - -describe("Null references", () => { - it("should parse successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.parse(path.rel("test/specs/null-ref/null.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(parsedSchema); - }); -}); diff --git a/test/specs/null-ref/null.ts b/test/specs/null-ref/null.ts deleted file mode 100644 index ef111190..00000000 --- a/test/specs/null-ref/null.ts +++ /dev/null @@ -1,49 +0,0 @@ -export default { - openapi: "3.0.3", - components: { - schemas: { - ReadyToPayMethods: { - example: [ - { - brands: ["Visa", "MasterCard"], - feature: { - name: "Google Pay", - }, - filters: ["brand:Visa,MasterCard;bin:!411111"], - method: "payment-card", - }, - { - feature: { - expirationTime: "2006-01-02T15:04:05Z", - linkToken: "some-random-link_token-for-plaid", - name: "Plaid", - }, - method: "ach", - }, - { - brands: ["Visa"], - feature: null, - filters: ["brand:Visa;bin:411111,444433"], - method: "payment-card", - }, - { - feature: { - $ref: "#/components/schemas/ReadyToPayMethods/example/2/feature", - }, - filters: [], - method: "ach", - }, - { - filters: [], - method: "paypal", - }, - { - filters: [], - method: "Skrill", - }, - ], - type: "array", - }, - }, - }, -}; diff --git a/test/specs/null-ref/null.yaml b/test/specs/null-ref/null.yaml deleted file mode 100644 index 69e1fd7b..00000000 --- a/test/specs/null-ref/null.yaml +++ /dev/null @@ -1,33 +0,0 @@ -openapi: 3.0.3 -components: - schemas: - ReadyToPayMethods: - example: - - brands: - - Visa - - MasterCard - feature: - name: Google Pay - filters: - - brand:Visa,MasterCard;bin:!411111 - method: payment-card - - feature: - expirationTime: 2006-01-02T15:04:05Z - linkToken: some-random-link_token-for-plaid - name: Plaid - method: ach - - brands: - - Visa - feature: null - filters: - - brand:Visa;bin:411111,444433 - method: payment-card - - feature: - $ref: "#/components/schemas/ReadyToPayMethods/example/2/feature" - filters: [] - method: ach - - filters: [] - method: paypal - - filters: [] - method: Skrill - type: array diff --git a/test/specs/object-source-with-path/bundled.ts b/test/specs/object-source-with-path/bundled.ts deleted file mode 100644 index 4dc46a6d..00000000 --- a/test/specs/object-source-with-path/bundled.ts +++ /dev/null @@ -1,58 +0,0 @@ -export default { - title: "Person", - type: "object", - required: ["name"], - properties: { - name: { - $ref: "#/definitions/name", - }, - age: { - type: "integer", - minimum: 0, - }, - gender: { - type: "string", - enum: ["male", "female"], - }, - }, - definitions: { - requiredString: { - title: "requiredString", - type: "string", - minLength: 1, - }, - string: { - $ref: "#/definitions/requiredString/type", - }, - name: { - title: "name", - type: "object", - required: ["first", "last"], - properties: { - first: { - $ref: "#/definitions/requiredString", - }, - last: { - $ref: "#/definitions/requiredString", - }, - middle: { - type: { - $ref: "#/definitions/requiredString/type", - }, - minLength: { - $ref: "#/definitions/requiredString/minLength", - }, - }, - prefix: { - $ref: "#/definitions/requiredString", - minLength: 3, - }, - suffix: { - $ref: "#/definitions/name/properties/prefix", - type: "string", - maxLength: 3, - }, - }, - }, - }, -}; diff --git a/test/specs/object-source-with-path/definitions/definitions.json b/test/specs/object-source-with-path/definitions/definitions.json deleted file mode 100644 index 9b2b1336..00000000 --- a/test/specs/object-source-with-path/definitions/definitions.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "requiredString": { - "$ref": "required-string.yaml" - }, - "string": { - "$ref": "#/requiredString/type" - }, - "name": { - "$ref": "../definitions/name.yaml" - } -} diff --git a/test/specs/object-source-with-path/definitions/name.yaml b/test/specs/object-source-with-path/definitions/name.yaml deleted file mode 100644 index 9d795707..00000000 --- a/test/specs/object-source-with-path/definitions/name.yaml +++ /dev/null @@ -1,22 +0,0 @@ -title: name -type: object -required: - - first - - last -properties: - first: - $ref: ../definitions/definitions.json#/requiredString - last: - $ref: ./required-string.yaml - middle: - type: - $ref: "#/properties/first/type" - minLength: - $ref: "#/properties/first/minLength" - prefix: - $ref: "#/properties/last" - minLength: 3 - suffix: - type: string - $ref: "#/properties/prefix" - maxLength: 3 diff --git a/test/specs/object-source-with-path/definitions/required-string.yaml b/test/specs/object-source-with-path/definitions/required-string.yaml deleted file mode 100644 index 3970e6ba..00000000 --- a/test/specs/object-source-with-path/definitions/required-string.yaml +++ /dev/null @@ -1,3 +0,0 @@ -title: requiredString -type: string -minLength: 1 diff --git a/test/specs/object-source-with-path/dereferenced.ts b/test/specs/object-source-with-path/dereferenced.ts deleted file mode 100644 index 56bb8248..00000000 --- a/test/specs/object-source-with-path/dereferenced.ts +++ /dev/null @@ -1,87 +0,0 @@ -export default { - title: "Person", - type: "object", - required: ["name"], - properties: { - name: { - title: "name", - type: "object", - required: ["first", "last"], - properties: { - first: { - title: "requiredString", - type: "string", - minLength: 1, - }, - last: { - title: "requiredString", - type: "string", - minLength: 1, - }, - middle: { - type: "string", - minLength: 1, - }, - prefix: { - title: "requiredString", - type: "string", - minLength: 3, - }, - suffix: { - title: "requiredString", - type: "string", - minLength: 3, - maxLength: 3, - }, - }, - }, - age: { - type: "integer", - minimum: 0, - }, - gender: { - type: "string", - enum: ["male", "female"], - }, - }, - definitions: { - requiredString: { - title: "requiredString", - type: "string", - minLength: 1, - }, - string: "string", - name: { - title: "name", - type: "object", - required: ["first", "last"], - properties: { - first: { - title: "requiredString", - type: "string", - minLength: 1, - }, - last: { - title: "requiredString", - type: "string", - minLength: 1, - }, - middle: { - type: "string", - minLength: 1, - }, - prefix: { - title: "requiredString", - type: "string", - minLength: 3, - }, - suffix: { - title: "requiredString", - type: "string", - minLength: 3, - maxLength: 3, - }, - }, - }, - }, -}; diff --git a/test/specs/object-source-with-path/object-source-with-path.spec.ts b/test/specs/object-source-with-path/object-source-with-path.spec.ts deleted file mode 100644 index 95f043cd..00000000 --- a/test/specs/object-source-with-path/object-source-with-path.spec.ts +++ /dev/null @@ -1,108 +0,0 @@ -import { describe, it } from "vitest"; -import $RefParser from "../../../lib/index.js"; -import helper from "../../utils/helper.js"; -import path from "../../utils/path.js"; -import internalRefsParsedSchema from "../internal/parsed.js"; -import internalRefsDereferencedSchema from "../internal/dereferenced.js"; -import parsedSchema from "./parsed.js"; -import dereferencedSchema from "./dereferenced.js"; -import bundledSchema from "./bundled.js"; - -import { expect } from "vitest"; -import type { JSONSchema } from "../../../lib/types"; - -describe("Object sources with file paths", () => { - it("should dereference a single object", async () => { - const parser = new $RefParser(); - const schema = await parser.dereference( - // This file doesn't actually need to exist. But its path will be used to resolve external $refs - path.abs("path/that/does/not/exist.yaml"), - // This schema object does not contain any external $refs - helper.cloneDeep(internalRefsParsedSchema), - // An options object MUST be passed (even if it's empty) - {}, - ); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(internalRefsDereferencedSchema); - // The schema path should match the one we pass-in - const expectedPaths = [path.abs("path/that/does/not/exist.yaml")]; - expect(parser.$refs.paths()).to.have.same.members(expectedPaths); - expect(parser.$refs.values()).to.have.keys(expectedPaths); - // Reference equality - // @ts-expect-error TS(2339): Property 'properties' does not exist on type 'void... Remove this comment to see the full error message - expect(schema.properties.name).to.equal(schema.definitions.name); - // @ts-expect-error TS(2339): Property 'definitions' does not exist on type 'voi... Remove this comment to see the full error message - expect(schema.definitions.requiredString) - // @ts-expect-error TS(2339): Property 'definitions' does not exist on type 'voi... Remove this comment to see the full error message - .to.equal(schema.definitions.name.properties.first) - // @ts-expect-error TS(2339): Property 'definitions' does not exist on type 'voi... Remove this comment to see the full error message - .to.equal(schema.definitions.name.properties.last) - // @ts-expect-error TS(2339): Property 'properties' does not exist on type 'void... Remove this comment to see the full error message - .to.equal(schema.properties.name.properties.first) - // @ts-expect-error TS(2339): Property 'properties' does not exist on type 'void... Remove this comment to see the full error message - .to.equal(schema.properties.name.properties.last); - }); - - it("should dereference an object that references external files", async () => { - const parser = new $RefParser(); - const schema = await parser.dereference( - // This file doesn't actually need to exist. But its path will be used to resolve external $refs - path.abs("test/specs/object-source-with-path/schema-file-that-does-not-exist.yaml"), - // This schema object contains external $refs - helper.cloneDeep(parsedSchema.schema) as JSONSchema, - // An options object MUST be passed (even if it's empty) - {}, - ); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(dereferencedSchema); - // The schema path should match the one we passed-in. - // All other paths should be the actual paths of referenced files. - const expectedPaths = [ - path.abs("test/specs/object-source-with-path/schema-file-that-does-not-exist.yaml"), - path.abs("test/specs/object-source-with-path/definitions/definitions.json"), - path.abs("test/specs/object-source-with-path/definitions/name.yaml"), - path.abs("test/specs/object-source-with-path/definitions/required-string.yaml"), - ]; - expect(parser.$refs.paths()).to.have.same.members(expectedPaths); - expect(parser.$refs.values()).to.have.keys(expectedPaths); - // Reference equality - // @ts-expect-error TS(2339): Property 'properties' does not exist on type 'void... Remove this comment to see the full error message - expect(schema.properties.name).to.equal(schema.definitions.name); - // @ts-expect-error TS(2339): Property 'definitions' does not exist on type 'voi... Remove this comment to see the full error message - expect(schema.definitions.requiredString) - // @ts-expect-error TS(2339): Property 'definitions' does not exist on type 'voi... Remove this comment to see the full error message - .to.equal(schema.definitions.name.properties.first) - // @ts-expect-error TS(2339): Property 'definitions' does not exist on type 'voi... Remove this comment to see the full error message - .to.equal(schema.definitions.name.properties.last) - // @ts-expect-error TS(2339): Property 'properties' does not exist on type 'void... Remove this comment to see the full error message - .to.equal(schema.properties.name.properties.first) - // @ts-expect-error TS(2339): Property 'properties' does not exist on type 'void... Remove this comment to see the full error message - .to.equal(schema.properties.name.properties.last); - // The "circular" flag should NOT be set - expect(parser.$refs.circular).to.equal(false); - }); - - it("should bundle an object that references external files", async () => { - const parser = new $RefParser(); - const schema = await parser.bundle( - // This file doesn't actually need to exist. But its path will be used to resolve external $refs - path.rel("test/specs/object-source-with-path/schema-file-that-does-not-exist.yaml"), - // This schema object contains external $refs - helper.cloneDeep(parsedSchema.schema), - // An options object MUST be passed (even if it's empty) - {}, - ); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(bundledSchema); - // The schema path should match the one we passed-in. - // All other paths should be the actual paths of referenced files. - const expectedPaths = [ - path.abs("test/specs/object-source-with-path/schema-file-that-does-not-exist.yaml"), - path.abs("test/specs/object-source-with-path/definitions/definitions.json"), - path.abs("test/specs/object-source-with-path/definitions/name.yaml"), - path.abs("test/specs/object-source-with-path/definitions/required-string.yaml"), - ]; - expect(parser.$refs.paths()).to.have.same.members(expectedPaths); - expect(parser.$refs.values()).to.have.keys(expectedPaths); - }); -}); diff --git a/test/specs/object-source-with-path/parsed.ts b/test/specs/object-source-with-path/parsed.ts deleted file mode 100644 index 0d7ed714..00000000 --- a/test/specs/object-source-with-path/parsed.ts +++ /dev/null @@ -1,75 +0,0 @@ -export default { - schema: { - definitions: { - // Because we've specified the full path to this directory, - // this path can simply be relative to the current directory, - // rather than having to be relative to the "test" directory - $ref: "definitions/definitions.json", - }, - required: ["name"], - type: "object", - properties: { - gender: { - enum: ["male", "female"], - type: "string", - }, - age: { - minimum: 0, - type: "integer", - }, - name: { - $ref: "#/definitions/name", - }, - }, - title: "Person", - }, - - definitions: { - requiredString: { - $ref: "required-string.yaml", - }, - string: { - $ref: "#/requiredString/type", - }, - name: { - $ref: "../definitions/name.yaml", - }, - }, - - name: { - required: ["first", "last"], - type: "object", - properties: { - middle: { - minLength: { - $ref: "#/properties/first/minLength", - }, - type: { - $ref: "#/properties/first/type", - }, - }, - prefix: { - minLength: 3, - $ref: "#/properties/last", - }, - last: { - $ref: "./required-string.yaml", - }, - suffix: { - $ref: "#/properties/prefix", - type: "string", - maxLength: 3, - }, - first: { - $ref: "../definitions/definitions.json#/requiredString", - }, - }, - title: "name", - }, - - requiredString: { - minLength: 1, - type: "string", - title: "requiredString", - }, -}; diff --git a/test/specs/object-source/bundled.ts b/test/specs/object-source/bundled.ts deleted file mode 100644 index 4dc46a6d..00000000 --- a/test/specs/object-source/bundled.ts +++ /dev/null @@ -1,58 +0,0 @@ -export default { - title: "Person", - type: "object", - required: ["name"], - properties: { - name: { - $ref: "#/definitions/name", - }, - age: { - type: "integer", - minimum: 0, - }, - gender: { - type: "string", - enum: ["male", "female"], - }, - }, - definitions: { - requiredString: { - title: "requiredString", - type: "string", - minLength: 1, - }, - string: { - $ref: "#/definitions/requiredString/type", - }, - name: { - title: "name", - type: "object", - required: ["first", "last"], - properties: { - first: { - $ref: "#/definitions/requiredString", - }, - last: { - $ref: "#/definitions/requiredString", - }, - middle: { - type: { - $ref: "#/definitions/requiredString/type", - }, - minLength: { - $ref: "#/definitions/requiredString/minLength", - }, - }, - prefix: { - $ref: "#/definitions/requiredString", - minLength: 3, - }, - suffix: { - $ref: "#/definitions/name/properties/prefix", - type: "string", - maxLength: 3, - }, - }, - }, - }, -}; diff --git a/test/specs/object-source/definitions/definitions.json b/test/specs/object-source/definitions/definitions.json deleted file mode 100644 index 9b2b1336..00000000 --- a/test/specs/object-source/definitions/definitions.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "requiredString": { - "$ref": "required-string.yaml" - }, - "string": { - "$ref": "#/requiredString/type" - }, - "name": { - "$ref": "../definitions/name.yaml" - } -} diff --git a/test/specs/object-source/definitions/name.yaml b/test/specs/object-source/definitions/name.yaml deleted file mode 100644 index 9d795707..00000000 --- a/test/specs/object-source/definitions/name.yaml +++ /dev/null @@ -1,22 +0,0 @@ -title: name -type: object -required: - - first - - last -properties: - first: - $ref: ../definitions/definitions.json#/requiredString - last: - $ref: ./required-string.yaml - middle: - type: - $ref: "#/properties/first/type" - minLength: - $ref: "#/properties/first/minLength" - prefix: - $ref: "#/properties/last" - minLength: 3 - suffix: - type: string - $ref: "#/properties/prefix" - maxLength: 3 diff --git a/test/specs/object-source/definitions/required-string.yaml b/test/specs/object-source/definitions/required-string.yaml deleted file mode 100644 index 3970e6ba..00000000 --- a/test/specs/object-source/definitions/required-string.yaml +++ /dev/null @@ -1,3 +0,0 @@ -title: requiredString -type: string -minLength: 1 diff --git a/test/specs/object-source/dereferenced.ts b/test/specs/object-source/dereferenced.ts deleted file mode 100644 index 56bb8248..00000000 --- a/test/specs/object-source/dereferenced.ts +++ /dev/null @@ -1,87 +0,0 @@ -export default { - title: "Person", - type: "object", - required: ["name"], - properties: { - name: { - title: "name", - type: "object", - required: ["first", "last"], - properties: { - first: { - title: "requiredString", - type: "string", - minLength: 1, - }, - last: { - title: "requiredString", - type: "string", - minLength: 1, - }, - middle: { - type: "string", - minLength: 1, - }, - prefix: { - title: "requiredString", - type: "string", - minLength: 3, - }, - suffix: { - title: "requiredString", - type: "string", - minLength: 3, - maxLength: 3, - }, - }, - }, - age: { - type: "integer", - minimum: 0, - }, - gender: { - type: "string", - enum: ["male", "female"], - }, - }, - definitions: { - requiredString: { - title: "requiredString", - type: "string", - minLength: 1, - }, - string: "string", - name: { - title: "name", - type: "object", - required: ["first", "last"], - properties: { - first: { - title: "requiredString", - type: "string", - minLength: 1, - }, - last: { - title: "requiredString", - type: "string", - minLength: 1, - }, - middle: { - type: "string", - minLength: 1, - }, - prefix: { - title: "requiredString", - type: "string", - minLength: 3, - }, - suffix: { - title: "requiredString", - type: "string", - minLength: 3, - maxLength: 3, - }, - }, - }, - }, -}; diff --git a/test/specs/object-source/object-source.spec.ts b/test/specs/object-source/object-source.spec.ts deleted file mode 100644 index 6de136d4..00000000 --- a/test/specs/object-source/object-source.spec.ts +++ /dev/null @@ -1,93 +0,0 @@ -import { describe, it } from "vitest"; -import $RefParser from "../../../lib/index.js"; -import helper from "../../utils/helper.js"; -import path from "../../utils/path.js"; -import internalRefsParsedSchema from "../internal/parsed.js"; -import internalRefsDereferencedSchema from "../internal/dereferenced.js"; -import parsedSchema from "./parsed.js"; -import dereferencedSchema from "./dereferenced.js"; -import bundledSchema from "./bundled.js"; - -import { expect } from "vitest"; - -// @ts-expect-error TS(2345): Argument of type 'string | undefined' is not assig... Remove this comment to see the full error message -const isWindows = /^win/.test(globalThis.process ? globalThis.process.platform : undefined); - -describe("Object sources (instead of file paths)", () => { - it("should dereference a single object", async () => { - const parser = new $RefParser(); - const schema = await parser.dereference(helper.cloneDeep(internalRefsParsedSchema)); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(internalRefsDereferencedSchema); - // The schema path should be the current directory - const expectedPaths = [path.cwd()]; - if (!isWindows) { - expect(parser.$refs.paths()).to.have.same.members(expectedPaths); - expect(parser.$refs.values()).to.have.keys(expectedPaths); - } - // Reference equality - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - expect(schema.properties.name).to.equal(schema.definitions.name); - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - expect(schema.definitions.requiredString) - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - .to.equal(schema.definitions.name.properties.first) - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - .to.equal(schema.definitions.name.properties.last) - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - .to.equal(schema.properties.name.properties.first) - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - .to.equal(schema.properties.name.properties.last); - }); - - it("should dereference an object that references external files", async () => { - const parser = new $RefParser(); - const schema = await parser.dereference(helper.cloneDeep(parsedSchema.schema)); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(dereferencedSchema); - // The schema path should be the current directory, and all other paths should be absolute - const expectedPaths = [ - path.cwd(), - path.abs("test/specs/object-source/definitions/definitions.json"), - path.abs("test/specs/object-source/definitions/name.yaml"), - path.abs("test/specs/object-source/definitions/required-string.yaml"), - ]; - if (!isWindows) { - expect(parser.$refs.paths()).to.have.same.members(expectedPaths); - expect(parser.$refs.values()).to.have.keys(expectedPaths); - } - // Reference equality - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - expect(schema.properties.name).to.equal(schema.definitions.name); - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - expect(schema.definitions.requiredString) - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - .to.equal(schema.definitions.name.properties.first) - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - .to.equal(schema.definitions.name.properties.last) - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - .to.equal(schema.properties.name.properties.first) - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - .to.equal(schema.properties.name.properties.last); - // The "circular" flag should NOT be set - expect(parser.$refs.circular).to.equal(false); - }); - - it("should bundle an object that references external files", async () => { - const parser = new $RefParser(); - const schema = await parser.bundle(helper.cloneDeep(parsedSchema.schema)); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(bundledSchema); - // The schema path should be the current directory, and all other paths should be absolute - const expectedPaths = [ - path.cwd(), - path.abs("test/specs/object-source/definitions/definitions.json"), - path.abs("test/specs/object-source/definitions/name.yaml"), - path.abs("test/specs/object-source/definitions/required-string.yaml"), - ]; - if (!isWindows) { - expect(parser.$refs.paths()).to.have.same.members(expectedPaths); - expect(parser.$refs.values()).to.have.keys(expectedPaths); - } - }); -}); diff --git a/test/specs/object-source/parsed.ts b/test/specs/object-source/parsed.ts deleted file mode 100644 index 62f94dc6..00000000 --- a/test/specs/object-source/parsed.ts +++ /dev/null @@ -1,76 +0,0 @@ -import path from "../../utils/path.js"; - -export default { - schema: { - definitions: { - // Because we're not specifying a path, the current directory (the "test" directory) - // will be assumed. So this path must be relative to the "test" directory. - $ref: path.rel("test/specs/object-source/definitions/definitions.json"), - }, - required: ["name"], - type: "object", - properties: { - gender: { - enum: ["male", "female"], - type: "string", - }, - age: { - minimum: 0, - type: "integer", - }, - name: { - $ref: "#/definitions/name", - }, - }, - title: "Person", - }, - - definitions: { - requiredString: { - $ref: "required-string.yaml", - }, - string: { - $ref: "#/requiredString/type", - }, - name: { - $ref: "../definitions/name.yaml", - }, - }, - - name: { - required: ["first", "last"], - type: "object", - properties: { - middle: { - minLength: { - $ref: "#/properties/first/minLength", - }, - type: { - $ref: "#/properties/first/type", - }, - }, - prefix: { - minLength: 3, - $ref: "#/properties/last", - }, - last: { - $ref: "./required-string.yaml", - }, - suffix: { - $ref: "#/properties/prefix", - type: "string", - maxLength: 3, - }, - first: { - $ref: "../definitions/definitions.json#/requiredString", - }, - }, - title: "name", - }, - - requiredString: { - minLength: 1, - type: "string", - title: "requiredString", - }, -}; diff --git a/test/specs/parsers/dereferenced.ts b/test/specs/parsers/dereferenced.ts deleted file mode 100644 index 06288807..00000000 --- a/test/specs/parsers/dereferenced.ts +++ /dev/null @@ -1,447 +0,0 @@ -export default { - defaultParsers: { - definitions: { - markdown: "Hello\nWorld:\n", - - html: ` - - - - - - -

Hello World:

- - -`, - - css: "html {\n color: #888;\n font-family: sans-serif;\n height: 100%;\n width: 100%;\n}\n", - - binary: { - type: "Buffer", - data: [ - 137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 32, 0, 0, 0, 32, 8, 6, 0, 0, 0, 115, - 122, 122, 244, 0, 0, 0, 4, 115, 66, 73, 84, 8, 8, 8, 8, 124, 8, 100, 136, 0, 0, 0, 25, 116, 69, 88, 116, 83, - 111, 102, 116, 119, 97, 114, 101, 0, 119, 119, 119, 46, 105, 110, 107, 115, 99, 97, 112, 101, 46, 111, 114, - 103, 155, 238, 60, 26, 0, 0, 9, 170, 73, 68, 65, 84, 88, 133, 197, 151, 125, 76, 84, 103, 22, 198, 127, 247, - 206, 64, 7, 44, 227, 0, 149, 15, 97, 176, 34, 139, 174, 182, 86, 49, 46, 69, 148, 197, 80, 234, 118, 73, 181, - 49, 213, 38, 146, 172, 218, 221, 86, 151, 98, 106, 218, 198, 212, 102, 179, 180, 221, 173, 154, 102, 187, 182, - 113, 171, 181, 113, 165, 145, 138, 41, 152, 173, 160, 130, 73, 149, 116, 23, 131, 34, 42, 203, 48, 128, 195, - 135, 128, 200, 200, 71, 103, 24, 6, 24, 135, 59, 115, 239, 187, 127, 32, 179, 69, 112, 179, 127, 108, 178, - 111, 114, 63, 222, 251, 158, 155, 243, 188, 207, 121, 206, 57, 247, 74, 66, 8, 254, 159, 67, 63, 211, 195, 95, - 231, 189, 149, 168, 73, 186, 95, 161, 73, 166, 255, 181, 67, 73, 214, 106, 131, 252, 35, 167, 143, 30, 61, - 234, 3, 144, 30, 102, 96, 123, 222, 158, 143, 146, 147, 158, 124, 119, 237, 154, 52, 121, 254, 188, 120, 38, - 215, 255, 125, 157, 60, 129, 16, 26, 2, 129, 16, 160, 169, 26, 154, 208, 208, 84, 13, 191, 234, 71, 211, 52, - 132, 166, 161, 106, 19, 207, 84, 77, 195, 229, 114, 209, 216, 210, 70, 75, 235, 237, 65, 191, 207, 187, 234, - 216, 231, 127, 110, 151, 127, 236, 124, 199, 142, 119, 103, 199, 205, 141, 126, 107, 99, 78, 150, 92, 114, - 170, 136, 47, 142, 28, 102, 206, 19, 145, 220, 106, 105, 102, 87, 254, 27, 92, 175, 187, 70, 76, 244, 28, 244, - 122, 153, 195, 135, 255, 194, 167, 159, 30, 100, 86, 104, 40, 67, 78, 7, 123, 246, 188, 195, 217, 242, 50, - 226, 226, 98, 145, 16, 252, 225, 195, 15, 248, 246, 219, 191, 49, 47, 193, 76, 92, 92, 44, 229, 101, 223, 114, - 170, 248, 107, 150, 36, 63, 201, 218, 213, 63, 155, 51, 236, 246, 252, 94, 146, 164, 160, 41, 0, 20, 89, 125, - 33, 115, 117, 170, 225, 240, 225, 195, 188, 252, 242, 203, 132, 133, 133, 81, 89, 89, 201, 234, 213, 171, 201, - 201, 201, 161, 181, 181, 21, 33, 4, 37, 37, 37, 44, 90, 180, 136, 212, 212, 84, 10, 11, 11, 73, 78, 78, 102, - 199, 142, 29, 180, 180, 180, 32, 132, 32, 46, 46, 142, 221, 187, 119, 211, 212, 212, 132, 170, 170, 88, 44, - 22, 70, 71, 71, 217, 185, 115, 39, 199, 142, 29, 35, 121, 193, 60, 34, 35, 35, 54, 0, 115, 166, 0, 64, 150, - 12, 115, 99, 162, 25, 24, 24, 32, 41, 41, 137, 212, 212, 84, 110, 222, 188, 137, 78, 167, 99, 246, 236, 217, - 1, 179, 186, 186, 58, 150, 46, 93, 202, 138, 21, 43, 104, 105, 105, 65, 146, 36, 34, 35, 35, 145, 36, 41, 16, - 174, 240, 240, 112, 36, 73, 66, 85, 85, 26, 26, 26, 152, 55, 111, 30, 209, 209, 209, 184, 92, 46, 244, 122, - 61, 225, 225, 70, 3, 16, 63, 21, 0, 32, 73, 18, 70, 163, 17, 69, 81, 232, 233, 233, 33, 33, 33, 1, 33, 196, - 20, 45, 44, 88, 176, 128, 190, 190, 62, 238, 222, 189, 139, 217, 108, 158, 178, 174, 170, 42, 170, 170, 162, - 105, 26, 154, 166, 161, 170, 42, 137, 137, 137, 220, 187, 119, 143, 251, 247, 239, 19, 18, 18, 50, 225, 72, - 32, 1, 97, 211, 0, 8, 33, 216, 186, 117, 43, 123, 247, 238, 165, 170, 170, 138, 180, 180, 52, 26, 26, 26, 40, - 42, 42, 162, 162, 162, 130, 154, 154, 26, 54, 111, 222, 76, 97, 97, 33, 95, 125, 245, 21, 25, 25, 25, 216, - 237, 118, 62, 249, 228, 19, 234, 234, 234, 40, 43, 43, 195, 233, 116, 178, 127, 255, 126, 154, 154, 154, 56, - 125, 250, 52, 75, 150, 44, 193, 102, 179, 81, 80, 80, 192, 154, 53, 107, 16, 98, 194, 251, 180, 44, 216, 254, - 198, 158, 109, 239, 228, 255, 166, 112, 241, 162, 159, 160, 40, 10, 30, 143, 7, 163, 209, 136, 16, 130, 193, - 193, 65, 52, 77, 35, 56, 56, 24, 163, 209, 136, 170, 170, 184, 92, 46, 194, 195, 195, 3, 235, 62, 159, 15, 89, - 150, 49, 26, 141, 56, 28, 14, 198, 199, 199, 17, 66, 96, 50, 153, 240, 249, 124, 252, 240, 195, 15, 1, 118, - 75, 206, 92, 240, 237, 255, 96, 239, 11, 211, 24, 0, 24, 24, 24, 160, 178, 178, 18, 175, 215, 139, 16, 2, 167, - 211, 73, 109, 109, 45, 138, 162, 96, 52, 26, 1, 184, 121, 243, 38, 253, 253, 253, 8, 33, 80, 85, 21, 187, 221, - 78, 111, 111, 47, 70, 163, 145, 177, 177, 49, 234, 235, 235, 233, 239, 239, 39, 60, 60, 28, 175, 215, 203, - 149, 43, 87, 232, 233, 233, 153, 72, 79, 33, 224, 129, 94, 166, 21, 34, 33, 4, 109, 109, 109, 156, 62, 125, - 154, 129, 129, 1, 94, 125, 245, 85, 58, 59, 59, 57, 119, 238, 28, 54, 155, 141, 221, 187, 119, 83, 81, 81, - 193, 213, 171, 87, 113, 56, 28, 228, 228, 228, 96, 48, 24, 40, 43, 43, 67, 175, 215, 99, 179, 217, 120, 246, - 217, 103, 169, 175, 175, 167, 173, 173, 141, 131, 7, 15, 50, 54, 54, 134, 205, 102, 163, 166, 166, 134, 67, - 135, 14, 77, 145, 220, 140, 12, 164, 165, 165, 145, 153, 153, 25, 0, 180, 124, 249, 114, 214, 173, 91, 135, - 36, 73, 8, 33, 168, 170, 170, 98, 195, 134, 13, 228, 229, 229, 113, 233, 210, 37, 170, 171, 171, 201, 202, - 202, 34, 47, 47, 143, 234, 234, 106, 162, 162, 162, 216, 178, 101, 11, 122, 253, 196, 254, 34, 34, 34, 200, - 205, 205, 37, 56, 56, 24, 89, 150, 209, 233, 116, 129, 140, 153, 145, 129, 71, 29, 147, 235, 62, 159, 15, 189, - 94, 143, 166, 105, 0, 248, 253, 126, 244, 122, 61, 63, 214, 211, 228, 189, 78, 167, 67, 211, 52, 100, 121, 98, - 175, 65, 65, 65, 83, 236, 102, 236, 5, 253, 253, 253, 220, 190, 125, 27, 33, 4, 46, 151, 11, 159, 207, 71, 91, - 91, 27, 118, 187, 157, 193, 193, 65, 178, 178, 178, 40, 46, 46, 70, 150, 101, 82, 82, 82, 136, 141, 141, 165, - 180, 180, 148, 184, 184, 56, 86, 172, 88, 129, 162, 40, 88, 173, 86, 156, 78, 39, 118, 187, 157, 152, 152, 24, - 44, 22, 11, 110, 183, 27, 187, 221, 78, 84, 84, 212, 100, 57, 151, 166, 3, 16, 130, 209, 209, 81, 162, 162, - 162, 240, 249, 124, 116, 117, 117, 17, 25, 25, 73, 72, 72, 8, 102, 179, 153, 206, 206, 78, 178, 179, 179, 209, - 233, 116, 8, 33, 88, 185, 114, 37, 161, 161, 161, 8, 33, 112, 56, 28, 164, 167, 167, 163, 105, 26, 125, 125, - 125, 100, 100, 100, 208, 218, 218, 74, 76, 76, 12, 221, 221, 221, 100, 103, 103, 99, 179, 217, 136, 141, 141, - 125, 180, 8, 17, 130, 249, 243, 231, 147, 151, 151, 55, 133, 246, 215, 95, 127, 61, 160, 120, 33, 4, 153, 153, - 153, 83, 66, 147, 154, 154, 58, 133, 218, 109, 219, 182, 5, 52, 51, 57, 159, 180, 31, 25, 25, 9, 216, 77, 19, - 161, 42, 84, 206, 159, 63, 79, 118, 118, 54, 101, 101, 101, 8, 33, 176, 90, 173, 236, 218, 181, 139, 157, 59, - 119, 50, 48, 48, 192, 245, 235, 215, 121, 229, 149, 87, 56, 114, 228, 8, 0, 125, 125, 125, 188, 253, 246, 219, - 228, 231, 231, 211, 217, 217, 201, 216, 216, 24, 123, 246, 236, 97, 215, 174, 93, 52, 54, 54, 162, 170, 42, - 239, 189, 247, 30, 111, 190, 249, 38, 181, 181, 181, 19, 34, 124, 20, 0, 159, 79, 37, 45, 45, 141, 141, 27, - 55, 226, 112, 56, 80, 85, 149, 83, 167, 78, 177, 101, 203, 22, 114, 114, 114, 40, 47, 47, 103, 249, 242, 229, - 188, 246, 218, 107, 140, 140, 140, 32, 73, 18, 151, 46, 93, 34, 61, 61, 157, 252, 252, 124, 138, 139, 139, - 185, 118, 237, 26, 79, 63, 253, 52, 7, 14, 28, 160, 168, 168, 8, 171, 213, 138, 217, 108, 230, 208, 161, 67, - 156, 60, 121, 18, 157, 78, 247, 104, 6, 252, 126, 63, 189, 189, 189, 56, 157, 78, 250, 250, 250, 232, 234, - 234, 162, 181, 181, 21, 163, 209, 72, 84, 84, 20, 237, 237, 237, 140, 143, 143, 35, 203, 50, 170, 170, 226, - 247, 251, 185, 117, 235, 22, 102, 179, 153, 196, 196, 68, 236, 118, 59, 237, 237, 237, 36, 36, 36, 48, 103, - 206, 28, 28, 14, 71, 64, 7, 161, 161, 161, 120, 189, 94, 84, 85, 13, 164, 225, 244, 16, 168, 234, 148, 249, - 248, 248, 56, 115, 231, 206, 165, 173, 173, 141, 198, 198, 70, 18, 18, 18, 80, 20, 37, 144, 130, 178, 44, 243, - 204, 51, 207, 208, 221, 221, 77, 71, 71, 7, 11, 23, 46, 100, 217, 178, 101, 116, 116, 116, 4, 154, 85, 74, 74, - 10, 157, 157, 157, 184, 221, 110, 194, 195, 195, 9, 10, 10, 66, 25, 191, 63, 246, 72, 0, 22, 139, 133, 171, - 87, 175, 114, 249, 242, 101, 26, 27, 27, 217, 180, 105, 19, 103, 207, 158, 165, 185, 185, 153, 244, 244, 116, - 186, 186, 186, 40, 45, 45, 197, 98, 177, 112, 241, 226, 69, 94, 124, 241, 69, 44, 22, 11, 37, 37, 37, 172, 95, - 191, 158, 244, 244, 116, 250, 251, 251, 249, 236, 179, 207, 216, 188, 121, 51, 75, 151, 46, 5, 224, 253, 247, - 223, 39, 55, 55, 151, 214, 142, 46, 173, 185, 229, 86, 51, 224, 159, 214, 140, 182, 110, 94, 95, 24, 246, 120, - 8, 138, 162, 4, 118, 104, 48, 24, 208, 235, 245, 72, 146, 132, 193, 96, 32, 40, 40, 8, 77, 211, 208, 235, 245, - 4, 7, 7, 19, 18, 18, 130, 78, 167, 67, 85, 213, 128, 157, 36, 73, 244, 245, 15, 210, 216, 98, 67, 211, 38, - 178, 199, 167, 40, 184, 71, 70, 208, 84, 149, 130, 130, 223, 125, 120, 175, 167, 187, 112, 90, 26, 170, 154, - 138, 215, 235, 165, 188, 188, 156, 152, 152, 24, 50, 50, 50, 240, 251, 253, 156, 57, 115, 6, 147, 201, 196, - 134, 13, 27, 16, 66, 112, 246, 236, 89, 36, 73, 34, 55, 55, 151, 193, 193, 65, 138, 138, 138, 88, 182, 108, - 89, 160, 100, 215, 92, 187, 65, 66, 124, 28, 191, 200, 250, 57, 138, 162, 160, 40, 10, 67, 67, 67, 12, 13, 13, - 113, 178, 164, 236, 238, 189, 158, 238, 6, 160, 111, 90, 8, 52, 77, 112, 226, 196, 9, 162, 163, 163, 169, 171, - 171, 163, 161, 161, 129, 210, 210, 82, 130, 131, 131, 233, 232, 232, 224, 226, 197, 139, 84, 86, 86, 226, 114, - 185, 240, 120, 60, 20, 21, 21, 97, 48, 24, 48, 155, 205, 84, 84, 84, 160, 105, 26, 150, 70, 43, 79, 68, 68, - 144, 248, 100, 66, 64, 43, 99, 99, 99, 184, 221, 110, 46, 215, 222, 240, 254, 245, 139, 67, 71, 129, 118, 33, - 132, 119, 70, 13, 220, 185, 115, 135, 37, 75, 150, 176, 118, 237, 90, 234, 235, 235, 177, 90, 173, 172, 92, - 185, 146, 117, 235, 214, 81, 95, 95, 79, 93, 93, 29, 233, 233, 233, 188, 244, 210, 75, 220, 184, 113, 3, 147, - 201, 68, 74, 74, 10, 178, 44, 99, 179, 217, 248, 190, 186, 134, 159, 46, 76, 194, 239, 247, 163, 170, 42, 195, - 195, 195, 12, 13, 13, 113, 171, 237, 182, 246, 241, 254, 253, 135, 93, 46, 231, 101, 224, 22, 204, 80, 9, 39, - 227, 40, 203, 50, 110, 183, 155, 176, 176, 48, 102, 205, 154, 133, 223, 239, 199, 237, 118, 51, 123, 246, 108, - 124, 62, 31, 30, 143, 135, 225, 225, 97, 34, 34, 34, 2, 239, 78, 126, 152, 184, 221, 110, 252, 126, 63, 66, 8, - 220, 110, 247, 68, 79, 232, 27, 96, 223, 190, 253, 197, 119, 239, 220, 174, 2, 174, 11, 33, 148, 25, 1, 104, - 154, 198, 154, 53, 107, 56, 126, 252, 56, 35, 35, 35, 228, 230, 230, 146, 152, 152, 72, 97, 97, 33, 0, 155, - 54, 109, 194, 100, 50, 241, 229, 151, 95, 98, 50, 153, 120, 254, 249, 231, 113, 56, 28, 124, 243, 205, 55, 88, - 173, 86, 146, 147, 147, 209, 52, 13, 69, 81, 240, 122, 189, 56, 157, 78, 122, 122, 239, 241, 241, 159, 62, - 173, 104, 184, 121, 237, 28, 112, 85, 8, 49, 58, 233, 111, 10, 0, 73, 104, 98, 204, 115, 159, 172, 172, 44, - 22, 46, 92, 136, 36, 73, 196, 199, 199, 19, 28, 28, 76, 82, 82, 18, 154, 166, 145, 152, 152, 200, 99, 143, 61, - 70, 65, 65, 1, 163, 163, 163, 44, 94, 188, 24, 77, 211, 120, 238, 185, 231, 200, 204, 204, 164, 187, 187, 27, - 167, 219, 131, 199, 227, 193, 229, 114, 81, 223, 216, 172, 126, 180, 239, 192, 137, 166, 127, 214, 93, 0, 170, - 133, 16, 142, 31, 251, 156, 2, 64, 136, 160, 191, 55, 217, 58, 68, 210, 124, 179, 20, 31, 31, 63, 1, 234, 65, - 67, 137, 137, 137, 33, 40, 40, 8, 89, 150, 17, 66, 16, 21, 21, 69, 92, 92, 28, 178, 44, 163, 215, 235, 89, - 181, 106, 21, 146, 36, 113, 229, 202, 21, 122, 7, 38, 212, 126, 161, 234, 31, 99, 31, 239, 251, 227, 231, 247, - 122, 123, 190, 7, 106, 133, 16, 206, 135, 25, 159, 246, 107, 182, 237, 183, 239, 156, 95, 185, 252, 169, 95, - 62, 181, 104, 1, 179, 66, 67, 144, 36, 41, 240, 21, 35, 203, 114, 224, 120, 120, 62, 9, 246, 194, 119, 85, - 154, 226, 23, 52, 53, 183, 180, 125, 125, 252, 104, 225, 232, 168, 251, 202, 131, 152, 123, 30, 118, 62, 35, - 128, 237, 219, 63, 48, 12, 221, 239, 202, 55, 24, 12, 219, 141, 70, 99, 164, 52, 67, 181, 124, 212, 240, 249, - 125, 227, 157, 29, 237, 214, 27, 181, 151, 191, 27, 25, 30, 106, 5, 58, 152, 72, 55, 223, 163, 222, 153, 6, - 224, 193, 78, 116, 128, 9, 136, 3, 30, 255, 111, 1, 60, 24, 42, 208, 11, 12, 76, 42, 253, 63, 141, 127, 1, - 173, 193, 47, 22, 232, 14, 87, 117, 0, 0, 0, 0, 73, 69, 78, 68, 174, 66, 96, 130, - ], - }, - - unknown: "This is an : unknown : file type", - - empty: undefined, - }, - }, - - staticParser: { - definitions: { - markdown: "The quick brown fox jumped over the lazy dog", - - html: "The quick brown fox jumped over the lazy dog", - - css: "The quick brown fox jumped over the lazy dog", - - binary: "The quick brown fox jumped over the lazy dog", - - unknown: "The quick brown fox jumped over the lazy dog", - - empty: "The quick brown fox jumped over the lazy dog", - }, - }, - - customParser: { - definitions: { - markdown: "Hello\nWorld:\n", - - html: - "\n" + - '\n' + - " \n" + - ' \n' + - ' \n' + - " \n" + - " \n" + - "

Hello World:

\n" + - " \n" + - "\n", - - css: "html {\n color: #888;\n font-family: sans-serif;\n height: 100%;\n width: 100%;\n}\n", - - binary: { - type: "Buffer", - data: [ - 137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 32, 0, 0, 0, 32, 8, 6, 0, 0, 0, 115, - 122, 122, 244, 0, 0, 0, 4, 115, 66, 73, 84, 8, 8, 8, 8, 124, 8, 100, 136, 0, 0, 0, 25, 116, 69, 88, 116, 83, - 111, 102, 116, 119, 97, 114, 101, 0, 119, 119, 119, 46, 105, 110, 107, 115, 99, 97, 112, 101, 46, 111, 114, - 103, 155, 238, 60, 26, 0, 0, 9, 170, 73, 68, 65, 84, 88, 133, 197, 151, 125, 76, 84, 103, 22, 198, 127, 247, - 206, 64, 7, 44, 227, 0, 149, 15, 97, 176, 34, 139, 174, 182, 86, 49, 46, 69, 148, 197, 80, 234, 118, 73, 181, - 49, 213, 38, 146, 172, 218, 221, 86, 151, 98, 106, 218, 198, 212, 102, 179, 180, 221, 173, 154, 102, 187, 182, - 113, 171, 181, 113, 165, 145, 138, 41, 152, 173, 160, 130, 73, 149, 116, 23, 131, 34, 42, 203, 48, 128, 195, - 135, 128, 200, 200, 71, 103, 24, 6, 24, 135, 59, 115, 239, 187, 127, 32, 179, 69, 112, 179, 127, 108, 178, - 111, 114, 63, 222, 251, 158, 155, 243, 188, 207, 121, 206, 57, 247, 74, 66, 8, 254, 159, 67, 63, 211, 195, 95, - 231, 189, 149, 168, 73, 186, 95, 161, 73, 166, 255, 181, 67, 73, 214, 106, 131, 252, 35, 167, 143, 30, 61, - 234, 3, 144, 30, 102, 96, 123, 222, 158, 143, 146, 147, 158, 124, 119, 237, 154, 52, 121, 254, 188, 120, 38, - 215, 255, 125, 157, 60, 129, 16, 26, 2, 129, 16, 160, 169, 26, 154, 208, 208, 84, 13, 191, 234, 71, 211, 52, - 132, 166, 161, 106, 19, 207, 84, 77, 195, 229, 114, 209, 216, 210, 70, 75, 235, 237, 65, 191, 207, 187, 234, - 216, 231, 127, 110, 151, 127, 236, 124, 199, 142, 119, 103, 199, 205, 141, 126, 107, 99, 78, 150, 92, 114, - 170, 136, 47, 142, 28, 102, 206, 19, 145, 220, 106, 105, 102, 87, 254, 27, 92, 175, 187, 70, 76, 244, 28, 244, - 122, 153, 195, 135, 255, 194, 167, 159, 30, 100, 86, 104, 40, 67, 78, 7, 123, 246, 188, 195, 217, 242, 50, - 226, 226, 98, 145, 16, 252, 225, 195, 15, 248, 246, 219, 191, 49, 47, 193, 76, 92, 92, 44, 229, 101, 223, 114, - 170, 248, 107, 150, 36, 63, 201, 218, 213, 63, 155, 51, 236, 246, 252, 94, 146, 164, 160, 41, 0, 20, 89, 125, - 33, 115, 117, 170, 225, 240, 225, 195, 188, 252, 242, 203, 132, 133, 133, 81, 89, 89, 201, 234, 213, 171, 201, - 201, 201, 161, 181, 181, 21, 33, 4, 37, 37, 37, 44, 90, 180, 136, 212, 212, 84, 10, 11, 11, 73, 78, 78, 102, - 199, 142, 29, 180, 180, 180, 32, 132, 32, 46, 46, 142, 221, 187, 119, 211, 212, 212, 132, 170, 170, 88, 44, - 22, 70, 71, 71, 217, 185, 115, 39, 199, 142, 29, 35, 121, 193, 60, 34, 35, 35, 54, 0, 115, 166, 0, 64, 150, - 12, 115, 99, 162, 25, 24, 24, 32, 41, 41, 137, 212, 212, 84, 110, 222, 188, 137, 78, 167, 99, 246, 236, 217, - 1, 179, 186, 186, 58, 150, 46, 93, 202, 138, 21, 43, 104, 105, 105, 65, 146, 36, 34, 35, 35, 145, 36, 41, 16, - 174, 240, 240, 112, 36, 73, 66, 85, 85, 26, 26, 26, 152, 55, 111, 30, 209, 209, 209, 184, 92, 46, 244, 122, - 61, 225, 225, 70, 3, 16, 63, 21, 0, 32, 73, 18, 70, 163, 17, 69, 81, 232, 233, 233, 33, 33, 33, 1, 33, 196, - 20, 45, 44, 88, 176, 128, 190, 190, 62, 238, 222, 189, 139, 217, 108, 158, 178, 174, 170, 42, 170, 170, 162, - 105, 26, 154, 166, 161, 170, 42, 137, 137, 137, 220, 187, 119, 143, 251, 247, 239, 19, 18, 18, 50, 225, 72, - 32, 1, 97, 211, 0, 8, 33, 216, 186, 117, 43, 123, 247, 238, 165, 170, 170, 138, 180, 180, 52, 26, 26, 26, 40, - 42, 42, 162, 162, 162, 130, 154, 154, 26, 54, 111, 222, 76, 97, 97, 33, 95, 125, 245, 21, 25, 25, 25, 216, - 237, 118, 62, 249, 228, 19, 234, 234, 234, 40, 43, 43, 195, 233, 116, 178, 127, 255, 126, 154, 154, 154, 56, - 125, 250, 52, 75, 150, 44, 193, 102, 179, 81, 80, 80, 192, 154, 53, 107, 16, 98, 194, 251, 180, 44, 216, 254, - 198, 158, 109, 239, 228, 255, 166, 112, 241, 162, 159, 160, 40, 10, 30, 143, 7, 163, 209, 136, 16, 130, 193, - 193, 65, 52, 77, 35, 56, 56, 24, 163, 209, 136, 170, 170, 184, 92, 46, 194, 195, 195, 3, 235, 62, 159, 15, 89, - 150, 49, 26, 141, 56, 28, 14, 198, 199, 199, 17, 66, 96, 50, 153, 240, 249, 124, 252, 240, 195, 15, 1, 118, - 75, 206, 92, 240, 237, 255, 96, 239, 11, 211, 24, 0, 24, 24, 24, 160, 178, 178, 18, 175, 215, 139, 16, 2, 167, - 211, 73, 109, 109, 45, 138, 162, 96, 52, 26, 1, 184, 121, 243, 38, 253, 253, 253, 8, 33, 80, 85, 21, 187, 221, - 78, 111, 111, 47, 70, 163, 145, 177, 177, 49, 234, 235, 235, 233, 239, 239, 39, 60, 60, 28, 175, 215, 203, - 149, 43, 87, 232, 233, 233, 153, 72, 79, 33, 224, 129, 94, 166, 21, 34, 33, 4, 109, 109, 109, 156, 62, 125, - 154, 129, 129, 1, 94, 125, 245, 85, 58, 59, 59, 57, 119, 238, 28, 54, 155, 141, 221, 187, 119, 83, 81, 81, - 193, 213, 171, 87, 113, 56, 28, 228, 228, 228, 96, 48, 24, 40, 43, 43, 67, 175, 215, 99, 179, 217, 120, 246, - 217, 103, 169, 175, 175, 167, 173, 173, 141, 131, 7, 15, 50, 54, 54, 134, 205, 102, 163, 166, 166, 134, 67, - 135, 14, 77, 145, 220, 140, 12, 164, 165, 165, 145, 153, 153, 25, 0, 180, 124, 249, 114, 214, 173, 91, 135, - 36, 73, 8, 33, 168, 170, 170, 98, 195, 134, 13, 228, 229, 229, 113, 233, 210, 37, 170, 171, 171, 201, 202, - 202, 34, 47, 47, 143, 234, 234, 106, 162, 162, 162, 216, 178, 101, 11, 122, 253, 196, 254, 34, 34, 34, 200, - 205, 205, 37, 56, 56, 24, 89, 150, 209, 233, 116, 129, 140, 153, 145, 129, 71, 29, 147, 235, 62, 159, 15, 189, - 94, 143, 166, 105, 0, 248, 253, 126, 244, 122, 61, 63, 214, 211, 228, 189, 78, 167, 67, 211, 52, 100, 121, 98, - 175, 65, 65, 65, 83, 236, 102, 236, 5, 253, 253, 253, 220, 190, 125, 27, 33, 4, 46, 151, 11, 159, 207, 71, 91, - 91, 27, 118, 187, 157, 193, 193, 65, 178, 178, 178, 40, 46, 46, 70, 150, 101, 82, 82, 82, 136, 141, 141, 165, - 180, 180, 148, 184, 184, 56, 86, 172, 88, 129, 162, 40, 88, 173, 86, 156, 78, 39, 118, 187, 157, 152, 152, 24, - 44, 22, 11, 110, 183, 27, 187, 221, 78, 84, 84, 212, 100, 57, 151, 166, 3, 16, 130, 209, 209, 81, 162, 162, - 162, 240, 249, 124, 116, 117, 117, 17, 25, 25, 73, 72, 72, 8, 102, 179, 153, 206, 206, 78, 178, 179, 179, 209, - 233, 116, 8, 33, 88, 185, 114, 37, 161, 161, 161, 8, 33, 112, 56, 28, 164, 167, 167, 163, 105, 26, 125, 125, - 125, 100, 100, 100, 208, 218, 218, 74, 76, 76, 12, 221, 221, 221, 100, 103, 103, 99, 179, 217, 136, 141, 141, - 125, 180, 8, 17, 130, 249, 243, 231, 147, 151, 151, 55, 133, 246, 215, 95, 127, 61, 160, 120, 33, 4, 153, 153, - 153, 83, 66, 147, 154, 154, 58, 133, 218, 109, 219, 182, 5, 52, 51, 57, 159, 180, 31, 25, 25, 9, 216, 77, 19, - 161, 42, 84, 206, 159, 63, 79, 118, 118, 54, 101, 101, 101, 8, 33, 176, 90, 173, 236, 218, 181, 139, 157, 59, - 119, 50, 48, 48, 192, 245, 235, 215, 121, 229, 149, 87, 56, 114, 228, 8, 0, 125, 125, 125, 188, 253, 246, 219, - 228, 231, 231, 211, 217, 217, 201, 216, 216, 24, 123, 246, 236, 97, 215, 174, 93, 52, 54, 54, 162, 170, 42, - 239, 189, 247, 30, 111, 190, 249, 38, 181, 181, 181, 19, 34, 124, 20, 0, 159, 79, 37, 45, 45, 141, 141, 27, - 55, 226, 112, 56, 80, 85, 149, 83, 167, 78, 177, 101, 203, 22, 114, 114, 114, 40, 47, 47, 103, 249, 242, 229, - 188, 246, 218, 107, 140, 140, 140, 32, 73, 18, 151, 46, 93, 34, 61, 61, 157, 252, 252, 124, 138, 139, 139, - 185, 118, 237, 26, 79, 63, 253, 52, 7, 14, 28, 160, 168, 168, 8, 171, 213, 138, 217, 108, 230, 208, 161, 67, - 156, 60, 121, 18, 157, 78, 247, 104, 6, 252, 126, 63, 189, 189, 189, 56, 157, 78, 250, 250, 250, 232, 234, - 234, 162, 181, 181, 21, 163, 209, 72, 84, 84, 20, 237, 237, 237, 140, 143, 143, 35, 203, 50, 170, 170, 226, - 247, 251, 185, 117, 235, 22, 102, 179, 153, 196, 196, 68, 236, 118, 59, 237, 237, 237, 36, 36, 36, 48, 103, - 206, 28, 28, 14, 71, 64, 7, 161, 161, 161, 120, 189, 94, 84, 85, 13, 164, 225, 244, 16, 168, 234, 148, 249, - 248, 248, 56, 115, 231, 206, 165, 173, 173, 141, 198, 198, 70, 18, 18, 18, 80, 20, 37, 144, 130, 178, 44, 243, - 204, 51, 207, 208, 221, 221, 77, 71, 71, 7, 11, 23, 46, 100, 217, 178, 101, 116, 116, 116, 4, 154, 85, 74, 74, - 10, 157, 157, 157, 184, 221, 110, 194, 195, 195, 9, 10, 10, 66, 25, 191, 63, 246, 72, 0, 22, 139, 133, 171, - 87, 175, 114, 249, 242, 101, 26, 27, 27, 217, 180, 105, 19, 103, 207, 158, 165, 185, 185, 153, 244, 244, 116, - 186, 186, 186, 40, 45, 45, 197, 98, 177, 112, 241, 226, 69, 94, 124, 241, 69, 44, 22, 11, 37, 37, 37, 172, 95, - 191, 158, 244, 244, 116, 250, 251, 251, 249, 236, 179, 207, 216, 188, 121, 51, 75, 151, 46, 5, 224, 253, 247, - 223, 39, 55, 55, 151, 214, 142, 46, 173, 185, 229, 86, 51, 224, 159, 214, 140, 182, 110, 94, 95, 24, 246, 120, - 8, 138, 162, 4, 118, 104, 48, 24, 208, 235, 245, 72, 146, 132, 193, 96, 32, 40, 40, 8, 77, 211, 208, 235, 245, - 4, 7, 7, 19, 18, 18, 130, 78, 167, 67, 85, 213, 128, 157, 36, 73, 244, 245, 15, 210, 216, 98, 67, 211, 38, - 178, 199, 167, 40, 184, 71, 70, 208, 84, 149, 130, 130, 223, 125, 120, 175, 167, 187, 112, 90, 26, 170, 154, - 138, 215, 235, 165, 188, 188, 156, 152, 152, 24, 50, 50, 50, 240, 251, 253, 156, 57, 115, 6, 147, 201, 196, - 134, 13, 27, 16, 66, 112, 246, 236, 89, 36, 73, 34, 55, 55, 151, 193, 193, 65, 138, 138, 138, 88, 182, 108, - 89, 160, 100, 215, 92, 187, 65, 66, 124, 28, 191, 200, 250, 57, 138, 162, 160, 40, 10, 67, 67, 67, 12, 13, 13, - 113, 178, 164, 236, 238, 189, 158, 238, 6, 160, 111, 90, 8, 52, 77, 112, 226, 196, 9, 162, 163, 163, 169, 171, - 171, 163, 161, 161, 129, 210, 210, 82, 130, 131, 131, 233, 232, 232, 224, 226, 197, 139, 84, 86, 86, 226, 114, - 185, 240, 120, 60, 20, 21, 21, 97, 48, 24, 48, 155, 205, 84, 84, 84, 160, 105, 26, 150, 70, 43, 79, 68, 68, - 144, 248, 100, 66, 64, 43, 99, 99, 99, 184, 221, 110, 46, 215, 222, 240, 254, 245, 139, 67, 71, 129, 118, 33, - 132, 119, 70, 13, 220, 185, 115, 135, 37, 75, 150, 176, 118, 237, 90, 234, 235, 235, 177, 90, 173, 172, 92, - 185, 146, 117, 235, 214, 81, 95, 95, 79, 93, 93, 29, 233, 233, 233, 188, 244, 210, 75, 220, 184, 113, 3, 147, - 201, 68, 74, 74, 10, 178, 44, 99, 179, 217, 248, 190, 186, 134, 159, 46, 76, 194, 239, 247, 163, 170, 42, 195, - 195, 195, 12, 13, 13, 113, 171, 237, 182, 246, 241, 254, 253, 135, 93, 46, 231, 101, 224, 22, 204, 80, 9, 39, - 227, 40, 203, 50, 110, 183, 155, 176, 176, 48, 102, 205, 154, 133, 223, 239, 199, 237, 118, 51, 123, 246, 108, - 124, 62, 31, 30, 143, 135, 225, 225, 97, 34, 34, 34, 2, 239, 78, 126, 152, 184, 221, 110, 252, 126, 63, 66, 8, - 220, 110, 247, 68, 79, 232, 27, 96, 223, 190, 253, 197, 119, 239, 220, 174, 2, 174, 11, 33, 148, 25, 1, 104, - 154, 198, 154, 53, 107, 56, 126, 252, 56, 35, 35, 35, 228, 230, 230, 146, 152, 152, 72, 97, 97, 33, 0, 155, - 54, 109, 194, 100, 50, 241, 229, 151, 95, 98, 50, 153, 120, 254, 249, 231, 113, 56, 28, 124, 243, 205, 55, 88, - 173, 86, 146, 147, 147, 209, 52, 13, 69, 81, 240, 122, 189, 56, 157, 78, 122, 122, 239, 241, 241, 159, 62, - 173, 104, 184, 121, 237, 28, 112, 85, 8, 49, 58, 233, 111, 10, 0, 73, 104, 98, 204, 115, 159, 172, 172, 44, - 22, 46, 92, 136, 36, 73, 196, 199, 199, 19, 28, 28, 76, 82, 82, 18, 154, 166, 145, 152, 152, 200, 99, 143, 61, - 70, 65, 65, 1, 163, 163, 163, 44, 94, 188, 24, 77, 211, 120, 238, 185, 231, 200, 204, 204, 164, 187, 187, 27, - 167, 219, 131, 199, 227, 193, 229, 114, 81, 223, 216, 172, 126, 180, 239, 192, 137, 166, 127, 214, 93, 0, 170, - 133, 16, 142, 31, 251, 156, 2, 64, 136, 160, 191, 55, 217, 58, 68, 210, 124, 179, 20, 31, 31, 63, 1, 234, 65, - 67, 137, 137, 137, 33, 40, 40, 8, 89, 150, 17, 66, 16, 21, 21, 69, 92, 92, 28, 178, 44, 163, 215, 235, 89, - 181, 106, 21, 146, 36, 113, 229, 202, 21, 122, 7, 38, 212, 126, 161, 234, 31, 99, 31, 239, 251, 227, 231, 247, - 122, 123, 190, 7, 106, 133, 16, 206, 135, 25, 159, 246, 107, 182, 237, 183, 239, 156, 95, 185, 252, 169, 95, - 62, 181, 104, 1, 179, 66, 67, 144, 36, 41, 240, 21, 35, 203, 114, 224, 120, 120, 62, 9, 246, 194, 119, 85, - 154, 226, 23, 52, 53, 183, 180, 125, 125, 252, 104, 225, 232, 168, 251, 202, 131, 152, 123, 30, 118, 62, 35, - 128, 237, 219, 63, 48, 12, 221, 239, 202, 55, 24, 12, 219, 141, 70, 99, 164, 52, 67, 181, 124, 212, 240, 249, - 125, 227, 157, 29, 237, 214, 27, 181, 151, 191, 27, 25, 30, 106, 5, 58, 152, 72, 55, 223, 163, 222, 153, 6, - 224, 193, 78, 116, 128, 9, 136, 3, 30, 255, 111, 1, 60, 24, 42, 208, 11, 12, 76, 42, 253, 63, 141, 127, 1, - 173, 193, 47, 22, 232, 14, 87, 117, 0, 0, 0, 0, 73, 69, 78, 68, 174, 66, 96, 130, - ], - }, - - unknown: "epyt elif : nwonknu : na si sihT", - - empty: undefined, - }, - }, - - binaryParser: { - definitions: { - markdown: { type: "Buffer", data: [72, 101, 108, 108, 111, 10, 87, 111, 114, 108, 100, 58, 10] }, - - html: { - type: "Buffer", - data: [ - 60, 33, 100, 111, 99, 116, 121, 112, 101, 32, 104, 116, 109, 108, 62, 10, 60, 104, 116, 109, 108, 32, 108, 97, - 110, 103, 61, 34, 101, 110, 34, 62, 10, 32, 32, 60, 104, 101, 97, 100, 62, 10, 32, 32, 32, 32, 60, 109, 101, - 116, 97, 32, 99, 104, 97, 114, 115, 101, 116, 61, 34, 117, 116, 102, 45, 56, 34, 32, 47, 62, 10, 32, 32, 32, - 32, 60, 108, 105, 110, 107, 32, 114, 101, 108, 61, 34, 115, 116, 121, 108, 101, 115, 104, 101, 101, 116, 34, - 32, 104, 114, 101, 102, 61, 34, 115, 116, 121, 108, 101, 46, 99, 115, 115, 34, 32, 47, 62, 10, 32, 32, 60, 47, - 104, 101, 97, 100, 62, 10, 32, 32, 60, 98, 111, 100, 121, 62, 10, 32, 32, 32, 32, 60, 104, 49, 62, 72, 101, - 108, 108, 111, 32, 87, 111, 114, 108, 100, 58, 60, 47, 104, 49, 62, 10, 32, 32, 60, 47, 98, 111, 100, 121, 62, - 10, 60, 47, 104, 116, 109, 108, 62, 10, - ], - }, - - css: { - type: "Buffer", - data: [ - 104, 116, 109, 108, 32, 123, 10, 32, 32, 99, 111, 108, 111, 114, 58, 32, 35, 56, 56, 56, 59, 10, 32, 32, 102, - 111, 110, 116, 45, 102, 97, 109, 105, 108, 121, 58, 32, 115, 97, 110, 115, 45, 115, 101, 114, 105, 102, 59, - 10, 32, 32, 104, 101, 105, 103, 104, 116, 58, 32, 49, 48, 48, 37, 59, 10, 32, 32, 119, 105, 100, 116, 104, 58, - 32, 49, 48, 48, 37, 59, 10, 125, 10, - ], - }, - - binary: { - type: "Buffer", - data: [ - 137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 32, 0, 0, 0, 32, 8, 6, 0, 0, 0, 115, - 122, 122, 244, 0, 0, 0, 4, 115, 66, 73, 84, 8, 8, 8, 8, 124, 8, 100, 136, 0, 0, 0, 25, 116, 69, 88, 116, 83, - 111, 102, 116, 119, 97, 114, 101, 0, 119, 119, 119, 46, 105, 110, 107, 115, 99, 97, 112, 101, 46, 111, 114, - 103, 155, 238, 60, 26, 0, 0, 9, 170, 73, 68, 65, 84, 88, 133, 197, 151, 125, 76, 84, 103, 22, 198, 127, 247, - 206, 64, 7, 44, 227, 0, 149, 15, 97, 176, 34, 139, 174, 182, 86, 49, 46, 69, 148, 197, 80, 234, 118, 73, 181, - 49, 213, 38, 146, 172, 218, 221, 86, 151, 98, 106, 218, 198, 212, 102, 179, 180, 221, 173, 154, 102, 187, 182, - 113, 171, 181, 113, 165, 145, 138, 41, 152, 173, 160, 130, 73, 149, 116, 23, 131, 34, 42, 203, 48, 128, 195, - 135, 128, 200, 200, 71, 103, 24, 6, 24, 135, 59, 115, 239, 187, 127, 32, 179, 69, 112, 179, 127, 108, 178, - 111, 114, 63, 222, 251, 158, 155, 243, 188, 207, 121, 206, 57, 247, 74, 66, 8, 254, 159, 67, 63, 211, 195, 95, - 231, 189, 149, 168, 73, 186, 95, 161, 73, 166, 255, 181, 67, 73, 214, 106, 131, 252, 35, 167, 143, 30, 61, - 234, 3, 144, 30, 102, 96, 123, 222, 158, 143, 146, 147, 158, 124, 119, 237, 154, 52, 121, 254, 188, 120, 38, - 215, 255, 125, 157, 60, 129, 16, 26, 2, 129, 16, 160, 169, 26, 154, 208, 208, 84, 13, 191, 234, 71, 211, 52, - 132, 166, 161, 106, 19, 207, 84, 77, 195, 229, 114, 209, 216, 210, 70, 75, 235, 237, 65, 191, 207, 187, 234, - 216, 231, 127, 110, 151, 127, 236, 124, 199, 142, 119, 103, 199, 205, 141, 126, 107, 99, 78, 150, 92, 114, - 170, 136, 47, 142, 28, 102, 206, 19, 145, 220, 106, 105, 102, 87, 254, 27, 92, 175, 187, 70, 76, 244, 28, 244, - 122, 153, 195, 135, 255, 194, 167, 159, 30, 100, 86, 104, 40, 67, 78, 7, 123, 246, 188, 195, 217, 242, 50, - 226, 226, 98, 145, 16, 252, 225, 195, 15, 248, 246, 219, 191, 49, 47, 193, 76, 92, 92, 44, 229, 101, 223, 114, - 170, 248, 107, 150, 36, 63, 201, 218, 213, 63, 155, 51, 236, 246, 252, 94, 146, 164, 160, 41, 0, 20, 89, 125, - 33, 115, 117, 170, 225, 240, 225, 195, 188, 252, 242, 203, 132, 133, 133, 81, 89, 89, 201, 234, 213, 171, 201, - 201, 201, 161, 181, 181, 21, 33, 4, 37, 37, 37, 44, 90, 180, 136, 212, 212, 84, 10, 11, 11, 73, 78, 78, 102, - 199, 142, 29, 180, 180, 180, 32, 132, 32, 46, 46, 142, 221, 187, 119, 211, 212, 212, 132, 170, 170, 88, 44, - 22, 70, 71, 71, 217, 185, 115, 39, 199, 142, 29, 35, 121, 193, 60, 34, 35, 35, 54, 0, 115, 166, 0, 64, 150, - 12, 115, 99, 162, 25, 24, 24, 32, 41, 41, 137, 212, 212, 84, 110, 222, 188, 137, 78, 167, 99, 246, 236, 217, - 1, 179, 186, 186, 58, 150, 46, 93, 202, 138, 21, 43, 104, 105, 105, 65, 146, 36, 34, 35, 35, 145, 36, 41, 16, - 174, 240, 240, 112, 36, 73, 66, 85, 85, 26, 26, 26, 152, 55, 111, 30, 209, 209, 209, 184, 92, 46, 244, 122, - 61, 225, 225, 70, 3, 16, 63, 21, 0, 32, 73, 18, 70, 163, 17, 69, 81, 232, 233, 233, 33, 33, 33, 1, 33, 196, - 20, 45, 44, 88, 176, 128, 190, 190, 62, 238, 222, 189, 139, 217, 108, 158, 178, 174, 170, 42, 170, 170, 162, - 105, 26, 154, 166, 161, 170, 42, 137, 137, 137, 220, 187, 119, 143, 251, 247, 239, 19, 18, 18, 50, 225, 72, - 32, 1, 97, 211, 0, 8, 33, 216, 186, 117, 43, 123, 247, 238, 165, 170, 170, 138, 180, 180, 52, 26, 26, 26, 40, - 42, 42, 162, 162, 162, 130, 154, 154, 26, 54, 111, 222, 76, 97, 97, 33, 95, 125, 245, 21, 25, 25, 25, 216, - 237, 118, 62, 249, 228, 19, 234, 234, 234, 40, 43, 43, 195, 233, 116, 178, 127, 255, 126, 154, 154, 154, 56, - 125, 250, 52, 75, 150, 44, 193, 102, 179, 81, 80, 80, 192, 154, 53, 107, 16, 98, 194, 251, 180, 44, 216, 254, - 198, 158, 109, 239, 228, 255, 166, 112, 241, 162, 159, 160, 40, 10, 30, 143, 7, 163, 209, 136, 16, 130, 193, - 193, 65, 52, 77, 35, 56, 56, 24, 163, 209, 136, 170, 170, 184, 92, 46, 194, 195, 195, 3, 235, 62, 159, 15, 89, - 150, 49, 26, 141, 56, 28, 14, 198, 199, 199, 17, 66, 96, 50, 153, 240, 249, 124, 252, 240, 195, 15, 1, 118, - 75, 206, 92, 240, 237, 255, 96, 239, 11, 211, 24, 0, 24, 24, 24, 160, 178, 178, 18, 175, 215, 139, 16, 2, 167, - 211, 73, 109, 109, 45, 138, 162, 96, 52, 26, 1, 184, 121, 243, 38, 253, 253, 253, 8, 33, 80, 85, 21, 187, 221, - 78, 111, 111, 47, 70, 163, 145, 177, 177, 49, 234, 235, 235, 233, 239, 239, 39, 60, 60, 28, 175, 215, 203, - 149, 43, 87, 232, 233, 233, 153, 72, 79, 33, 224, 129, 94, 166, 21, 34, 33, 4, 109, 109, 109, 156, 62, 125, - 154, 129, 129, 1, 94, 125, 245, 85, 58, 59, 59, 57, 119, 238, 28, 54, 155, 141, 221, 187, 119, 83, 81, 81, - 193, 213, 171, 87, 113, 56, 28, 228, 228, 228, 96, 48, 24, 40, 43, 43, 67, 175, 215, 99, 179, 217, 120, 246, - 217, 103, 169, 175, 175, 167, 173, 173, 141, 131, 7, 15, 50, 54, 54, 134, 205, 102, 163, 166, 166, 134, 67, - 135, 14, 77, 145, 220, 140, 12, 164, 165, 165, 145, 153, 153, 25, 0, 180, 124, 249, 114, 214, 173, 91, 135, - 36, 73, 8, 33, 168, 170, 170, 98, 195, 134, 13, 228, 229, 229, 113, 233, 210, 37, 170, 171, 171, 201, 202, - 202, 34, 47, 47, 143, 234, 234, 106, 162, 162, 162, 216, 178, 101, 11, 122, 253, 196, 254, 34, 34, 34, 200, - 205, 205, 37, 56, 56, 24, 89, 150, 209, 233, 116, 129, 140, 153, 145, 129, 71, 29, 147, 235, 62, 159, 15, 189, - 94, 143, 166, 105, 0, 248, 253, 126, 244, 122, 61, 63, 214, 211, 228, 189, 78, 167, 67, 211, 52, 100, 121, 98, - 175, 65, 65, 65, 83, 236, 102, 236, 5, 253, 253, 253, 220, 190, 125, 27, 33, 4, 46, 151, 11, 159, 207, 71, 91, - 91, 27, 118, 187, 157, 193, 193, 65, 178, 178, 178, 40, 46, 46, 70, 150, 101, 82, 82, 82, 136, 141, 141, 165, - 180, 180, 148, 184, 184, 56, 86, 172, 88, 129, 162, 40, 88, 173, 86, 156, 78, 39, 118, 187, 157, 152, 152, 24, - 44, 22, 11, 110, 183, 27, 187, 221, 78, 84, 84, 212, 100, 57, 151, 166, 3, 16, 130, 209, 209, 81, 162, 162, - 162, 240, 249, 124, 116, 117, 117, 17, 25, 25, 73, 72, 72, 8, 102, 179, 153, 206, 206, 78, 178, 179, 179, 209, - 233, 116, 8, 33, 88, 185, 114, 37, 161, 161, 161, 8, 33, 112, 56, 28, 164, 167, 167, 163, 105, 26, 125, 125, - 125, 100, 100, 100, 208, 218, 218, 74, 76, 76, 12, 221, 221, 221, 100, 103, 103, 99, 179, 217, 136, 141, 141, - 125, 180, 8, 17, 130, 249, 243, 231, 147, 151, 151, 55, 133, 246, 215, 95, 127, 61, 160, 120, 33, 4, 153, 153, - 153, 83, 66, 147, 154, 154, 58, 133, 218, 109, 219, 182, 5, 52, 51, 57, 159, 180, 31, 25, 25, 9, 216, 77, 19, - 161, 42, 84, 206, 159, 63, 79, 118, 118, 54, 101, 101, 101, 8, 33, 176, 90, 173, 236, 218, 181, 139, 157, 59, - 119, 50, 48, 48, 192, 245, 235, 215, 121, 229, 149, 87, 56, 114, 228, 8, 0, 125, 125, 125, 188, 253, 246, 219, - 228, 231, 231, 211, 217, 217, 201, 216, 216, 24, 123, 246, 236, 97, 215, 174, 93, 52, 54, 54, 162, 170, 42, - 239, 189, 247, 30, 111, 190, 249, 38, 181, 181, 181, 19, 34, 124, 20, 0, 159, 79, 37, 45, 45, 141, 141, 27, - 55, 226, 112, 56, 80, 85, 149, 83, 167, 78, 177, 101, 203, 22, 114, 114, 114, 40, 47, 47, 103, 249, 242, 229, - 188, 246, 218, 107, 140, 140, 140, 32, 73, 18, 151, 46, 93, 34, 61, 61, 157, 252, 252, 124, 138, 139, 139, - 185, 118, 237, 26, 79, 63, 253, 52, 7, 14, 28, 160, 168, 168, 8, 171, 213, 138, 217, 108, 230, 208, 161, 67, - 156, 60, 121, 18, 157, 78, 247, 104, 6, 252, 126, 63, 189, 189, 189, 56, 157, 78, 250, 250, 250, 232, 234, - 234, 162, 181, 181, 21, 163, 209, 72, 84, 84, 20, 237, 237, 237, 140, 143, 143, 35, 203, 50, 170, 170, 226, - 247, 251, 185, 117, 235, 22, 102, 179, 153, 196, 196, 68, 236, 118, 59, 237, 237, 237, 36, 36, 36, 48, 103, - 206, 28, 28, 14, 71, 64, 7, 161, 161, 161, 120, 189, 94, 84, 85, 13, 164, 225, 244, 16, 168, 234, 148, 249, - 248, 248, 56, 115, 231, 206, 165, 173, 173, 141, 198, 198, 70, 18, 18, 18, 80, 20, 37, 144, 130, 178, 44, 243, - 204, 51, 207, 208, 221, 221, 77, 71, 71, 7, 11, 23, 46, 100, 217, 178, 101, 116, 116, 116, 4, 154, 85, 74, 74, - 10, 157, 157, 157, 184, 221, 110, 194, 195, 195, 9, 10, 10, 66, 25, 191, 63, 246, 72, 0, 22, 139, 133, 171, - 87, 175, 114, 249, 242, 101, 26, 27, 27, 217, 180, 105, 19, 103, 207, 158, 165, 185, 185, 153, 244, 244, 116, - 186, 186, 186, 40, 45, 45, 197, 98, 177, 112, 241, 226, 69, 94, 124, 241, 69, 44, 22, 11, 37, 37, 37, 172, 95, - 191, 158, 244, 244, 116, 250, 251, 251, 249, 236, 179, 207, 216, 188, 121, 51, 75, 151, 46, 5, 224, 253, 247, - 223, 39, 55, 55, 151, 214, 142, 46, 173, 185, 229, 86, 51, 224, 159, 214, 140, 182, 110, 94, 95, 24, 246, 120, - 8, 138, 162, 4, 118, 104, 48, 24, 208, 235, 245, 72, 146, 132, 193, 96, 32, 40, 40, 8, 77, 211, 208, 235, 245, - 4, 7, 7, 19, 18, 18, 130, 78, 167, 67, 85, 213, 128, 157, 36, 73, 244, 245, 15, 210, 216, 98, 67, 211, 38, - 178, 199, 167, 40, 184, 71, 70, 208, 84, 149, 130, 130, 223, 125, 120, 175, 167, 187, 112, 90, 26, 170, 154, - 138, 215, 235, 165, 188, 188, 156, 152, 152, 24, 50, 50, 50, 240, 251, 253, 156, 57, 115, 6, 147, 201, 196, - 134, 13, 27, 16, 66, 112, 246, 236, 89, 36, 73, 34, 55, 55, 151, 193, 193, 65, 138, 138, 138, 88, 182, 108, - 89, 160, 100, 215, 92, 187, 65, 66, 124, 28, 191, 200, 250, 57, 138, 162, 160, 40, 10, 67, 67, 67, 12, 13, 13, - 113, 178, 164, 236, 238, 189, 158, 238, 6, 160, 111, 90, 8, 52, 77, 112, 226, 196, 9, 162, 163, 163, 169, 171, - 171, 163, 161, 161, 129, 210, 210, 82, 130, 131, 131, 233, 232, 232, 224, 226, 197, 139, 84, 86, 86, 226, 114, - 185, 240, 120, 60, 20, 21, 21, 97, 48, 24, 48, 155, 205, 84, 84, 84, 160, 105, 26, 150, 70, 43, 79, 68, 68, - 144, 248, 100, 66, 64, 43, 99, 99, 99, 184, 221, 110, 46, 215, 222, 240, 254, 245, 139, 67, 71, 129, 118, 33, - 132, 119, 70, 13, 220, 185, 115, 135, 37, 75, 150, 176, 118, 237, 90, 234, 235, 235, 177, 90, 173, 172, 92, - 185, 146, 117, 235, 214, 81, 95, 95, 79, 93, 93, 29, 233, 233, 233, 188, 244, 210, 75, 220, 184, 113, 3, 147, - 201, 68, 74, 74, 10, 178, 44, 99, 179, 217, 248, 190, 186, 134, 159, 46, 76, 194, 239, 247, 163, 170, 42, 195, - 195, 195, 12, 13, 13, 113, 171, 237, 182, 246, 241, 254, 253, 135, 93, 46, 231, 101, 224, 22, 204, 80, 9, 39, - 227, 40, 203, 50, 110, 183, 155, 176, 176, 48, 102, 205, 154, 133, 223, 239, 199, 237, 118, 51, 123, 246, 108, - 124, 62, 31, 30, 143, 135, 225, 225, 97, 34, 34, 34, 2, 239, 78, 126, 152, 184, 221, 110, 252, 126, 63, 66, 8, - 220, 110, 247, 68, 79, 232, 27, 96, 223, 190, 253, 197, 119, 239, 220, 174, 2, 174, 11, 33, 148, 25, 1, 104, - 154, 198, 154, 53, 107, 56, 126, 252, 56, 35, 35, 35, 228, 230, 230, 146, 152, 152, 72, 97, 97, 33, 0, 155, - 54, 109, 194, 100, 50, 241, 229, 151, 95, 98, 50, 153, 120, 254, 249, 231, 113, 56, 28, 124, 243, 205, 55, 88, - 173, 86, 146, 147, 147, 209, 52, 13, 69, 81, 240, 122, 189, 56, 157, 78, 122, 122, 239, 241, 241, 159, 62, - 173, 104, 184, 121, 237, 28, 112, 85, 8, 49, 58, 233, 111, 10, 0, 73, 104, 98, 204, 115, 159, 172, 172, 44, - 22, 46, 92, 136, 36, 73, 196, 199, 199, 19, 28, 28, 76, 82, 82, 18, 154, 166, 145, 152, 152, 200, 99, 143, 61, - 70, 65, 65, 1, 163, 163, 163, 44, 94, 188, 24, 77, 211, 120, 238, 185, 231, 200, 204, 204, 164, 187, 187, 27, - 167, 219, 131, 199, 227, 193, 229, 114, 81, 223, 216, 172, 126, 180, 239, 192, 137, 166, 127, 214, 93, 0, 170, - 133, 16, 142, 31, 251, 156, 2, 64, 136, 160, 191, 55, 217, 58, 68, 210, 124, 179, 20, 31, 31, 63, 1, 234, 65, - 67, 137, 137, 137, 33, 40, 40, 8, 89, 150, 17, 66, 16, 21, 21, 69, 92, 92, 28, 178, 44, 163, 215, 235, 89, - 181, 106, 21, 146, 36, 113, 229, 202, 21, 122, 7, 38, 212, 126, 161, 234, 31, 99, 31, 239, 251, 227, 231, 247, - 122, 123, 190, 7, 106, 133, 16, 206, 135, 25, 159, 246, 107, 182, 237, 183, 239, 156, 95, 185, 252, 169, 95, - 62, 181, 104, 1, 179, 66, 67, 144, 36, 41, 240, 21, 35, 203, 114, 224, 120, 120, 62, 9, 246, 194, 119, 85, - 154, 226, 23, 52, 53, 183, 180, 125, 125, 252, 104, 225, 232, 168, 251, 202, 131, 152, 123, 30, 118, 62, 35, - 128, 237, 219, 63, 48, 12, 221, 239, 202, 55, 24, 12, 219, 141, 70, 99, 164, 52, 67, 181, 124, 212, 240, 249, - 125, 227, 157, 29, 237, 214, 27, 181, 151, 191, 27, 25, 30, 106, 5, 58, 152, 72, 55, 223, 163, 222, 153, 6, - 224, 193, 78, 116, 128, 9, 136, 3, 30, 255, 111, 1, 60, 24, 42, 208, 11, 12, 76, 42, 253, 63, 141, 127, 1, - 173, 193, 47, 22, 232, 14, 87, 117, 0, 0, 0, 0, 73, 69, 78, 68, 174, 66, 96, 130, - ], - }, - - unknown: { - type: "Buffer", - data: [ - 84, 104, 105, 115, 32, 105, 115, 32, 97, 110, 32, 58, 32, 117, 110, 107, 110, 111, 119, 110, 32, 58, 32, 102, - 105, 108, 101, 32, 116, 121, 112, 101, - ], - }, - - empty: { type: "Buffer", data: [] }, - }, - }, -}; diff --git a/test/specs/parsers/files/README.md b/test/specs/parsers/files/README.md deleted file mode 100644 index 0776df99..00000000 --- a/test/specs/parsers/files/README.md +++ /dev/null @@ -1,2 +0,0 @@ -Hello -World: diff --git a/test/specs/parsers/files/binary.png b/test/specs/parsers/files/binary.png deleted file mode 100644 index 737995ae..00000000 Binary files a/test/specs/parsers/files/binary.png and /dev/null differ diff --git a/test/specs/parsers/files/empty b/test/specs/parsers/files/empty deleted file mode 100644 index e69de29b..00000000 diff --git a/test/specs/parsers/files/page.html b/test/specs/parsers/files/page.html deleted file mode 100644 index 46c8cd49..00000000 --- a/test/specs/parsers/files/page.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - -

Hello World:

- - diff --git a/test/specs/parsers/files/style.css b/test/specs/parsers/files/style.css deleted file mode 100644 index 4807606d..00000000 --- a/test/specs/parsers/files/style.css +++ /dev/null @@ -1,6 +0,0 @@ -html { - color: #888; - font-family: sans-serif; - height: 100%; - width: 100%; -} diff --git a/test/specs/parsers/files/unknown.foo b/test/specs/parsers/files/unknown.foo deleted file mode 100644 index 13134194..00000000 --- a/test/specs/parsers/files/unknown.foo +++ /dev/null @@ -1 +0,0 @@ -This is an : unknown : file type \ No newline at end of file diff --git a/test/specs/parsers/parsed.ts b/test/specs/parsers/parsed.ts deleted file mode 100644 index 4c211f89..00000000 --- a/test/specs/parsers/parsed.ts +++ /dev/null @@ -1,24 +0,0 @@ -export default { - schema: { - definitions: { - markdown: { - $ref: "files/README.md", - }, - html: { - $ref: "files/page.html", - }, - css: { - $ref: "files/style.css", - }, - binary: { - $ref: "files/binary.png", - }, - unknown: { - $ref: "files/unknown.foo", - }, - empty: { - $ref: "files/empty", - }, - }, - }, -}; diff --git a/test/specs/parsers/parsers.spec.ts b/test/specs/parsers/parsers.spec.ts deleted file mode 100644 index 4853f8a0..00000000 --- a/test/specs/parsers/parsers.spec.ts +++ /dev/null @@ -1,278 +0,0 @@ -import { describe, it } from "vitest"; -import { expect } from "vitest"; -import $RefParser from "../../../lib/index.js"; -import helper from "../../utils/helper.js"; -import path from "../../utils/path.js"; -import parsedSchema from "./parsed.js"; -import dereferencedSchema from "./dereferenced.js"; -import { JSONParserErrorGroup, ParserError, UnmatchedParserError } from "../../../lib/util/errors.js"; -import type { Options } from "../../../lib/options"; -import type { ParserOptions } from "../../../lib/options"; - -describe("References to non-JSON files", () => { - const baseUrl = path.rel("test/specs/parsers/parsers.yaml"); - it("should parse successfully", async () => { - const schema = await $RefParser.parse(baseUrl); - expect(schema).to.deep.equal(parsedSchema.schema); - }); - - it( - "should resolve successfully", - helper.testResolve( - baseUrl, - path.abs("test/specs/parsers/parsers.yaml"), - parsedSchema.schema, - path.abs("test/specs/parsers/files/README.md"), - dereferencedSchema.defaultParsers.definitions.markdown, - path.abs("test/specs/parsers/files/page.html"), - dereferencedSchema.defaultParsers.definitions.html, - path.abs("test/specs/parsers/files/style.css"), - dereferencedSchema.defaultParsers.definitions.css, - path.abs("test/specs/parsers/files/binary.png"), - dereferencedSchema.defaultParsers.definitions.binary, - path.abs("test/specs/parsers/files/unknown.foo"), - dereferencedSchema.defaultParsers.definitions.unknown, - path.abs("test/specs/parsers/files/empty"), - dereferencedSchema.defaultParsers.definitions.empty, - ), - ); - - it("should dereference successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.dereference(baseUrl); - expect(schema).to.equal(parser.schema); - // @ts-expect-error TS(2532): Object is possibly 'undefined'. - schema.definitions.binary = helper.convertNodeBuffersToPOJOs(schema.definitions.binary); - expect(schema).to.deep.equal(dereferencedSchema.defaultParsers); - // The "circular" flag should NOT be set - expect(parser.$refs.circular).to.equal(false); - }); - - it("should bundle successfully", async () => { - const schema = await $RefParser.bundle(baseUrl); - schema.definitions!.binary = helper.convertNodeBuffersToPOJOs(schema.definitions!.binary); - expect(schema).to.deep.equal(dereferencedSchema.defaultParsers); - }); - - it('should parse text as binary if "parse.text" is disabled', async () => { - const opts = { - parse: { - // Disable the text parser - text: false, - // Parse all non-YAML files as binary - binary: { - canParse(file: any) { - return file.url.substr(-5) !== ".yaml"; - }, - }, - }, - } as Options; - const schema = await $RefParser.dereference(baseUrl, opts); - const definitions = schema.definitions!; - definitions.markdown = helper.convertNodeBuffersToPOJOs(definitions.markdown); - definitions.html = helper.convertNodeBuffersToPOJOs(definitions.html); - definitions.css = helper.convertNodeBuffersToPOJOs(definitions.css); - definitions.binary = helper.convertNodeBuffersToPOJOs(definitions.binary); - definitions.unknown = helper.convertNodeBuffersToPOJOs(definitions.unknown); - definitions.empty = helper.convertNodeBuffersToPOJOs(definitions.empty); - expect(schema).to.deep.equal(dereferencedSchema.binaryParser); - }); - - it("should throw an error if no parser can be matched", async () => { - try { - await $RefParser.dereference(baseUrl, { - parse: { - yaml: false, - json: false, - text: false, - binary: false, - }, - }); - helper.shouldNotGetCalled(); - } catch (err) { - expect(err).to.be.an.instanceOf(SyntaxError); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain("Unable to parse "); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain("parsers/parsers.yaml"); - } - }); - - it("should throw an error if no parser returned a result", async () => { - try { - await $RefParser.dereference(baseUrl, { - parse: { - yaml: { - canParse: true, - parse() { - return; - }, - }, - json: false, - text: false, - binary: false, - }, - }); - helper.shouldNotGetCalled(); - } catch (err) { - // would time out otherwise - expect(err).to.be.an.instanceOf(ParserError); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain("No promise has been returned or callback has been called."); - } - }); - - it('should throw an error if "parse.text" and "parse.binary" are disabled', async () => { - try { - await $RefParser.dereference(baseUrl, { - parse: { text: false, binary: false }, - }); - helper.shouldNotGetCalled(); - } catch (err) { - expect(err).to.be.an.instanceOf(ParserError); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain("Error parsing "); - } - }); - - it("should use a custom parser with static values", async () => { - const schema = await $RefParser.dereference(baseUrl, { - parse: { - // A custom parser that always returns the same value - staticParser: { - order: 201, - canParse: true, - parse: "The quick brown fox jumped over the lazy dog", - }, - }, - } as ParserOptions); - expect(schema).to.deep.equal(dereferencedSchema.staticParser); - }); - - it("should use a custom parser that returns a value", async () => { - const schema = await $RefParser.dereference(baseUrl, { - parse: { - // A custom parser that returns the contents of ".foo" files, in reverse - reverseFooParser: { - canParse(file: any) { - return file.url.substr(-4) === ".foo"; - }, - parse(file: any) { - return file.data.toString().split("").reverse().join(""); - }, - }, - }, - }); - schema.definitions.binary = helper.convertNodeBuffersToPOJOs(schema.definitions.binary); - expect(schema).to.deep.equal(dereferencedSchema.customParser); - }); - - it("should use a custom parser that calls a callback", async () => { - const schema = await $RefParser.dereference(baseUrl, { - parse: { - // A custom parser that returns the contents of ".foo" files, in reverse - reverseFooParser: { - canParse: /\.FOO$/i, - parse(file: any, callback: any) { - const reversed = file.data.toString().split("").reverse().join(""); - callback(null, reversed); - }, - }, - }, - }); - schema.definitions.binary = helper.convertNodeBuffersToPOJOs(schema.definitions.binary); - expect(schema).to.deep.equal(dereferencedSchema.customParser); - }); - - it("should use a custom parser that returns a promise", async () => { - const schema = await $RefParser.dereference(baseUrl, { - parse: { - // A custom parser that returns the contents of ".foo" files, in reverse - reverseFooParser: { - canParse: [".foo"], - async parse(file: any) { - const reversed = await new Promise((resolve) => { - resolve(file.data.toString().split("").reverse().join("")); - }); - return reversed; - }, - }, - }, - }); - schema.definitions.binary = helper.convertNodeBuffersToPOJOs(schema.definitions.binary); - expect(schema).to.deep.equal(dereferencedSchema.customParser); - }); - - it("should continue parsing if a custom parser fails", async () => { - const schema = await $RefParser.dereference(baseUrl, { - parse: { - // A custom parser that always fails, - // so the built-in parsers will be used as a fallback - badParser: { - order: 1, - canParse: /\.(md|html|css|png)$/i, - parse(file: any, callback: any) { - callback("BOMB!!!"); - }, - }, - }, - }); - schema.definitions.binary = helper.convertNodeBuffersToPOJOs(schema.definitions.binary); - expect(schema).to.deep.equal(dereferencedSchema.defaultParsers); - }); - - it("should normalize errors thrown by parsers", async () => { - try { - await $RefParser.dereference(baseUrl, { - parse: { - // A custom parser that always fails, - // so the built-in parsers will be used as a fallback - yaml: { - order: 1, - parse() { - throw new Error("Woops"); - }, - }, - }, - }); - helper.shouldNotGetCalled(); - } catch (err) { - expect(err).to.be.instanceof(ParserError); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain("Error parsing"); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain("arsers/parsers.yaml: Woops"); - } - }); - - it("should throw a grouped error if no parser can be matched and continueOnError is true", async () => { - try { - const parser = new $RefParser(); - - await parser.dereference(baseUrl, { - parse: { - yaml: false, - json: false, - text: false, - binary: false, - }, - continueOnError: true, - }); - helper.shouldNotGetCalled(); - } catch (err) { - expect(err).to.be.instanceof(JSONParserErrorGroup); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.errors.length).to.equal(1); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.errors).to.containSubset([ - { - name: UnmatchedParserError.name, - message: (message: any) => message.startsWith("Could not find parser for"), - path: [], - source: (message: any) => - message.endsWith("specs/parsers/parsers.yaml") || message.startsWith("http://localhost"), - }, - ]); - } - }); -}); diff --git a/test/specs/parsers/parsers.yaml b/test/specs/parsers/parsers.yaml deleted file mode 100644 index 2e0de43b..00000000 --- a/test/specs/parsers/parsers.yaml +++ /dev/null @@ -1,13 +0,0 @@ -definitions: - markdown: - $ref: files/README.md - html: - $ref: files/page.html - css: - $ref: files/style.css - binary: - $ref: files/binary.png - unknown: - $ref: files/unknown.foo - empty: - $ref: files/empty diff --git a/test/specs/pointer/null.spec.ts b/test/specs/pointer/null.spec.ts deleted file mode 100644 index d8d912ed..00000000 --- a/test/specs/pointer/null.spec.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { describe, it } from "vitest"; -import Pointer from "../../../lib/pointer"; - -describe("Pointers", () => { - it("should parse successfully", async () => { - Pointer.parse("#/c%d"); - }); -}); diff --git a/test/specs/ref-in-excluded-path/dereferenced.ts b/test/specs/ref-in-excluded-path/dereferenced.ts deleted file mode 100644 index c9bfccab..00000000 --- a/test/specs/ref-in-excluded-path/dereferenced.ts +++ /dev/null @@ -1,108 +0,0 @@ -export default { - components: { - examples: { - "confirmation-failure": { - value: { - $ref: "#/literal-component-example", - }, - }, - "confirmation-success": { - value: { - abc: "def", - }, - }, - "query-example": { - value: "abc", - }, - }, - parameters: { - a: { - example: { - $ref: "#/literal-param-component-example", - }, - }, - b: { - examples: { - example1: { - value: { - $ref: "#/literal-param-component-examples1", - }, - }, - }, - }, - }, - }, - paths: { - "/x/{id}": { - parameters: [ - { - example: 123, - in: "path", - name: "id", - }, - { - examples: { - e1: { - value: { - $ref: "#/literal-h1", - }, - }, - }, - in: "header", - name: "h1", - }, - { - example: { - $ref: "#/literal-q1", - }, - in: "query", - name: "q1", - }, - { - examples: { - q2: { - value: "abc", - }, - }, - in: "query", - name: "q2", - }, - ], - responses: { - 200: { - content: { - "application/json": { - examples: { - "confirmation-failure": { - value: { - $ref: "#/literal-component-example", - }, - }, - "confirmation-in-progress": { - summary: "In progress response", - value: { - $ref: "#/abc", - }, - }, - "confirmation-success": { - value: { - abc: "def", - }, - }, - }, - }, - }, - }, - 400: { - content: { - "application/json": { - example: { - $ref: "#/literal-example", - }, - }, - }, - }, - }, - }, - }, -}; diff --git a/test/specs/ref-in-excluded-path/ref-in-excluded-path.spec.ts b/test/specs/ref-in-excluded-path/ref-in-excluded-path.spec.ts deleted file mode 100644 index 2e55bf16..00000000 --- a/test/specs/ref-in-excluded-path/ref-in-excluded-path.spec.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { describe, it } from "vitest"; -import $RefParser from "../../../lib/index.js"; -import path from "../../utils/path.js"; -import dereferencedSchema from "./dereferenced.js"; - -import { expect } from "vitest"; - -describe("Schema with literal $refs in examples", () => { - it("should exclude the given paths from dereferencing", async () => { - const parser = new $RefParser(); - - const schema = await parser.dereference(path.rel("test/specs/ref-in-excluded-path/ref-in-excluded-path.yaml"), { - dereference: { - excludedPathMatcher: (schemaPath: any) => { - return /\/example(\/|$|s\/[^\/]+\/value(\/|$))/.test(schemaPath); - }, - }, - }); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(dereferencedSchema); - }); -}); diff --git a/test/specs/ref-in-excluded-path/ref-in-excluded-path.yaml b/test/specs/ref-in-excluded-path/ref-in-excluded-path.yaml deleted file mode 100644 index 284e44d9..00000000 --- a/test/specs/ref-in-excluded-path/ref-in-excluded-path.yaml +++ /dev/null @@ -1,59 +0,0 @@ -# Minimal parts of an OpenAPI 3.1.0 document, including various examples that should be literal: -paths: - "/x/{id}": - parameters: - - name: id - in: path - example: 123 - - name: h1 - in: header - examples: - e1: - value: # Literal value - $ref: "#/literal-h1" - - name: q1 - in: query - example: - $ref: "#/literal-q1" - - name: q2 - in: query - examples: - q2: - $ref: "#/components/examples/query-example" - responses: - "200": - content: - application/json: - examples: - confirmation-success: # Real ref - $ref: "#/components/examples/confirmation-success" - confirmation-in-progress: - summary: In progress response - value: # Literal ref! The $ref should not be dereferenced - $ref: "#/abc" - confirmation-failure: # Real ref to example with literal $ref - $ref: "#/components/examples/confirmation-failure" - "400": - content: - application/json: - example: - $ref: "#/literal-example" -components: - examples: - query-example: - value: abc - confirmation-success: - value: - abc: def - confirmation-failure: - value: # Literal value! The $ref should not be dereferenced - $ref: "#/literal-component-example" - parameters: - a: - example: - $ref: "#/literal-param-component-example" - b: - examples: - example1: - value: - $ref: "#/literal-param-component-examples1" diff --git a/test/specs/refs.spec.ts b/test/specs/refs.spec.ts deleted file mode 100644 index 25246565..00000000 --- a/test/specs/refs.spec.ts +++ /dev/null @@ -1,320 +0,0 @@ -import { describe, it } from "vitest"; -import $RefParser from "../../lib/index.js"; -import helper from "../utils/helper.js"; -import path from "../utils/path.js"; -import parsedSchema from "./external/parsed.js"; -import dereferencedSchema from "./external/dereferenced.js"; -import bundledSchema from "./external/bundled.js"; - -import { expect } from "vitest"; - -describe("$Refs object", () => { - const isBrowser = typeof window !== "undefined"; - describe("paths", () => { - it("should only contain the main file when calling `parse()`", async () => { - const parser = new $RefParser(); - await parser.parse(path.abs("test/specs/external/external.yaml")); - const paths = parser.$refs.paths(); - expect(paths).to.have.same.members([path.abs("test/specs/external/external.yaml")]); - }); - - it("should contain all files when calling `resolve()`", async () => { - const parser = new $RefParser(); - const $refs = await parser.resolve(path.abs("test/specs/external/external.yaml")); - expect($refs).to.equal(parser.$refs); - const paths = $refs.paths(); - expect(paths).to.have.same.members([ - path.abs("test/specs/external/external.yaml"), - path.abs("test/specs/external/definitions/definitions.json"), - path.abs("test/specs/external/definitions/name.yaml"), - path.abs("test/specs/external/definitions/required-string.yaml"), - ]); - }); - - it("should return only local files", async () => { - const $refs = await $RefParser.resolve(path.abs("test/specs/external/external.yaml")); - const paths = $refs.paths("file"); - if (!isBrowser) { - expect(paths).to.have.same.members([ - path.abs("test/specs/external/external.yaml"), - path.abs("test/specs/external/definitions/definitions.json"), - path.abs("test/specs/external/definitions/name.yaml"), - path.abs("test/specs/external/definitions/required-string.yaml"), - ]); - } else { - expect(paths).to.be.an("array").with.lengthOf(0); - } - }); - - it("should return only URLs", async () => { - const $refs = await $RefParser.resolve(path.abs("test/specs/external/external.yaml")); - const paths = $refs.paths(["http"]); - - if (isBrowser) { - expect(paths).to.have.same.members([ - path.url("test/specs/external/external.yaml"), - path.url("test/specs/external/definitions/definitions.json"), - path.url("test/specs/external/definitions/name.yaml"), - path.url("test/specs/external/definitions/required-string.yaml"), - ]); - } else { - expect(paths).to.be.an("array").with.lengthOf(0); - } - }); - }); - - describe("values", () => { - it("should be the same as `toJSON()`", async () => { - const $refs = await $RefParser.resolve(path.abs("test/specs/external/external.yaml")); - expect($refs.values).to.equal($refs.toJSON); - }); - - it("should return the paths and values of all resolved files", async () => { - const $refs = await $RefParser.resolve(path.abs("test/specs/external/external.yaml")); - const expected = {}; - // @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message - expected[path.abs("test/specs/external/external.yaml")] = parsedSchema.schema; - // @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message - expected[path.abs("test/specs/external/definitions/definitions.json")] = parsedSchema.definitions; - // @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message - expected[path.abs("test/specs/external/definitions/name.yaml")] = parsedSchema.name; - // @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message - expected[path.abs("test/specs/external/definitions/required-string.yaml")] = parsedSchema.requiredString; - const values = $refs.values(); - expect(values).to.deep.equal(expected); - }); - - it("should return the paths and values of all dereferenced files", async () => { - const parser = new $RefParser(); - await parser.dereference(path.abs("test/specs/external/external.yaml")); - const expected = {}; - // @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message - expected[path.abs("test/specs/external/external.yaml")] = dereferencedSchema; - // @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message - expected[path.abs("test/specs/external/definitions/definitions.json")] = dereferencedSchema.definitions; - // @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message - expected[path.abs("test/specs/external/definitions/name.yaml")] = dereferencedSchema.definitions.name; - // @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message - expected[path.abs("test/specs/external/definitions/required-string.yaml")] = - dereferencedSchema.definitions["required string"]; - const values = parser.$refs.values(); - expect(values).to.deep.equal(expected); - }); - - it("should return the paths and values of all bundled files", async () => { - const parser = new $RefParser(); - await parser.bundle(path.abs("test/specs/external/external.yaml")); - const expected = {}; - // @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message - expected[path.abs("test/specs/external/external.yaml")] = bundledSchema; - // @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message - expected[path.abs("test/specs/external/definitions/definitions.json")] = bundledSchema.definitions; - // @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message - expected[path.abs("test/specs/external/definitions/name.yaml")] = bundledSchema.definitions.name; - // @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message - expected[path.abs("test/specs/external/definitions/required-string.yaml")] = - bundledSchema.definitions["required string"]; - const values = parser.$refs.values(); - expect(values).to.deep.equal(expected); - }); - - it("should return only local files and values", async () => { - const $refs = await $RefParser.resolve(path.abs("test/specs/external/external.yaml")); - let values = $refs.values("file"); - if (typeof window === "undefined") { - const expected = {}; - // @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message - expected[path.abs("test/specs/external/external.yaml")] = parsedSchema.schema; - // @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message - expected[path.abs("test/specs/external/definitions/definitions.json")] = parsedSchema.definitions; - // @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message - expected[path.abs("test/specs/external/definitions/name.yaml")] = parsedSchema.name; - // @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message - expected[path.abs("test/specs/external/definitions/required-string.yaml")] = parsedSchema.requiredString; - values = $refs.values(); - expect(values).to.deep.equal(expected); - } else { - expect(values).to.be.an("object").and.empty; // eslint-disable-line no-unused-expressions - } - }); - - it("should return only URLs and values", async () => { - const $refs = await $RefParser.resolve(path.abs("test/specs/external/external.yaml")); - let values = $refs.values(["http"]); - if (isBrowser) { - const expected = {}; - // @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message - expected[path.url("test/specs/external/external.yaml")] = parsedSchema.schema; - // @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message - expected[path.url("test/specs/external/definitions/definitions.json")] = parsedSchema.definitions; - // @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message - expected[path.url("test/specs/external/definitions/name.yaml")] = parsedSchema.name; - // @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message - expected[path.url("test/specs/external/definitions/required-string.yaml")] = parsedSchema.requiredString; - values = $refs.values(); - expect(values).to.deep.equal(expected); - } else { - expect(values).to.be.an("object").and.empty; // eslint-disable-line no-unused-expressions - } - }); - }); - - describe("exists", () => { - it("should work with absolute paths", async () => { - const $refs = await $RefParser.resolve(path.abs("test/specs/external/external.yaml")); - // @ts-expect-error TS(2554): Expected 2 arguments, but got 1. - expect($refs.exists(path.abs("test/specs/external/external.yaml"))).to.equal(true); - // @ts-expect-error TS(2554): Expected 2 arguments, but got 1. - expect($refs.exists(path.abs("test/specs/external/definitions/definitions.json"))).to.equal(true); - // @ts-expect-error TS(2554): Expected 2 arguments, but got 1. - expect($refs.exists(path.abs("test/specs/external/definitions/name.yaml"))).to.equal(true); - // @ts-expect-error TS(2554): Expected 2 arguments, but got 1. - expect($refs.exists(path.abs("test/specs/external/definitions/required-string.yaml"))).to.equal(true); - }); - - it("should work with relative paths", async () => { - const $refs = await $RefParser.resolve(path.abs("test/specs/external/external.yaml")); - // @ts-expect-error TS(2554): Expected 2 arguments, but got 1. - expect($refs.exists("external.yaml")).to.equal(true); - // @ts-expect-error TS(2554): Expected 2 arguments, but got 1. - expect($refs.exists("definitions/definitions.json")).to.equal(true); - // @ts-expect-error TS(2554): Expected 2 arguments, but got 1. - expect($refs.exists("definitions/name.yaml")).to.equal(true); - // @ts-expect-error TS(2554): Expected 2 arguments, but got 1. - expect($refs.exists("definitions/required-string.yaml")).to.equal(true); - }); - - it("should return false if the $ref does not exist", async () => { - const $refs = await $RefParser.resolve(path.abs("test/specs/external/external.yaml")); - // @ts-expect-error TS(2554): Expected 2 arguments, but got 1. - expect($refs.exists("foo bar")).to.equal(false); - }); - }); - - describe("get", () => { - it("should work with absolute paths", async () => { - const $refs = await $RefParser.resolve(path.abs("test/specs/external/external.yaml")); - expect($refs.get(path.abs("test/specs/external/external.yaml"))).to.deep.equal(parsedSchema.schema); - expect($refs.get(path.abs("test/specs/external/definitions/definitions.json"))).to.deep.equal( - parsedSchema.definitions, - ); - expect($refs.get(path.abs("test/specs/external/definitions/name.yaml"))).to.deep.equal(parsedSchema.name); - expect($refs.get(path.abs("test/specs/external/definitions/required-string.yaml"))).to.deep.equal( - parsedSchema.requiredString, - ); - }); - - it("should work with relative paths", async () => { - const $refs = await $RefParser.resolve(path.abs("test/specs/external/external.yaml")); - expect($refs.get("external.yaml")).to.deep.equal(parsedSchema.schema); - expect($refs.get("definitions/definitions.json")).to.deep.equal(parsedSchema.definitions); - expect($refs.get("definitions/name.yaml")).to.deep.equal(parsedSchema.name); - expect($refs.get("definitions/required-string.yaml")).to.deep.equal(parsedSchema.requiredString); - }); - - it("should get the entire file if there is no hash", async () => { - const $refs = await $RefParser.resolve(path.abs("test/specs/external/external.yaml")); - const value = $refs.get("definitions/name.yaml"); - expect(value).to.deep.equal(parsedSchema.name); - }); - - it("should get the entire file if the hash is empty", async () => { - const $refs = await $RefParser.resolve(path.abs("test/specs/external/external.yaml")); - const value = $refs.get("definitions/name.yaml#"); - expect(value).to.deep.equal(parsedSchema.name); - }); - - it('should try to get an empty key if the hash is "#/"', async () => { - const $refs = await $RefParser.resolve(path.abs("test/specs/external/external.yaml")); - - try { - $refs.get("definitions/name.yaml#/"); - helper.shouldNotGetCalled(); - } catch (err) { - expect(err).to.be.an.instanceOf(Error); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.equal('Missing $ref pointer "#/". Token "" does not exist.'); - } - }); - - it("should resolve values across multiple files if necessary", async () => { - const $refs = await $RefParser.resolve(path.abs("test/specs/external/external.yaml")); - expect($refs.get("external.yaml#/properties/name/properties/first")).to.deep.equal({ - title: "required string", - type: "string", - minLength: 1, - }); - expect($refs.get("external.yaml#/properties/name/properties/first/title")).to.equal("required string"); - }); - - it("should throw an error if the file does not exist", async () => { - const $refs = await $RefParser.resolve(path.abs("test/specs/external/external.yaml")); - - try { - $refs.get("foo-bar.yaml#/some/value"); - helper.shouldNotGetCalled(); - } catch (err) { - expect(err).to.be.an.instanceOf(Error); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain('Error resolving $ref pointer "foo-bar.yaml#/some/value".'); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain('foo-bar.yaml" not found.'); - } - }); - - it("should throw an error if the JSON Pointer path does not exist", async () => { - const $refs = await $RefParser.resolve(path.abs("test/specs/external/external.yaml")); - - try { - $refs.get("external.yaml#/foo/bar"); - helper.shouldNotGetCalled(); - } catch (err) { - expect(err).to.be.an.instanceOf(Error); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.equal('Missing $ref pointer "#/foo/bar". Token "foo" does not exist.'); - } - }); - }); - - describe("set", () => { - it("should work with absolute paths", async () => { - const $refs = await $RefParser.resolve(path.abs("test/specs/external/external.yaml")); - const $ref = path.abs("test/specs/external/external.yaml") + "#/properties/name"; - $refs.set($ref, { foo: "bar" }); - expect($refs.get("external.yaml#/properties/name")).to.deep.equal({ foo: "bar" }); - }); - - it("should work with relative paths", async () => { - const $refs = await $RefParser.resolve(path.abs("test/specs/external/external.yaml")); - $refs.set("external.yaml#/properties/name", { foo: "bar" }); - expect($refs.get("external.yaml#/properties/name")).to.deep.equal({ foo: "bar" }); - }); - - it("should resolve values across multiple files if necessary", async () => { - const $refs = await $RefParser.resolve(path.abs("test/specs/external/external.yaml")); - $refs.set("external.yaml#/properties/name/properties/first/title", "foo bar"); - expect($refs.get("external.yaml#/properties/name/properties/first/title")).to.equal("foo bar"); - }); - - it("should throw an error if the file does not exist", async () => { - const $refs = await $RefParser.resolve(path.abs("test/specs/external/external.yaml")); - - try { - $refs.set("foo-bar.yaml#/some/path", "some value"); - helper.shouldNotGetCalled(); - } catch (err) { - expect(err).to.be.an.instanceOf(Error); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain('Error resolving $ref pointer "foo-bar.yaml#/some/path".'); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain('foo-bar.yaml" not found.'); - } - }); - - it("should NOT throw an error if the JSON Pointer path does not exist (it creates the new value instead)", async () => { - const $refs = await $RefParser.resolve(path.abs("test/specs/external/external.yaml")); - $refs.set("external.yaml#/foo/bar/baz", { hello: "world" }); - expect($refs.get("external.yaml#/foo/bar/baz")).to.deep.equal({ hello: "world" }); - }); - }); -}); diff --git a/test/specs/relative-path/root.spec.ts b/test/specs/relative-path/root.spec.ts deleted file mode 100644 index 2088b382..00000000 --- a/test/specs/relative-path/root.spec.ts +++ /dev/null @@ -1,66 +0,0 @@ -import { afterAll, beforeAll, describe, it } from "vitest"; -import $RefParser, { JSONParserError } from "../../../lib/index.js"; -import path from "../../utils/path.js"; - -import { expect, vi } from "vitest"; -import helper from "../../utils/helper"; - -describe.skipIf(process.env.BROWSER)("Schemas with imports in relative and absolute locations work", () => { - describe("Schemas with relative imports that should be resolved from the root", () => { - beforeAll(() => { - vi.spyOn(process, "cwd").mockImplementation(() => { - return __dirname; - }); - }); - afterAll(() => { - vi.restoreAllMocks(); - }); - it("should not parse successfully when set to resolve relative (default)", async () => { - const parser = new $RefParser(); - try { - await parser.dereference(path.rel("schemas/accountList.json")); - helper.shouldNotGetCalled(); - } catch (err) { - expect(err).to.be.an.instanceOf(JSONParserError); - } - }); - - it("should parse successfully when set to resolve relative (default)", async () => { - const parser = new $RefParser(); - const schema = await parser.dereference(path.rel("schemas/accountList.json"), { - dereference: { externalReferenceResolution: "root" }, - }); - expect(schema).to.eql(parser.schema); - }); - }); - - describe("Schemas with relative imports that should be resolved relatively", () => { - beforeAll(() => { - vi.spyOn(process, "cwd").mockImplementation(() => { - return __dirname; - }); - }); - afterAll(() => { - vi.restoreAllMocks(); - }); - it("should parse successfully when set to resolve relative (default)", async () => { - const parser = new $RefParser(); - const schema = await parser.dereference(path.rel("schemas-relative/accountList.json"), { - dereference: { externalReferenceResolution: "relative" }, - }); - expect(schema).to.eql(parser.schema); - }); - - it("should not parse successfully when set to resolve relative (default)", async () => { - const parser = new $RefParser(); - try { - await parser.dereference(path.rel("schemas-relative/accountList.json"), { - dereference: { externalReferenceResolution: "root" }, - }); - helper.shouldNotGetCalled(); - } catch (err) { - expect(err).to.be.an.instanceOf(JSONParserError); - } - }); - }); -}); diff --git a/test/specs/relative-path/schemas-relative/account.json b/test/specs/relative-path/schemas-relative/account.json deleted file mode 100644 index 21ea1bfa..00000000 --- a/test/specs/relative-path/schemas-relative/account.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema", - "title": "Account", - "$id": "account.json", - "type": "object", - "description": "An account.", - "additionalProperties": false, - "required": ["accountOwner", "accountId"], - "properties": { - "accountOwner": { - "$ref": "user.json" - }, - "accountId": { - "$id": "#/properties/accountId", - "type": "string", - "description": "An explanation about the purpose of this instance.", - "default": "", - "examples": ["186383568343"] - } - } -} diff --git a/test/specs/relative-path/schemas-relative/accountList.json b/test/specs/relative-path/schemas-relative/accountList.json deleted file mode 100644 index d158c95d..00000000 --- a/test/specs/relative-path/schemas-relative/accountList.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema", - "title": "AccountList", - "$id": "accountList.json", - "type": "object", - "description": "An account list result.", - "additionalProperties": false, - "required": ["data", "total", "pages"], - "properties": { - "data": { - "type": "array", - "default": [], - "items": { - "$ref": "account.json" - } - }, - "total": { - "type": "integer", - "description": "The number of total items found." - }, - "pages": { - "type": "integer", - "description": "The number of pages found" - } - } -} diff --git a/test/specs/relative-path/schemas-relative/user.json b/test/specs/relative-path/schemas-relative/user.json deleted file mode 100644 index b5ad6c99..00000000 --- a/test/specs/relative-path/schemas-relative/user.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema", - "$id": "user.json", - "type": "object", - "title": "User", - "description": "A User", - "default": {}, - "additionalProperties": false, - "required": ["id", "name", "email"], - "properties": { - "id": { - "$id": "#/user/properties/id", - "type": "string", - "description": "The users id.", - "default": "" - }, - "name": { - "$id": "#/user/properties/name", - "type": "string", - "description": "The users full name with id.", - "default": "" - }, - "email": { - "$id": "#/user/properties/email", - "type": "string", - "description": "The users email address.", - "default": "" - } - } -} diff --git a/test/specs/relative-path/schemas/account.json b/test/specs/relative-path/schemas/account.json deleted file mode 100644 index 141e1b67..00000000 --- a/test/specs/relative-path/schemas/account.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema", - "title": "Account", - "type": "object", - "description": "An account.", - "additionalProperties": false, - "required": ["accountOwner", "accountId"], - "properties": { - "accountOwner": { - "$ref": "schemas/user.json" - }, - "accountId": { - "$id": "#/properties/accountId", - "type": "string", - "description": "An explanation about the purpose of this instance.", - "default": "", - "examples": ["186383568343"] - } - } -} diff --git a/test/specs/relative-path/schemas/accountList.json b/test/specs/relative-path/schemas/accountList.json deleted file mode 100644 index c839610c..00000000 --- a/test/specs/relative-path/schemas/accountList.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema", - "title": "AccountList", - "type": "object", - "description": "An account list result.", - "additionalProperties": false, - "required": ["data", "total", "pages"], - "properties": { - "data": { - "type": "array", - "default": [], - "items": { - "$ref": "schemas/account.json" - } - }, - "total": { - "type": "integer", - "description": "The number of total items found." - }, - "pages": { - "type": "integer", - "description": "The number of pages found" - } - } -} diff --git a/test/specs/relative-path/schemas/user.json b/test/specs/relative-path/schemas/user.json deleted file mode 100644 index 0a5cb6bc..00000000 --- a/test/specs/relative-path/schemas/user.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema", - "type": "object", - "title": "User", - "description": "A User", - "default": {}, - "additionalProperties": false, - "required": ["id", "name", "email"], - "properties": { - "id": { - "$id": "#/user/properties/id", - "type": "string", - "description": "The users id.", - "default": "" - }, - "name": { - "$id": "#/user/properties/name", - "type": "string", - "description": "The users full name with id.", - "default": "" - }, - "email": { - "$id": "#/user/properties/email", - "type": "string", - "description": "The users email address.", - "default": "" - } - } -} diff --git a/test/specs/resolvers/definitions/pet.yaml b/test/specs/resolvers/definitions/pet.yaml deleted file mode 100644 index 2e38294e..00000000 --- a/test/specs/resolvers/definitions/pet.yaml +++ /dev/null @@ -1,14 +0,0 @@ -title: pet -type: object -properties: - name: - type: string - age: - type: number - species: - type: string - enum: - - cat - - dog - - bird - - fish diff --git a/test/specs/resolvers/dereferenced.ts b/test/specs/resolvers/dereferenced.ts deleted file mode 100644 index 1ee6a9c5..00000000 --- a/test/specs/resolvers/dereferenced.ts +++ /dev/null @@ -1,71 +0,0 @@ -export default { - definitions: { - foo: { - bar: { - baz: "hello world", - }, - }, - bar: { - Foo: { - Baz: "hello world", - }, - }, - name: { - required: ["first", "last"], - type: "object", - properties: { - last: { - minLength: 1, - type: "string", - }, - first: { - minLength: 1, - type: "string", - }, - }, - }, - pet: { - type: "object", - properties: { - age: { - type: "number", - }, - name: { - type: "string", - }, - species: { - enum: ["cat", "dog", "bird", "fish"], - type: "string", - }, - }, - title: "pet", - }, - }, - required: ["name"], - type: "object", - properties: { - gender: { - enum: ["male", "female"], - type: "string", - }, - age: { - minimum: 0, - type: "integer", - }, - name: { - required: ["first", "last"], - type: "object", - properties: { - last: { - minLength: 1, - type: "string", - }, - first: { - minLength: 1, - type: "string", - }, - }, - }, - }, - title: "Person", -}; diff --git a/test/specs/resolvers/parsed.ts b/test/specs/resolvers/parsed.ts deleted file mode 100644 index 6411cf0b..00000000 --- a/test/specs/resolvers/parsed.ts +++ /dev/null @@ -1,54 +0,0 @@ -export default { - definitions: { - foo: { - $ref: "foo://bar.baz", - }, - bar: { - $ref: "bar://Foo.Baz", - }, - pet: { - $ref: "definitions/pet.yaml", - }, - name: { - required: ["first", "last"], - type: "object", - properties: { - last: { - minLength: 1, - type: "string", - }, - first: { - minLength: 1, - type: "string", - }, - }, - }, - }, - required: ["name"], - type: "object", - properties: { - gender: { - enum: ["male", "female"], - type: "string", - }, - age: { - minimum: 0, - type: "integer", - }, - name: { - required: ["first", "last"], - type: "object", - properties: { - last: { - minLength: 1, - type: "string", - }, - first: { - minLength: 1, - type: "string", - }, - }, - }, - }, - title: "Person", -}; diff --git a/test/specs/resolvers/resolvers.spec.ts b/test/specs/resolvers/resolvers.spec.ts deleted file mode 100644 index 0be44ecd..00000000 --- a/test/specs/resolvers/resolvers.spec.ts +++ /dev/null @@ -1,255 +0,0 @@ -import { describe, it } from "vitest"; -import { expect } from "vitest"; -import type { FileInfo } from "../../../lib/index.js"; -import $RefParser from "../../../lib/index.js"; -import helper from "../../utils/helper.js"; -import path from "../../utils/path.js"; -import parsedSchema from "./parsed.js"; -import dereferencedSchema from "./dereferenced.js"; -import { ResolverError, UnmatchedResolverError, JSONParserErrorGroup } from "../../../lib/util/errors.js"; -import type { ParserOptions } from "../../../lib/options"; - -describe("options.resolve", () => { - it('should not resolve external links if "resolve.external" is disabled', async () => { - const schema = await $RefParser.dereference(path.abs("test/specs/resolvers/resolvers.yaml"), { - resolve: { external: false }, - }); - expect(schema).to.deep.equal(parsedSchema); - }); - - it("should throw an error for unrecognized protocols", async () => { - try { - await $RefParser.dereference(path.abs("test/specs/resolvers/resolvers.yaml")); - helper.shouldNotGetCalled(); - } catch (err) { - expect(err).to.be.an.instanceOf(SyntaxError); - expect((err as Error).message).to.equal('Unable to resolve $ref pointer "foo://bar.baz"'); - } - }); - - it("should use a custom resolver with static values", async () => { - const schema = await $RefParser.dereference(path.abs("test/specs/resolvers/resolvers.yaml"), { - resolve: { - // A custom resolver for "foo://" URLs - foo: { - canRead: /^foo:\/\//i, - read: { bar: { baz: "hello world" } }, - }, - bar: { - canRead: /^bar:\/\//i, - read: { Foo: { Baz: "hello world" } }, - }, - }, - } as ParserOptions); - - expect(schema).to.deep.equal(dereferencedSchema); - }); - - it("should use a custom resolver that returns a value", async () => { - const schema = await $RefParser.dereference(path.abs("test/specs/resolvers/resolvers.yaml"), { - resolve: { - // A custom resolver for "foo://" URLs - foo: { - canRead: /^foo:\/\//i, - read(_file: any) { - return { bar: { baz: "hello world" } }; - }, - }, - bar: { - canRead: /^bar:\/\//i, - read(_file: any) { - return { Foo: { Baz: "hello world" } }; - }, - }, - }, - }); - expect(schema).to.deep.equal(dereferencedSchema); - }); - - it("should return _file url as it's written", async () => { - const schema = await $RefParser.dereference(path.abs("test/specs/resolvers/resolvers.yaml"), { - resolve: { - // A custom resolver for "foo://" URLs - foo: { - canRead: /^foo:\/\//i, - read(_file: any) { - return { bar: { baz: "hello world" } }; - }, - }, - // A custom resolver with uppercase symbols - bar: { - canRead: /^bar:\/\//i, - read(_file: any) { - expect(_file.url).to.be.equal("bar://Foo.Baz"); - - return { Foo: { Baz: "hello world" } }; - }, - }, - }, - }); - - expect(schema).to.deep.equal(dereferencedSchema); - }); - - it("should use a custom resolver that calls a callback", async () => { - const schema = await $RefParser.dereference(path.abs("test/specs/resolvers/resolvers.yaml"), { - resolve: { - // A custom resolver for "foo://" URLs - foo: { - canRead: /^foo:\/\//i, - read(_file: any, callback: any) { - callback(null, { bar: { baz: "hello world" } }); - }, - }, - bar: { - canRead: /^bar:\/\//i, - read(_file: any, callback: any) { - callback(null, { Foo: { Baz: "hello world" } }); - }, - }, - }, - }); - expect(schema).to.deep.equal(dereferencedSchema); - }); - - if (typeof Promise === "function") { - it("should use a custom resolver that returns a promise", async () => { - const schema = await $RefParser.dereference(path.abs("test/specs/resolvers/resolvers.yaml"), { - resolve: { - // A custom resolver for "foo://" URLs - foo: { - canRead: /^foo:\/\//i, - read(_file: any) { - return Promise.resolve({ bar: { baz: "hello world" } }); - }, - }, - bar: { - canRead: /^bar:\/\//i, - read(_file: any) { - return Promise.resolve({ Foo: { Baz: "hello world" } }); - }, - }, - }, - }); - expect(schema).to.deep.equal(dereferencedSchema); - }); - } - - it("should continue resolving if a custom resolver fails", async () => { - const schema = await $RefParser.dereference(path.abs("test/specs/resolvers/resolvers.yaml"), { - resolve: { - // A custom resolver that always fails - badResolver: { - order: 1, - canRead: true, - read(_file: any) { - throw new Error("BOMB!!!"); - }, - }, - // A custom resolver for "foo://" URLs - foo: { - canRead: /^foo:\/\//i, - read: { bar: { baz: "hello world" } }, - }, - bar: { - canRead: /^bar:\/\//i, - read: { Foo: { Baz: "hello world" } }, - }, - }, - }); - expect(schema).to.deep.equal(dereferencedSchema); - }); - - it("should normalize errors thrown by resolvers", async () => { - try { - await $RefParser.dereference({ $ref: path.abs("test/specs/resolvers/resolvers.yaml") }, { - resolve: { - // A custom resolver that always fails - file: { - order: 1, - canRead: true, - parse() { - throw new Error("Woops"); - }, - }, - }, - } as ParserOptions); - helper.shouldNotGetCalled(); - } catch (err) { - expect(err).to.be.instanceof(ResolverError); - expect((err as ResolverError).message).to.contain("Error opening file"); - } - }); - - it("should throw an error if no resolver returned a result", async () => { - try { - await $RefParser.dereference(path.rel("test/specs/resolvers/resolvers.yaml"), { - resolve: { - http: false, - file: { - order: 1, - canRead: true, - read() { - return; - }, - }, - }, - }); - helper.shouldNotGetCalled(); - } catch (err) { - // would time out otherwise - expect(err).to.be.an.instanceOf(ResolverError); - } - }); - - it("should throw a grouped error if no resolver can be matched and continueOnError is true", async () => { - const parser = new $RefParser(); - try { - await parser.dereference(path.abs("test/specs/resolvers/resolvers.yaml"), { - resolve: { - file: false, - http: false, - }, - continueOnError: true, - }); - helper.shouldNotGetCalled(); - } catch (err) { - expect(err).to.be.instanceof(JSONParserErrorGroup); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.errors.length).to.equal(1); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.errors).to.containSubset([ - { - name: UnmatchedResolverError.name, - message: (message: any) => message.startsWith("Could not find resolver for"), - path: [], - source: (message: any) => message.endsWith("specs/resolvers/resolvers.yaml"), - }, - ]); - } - }); - - it("should preserver capitalization", async () => { - const parser = new $RefParser(); - let parsed: string | undefined; - await parser.dereference( - { - $ref: "custom://Path/Is/Case/Sensitive", - }, - { - resolve: { - custom: { - order: 1, - canRead: /^custom:\/\//i, - read(file: FileInfo, callback?: (error: Error | null, data: string | null) => any) { - console.log(file.url); - parsed = file.url; - callback?.(null, "custom://Path/Is/Case/Sensitive"); - }, - }, - }, - } as ParserOptions, - ); - expect(parsed).to.equal("custom://Path/Is/Case/Sensitive"); - }); -}); diff --git a/test/specs/resolvers/resolvers.yaml b/test/specs/resolvers/resolvers.yaml deleted file mode 100644 index b23ff202..00000000 --- a/test/specs/resolvers/resolvers.yaml +++ /dev/null @@ -1,33 +0,0 @@ -title: Person -type: object -required: - - name -properties: - name: - $ref: "#/definitions/name" - age: - type: integer - minimum: 0 - gender: - type: string - enum: - - male - - female -definitions: - name: - type: object - required: - - first - - last - properties: - first: - type: string - minLength: 1 - last: - $ref: "#/definitions/name/properties/first" - foo: - $ref: foo://bar.baz - bar: - $ref: bar://Foo.Baz - pet: - $ref: definitions/pet.yaml diff --git a/test/specs/root/bundled.ts b/test/specs/root/bundled.ts deleted file mode 100644 index 8ac5913a..00000000 --- a/test/specs/root/bundled.ts +++ /dev/null @@ -1,13 +0,0 @@ -export default { - title: "Extending a root $ref", - required: ["first", "last"], - type: "object", - properties: { - last: { - type: "string", - }, - first: { - type: "string", - }, - }, -}; diff --git a/test/specs/root/definitions/extended.yaml b/test/specs/root/definitions/extended.yaml deleted file mode 100644 index c6c18a80..00000000 --- a/test/specs/root/definitions/extended.yaml +++ /dev/null @@ -1,2 +0,0 @@ -title: Extending a root $ref -$ref: name.yaml diff --git a/test/specs/root/definitions/name.yaml b/test/specs/root/definitions/name.yaml deleted file mode 100644 index 0dd6cd68..00000000 --- a/test/specs/root/definitions/name.yaml +++ /dev/null @@ -1,10 +0,0 @@ -title: name -type: object -required: - - first - - last -properties: - first: - type: string - last: - $ref: ./name.yaml#/properties/first diff --git a/test/specs/root/definitions/root.json b/test/specs/root/definitions/root.json deleted file mode 100644 index bf35fa70..00000000 --- a/test/specs/root/definitions/root.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "$ref": "../definitions/extended.yaml" -} diff --git a/test/specs/root/dereferenced.ts b/test/specs/root/dereferenced.ts deleted file mode 100644 index 8ac5913a..00000000 --- a/test/specs/root/dereferenced.ts +++ /dev/null @@ -1,13 +0,0 @@ -export default { - title: "Extending a root $ref", - required: ["first", "last"], - type: "object", - properties: { - last: { - type: "string", - }, - first: { - type: "string", - }, - }, -}; diff --git a/test/specs/root/parsed.ts b/test/specs/root/parsed.ts deleted file mode 100644 index be5b0c3c..00000000 --- a/test/specs/root/parsed.ts +++ /dev/null @@ -1,28 +0,0 @@ -export default { - schema: { - $ref: "definitions/root.json", - }, - - root: { - $ref: "../definitions/extended.yaml", - }, - - extended: { - title: "Extending a root $ref", - $ref: "name.yaml", - }, - - name: { - title: "name", - required: ["first", "last"], - type: "object", - properties: { - last: { - $ref: "./name.yaml#/properties/first", - }, - first: { - type: "string", - }, - }, - }, -}; diff --git a/test/specs/root/root.spec.ts b/test/specs/root/root.spec.ts deleted file mode 100644 index 8d6b6bd4..00000000 --- a/test/specs/root/root.spec.ts +++ /dev/null @@ -1,52 +0,0 @@ -import { describe, it } from "vitest"; -import $RefParser from "../../../lib/index.js"; -import helper from "../../utils/helper.js"; -import path from "../../utils/path.js"; -import parsedSchema from "./parsed.js"; -import dereferencedSchema from "./dereferenced.js"; -import bundledSchema from "./bundled.js"; - -import { expect } from "vitest"; - -describe("Schema with a top-level (root) $ref", () => { - it("should parse successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.parse(path.rel("test/specs/root/root.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(parsedSchema.schema); - expect(parser.$refs.paths()).to.deep.equal([path.abs("test/specs/root/root.yaml")]); - }); - - it( - "should resolve successfully", - helper.testResolve( - path.rel("test/specs/root/root.yaml"), - path.abs("test/specs/root/root.yaml"), - parsedSchema.schema, - path.abs("test/specs/root/definitions/root.json"), - parsedSchema.root, - path.abs("test/specs/root/definitions/extended.yaml"), - parsedSchema.extended, - path.abs("test/specs/root/definitions/name.yaml"), - parsedSchema.name, - ), - ); - - it("should dereference successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.dereference(path.rel("test/specs/root/root.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(dereferencedSchema); - // Reference equality - expect(schema.properties!.first).to.deep.equal(schema.properties!.last); - // The "circular" flag should NOT be set - expect(parser.$refs.circular).to.equal(false); - }); - - it("should bundle successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.bundle(path.rel("test/specs/root/root.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(bundledSchema); - }); -}); diff --git a/test/specs/root/root.yaml b/test/specs/root/root.yaml deleted file mode 100644 index 4c4959b2..00000000 --- a/test/specs/root/root.yaml +++ /dev/null @@ -1 +0,0 @@ -$ref: definitions/root.json diff --git a/test/specs/substrings/bundled.ts b/test/specs/substrings/bundled.ts deleted file mode 100644 index 573913fd..00000000 --- a/test/specs/substrings/bundled.ts +++ /dev/null @@ -1,30 +0,0 @@ -export default { - title: "Person", - definitions: { - "name-with-min-length": { - "min-length": 1, - type: "string", - }, - "name-with-min-length-max-length": { - "min-length": 1, - "max-length": 20, - type: "string", - }, - name: { - type: "string", - }, - }, - required: ["name"], - type: "object", - properties: { - middleName: { - $ref: "#/definitions/name-with-min-length", - }, - lastName: { - $ref: "#/definitions/name-with-min-length-max-length", - }, - firstName: { - $ref: "#/definitions/name", - }, - }, -}; diff --git a/test/specs/substrings/definitions/definitions.json b/test/specs/substrings/definitions/definitions.json deleted file mode 100644 index c93c60f9..00000000 --- a/test/specs/substrings/definitions/definitions.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "name": { - "$ref": "strings.yaml#/definitions/string" - }, - "name-with-min-length": { - "$ref": "../definitions/strings.yaml#/definitions/string-with-min-length" - }, - "name-with-min-length-max-length": { - "$ref": "./strings.yaml#/definitions/string-with-min-length-max-length" - } -} diff --git a/test/specs/substrings/definitions/slash-strings.yaml b/test/specs/substrings/definitions/slash-strings.yaml deleted file mode 100644 index e4ca5d1a..00000000 --- a/test/specs/substrings/definitions/slash-strings.yaml +++ /dev/null @@ -1,8 +0,0 @@ -channels: - "smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured": - description: The topic on which measured values may be produced and consumed. - parameters: - streetlightId: - description: The ID of the streetlight. - schema: - type: string diff --git a/test/specs/substrings/definitions/strings.yaml b/test/specs/substrings/definitions/strings.yaml deleted file mode 100644 index c33b6c4f..00000000 --- a/test/specs/substrings/definitions/strings.yaml +++ /dev/null @@ -1,10 +0,0 @@ -definitions: - string: - type: string - string-with-min-length: - type: string - min-length: 1 - string-with-min-length-max-length: - type: string - min-length: 1 - max-length: 20 diff --git a/test/specs/substrings/dereferenced.ts b/test/specs/substrings/dereferenced.ts deleted file mode 100644 index 96d0fe36..00000000 --- a/test/specs/substrings/dereferenced.ts +++ /dev/null @@ -1,33 +0,0 @@ -export default { - title: "Person", - definitions: { - "name-with-min-length": { - "min-length": 1, - type: "string", - }, - "name-with-min-length-max-length": { - "min-length": 1, - "max-length": 20, - type: "string", - }, - name: { - type: "string", - }, - }, - required: ["name"], - type: "object", - properties: { - middleName: { - "min-length": 1, - type: "string", - }, - lastName: { - "min-length": 1, - "max-length": 20, - type: "string", - }, - firstName: { - type: "string", - }, - }, -}; diff --git a/test/specs/substrings/parsed.ts b/test/specs/substrings/parsed.ts deleted file mode 100644 index e2f32767..00000000 --- a/test/specs/substrings/parsed.ts +++ /dev/null @@ -1,50 +0,0 @@ -export default { - schema: { - definitions: { - $ref: "definitions/definitions.json", - }, - required: ["name"], - type: "object", - properties: { - middleName: { - $ref: "#/definitions/name-with-min-length", - }, - lastName: { - $ref: "#/definitions/name-with-min-length-max-length", - }, - firstName: { - $ref: "#/definitions/name", - }, - }, - title: "Person", - }, - - definitions: { - name: { - $ref: "strings.yaml#/definitions/string", - }, - "name-with-min-length": { - $ref: "../definitions/strings.yaml#/definitions/string-with-min-length", - }, - "name-with-min-length-max-length": { - $ref: "./strings.yaml#/definitions/string-with-min-length-max-length", - }, - }, - - strings: { - definitions: { - "string-with-min-length": { - type: "string", - "min-length": 1, - }, - "string-with-min-length-max-length": { - type: "string", - "min-length": 1, - "max-length": 20, - }, - string: { - type: "string", - }, - }, - }, -}; diff --git a/test/specs/substrings/slash.spec.ts b/test/specs/substrings/slash.spec.ts deleted file mode 100644 index 5356e00e..00000000 --- a/test/specs/substrings/slash.spec.ts +++ /dev/null @@ -1,77 +0,0 @@ -import { describe, it } from "vitest"; -import $RefParser from "../../../lib/index.js"; -import path from "../../utils/path.js"; - -import { expect } from "vitest"; - -describe("$refs that include slashes", () => { - it("should parse successfully", async () => { - const parser = new $RefParser(); - await parser.parse(path.rel("test/specs/substrings/definitions/slash-strings.yaml")); - const $refs = parser.$refs; - const ref = $refs.get( - "#/channels/smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured/parameters", - ); - expect(ref).to.deep.equal({ - streetlightId: { - description: "The ID of the streetlight.", - schema: { - type: "string", - }, - }, - }); - }); - - it("should parse trailing spaces successfully", async () => { - const parser = new $RefParser(); - const derefed = await parser.dereference({ - swagger: "2.0", - paths: { - somepath: { - post: { - $ref: "#/definitions/ABC ", - }, - }, - }, - definitions: { - "ABC ": { - // tested removing space at the end of "ABC " - type: "object", - properties: { - abc: { - type: "string", - }, - }, - title: "ABC ", - }, - }, - }); - expect(derefed).to.deep.equal({ - swagger: "2.0", - paths: { - somepath: { - post: { - type: "object", - properties: { - abc: { - type: "string", - }, - }, - title: "ABC ", - }, - }, - }, - definitions: { - "ABC ": { - type: "object", - properties: { - abc: { - type: "string", - }, - }, - title: "ABC ", - }, - }, - }); - }); -}); diff --git a/test/specs/substrings/substrings.spec.ts b/test/specs/substrings/substrings.spec.ts deleted file mode 100644 index c8a958fa..00000000 --- a/test/specs/substrings/substrings.spec.ts +++ /dev/null @@ -1,54 +0,0 @@ -import { describe, it } from "vitest"; -import $RefParser from "../../../lib/index.js"; -import helper from "../../utils/helper.js"; -import path from "../../utils/path.js"; -import parsedSchema from "./parsed.js"; -import dereferencedSchema from "./dereferenced.js"; -import bundledSchema from "./bundled.js"; - -import { expect } from "vitest"; - -describe("$refs that are substrings of each other", () => { - it("should parse successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.parse(path.rel("test/specs/substrings/substrings.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(parsedSchema.schema); - expect(parser.$refs.paths()).to.deep.equal([path.abs("test/specs/substrings/substrings.yaml")]); - }); - - it( - "should resolve successfully", - helper.testResolve( - path.rel("test/specs/substrings/substrings.yaml"), - path.abs("test/specs/substrings/substrings.yaml"), - parsedSchema.schema, - path.abs("test/specs/substrings/definitions/definitions.json"), - parsedSchema.definitions, - path.abs("test/specs/substrings/definitions/strings.yaml"), - parsedSchema.strings, - ), - ); - - it("should dereference successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.dereference(path.rel("test/specs/substrings/substrings.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(dereferencedSchema); - // Reference equality - const properties = schema.properties!; - const definitions = schema.definitions!; - expect(properties.firstName).to.equal(definitions.name); - expect(properties.middleName).to.equal(definitions["name-with-min-length"]); - expect(properties.lastName).to.equal(definitions["name-with-min-length-max-length"]); - // The "circular" flag should NOT be set - expect(parser.$refs.circular).to.equal(false); - }); - - it("should bundle successfully", async () => { - const parser = new $RefParser(); - const schema = await parser.bundle(path.rel("test/specs/substrings/substrings.yaml")); - expect(schema).to.equal(parser.schema); - expect(schema).to.deep.equal(bundledSchema); - }); -}); diff --git a/test/specs/substrings/substrings.yaml b/test/specs/substrings/substrings.yaml deleted file mode 100644 index d9087901..00000000 --- a/test/specs/substrings/substrings.yaml +++ /dev/null @@ -1,13 +0,0 @@ -title: Person -type: object -required: - - name -properties: - firstName: - $ref: "#/definitions/name" - middleName: - $ref: "#/definitions/name-with-min-length" - lastName: - $ref: "#/definitions/name-with-min-length-max-length" -definitions: - $ref: definitions/definitions.json diff --git a/test/specs/timeout/definitions/name.yaml b/test/specs/timeout/definitions/name.yaml deleted file mode 100644 index 02eeba43..00000000 --- a/test/specs/timeout/definitions/name.yaml +++ /dev/null @@ -1,22 +0,0 @@ -title: name -type: object -required: - - first - - last -properties: - first: - $ref: ../definitions/required-string.yaml - last: - $ref: ./required-string.yaml - middle: - type: - $ref: "#/properties/first/type" - minLength: - $ref: "#/properties/first/minLength" - prefix: - $ref: "#/properties/last" - minLength: 3 - suffix: - type: string - $ref: "#/properties/prefix" - maxLength: 3 diff --git a/test/specs/timeout/definitions/required-string.yaml b/test/specs/timeout/definitions/required-string.yaml deleted file mode 100644 index 3970e6ba..00000000 --- a/test/specs/timeout/definitions/required-string.yaml +++ /dev/null @@ -1,3 +0,0 @@ -title: requiredString -type: string -minLength: 1 diff --git a/test/specs/timeout/timeout.spec.ts b/test/specs/timeout/timeout.spec.ts deleted file mode 100644 index 538c96bf..00000000 --- a/test/specs/timeout/timeout.spec.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { describe, it } from "vitest"; -import { expect } from "vitest"; -import $RefParser from "../../../lib/index.js"; -import path from "../../utils/path"; -import helper from "../../utils/helper"; -import { TimeoutError } from "../../../lib/util/errors"; - -describe("Timeouts", () => { - it("should throw error when timeout is reached", async () => { - try { - const parser = new $RefParser(); - await parser.dereference(path.rel("test/specs/timeout/timeout.yaml"), { - timeoutMs: 0.01, - }); - helper.shouldNotGetCalled(); - } catch (err) { - expect(err).to.be.an.instanceOf(TimeoutError); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain("Dereferencing timeout reached"); - } - }); -}); diff --git a/test/specs/timeout/timeout.yaml b/test/specs/timeout/timeout.yaml deleted file mode 100644 index ce4c3406..00000000 --- a/test/specs/timeout/timeout.yaml +++ /dev/null @@ -1,213 +0,0 @@ -title: Deep Schema -type: object -properties: - name: - $ref: "#/definitions/name" - level1: - type: object - required: - - name - properties: - name: - $ref: definitions/name.yaml - level2: - type: object - required: - - name - properties: - name: - $ref: definitions/name.yaml - level3: - type: object - required: - - name - properties: - name: - $ref: "#/definitions/name" - level4: - type: object - required: - - name - properties: - name: - $ref: definitions/name.yaml - level5: - type: object - required: - - name - properties: - name: - $ref: definitions/name.yaml - level6: - type: object - required: - - name - properties: - name: - $ref: "#/definitions/name" - level7: - type: object - required: - - name - properties: - name: - $ref: definitions/name.yaml - level8: - type: object - required: - - name - properties: - name: - $ref: definitions/name.yaml - level9: - type: object - required: - - name - properties: - name: - $ref: definitions/name.yaml - level10: - type: object - required: - - name - properties: - name: - $ref: definitions/name.yaml - level11: - type: object - required: - - name - properties: - name: - $ref: definitions/name.yaml - level12: - type: object - required: - - name - properties: - name: - $ref: "#/definitions/name" - level13: - type: object - required: - - name - properties: - name: - $ref: "#/definitions/name" - level14: - type: object - required: - - name - properties: - name: - $ref: definitions/name.yaml - level15: - type: object - required: - - name - properties: - name: - $ref: definitions/name.yaml - level16: - type: object - required: - - name - properties: - name: - $ref: definitions/name.yaml - level17: - type: object - required: - - name - properties: - name: - $ref: definitions/name.yaml - level18: - type: object - required: - - name - properties: - name: - $ref: definitions/name.yaml - level19: - type: object - required: - - name - properties: - name: - $ref: definitions/name.yaml - level20: - type: object - required: - - name - properties: - name: - $ref: definitions/name.yaml - level21: - type: object - required: - - name - properties: - name: - $ref: definitions/name.yaml - level22: - type: object - required: - - name - properties: - name: - $ref: definitions/name.yaml - level23: - type: object - required: - - name - properties: - name: - $ref: definitions/name.yaml - level24: - type: object - required: - - name - properties: - name: - $ref: definitions/name.yaml - level25: - type: object - required: - - name - properties: - name: - $ref: definitions/name.yaml - level26: - type: object - required: - - name - properties: - name: - $ref: "#/definitions/name" - level27: - type: object - required: - - name - properties: - name: - $ref: definitions/name.yaml - level28: - type: object - required: - - name - properties: - name: - $ref: definitions/name.yaml - level29: - type: object - required: - - name - properties: - name: - $ref: definitions/name.yaml - level30: - $ref: "#" -definitions: - name: - $ref: definitions/name.yaml diff --git a/test/specs/util/url.spec.ts b/test/specs/util/url.spec.ts deleted file mode 100644 index 94d177a2..00000000 --- a/test/specs/util/url.spec.ts +++ /dev/null @@ -1,72 +0,0 @@ -import { afterAll, beforeAll, describe, expect, it, vi } from "vitest"; -import * as $url from "../../../lib/util/url.js"; -import * as isWin from "../../../lib/util/is-windows"; -import convertPathToPosix from "../../../lib/util/convert-path-to-posix"; -import { cwd } from "../../../lib/util/url.js"; -describe("Return the extension of a URL", () => { - it("should return an empty string if there isn't any extension", async () => { - const extension = $url.getExtension("/file"); - expect(extension).to.equal(""); - }); - - it("should return the extension in lowercase", async () => { - const extension = $url.getExtension("/file.YML"); - expect(extension).to.equal(".yml"); - }); - - it("should return the extension without the query", async () => { - const extension = $url.getExtension("/file.yml?foo=bar"); - expect(extension).to.equal(".yml"); - }); -}); - -if (!process.env.BROWSER) { - describe("Handle Windows file paths", () => { - beforeAll(function (this: any) { - vi.spyOn(isWin, "isWindows").mockReturnValue(true); - }); - - afterAll(function (this: any) { - vi.restoreAllMocks(); - }); - - it("should handle absolute paths", async () => { - const result = $url.fromFileSystemPath("Y:\\A\\Random\\Path\\file.json"); - expect(result) - .to.be.a("string") - .and.toSatisfy((msg: string) => msg.startsWith("Y:/A/Random/Path")); - }); - - it("should handle relative paths", async () => { - const result = $url.fromFileSystemPath("Path\\file.json"); - const pwd = convertPathToPosix(cwd()); - expect(result).to.be.a("string"); - expect(result).toSatisfy((msg: string) => msg.startsWith(pwd)); - }); - }); -} - -describe("Handle Linux file paths", () => { - beforeAll(function (this: any) { - //Force isWindows to always be false for this section of the test - vi.spyOn(isWin, "isWindows").mockReturnValue(false); - }); - - afterAll(function (this: any) { - vi.restoreAllMocks(); - }); - - it("should handle absolute paths", async () => { - const result = $url.fromFileSystemPath("/a/random/Path/file.json"); - expect(result) - .to.be.a("string") - .and.toSatisfy((msg: string) => msg.startsWith("/a/random/Path/file.json")); - }); - - it("should handle relative paths", async () => { - const result = $url.fromFileSystemPath("Path/file.json"); - expect(result) - .to.be.a("string") - .and.toSatisfy((msg: string) => msg.startsWith("Path/file.json")); - }); -}); diff --git a/test/specs/working-directory/api/example.yaml b/test/specs/working-directory/api/example.yaml deleted file mode 100644 index f4ba03d1..00000000 --- a/test/specs/working-directory/api/example.yaml +++ /dev/null @@ -1,273 +0,0 @@ ---- -openapi: 3.1.0 -info: - title: Test Example Example - description: Test Example Example API - version: "1" -servers: - - url: https://api.stage.Test Example.ai - description: Stage API - - url: https://api.Test Example.ai - description: Production API -security: - - BearerAuth: [] -paths: - /api/v2/create/{sensor_id}: - parameters: - - name: sensor_id - required: true - schema: - title: Sensor ID - type: string - format: uuid - example: 123e4567-e89b-12d3-a456-426614174000 - in: path - - $ref: "../common/components/parameters/Correlation.yaml#/CorrelationParameter" - - $ref: "../common/components/parameters/Tenant.yaml#/TenantParameter" - post: - summary: Request example scan - tags: - - v2 - operationId: example_api_v2_scan_create_post - requestBody: - description: Request body for create - required: true - content: - application/json: - schema: - $ref: "#/components/schemas/ScanCreateRequest" - application/octet-stream: - schema: - type: string - format: binary - responses: - 201: - $ref: "../common/components/responses/201.yaml#/CreatedResponse" - 400: - $ref: "../common/components/responses/400.yaml#/BadRequestResponse" - 422: - $ref: "../common/components/responses/422.yaml#/ValidationErrorResponse" - /api/v1/create/{sensor_id}: - parameters: - - name: sensor_id - required: true - schema: - title: Sensor ID - type: string - format: uuid - in: path - example: 123e4567-e89b-12d3-a456-426614174000 - - $ref: "../common/components/parameters/Correlation.yaml#/CorrelationParameter" - - $ref: "../common/components/parameters/Tenant.yaml#/TenantParameter" - post: - tags: - - v1 - summary: Request example scan - operationId: example_api_v1_scan_create_post - requestBody: - description: Request body for create - required: true - content: - application/json: - schema: - $ref: "#/components/schemas/ScanCreateRequest" - application/octet-stream: - schema: - type: string - format: binary - responses: - 201: - $ref: "../common/components/responses/201.yaml#/CreatedResponse" - 400: - $ref: "../common/components/responses/400.yaml#/BadRequestResponse" - 422: - $ref: "../common/components/responses/422.yaml#/ValidationErrorResponse" - /api/v2/status: - post: - tags: - - v2 - summary: Batch request status - operationId: example_api_v2_batch_status - requestBody: - description: Request for multiple sensorIds - required: true - content: - application/json: - schema: - type: array - items: - type: string - responses: - 201: - $ref: "../common/components/responses/201.yaml#/CreatedResponse" - 400: - $ref: "../common/components/responses/400.yaml#/BadRequestResponse" - 422: - $ref: "../common/components/responses/422.yaml#/ValidationErrorResponse" - - /api/v1/status/{sensor_id}: - parameters: - - name: sensor_id - required: true - schema: - title: Sensor ID - type: string - format: uuid - in: path - example: 123e4567-e89b-12d3-a456-426614174000 - - $ref: "../common/components/parameters/Correlation.yaml#/CorrelationParameter" - - $ref: "../common/components/parameters/Tenant.yaml#/TenantParameter" - get: - tags: - - v1 - summary: Get Status or Result of a Scan - operationId: example_api_v1_sensors_sensor_id_get - responses: - 200: - description: Successful response - content: - application/json: - schema: - type: array - items: - $ref: "#/components/schemas/ScanResultsV2" - 400: - $ref: "../common/components/responses/400.yaml#/BadRequestResponse" - 404: - $ref: "../common/components/responses/404.yaml#/NotFoundResponse" - /api/v2/status/{sensor_id}: - parameters: - - name: sensor_id - required: true - schema: - title: Sensor ID - type: string - format: uuid - in: path - example: 123e4567-e89b-12d3-a456-426614174000 - - $ref: "../common/components/parameters/Correlation.yaml#/CorrelationParameter" - - $ref: "../common/components/parameters/Tenant.yaml#/TenantParameter" - get: - tags: - - v2 - summary: Get Status or Result of a Scan - operationId: example_api_v2_sensors_sensor_id_get - responses: - 200: - description: Successful response - content: - application/json: - schema: - oneOf: - - $ref: "#/components/schemas/ScanResultsV2" - 400: - $ref: "../common/components/responses/400.yaml#/BadRequestResponse" - 404: - $ref: "../common/components/responses/404.yaml#/NotFoundResponse" -components: - schemas: - ScanCreateRequest: - title: ScanCreateRequest - required: - - location - type: object - properties: - location: - title: POSIX Path - type: string - ScanResultsV2: - title: Example V2 Response - required: - - scan_id - - status - - start_time - - end_time - - results - - detections - properties: - scan_id: - title: Scan ID - type: string - status: - title: Status - type: string - enum: - - done - - accepted - - failed - - pending - - created - - retry - start_time: - title: Scan Start Time - type: integer - format: int64 - end_time: - title: Scan End Time - type: integer - format: int64 - results: - title: Scan Results - type: object - properties: - md5: - type: string - sha256: - type: string - type: - type: string - subtype: - type: array - items: - type: string - tlsh: - type: string - additionalProperties: true - detections: - type: array - items: - type: string - - ScanResultsV1: - title: Example V1 Response - required: - - scan_id - - status - - start_time - - end_time - - results - - detections - properties: - scan_id: - title: Scan ID - type: string - status: - title: Status - type: string - enum: - - done - - accepted - - failed - - pending - - created - - retry - start_time: - title: Scan Start Time - type: integer - format: int64 - end_time: - title: Scan End Time - type: integer - format: int64 - results: - title: Scan Results - type: array - items: - type: string - detections: - type: array - items: - type: string - securitySchemes: - BearerAuth: - $ref: "../common/components/security-schemes/bearer-token.yaml" diff --git a/test/specs/working-directory/common/components/examples/lorem_ipsum.yaml b/test/specs/working-directory/common/components/examples/lorem_ipsum.yaml deleted file mode 100644 index 8a96a45a..00000000 --- a/test/specs/working-directory/common/components/examples/lorem_ipsum.yaml +++ /dev/null @@ -1 +0,0 @@ -Lorem_Ipsum: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." diff --git a/test/specs/working-directory/common/components/parameters/Correlation.yaml b/test/specs/working-directory/common/components/parameters/Correlation.yaml deleted file mode 100644 index 357f8bac..00000000 --- a/test/specs/working-directory/common/components/parameters/Correlation.yaml +++ /dev/null @@ -1,9 +0,0 @@ -CorrelationParameter: - in: header - name: X-Correlation-Id - required: true - schema: - type: string - format: uuid - description: The unique identifier for the request. - example: 864e00cb-fb53-4016-97f1-78e2f07f25d3 diff --git a/test/specs/working-directory/common/components/parameters/Tenant.yaml b/test/specs/working-directory/common/components/parameters/Tenant.yaml deleted file mode 100644 index 35ebdce5..00000000 --- a/test/specs/working-directory/common/components/parameters/Tenant.yaml +++ /dev/null @@ -1,9 +0,0 @@ -TenantParameter: - in: header - name: X-Tenant-Id - required: true - schema: - type: string - format: uuid - description: The unique identifier for the tenant. - example: 1a618f53-8829-4ab7-b1e4-d4786617e1d0 diff --git a/test/specs/working-directory/common/components/parameters/User.yaml b/test/specs/working-directory/common/components/parameters/User.yaml deleted file mode 100644 index 2509f80f..00000000 --- a/test/specs/working-directory/common/components/parameters/User.yaml +++ /dev/null @@ -1,7 +0,0 @@ -HLUserParameter: - in: header - name: HL-User-Id - required: true - schema: - type: string - description: The unique identifier for the user inside the HL backend. diff --git a/test/specs/working-directory/common/components/responses/200.yaml b/test/specs/working-directory/common/components/responses/200.yaml deleted file mode 100644 index ef63c9b4..00000000 --- a/test/specs/working-directory/common/components/responses/200.yaml +++ /dev/null @@ -1,12 +0,0 @@ -EmptyResponse: - description: Successful Response - content: - application/json: - schema: {} -SuccessfulObjectResponse: - description: Successful Response - content: - application/json: - schema: - title: Any - type: object diff --git a/test/specs/working-directory/common/components/responses/201.yaml b/test/specs/working-directory/common/components/responses/201.yaml deleted file mode 100644 index bc5655c6..00000000 --- a/test/specs/working-directory/common/components/responses/201.yaml +++ /dev/null @@ -1,2 +0,0 @@ -CreatedResponse: - description: The resource was successfully created. diff --git a/test/specs/working-directory/common/components/responses/204.yaml b/test/specs/working-directory/common/components/responses/204.yaml deleted file mode 100644 index c66eee8c..00000000 --- a/test/specs/working-directory/common/components/responses/204.yaml +++ /dev/null @@ -1,2 +0,0 @@ -NoContentResponse: - description: Operation successful; no content returned. diff --git a/test/specs/working-directory/common/components/responses/400.yaml b/test/specs/working-directory/common/components/responses/400.yaml deleted file mode 100644 index c17d1fcf..00000000 --- a/test/specs/working-directory/common/components/responses/400.yaml +++ /dev/null @@ -1,5 +0,0 @@ -BadRequestResponse: - description: | - The request failed due to a client error, with one or more of the following possible causes: - 1. The request required a tenant_id field, which was missing. - 2. The request was malformed syntactically or semantically. diff --git a/test/specs/working-directory/common/components/responses/401.yaml b/test/specs/working-directory/common/components/responses/401.yaml deleted file mode 100644 index 897834c4..00000000 --- a/test/specs/working-directory/common/components/responses/401.yaml +++ /dev/null @@ -1,6 +0,0 @@ -AuthenticationErrorResponse: - description: Authentication Error - content: - application/json: - schema: - $ref: "../schemas/AuthenticationErrorModel.yaml#/AuthenticationErrorModel" diff --git a/test/specs/working-directory/common/components/responses/403.yaml b/test/specs/working-directory/common/components/responses/403.yaml deleted file mode 100644 index 897834c4..00000000 --- a/test/specs/working-directory/common/components/responses/403.yaml +++ /dev/null @@ -1,6 +0,0 @@ -AuthenticationErrorResponse: - description: Authentication Error - content: - application/json: - schema: - $ref: "../schemas/AuthenticationErrorModel.yaml#/AuthenticationErrorModel" diff --git a/test/specs/working-directory/common/components/responses/404.yaml b/test/specs/working-directory/common/components/responses/404.yaml deleted file mode 100644 index 1b190830..00000000 --- a/test/specs/working-directory/common/components/responses/404.yaml +++ /dev/null @@ -1,4 +0,0 @@ -NotFoundResponse: - description: The specified resource was not found. -NotFoundOrNotAuthorizedResponse: - description: The specified resource was not found or you are not authorized to access it. diff --git a/test/specs/working-directory/common/components/responses/409.yaml b/test/specs/working-directory/common/components/responses/409.yaml deleted file mode 100644 index fe7b1202..00000000 --- a/test/specs/working-directory/common/components/responses/409.yaml +++ /dev/null @@ -1,2 +0,0 @@ -ConflictResponse: - description: The specified resource is in an incompatible state diff --git a/test/specs/working-directory/common/components/responses/422.yaml b/test/specs/working-directory/common/components/responses/422.yaml deleted file mode 100644 index b19df654..00000000 --- a/test/specs/working-directory/common/components/responses/422.yaml +++ /dev/null @@ -1,6 +0,0 @@ -ValidationErrorResponse: - description: Validation Error - content: - application/json: - schema: - $ref: "../schemas/ValidationErrorModel.yaml#/ValidationErrorModel" diff --git a/test/specs/working-directory/common/components/schemas/AuthenticationErrorModel.yaml b/test/specs/working-directory/common/components/schemas/AuthenticationErrorModel.yaml deleted file mode 100644 index e4d93003..00000000 --- a/test/specs/working-directory/common/components/schemas/AuthenticationErrorModel.yaml +++ /dev/null @@ -1,10 +0,0 @@ -AuthenticationErrorModel: - title: AuthenticationErrorModel - required: - - detail - type: object - properties: - detail: - title: Detail - type: string - default: "Failed to authenticate" diff --git a/test/specs/working-directory/common/components/schemas/HealthModel.yaml b/test/specs/working-directory/common/components/schemas/HealthModel.yaml deleted file mode 100644 index 47a7df88..00000000 --- a/test/specs/working-directory/common/components/schemas/HealthModel.yaml +++ /dev/null @@ -1,17 +0,0 @@ -HealthModel: - title: HealthResponse - required: - - title - - version - - status - type: object - properties: - title: - title: Title - type: string - version: - title: Version - type: string - status: - title: Status - type: string diff --git a/test/specs/working-directory/common/components/schemas/PagedQuery.yaml b/test/specs/working-directory/common/components/schemas/PagedQuery.yaml deleted file mode 100644 index cf045bc6..00000000 --- a/test/specs/working-directory/common/components/schemas/PagedQuery.yaml +++ /dev/null @@ -1,18 +0,0 @@ -type: object -properties: - order_by: - title: Order By - type: string - order_dir: - title: Order direction - type: string - enum: ["asc", "desc", "ASC", "DESC"] - page_size: - title: Page Size - type: integer - default: 25 - page_number: - title: Page Number - type: integer - default: 0 - minimum: 0 diff --git a/test/specs/working-directory/common/components/schemas/ValidationErrorModel.yaml b/test/specs/working-directory/common/components/schemas/ValidationErrorModel.yaml deleted file mode 100644 index e23819b0..00000000 --- a/test/specs/working-directory/common/components/schemas/ValidationErrorModel.yaml +++ /dev/null @@ -1,21 +0,0 @@ -ValidationErrorModel: - title: ValidationErrorModel - required: - - loc - - msg - - type - type: object - properties: - loc: - title: Location - type: array - items: - anyOf: - - type: string - - type: integer - msg: - title: Message - type: string - type: - title: Error Type - type: string diff --git a/test/specs/working-directory/common/components/security-schemes/bearer-token.yaml b/test/specs/working-directory/common/components/security-schemes/bearer-token.yaml deleted file mode 100644 index df0ca1c2..00000000 --- a/test/specs/working-directory/common/components/security-schemes/bearer-token.yaml +++ /dev/null @@ -1,3 +0,0 @@ -type: http -scheme: bearer -bearerFormat: JWT diff --git a/test/specs/working-directory/common/paths/health.yaml b/test/specs/working-directory/common/paths/health.yaml deleted file mode 100644 index 1e36fae7..00000000 --- a/test/specs/working-directory/common/paths/health.yaml +++ /dev/null @@ -1,20 +0,0 @@ -get: - summary: Health - operationId: health - security: - - {} - responses: - 200: - description: Successful Response - content: - application/json: - schema: - $ref: "../components/schemas/HealthModel.yaml#/HealthModel" - 400: - description: Bad request - content: - application/json: - schema: - $ref: "../components/responses/400.yaml#/BadRequestResponse" - tags: - - Health and Metrics diff --git a/test/specs/working-directory/common/paths/metrics.yaml b/test/specs/working-directory/common/paths/metrics.yaml deleted file mode 100644 index f27ae46d..00000000 --- a/test/specs/working-directory/common/paths/metrics.yaml +++ /dev/null @@ -1,16 +0,0 @@ -get: - summary: Metrics - operationId: metrics - security: - - {} - responses: - 200: - description: Successful Response - content: - text/plain: - schema: - type: string - 400: - $ref: "../components/responses/400.yaml#/BadRequestResponse" - tags: - - Health and Metrics diff --git a/test/specs/working-directory/nested/working-dir.spec.ts b/test/specs/working-directory/nested/working-dir.spec.ts deleted file mode 100644 index e696e785..00000000 --- a/test/specs/working-directory/nested/working-dir.spec.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { describe, expect, it } from "vitest"; -import $RefParser from "../../../../lib"; -import path from "../../../utils/path"; -import yaml from "js-yaml"; -import fsp from "fs/promises"; -import helper from "../../../utils/helper"; -import { JSONParserError } from "../../../../lib/util/errors"; - -describe("Working directory", () => { - it("should parse using the relative directory of the resolved file", async () => { - const parser = new $RefParser(); - const schema = path.rel("test/specs/working-directory/api/example.yaml"); - await parser.dereference(schema); - }); - it("should throw an error when parsing an in memory schema using relative paths", async () => { - const parser = new $RefParser(); - const schema = path.rel("test/specs/working-directory/api/example.yaml"); - const contents = await fsp.readFile(schema, "utf-8"); - const parsed = await yaml.load(contents); - try { - await parser.dereference(parsed); - helper.shouldNotGetCalled(); - } catch (err) { - expect(err).to.be.an.instanceOf(JSONParserError); - // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain("Error"); - } - }); -}); diff --git a/test/tsconfig.json b/test/tsconfig.json deleted file mode 100644 index 7d3a4a76..00000000 --- a/test/tsconfig.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "extends": "../tsconfig.json", - "compilerOptions": { - "module": "ESNext", - "target": "ESNext", - "allowJs": true, - "noEmit": true, - "allowSyntheticDefaultImports": true, - "baseUrl": "..", - "declaration": true, - "esModuleInterop": true, - "inlineSourceMap": false, - "lib": ["esnext", "dom", "DOM"], - "listEmittedFiles": false, - "listFiles": false, - "moduleResolution": "node16", - "noFallthroughCasesInSwitch": true, - "pretty": true, - "resolveJsonModule": true, - "rootDir": "..", - "skipLibCheck": true, - "strict": true - }, - "compileOnSave": false, - "exclude": ["node_modules"], - "include": ["lib/**/*", "test/**/*", "../vite.config.ts"] -} diff --git a/test/utils/helper.ts b/test/utils/helper.ts deleted file mode 100644 index d6c123e4..00000000 --- a/test/utils/helper.ts +++ /dev/null @@ -1,94 +0,0 @@ -import $RefParser from "../../lib/index.js"; - -import { expect } from "vitest"; - -const helper = { - /** - * Throws an error if called. - */ - shouldNotGetCalled() { - throw new Error("This function should not have gotten called."); - }, - - /** - * Tests the {@link $RefParser.resolve} method, - * and asserts that the given file paths resolve to the given values. - * - * @param {string} filePath - The file path that should be resolved - * @param {...*} [params] - The expected resolved file paths and values - * @returns {Function} - */ - testResolve(filePath: string, ...params: (string | undefined | object)[]) { - const parsedSchema = arguments[2]; - const expectedFiles: any = []; - const messages: any = []; - let actualFiles: any; - - for (let i = 1; i < arguments.length; i += 2) { - expectedFiles.push(arguments[i]); - messages.push(arguments[i + 1]); - } - - return async () => { - const parser = new $RefParser(); - const $refs = await parser.resolve(filePath); - - expect(parser.schema).to.deep.equal(parsedSchema); - expect(parser.$refs).to.equal($refs); - - // Resolved file paths - try { - expect((actualFiles = $refs.paths())).to.have.same.members(expectedFiles); - if (typeof window === "undefined") { - expect((actualFiles = $refs.paths(["file"]))).to.have.same.members(expectedFiles); - expect($refs.paths("http")).to.be.an("array").with.lengthOf(0); - } else { - expect((actualFiles = $refs.paths(["http"]))).to.have.same.members(expectedFiles); - expect($refs.paths("file")).to.be.an("array").with.lengthOf(0); - } - } catch (e) { - console.log("Expected Files:", JSON.stringify(expectedFiles, null, 2)); - console.log("Actual Files:", JSON.stringify(actualFiles, null, 2)); - throw e; - } - - // Resolved values - const values = $refs.values(); - expect(values).to.have.keys(expectedFiles); - for (const [i, file] of expectedFiles.entries()) { - // @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message - const actual = helper.convertNodeBuffersToPOJOs(values[file]); - const expected = messages[i]; - expect(actual).to.deep.equal(expected, file); - } - }; - }, - - /** - * Converts Buffer objects to POJOs, so they can be compared using Chai - */ - convertNodeBuffersToPOJOs(value: any) { - if (value && (value._isBuffer || (value.constructor && value.constructor.name === "Buffer"))) { - // Convert Buffers to POJOs for comparison - value = value.toJSON(); - } - return value; - }, - - /** - * Creates a deep clone of the given value. - */ - cloneDeep(value: any) { - let clone = value; - if (value && typeof value === "object") { - clone = value instanceof Array ? [] : {}; - const keys = Object.keys(value); - for (let i = 0; i < keys.length; i++) { - clone[keys[i]] = helper.cloneDeep(value[keys[i]]); - } - } - return clone; - }, -}; - -export default helper; diff --git a/test/utils/path.ts b/test/utils/path.ts deleted file mode 100644 index 4ae5a42f..00000000 --- a/test/utils/path.ts +++ /dev/null @@ -1,165 +0,0 @@ -/// - -import nodePath from "path"; -import { isWindows } from "../../lib/util/is-windows"; -import convertPathToPosix from "../../lib/util/convert-path-to-posix"; - -const isDom = typeof window !== "undefined" && typeof window.document !== "undefined"; - -const pathHelpers = { - filesystem: filesystemPathHelpers(), - url: urlPathHelpers(), -}; - -/** - * Helper functions for getting local filesystem paths in various formats - */ -function filesystemPathHelpers() { - // Run all tests from the "test" directory - const path = { - /** - * Returns the relative path of a file in the "test" directory - */ - rel(file: any) { - const relativePath = nodePath.normalize(nodePath.join(file)); - const filePath = isWindows() ? nodePath.resolve(relativePath) : relativePath; - return convertPathToPosix(filePath); - }, - - /** - * Returns the absolute path of a file in the "test" directory - */ - abs(file: any) { - const absolutePath = nodePath.resolve(nodePath.join(file || nodePath.sep)); - return convertPathToPosix(absolutePath); - }, - - /** - * Returns the path with normalized, UNIX-like, slashes. Disk letter is lower-cased, if present. - */ - unixify(file: string) { - return convertPathToPosix(file).replace(/^[A-Z](?=:\/)/, (letter: any) => letter.toLowerCase()); - }, - - /** - * Returns the path of a file in the "test" directory as a URL. - * (e.g. "file://path/to/json-schema-ref-parser/test/files...") - */ - url(file: string) { - let pathname = path.abs(file); - - if (isWindows()) { - pathname = convertPathToPosix(pathname); - } - - return new URL(`file://${pathname}`).toString(); - }, - - /** - * Returns the absolute path of the current working directory. - */ - cwd() { - return convertPathToPosix(nodePath.join(process.cwd(), nodePath.sep)); - }, - }; - - return path; -} - -/** - * Helper functions for getting URLs in various formats - */ -function urlPathHelpers() { - if (!isDom) { - return; - } - - // Get the URL of the "test" directory - const testsDir = window.location.href; - - /** - * URI-encodes the given file name - */ - function encodePath(file: any) { - return encodeURIComponent(file).split("%2F").join("/"); - } - - const path = { - /** - * Returns the relative path of a file in the "test" directory - * - * NOTE: When running in Karma the absolute path is returned instead - */ - rel(file: any) { - // Encode special characters in paths - file = encodePath(file); - - if (window.location.href.indexOf(testsDir) === 0) { - // We're running from the "/test/index.html" page, directly in a browser. - // So return the relative path from the "test" directory. - return file; - } else { - // We're running in Karma, so return an absolute path, - // since we don't know the relative path of the "test" directory. - return testsDir.replace(/^https?:\/\/[^/]+(\/.*)/, "$1" + file); - } - }, - - /** - * Returns the absolute path of a file in the "test" directory - */ - abs(file: any) { - return testsDir + encodePath(file); - }, - - /** - * Does nothing. Needed to comply with Filesystem path helpers. - */ - unixify(file: any) { - return file; - }, - /** - * Returns the path of a file in the "test" directory as an absolute URL. - * (e.g. "http://localhost/test/files/...") - */ - url(file: any) { - return path.abs(file); - }, - - /** - * Returns the path of the current page. - */ - cwd() { - return location.href; - }, - }; - - return path; -} - -export default { - rel(file: any) { - // @ts-expect-error TS(2556): A spread argument must either have a tuple type or... Remove this comment to see the full error message - return !isDom ? pathHelpers.filesystem.rel(...arguments) : pathHelpers.url.rel(...arguments); - }, - - abs(file: any) { - // @ts-expect-error TS(2556): A spread argument must either have a tuple type or... Remove this comment to see the full error message - return !isDom ? pathHelpers.filesystem.abs(...arguments) : pathHelpers.url.abs(...arguments); - }, - - unixify(file: any) { - // @ts-expect-error TS(2556): A spread argument must either have a tuple type or... Remove this comment to see the full error message - return !isDom ? pathHelpers.filesystem.unixify(...arguments) : pathHelpers.url.unixify(...arguments); - }, - - url(file: any) { - // @ts-expect-error TS(2556): A spread argument must either have a tuple type or... Remove this comment to see the full error message - return !isDom ? pathHelpers.filesystem.url(...arguments) : pathHelpers.url.url(...arguments); - }, - - cwd() { - // @ts-expect-error TS(2556): A spread argument must either have a tuple type or... Remove this comment to see the full error message - return !isDom ? pathHelpers.filesystem.cwd(...arguments) : pathHelpers.url.cwd(...arguments); - }, -}; diff --git a/vite.config.ts b/vite.config.ts index 5461dfdc..f307a079 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -3,15 +3,16 @@ import { defineConfig } from "vitest/config"; const isBrowser = process.env.BROWSER === "true"; export default defineConfig({ test: { - environment: isBrowser ? "jsdom" : "node", + coverage: { reporter: ["lcov", "html", "text"] }, dir: "test", + environment: isBrowser ? "jsdom" : "node", exclude: ["**/__IGNORED__/**"], - watch: false, - globalSetup: isBrowser ? ["./test/fixtures/server.ts"] : undefined, - testTimeout: 5000, globals: true, + globalSetup: isBrowser ? ["./test/fixtures/server.ts"] : undefined, + include: ['./lib/**/*.test.ts'], passWithNoTests: true, reporters: ["verbose"], - coverage: { reporter: ["lcov", "html", "text"] }, + testTimeout: 5000, + watch: false, }, }); diff --git a/vitest.config.unit.ts b/vitest.config.unit.ts new file mode 100644 index 00000000..6e554624 --- /dev/null +++ b/vitest.config.unit.ts @@ -0,0 +1,16 @@ +import { fileURLToPath } from 'node:url'; + +import { configDefaults, defineConfig } from 'vitest/config'; + +export default defineConfig({ + plugins: [], + test: { + coverage: { + exclude: ['bin', 'dist', 'src/**/*.d.ts'], + include: ['src/**/*.ts'], + provider: 'v8', + }, + exclude: [...configDefaults.exclude, 'test/e2e/**/*.test.ts'], + root: fileURLToPath(new URL('./', import.meta.url)), + }, +});