@@ -6273,6 +6273,136 @@ describe('generateZod (content type handling - parity with res-req-types.test.ts
62736273})
62746274})
62756275
6276+ ` ) ;
6277+ } ) ;
6278+
6279+ it ( 'content type with charset precision: comprehensive content type handling' , async ( ) => {
6280+ // Matches type gen test structure in res-req-types.test.ts
6281+ const schema = {
6282+ pathRoute : '/upload-form' ,
6283+ context : {
6284+ spec : {
6285+ paths : {
6286+ '/upload-form' : {
6287+ post : {
6288+ operationId : 'uploadForm' ,
6289+ requestBody : {
6290+ required : true ,
6291+ content : {
6292+ 'multipart/form-data; charset=utf-8' : {
6293+ schema : {
6294+ type : 'object' ,
6295+ properties : {
6296+ encBinary : { type : 'string' } ,
6297+ encText : { type : 'string' } ,
6298+ cmtBinary : {
6299+ type : 'string' ,
6300+ contentMediaType : 'image/png' ,
6301+ } ,
6302+ cmtText : {
6303+ type : 'string' ,
6304+ contentMediaType : 'application/xml' ,
6305+ } ,
6306+ encOverride : {
6307+ type : 'string' ,
6308+ contentMediaType : 'image/png' ,
6309+ } ,
6310+ formatBinary : { type : 'string' , format : 'binary' } ,
6311+ base64Field : {
6312+ type : 'string' ,
6313+ contentMediaType : 'image/png' ,
6314+ contentEncoding : 'base64' ,
6315+ } ,
6316+ metadata : {
6317+ type : 'object' ,
6318+ properties : { name : { type : 'string' } } ,
6319+ } ,
6320+ } ,
6321+ required : [
6322+ 'encBinary' ,
6323+ 'encText' ,
6324+ 'cmtBinary' ,
6325+ 'cmtText' ,
6326+ 'encOverride' ,
6327+ 'formatBinary' ,
6328+ 'base64Field' ,
6329+ 'metadata' ,
6330+ ] ,
6331+ } ,
6332+ encoding : {
6333+ encBinary : { contentType : 'image/png' } ,
6334+ encText : { contentType : 'text/plain' } ,
6335+ encOverride : { contentType : 'text/csv' } ,
6336+ metadata : { contentType : 'application/json' } ,
6337+ } ,
6338+ } ,
6339+ } ,
6340+ } ,
6341+ responses : {
6342+ '200' : {
6343+ content : {
6344+ 'application/json; charset=utf-8' : {
6345+ schema : {
6346+ type : 'object' ,
6347+ properties : {
6348+ success : { type : 'boolean' } ,
6349+ uploaded : { type : 'number' } ,
6350+ } ,
6351+ } ,
6352+ } ,
6353+ } ,
6354+ } ,
6355+ } ,
6356+ } ,
6357+ } ,
6358+ } ,
6359+ } ,
6360+ output : { override : { zod : { generateEachHttpStatus : false } } } ,
6361+ } ,
6362+ } as unknown as GeneratorOptions ;
6363+ const result = await generateZod (
6364+ {
6365+ pathRoute : '/upload-form' ,
6366+ verb : 'post' ,
6367+ operationName : 'uploadForm' ,
6368+ override : {
6369+ ...zodOverride ,
6370+ zod : {
6371+ ...zodOverride . zod ,
6372+ generate : { ...zodOverride . zod . generate , response : true } ,
6373+ } ,
6374+ } ,
6375+ } as unknown as Parameters < typeof generateZod > [ 0 ] ,
6376+ schema ,
6377+ testOutput ,
6378+ ) ;
6379+ // encBinary: encoding image/png → File
6380+ // encText: encoding text/plain → File | string
6381+ // cmtBinary: contentMediaType image/png → File
6382+ // cmtText: contentMediaType application/xml → File | string
6383+ // encOverride: encoding text/csv overrides contentMediaType image/png → File | string
6384+ // formatBinary: format: binary → File (same as instanceof check)
6385+ // base64Field: contentEncoding base64 → stays string
6386+ // metadata: object → object schema
6387+ expect ( result . implementation )
6388+ . toBe ( `export const UploadFormBody = zod.object({
6389+ "encBinary": zod.instanceof(File),
6390+ "encText": zod.instanceof(File).or(zod.string()),
6391+ "cmtBinary": zod.instanceof(File),
6392+ "cmtText": zod.instanceof(File).or(zod.string()),
6393+ "encOverride": zod.instanceof(File).or(zod.string()),
6394+ "formatBinary": zod.instanceof(File),
6395+ "base64Field": zod.string(),
6396+ "metadata": zod.object({
6397+ "name": zod.string().optional()
6398+ })
6399+ })
6400+
6401+ export const UploadFormResponse = zod.object({
6402+ "success": zod.boolean().optional(),
6403+ "uploaded": zod.number().optional()
6404+ })
6405+
62766406` ) ;
62776407 } ) ;
62786408} ) ;
0 commit comments