@@ -3,6 +3,7 @@ import { describe, expect, it } from 'vitest';
33import type {
44 ContextSpec ,
55 OpenApiRequestBodyObject ,
6+ OpenApiResponseObject ,
67 OpenApiSchemaObject ,
78} from '../types' ;
89import { getResReqTypes , isBinaryContentType } from './res-req-types' ;
@@ -67,6 +68,7 @@ describe('isBinaryContentType', () => {
6768 expect ( isBinaryContentType ( 'image/jpeg' ) ) . toBe ( true ) ;
6869 expect ( isBinaryContentType ( 'audio/mp3' ) ) . toBe ( true ) ;
6970 expect ( isBinaryContentType ( 'video/mp4' ) ) . toBe ( true ) ;
71+ expect ( isBinaryContentType ( '*/*' ) ) . toBe ( true ) ; // Unknown type - using Blob for now since it handles both text and binary
7072 } ) ;
7173
7274 it ( 'should return false for text-based content types' , ( ) => {
@@ -81,7 +83,7 @@ describe('isBinaryContentType', () => {
8183describe ( 'getResReqTypes (content type handling)' , ( ) => {
8284 describe ( 'media key precedence (type generation)' , ( ) => {
8385 it ( 'binary media key → Blob; text/JSON media key ignores contentMediaType' , ( ) => {
84- // Binary media key overrides schema to Blob
86+ // Binary media key overrides schema to Blob (request)
8587 const binaryReq : [ string , OpenApiRequestBodyObject ] [ ] = [
8688 [
8789 'requestBody' ,
@@ -95,7 +97,22 @@ describe('getResReqTypes (content type handling)', () => {
9597 ] ;
9698 expect ( getResReqTypes ( binaryReq , 'Body' , context ) [ 0 ] . value ) . toBe ( 'Blob' ) ;
9799
98- // Text/JSON media key ignores contentMediaType (stays string)
100+ // Binary media key overrides schema to Blob (response)
101+ const binaryRes : [ string , OpenApiResponseObject ] [ ] = [
102+ [
103+ '200' ,
104+ {
105+ content : {
106+ 'application/octet-stream' : { schema : { type : 'string' } } ,
107+ } ,
108+ } ,
109+ ] ,
110+ ] ;
111+ expect ( getResReqTypes ( binaryRes , 'Response' , context ) [ 0 ] . value ) . toBe (
112+ 'Blob' ,
113+ ) ;
114+
115+ // Text/JSON media key ignores contentMediaType (request)
99116 const jsonReq : [ string , OpenApiRequestBodyObject ] [ ] = [
100117 [
101118 'requestBody' ,
@@ -110,6 +127,58 @@ describe('getResReqTypes (content type handling)', () => {
110127 ] ,
111128 ] ;
112129 expect ( getResReqTypes ( jsonReq , 'Body' , context ) [ 0 ] . value ) . toBe ( 'string' ) ;
130+
131+ // Text/JSON media key ignores contentMediaType (response)
132+ const jsonRes : [ string , OpenApiResponseObject ] [ ] = [
133+ [
134+ '200' ,
135+ {
136+ content : {
137+ 'application/json' : {
138+ schema : { type : 'string' , contentMediaType : 'image/png' } ,
139+ } ,
140+ } ,
141+ } ,
142+ ] ,
143+ ] ;
144+ expect ( getResReqTypes ( jsonRes , 'Response' , context ) [ 0 ] . value ) . toBe (
145+ 'string' ,
146+ ) ;
147+ } ) ;
148+
149+ it ( 'wildcard */* media → Blob for both request and response' , ( ) => {
150+ // Wildcard accepts any content type, generates Blob
151+ const reqWithCmt : [ string , OpenApiRequestBodyObject ] [ ] = [
152+ [
153+ 'requestBody' ,
154+ {
155+ content : {
156+ '*/*' : {
157+ schema : { type : 'string' , contentMediaType : '*/*' } ,
158+ } ,
159+ } ,
160+ required : true ,
161+ } ,
162+ ] ,
163+ ] ;
164+ expect ( getResReqTypes ( reqWithCmt , 'Body' , context ) [ 0 ] . value ) . toBe ( 'Blob' ) ;
165+
166+ // Response
167+ const resWithCmt : [ string , OpenApiResponseObject ] [ ] = [
168+ [
169+ '200' ,
170+ {
171+ content : {
172+ '*/*' : {
173+ schema : { type : 'string' , contentMediaType : '*/*' } ,
174+ } ,
175+ } ,
176+ } ,
177+ ] ,
178+ ] ;
179+ expect ( getResReqTypes ( resWithCmt , 'Response' , context ) [ 0 ] . value ) . toBe (
180+ 'Blob' ,
181+ ) ;
113182 } ) ;
114183 } ) ;
115184
@@ -145,6 +214,7 @@ describe('getResReqTypes (content type handling)', () => {
145214 type : 'object' ,
146215 properties : { name : { type : 'string' } } ,
147216 } ,
217+ wildcardFile : { type : 'string' , contentMediaType : '*/*' } ,
148218 } ,
149219 required : [
150220 'encBinary' ,
@@ -155,6 +225,7 @@ describe('getResReqTypes (content type handling)', () => {
155225 'formatBinary' ,
156226 'base64Field' ,
157227 'metadata' ,
228+ 'wildcardFile' ,
158229 ] ,
159230 } ,
160231 encoding : {
@@ -173,7 +244,7 @@ describe('getResReqTypes (content type handling)', () => {
173244 it ( 'generates correct types and FormData for all content type combinations' , ( ) => {
174245 const result = getResReqTypes ( reqBody , 'Body' , context ) [ 0 ] ;
175246
176- // encBinary/cmtBinary/formatBinary: Blob (binary)
247+ // encBinary/cmtBinary/formatBinary/wildcardFile : Blob (binary)
177248 // encText/cmtText/encOverride: Blob | string (text file)
178249 // base64Field: string (contentEncoding means not a file)
179250 // metadata: object (named type)
@@ -186,6 +257,7 @@ describe('getResReqTypes (content type handling)', () => {
186257 formatBinary: Blob;
187258 base64Field: string;
188259 metadata: BodyRequestBodyMetadata;
260+ wildcardFile: Blob;
189261}` ) ;
190262
191263 expect ( result . formData ) . toBe ( `const formData = new FormData();
@@ -197,6 +269,7 @@ formData.append(\`encOverride\`, bodyRequestBody.encOverride instanceof Blob ? b
197269formData.append(\`formatBinary\`, bodyRequestBody.formatBinary);
198270formData.append(\`base64Field\`, bodyRequestBody.base64Field);
199271formData.append(\`metadata\`, new Blob([JSON.stringify(bodyRequestBody.metadata)], { type: 'application/json' }));
272+ formData.append(\`wildcardFile\`, bodyRequestBody.wildcardFile);
200273` ) ;
201274 } ) ;
202275 } ) ;
0 commit comments