Skip to content

Commit 4df151e

Browse files
committed
feature(openapi-typescript): tighten JSON schema check
only assume JSON if the character following `{`, excluding white-space, is `"`
1 parent 0cc7ee7 commit 4df151e

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

packages/openapi-typescript/src/lib/redoc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export async function parseSchema(schema: unknown, { absoluteRef, resolver }: Pa
6464
});
6565
}
6666
// JSON
67-
if (schema[0] === "{") {
67+
if (/^\{\s*"/.test(schema.trimStart())) {
6868
return {
6969
source: new Source(absoluteRef, schema, "application/json"),
7070
parsed: parseJson(schema),

packages/openapi-typescript/test/node-api.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,25 @@ export interface components {
2929
pathItems: never;
3030
}
3131
export type $defs = Record<string, never>;
32+
export type operations = Record<string, never>;`,
33+
},
34+
// options: DEFAULT_OPTIONS,
35+
],
36+
[
37+
"input > string > YAML > flow-style",
38+
{
39+
given: `{ openapi: "3.1", info: { title: test, version: "1.0" } }`,
40+
want: `export type paths = Record<string, never>;
41+
export type webhooks = Record<string, never>;
42+
export interface components {
43+
schemas: never;
44+
responses: never;
45+
parameters: never;
46+
requestBodies: never;
47+
headers: never;
48+
pathItems: never;
49+
}
50+
export type $defs = Record<string, never>;
3251
export type operations = Record<string, never>;`,
3352
},
3453
// options: DEFAULT_OPTIONS,

0 commit comments

Comments
 (0)