Skip to content

Commit 15f28df

Browse files
authored
Add add’l parseRef tests (#1211)
1 parent 6b9054b commit 15f28df

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

packages/openapi-typescript/test/load.test.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,7 @@ const exampleSchema = {
9595
},
9696
};
9797

98-
async function load(
99-
schema: URL | Subschema | Readable,
100-
options?: Partial<LoadOptions>
101-
): Promise<{ [url: string]: Subschema }> {
98+
async function load(schema: URL | Subschema | Readable, options?: Partial<LoadOptions>): Promise<{ [url: string]: Subschema }> {
10299
return internalLoad(schema, {
103100
rootURL: schema as URL,
104101
schemas: {},

packages/openapi-typescript/test/utils.test.ts

+11-5
Original file line numberDiff line numberDiff line change
@@ -76,22 +76,28 @@ describe("utils", () => {
7676
expect(parseRef("#/test/~1~0")).toStrictEqual({ filename: ".", path: ["test", "/~"] });
7777
});
7878

79+
it("remote ref", () => {
80+
expect(parseRef("remote.yaml#/Subpath")).toStrictEqual({ filename: "remote.yaml", path: ["Subpath"] });
81+
expect(parseRef("../schemas/remote.yaml#/Subpath")).toStrictEqual({ filename: "../schemas/remote.yaml", path: ["Subpath"] });
82+
expect(parseRef("https://myschema.com/api/v1/openapi.yaml#/Subpath")).toStrictEqual({ filename: "https://myschema.com/api/v1/openapi.yaml", path: ["Subpath"] });
83+
});
84+
7985
it("js-yaml $ref", () => {
8086
expect(parseRef('components["schemas"]["SchemaObject"]')).toStrictEqual({ filename: ".", path: ["components", "schemas", "SchemaObject"] });
8187
});
8288
});
8389

8490
describe("escObjKey", () => {
8591
it("basic", () => {
86-
expect(escObjKey("some-prop")).toStrictEqual("\"some-prop\"");
92+
expect(escObjKey("some-prop")).toStrictEqual('"some-prop"');
8793
});
8894

8995
it("@ escapes", () => {
90-
expect(escObjKey("@type")).toStrictEqual("\"@type\"");
96+
expect(escObjKey("@type")).toStrictEqual('"@type"');
9197
});
9298

9399
it("number escapes", () => {
94-
expect(escObjKey("123var")).toStrictEqual("\"123var\"");
100+
expect(escObjKey("123var")).toStrictEqual('"123var"');
95101
});
96102

97103
it("only number no escapes", () => {
@@ -104,6 +110,6 @@ describe("utils", () => {
104110

105111
it("_ no escapes", () => {
106112
expect(escObjKey("_ref_")).toStrictEqual("_ref_");
107-
})
108-
})
113+
});
114+
});
109115
});

0 commit comments

Comments
 (0)