Skip to content

Commit 8967cc9

Browse files
committed
feat: multiline option
1 parent d20586a commit 8967cc9

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

lib/src/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ cli.command("<input>", "path/url to OpenAPI/Swagger document as json/yaml")
3434
"When true, will make all properties of an object required by default (rather than the current opposite), unless an explicitly `required` array is set"
3535
)
3636
.option("--with-deprecated", "when true, will keep deprecated endpoints in the api output")
37-
.option("--with-description", "when true, will add z.describe(xxx)")
37+
.option("--with-description", "when true, will add z.describe(xxx), 'multiline' will keep newlines as is")
3838
.option(
3939
"--group-strategy",
4040
"groups endpoints by a given strategy, possible values are: 'none' | 'tag' | 'method' | 'tag-file' | 'method-file'"

lib/src/getZodiosEndpointDefinitionList.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,6 @@ export const getZodiosEndpointDefinitionList = (doc: OpenAPIObject, options?: Te
226226
);
227227
}
228228

229-
230229
// this fallback is needed to autofix openapi docs that put the $ref in the wrong place
231230
// (it should be in the mediaTypeObject.schema, not in the mediaTypeObject itself)
232231
// https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#style-values (just above this anchor)
@@ -239,7 +238,9 @@ export const getZodiosEndpointDefinitionList = (doc: OpenAPIObject, options?: Te
239238
}
240239

241240
if (options?.withDescription && paramSchema) {
242-
(paramSchema as SchemaObject).description = (paramItem.description ?? "")?.replace("\n", "");
241+
const desc = paramItem.description ?? "";
242+
(paramSchema as SchemaObject).description =
243+
options?.withDescription === "multiline" ? desc : desc?.replaceAll(/\n\s*/g, " ");
243244
}
244245

245246
// resolve ref if needed, and fallback to default (unknown) value if needed

lib/src/template-context.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,12 @@ export type TemplateContextOptions = {
335335
defaultStatusBehavior?: "spec-compliant" | "auto-correct";
336336
willSuppressWarnings?: boolean;
337337
/**
338-
* when true, will add z.describe(xxx)
338+
* adds z.describe(xxx).
339+
*
340+
* - when true, will truncate newlines and trailing spaces into a single space.
341+
* - when "multiline", will not truncate newlines.
342+
*
339343
* @see https://github.com/astahmer/openapi-zod-client/pull/143
340344
*/
341-
withDescription?: boolean;
345+
withDescription?: boolean | "multiline";
342346
};

0 commit comments

Comments
 (0)