From 4df151e9dea2dc3586e9a755525dd5950716c313 Mon Sep 17 00:00:00 2001 From: Paul Date: Mon, 18 May 2026 13:02:20 +0300 Subject: [PATCH] feature(openapi-typescript): tighten JSON schema check only assume JSON if the character following `{`, excluding white-space, is `"` --- packages/openapi-typescript/src/lib/redoc.ts | 2 +- .../openapi-typescript/test/node-api.test.ts | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/openapi-typescript/src/lib/redoc.ts b/packages/openapi-typescript/src/lib/redoc.ts index 455695243..34a1b3118 100644 --- a/packages/openapi-typescript/src/lib/redoc.ts +++ b/packages/openapi-typescript/src/lib/redoc.ts @@ -64,7 +64,7 @@ export async function parseSchema(schema: unknown, { absoluteRef, resolver }: Pa }); } // JSON - if (schema[0] === "{") { + if (/^\{\s*"/.test(schema.trimStart())) { return { source: new Source(absoluteRef, schema, "application/json"), parsed: parseJson(schema), diff --git a/packages/openapi-typescript/test/node-api.test.ts b/packages/openapi-typescript/test/node-api.test.ts index b22f8ad18..f0e58205a 100644 --- a/packages/openapi-typescript/test/node-api.test.ts +++ b/packages/openapi-typescript/test/node-api.test.ts @@ -29,6 +29,25 @@ export interface components { pathItems: never; } export type $defs = Record; +export type operations = Record;`, + }, + // options: DEFAULT_OPTIONS, + ], + [ + "input > string > YAML > flow-style", + { + given: `{ openapi: "3.1", info: { title: test, version: "1.0" } }`, + want: `export type paths = Record; +export type webhooks = Record; +export interface components { + schemas: never; + responses: never; + parameters: never; + requestBodies: never; + headers: never; + pathItems: never; +} +export type $defs = Record; export type operations = Record;`, }, // options: DEFAULT_OPTIONS,