openapi-typescript
Advanced tools
Comparing version 6.2.6 to 6.2.7
@@ -22,3 +22,3 @@ import { escStr, getEntries, indent } from "../utils.js"; | ||
const pathParams = new Map([...extractPathParams(pathItemObject), ...OPERATIONS.flatMap((op) => Array.from(extractPathParams(pathItemObject[op])))]); | ||
if (ctx.pathParamsAsTypes && pathParams) { | ||
if (ctx.pathParamsAsTypes && pathParams.size) { | ||
for (const p of pathParams.values()) { | ||
@@ -25,0 +25,0 @@ const paramType = transformParameterObject(p, { path: `#/paths/${url}/parameters/${p.name}`, ctx }); |
@@ -28,9 +28,3 @@ import { escObjKey, escStr, getEntries, getSchemaObjectComment, indent, parseRef, tsArrayOf, tsIntersectionOf, tsOmit, tsOneOf, tsOptionalProperty, tsReadonly, tsTupleOf, tsUnionOf, tsWithRequired } from "../utils.js"; | ||
if (schemaObject.const !== null && schemaObject.const !== undefined) { | ||
let schemaConst = schemaObject.const; | ||
if ("type" in schemaObject) { | ||
if (schemaObject.type === "string") { | ||
schemaConst = escStr(schemaConst); | ||
} | ||
} | ||
return transformSchemaObject(schemaConst, { | ||
return transformSchemaObject(escStr(schemaObject.const), { | ||
path, | ||
@@ -37,0 +31,0 @@ ctx: { ...ctx, immutableTypes: false, indentLv: indentLv + 1 }, |
@@ -186,3 +186,3 @@ import c from "ansi-colors"; | ||
if (typeof input !== "string") | ||
return input; | ||
return JSON.stringify(input); | ||
return `"${input.trim().replace(DOUBLE_QUOTE_RE, '\\"')}"`; | ||
@@ -189,0 +189,0 @@ } |
{ | ||
"name": "openapi-typescript", | ||
"description": "Generate TypeScript types from Swagger OpenAPI specs", | ||
"version": "6.2.6", | ||
"version": "6.2.7", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Drew Powers", |
@@ -28,3 +28,3 @@ import type { GlobalContext, PathsObject, PathItemObject, ParameterObject, ReferenceObject, OperationObject } from "../types.js"; | ||
// build dynamic string template literal index | ||
if (ctx.pathParamsAsTypes && pathParams) { | ||
if (ctx.pathParamsAsTypes && pathParams.size) { | ||
for (const p of pathParams.values()) { | ||
@@ -31,0 +31,0 @@ const paramType = transformParameterObject(p, { path: `#/paths/${url}/parameters/${p.name}`, ctx }); |
@@ -44,9 +44,3 @@ import type { GlobalContext, ReferenceObject, SchemaObject } from "../types.js"; | ||
if (schemaObject.const !== null && schemaObject.const !== undefined) { | ||
let schemaConst = schemaObject.const as any; | ||
if ("type" in schemaObject) { | ||
if (schemaObject.type === "string") { | ||
schemaConst = escStr(schemaConst); | ||
} | ||
} | ||
return transformSchemaObject(schemaConst, { | ||
return transformSchemaObject(escStr(schemaObject.const) as any, { | ||
path, | ||
@@ -53,0 +47,0 @@ ctx: { ...ctx, immutableTypes: false, indentLv: indentLv + 1 }, // note: guarantee readonly happens once, here |
@@ -260,3 +260,3 @@ import c from "ansi-colors"; | ||
export function escStr(input: any): string { | ||
if (typeof input !== "string") return input; | ||
if (typeof input !== "string") return JSON.stringify(input); | ||
return `"${input.trim().replace(DOUBLE_QUOTE_RE, '\\"')}"`; | ||
@@ -263,0 +263,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
295018
4736