From 259af19815f6c40e7042cdbf719294ff8bedbf95 Mon Sep 17 00:00:00 2001 From: Drew Powers Date: Thu, 6 Jul 2023 20:53:38 -0500 Subject: [PATCH] =?UTF-8?q?Add=20add=E2=80=99l=20parseRef=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/openapi-typescript/test/load.test.ts | 5 +---- packages/openapi-typescript/test/utils.test.ts | 16 +++++++++++----- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/packages/openapi-typescript/test/load.test.ts b/packages/openapi-typescript/test/load.test.ts index 1477500dc..95eec4071 100644 --- a/packages/openapi-typescript/test/load.test.ts +++ b/packages/openapi-typescript/test/load.test.ts @@ -95,10 +95,7 @@ const exampleSchema = { }, }; -async function load( - schema: URL | Subschema | Readable, - options?: Partial -): Promise<{ [url: string]: Subschema }> { +async function load(schema: URL | Subschema | Readable, options?: Partial): Promise<{ [url: string]: Subschema }> { return internalLoad(schema, { rootURL: schema as URL, schemas: {}, diff --git a/packages/openapi-typescript/test/utils.test.ts b/packages/openapi-typescript/test/utils.test.ts index 2b3f92cca..9f054cc4a 100644 --- a/packages/openapi-typescript/test/utils.test.ts +++ b/packages/openapi-typescript/test/utils.test.ts @@ -76,6 +76,12 @@ describe("utils", () => { expect(parseRef("#/test/~1~0")).toStrictEqual({ filename: ".", path: ["test", "/~"] }); }); + it("remote ref", () => { + expect(parseRef("remote.yaml#/Subpath")).toStrictEqual({ filename: "remote.yaml", path: ["Subpath"] }); + expect(parseRef("../schemas/remote.yaml#/Subpath")).toStrictEqual({ filename: "../schemas/remote.yaml", path: ["Subpath"] }); + expect(parseRef("https://myschema.com/api/v1/openapi.yaml#/Subpath")).toStrictEqual({ filename: "https://myschema.com/api/v1/openapi.yaml", path: ["Subpath"] }); + }); + it("js-yaml $ref", () => { expect(parseRef('components["schemas"]["SchemaObject"]')).toStrictEqual({ filename: ".", path: ["components", "schemas", "SchemaObject"] }); }); @@ -83,15 +89,15 @@ describe("utils", () => { describe("escObjKey", () => { it("basic", () => { - expect(escObjKey("some-prop")).toStrictEqual("\"some-prop\""); + expect(escObjKey("some-prop")).toStrictEqual('"some-prop"'); }); it("@ escapes", () => { - expect(escObjKey("@type")).toStrictEqual("\"@type\""); + expect(escObjKey("@type")).toStrictEqual('"@type"'); }); it("number escapes", () => { - expect(escObjKey("123var")).toStrictEqual("\"123var\""); + expect(escObjKey("123var")).toStrictEqual('"123var"'); }); it("only number no escapes", () => { @@ -104,6 +110,6 @@ describe("utils", () => { it("_ no escapes", () => { expect(escObjKey("_ref_")).toStrictEqual("_ref_"); - }) - }) + }); + }); });