@@ -2,46 +2,49 @@ import type { OpenAPIObject } from "openapi3-ts";
22import { expect , test } from "vitest" ;
33import { generateZodClientFromOpenAPI } from "../src" ;
44
5- test ( "description-in-zod" , async ( ) => {
6- const openApiDoc : OpenAPIObject = {
7- openapi : "3.0.0" ,
8- info : {
9- version : "1.0.0" ,
10- title : "Numerical enums" ,
11- } ,
12- paths : {
13- "/sample" : {
14- get : {
15- parameters : [
16- {
17- in : "query" ,
18- name : "foo" ,
19- schema : {
20- type : "integer" ,
21- enum : [ 1 , - 2 , 3 ] ,
22- } ,
23- description : "foo description" ,
24- } ,
25- {
26- in : "query" ,
27- name : "bar" ,
28- schema : {
29- type : "number" ,
30- enum : [ 1.2 , 34 , - 56.789 ] ,
31- } ,
32- description : "bar description" ,
5+ const openApiDoc : OpenAPIObject = {
6+ openapi : "3.0.0" ,
7+ info : {
8+ version : "1.0.0" ,
9+ title : "Numerical enums" ,
10+ } ,
11+ paths : {
12+ "/sample" : {
13+ get : {
14+ parameters : [
15+ {
16+ in : "query" ,
17+ name : "foo" ,
18+ schema : {
19+ type : "integer" ,
20+ enum : [ 1 , - 2 , 3 ] ,
3321 } ,
34- ] ,
35- responses : {
36- "200" : {
37- description : "resoponse" ,
22+ description : "foo description" ,
23+ } ,
24+ {
25+ in : "query" ,
26+ name : "bar" ,
27+ schema : {
28+ type : "number" ,
29+ enum : [ 1.2 , 34 , - 56.789 ] ,
3830 } ,
31+ description : `multi
32+ line
33+ bar
34+ description` ,
35+ } ,
36+ ] ,
37+ responses : {
38+ "200" : {
39+ description : "resoponse" ,
3940 } ,
4041 } ,
4142 } ,
4243 } ,
43- } ;
44+ } ,
45+ } ;
4446
47+ test ( "description-in-zod" , async ( ) => {
4548 const output = await generateZodClientFromOpenAPI ( {
4649 disableWriteToFile : true ,
4750 openApiDoc,
@@ -62,15 +65,15 @@ test("description-in-zod", async () => {
6265 type: "Query",
6366 schema: z
6467 .union([z.literal(1), z.literal(-2), z.literal(3)])
65- .describe(" foo description" )
68+ .describe(\` foo description\` )
6669 .optional(),
6770 },
6871 {
6972 name: "bar",
7073 type: "Query",
7174 schema: z
7275 .union([z.literal(1.2), z.literal(34), z.literal(-56.789)])
73- .describe(" bar description" )
76+ .describe(\`multi line bar description\` )
7477 .optional(),
7578 },
7679 ],
@@ -86,3 +89,54 @@ test("description-in-zod", async () => {
8689 "
8790 ` ) ;
8891} ) ;
92+
93+ test ( "description-in-zod-multiline" , async ( ) => {
94+ const output = await generateZodClientFromOpenAPI ( {
95+ disableWriteToFile : true ,
96+ openApiDoc,
97+ options : { withDescription : "multiline" } ,
98+ } ) ;
99+ expect ( output ) . toMatchInlineSnapshot ( `
100+ "import { makeApi, Zodios, type ZodiosOptions } from "@zodios/core";
101+ import { z } from "zod";
102+
103+ const endpoints = makeApi([
104+ {
105+ method: "get",
106+ path: "/sample",
107+ requestFormat: "json",
108+ parameters: [
109+ {
110+ name: "foo",
111+ type: "Query",
112+ schema: z
113+ .union([z.literal(1), z.literal(-2), z.literal(3)])
114+ .describe(\`foo description\`)
115+ .optional(),
116+ },
117+ {
118+ name: "bar",
119+ type: "Query",
120+ schema: z
121+ .union([z.literal(1.2), z.literal(34), z.literal(-56.789)])
122+ .describe(
123+ \`multi
124+ line
125+ bar
126+ description\`
127+ )
128+ .optional(),
129+ },
130+ ],
131+ response: z.void(),
132+ },
133+ ]);
134+
135+ export const api = new Zodios(endpoints);
136+
137+ export function createApiClient(baseUrl: string, options?: ZodiosOptions) {
138+ return new Zodios(baseUrl, endpoints, options);
139+ }
140+ "
141+ ` )
142+ } )
0 commit comments