@@ -6273,6 +6273,119 @@ 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 : { type : 'string' } ,
6346+ } ,
6347+ } ,
6348+ } ,
6349+ } ,
6350+ } ,
6351+ } ,
6352+ } ,
6353+ } ,
6354+ output : { override : { zod : { generateEachHttpStatus : false } } } ,
6355+ } ,
6356+ } as unknown as GeneratorOptions ;
6357+ const result = await generateZod (
6358+ {
6359+ pathRoute : '/upload-form' ,
6360+ verb : 'post' ,
6361+ operationName : 'uploadForm' ,
6362+ override : zodOverride ,
6363+ } as unknown as Parameters < typeof generateZod > [ 0 ] ,
6364+ schema ,
6365+ testOutput ,
6366+ ) ;
6367+ // encBinary: encoding image/png → File
6368+ // encText: encoding text/plain → File | string
6369+ // cmtBinary: contentMediaType image/png → File
6370+ // cmtText: contentMediaType application/xml → File | string
6371+ // encOverride: encoding text/csv overrides contentMediaType image/png → File | string
6372+ // formatBinary: format: binary → File (same as instanceof check)
6373+ // base64Field: contentEncoding base64 → stays string
6374+ // metadata: object → object schema
6375+ expect ( result . implementation )
6376+ . toBe ( `export const UploadFormBody = zod.object({
6377+ "encBinary": zod.instanceof(File),
6378+ "encText": zod.instanceof(File).or(zod.string()),
6379+ "cmtBinary": zod.instanceof(File),
6380+ "cmtText": zod.instanceof(File).or(zod.string()),
6381+ "encOverride": zod.instanceof(File).or(zod.string()),
6382+ "formatBinary": zod.instanceof(File),
6383+ "base64Field": zod.string(),
6384+ "metadata": zod.object({
6385+ "name": zod.string().optional()
6386+ })
6387+ })
6388+
62766389` ) ;
62776390 } ) ;
62786391} ) ;
0 commit comments