@@ -110,6 +110,18 @@ export function getPrintableVal(val) {
110110 return val . toString ( ) . replace ( / ^ + | + $ / g, ( m ) => '●' . repeat ( m . length ) ) || '' ;
111111}
112112
113+ /* Helper to detect binary file fields across OpenAPI 3.0 and 3.1 */
114+ export function isBinaryFileField ( schema ) {
115+ if ( ! schema ) {
116+ return false ;
117+ }
118+ return (
119+ schema . format === 'binary' ||
120+ schema . contentEncoding === 'binary' ||
121+ ( Boolean ( schema . contentMediaType ) && schema . contentEncoding !== 'base64' )
122+ ) ;
123+ }
124+
113125/* Generates an schema object containing type and constraint info */
114126export function getTypeInfo ( schema ) {
115127 if ( ! schema ) {
@@ -165,6 +177,9 @@ export function getTypeInfo(schema) {
165177 const info = {
166178 type : dataType ,
167179 format : schema . format || effectiveSchema . format || '' ,
180+ contentMediaType : schema . contentMediaType || effectiveSchema . contentMediaType || '' ,
181+ contentEncoding : schema . contentEncoding || effectiveSchema . contentEncoding || '' ,
182+ contentSchema : schema . contentSchema || effectiveSchema . contentSchema || null ,
168183 pattern :
169184 ( schema . pattern || effectiveSchema . pattern ) && ! schema . enum && ! effectiveSchema . enum ? schema . pattern || effectiveSchema . pattern : '' ,
170185 readOrWriteOnly : schema . readOnly ? '🆁' : schema . writeOnly ? '🆆' : effectiveSchema . readOnly ? '🆁' : effectiveSchema . writeOnly ? '🆆' : '' ,
@@ -493,6 +508,30 @@ export function getSampleValueByType(schemaObj) {
493508 return schemaObj . pattern ;
494509 }
495510 }
511+ if ( schemaObj . contentEncoding ) {
512+ switch ( schemaObj . contentEncoding . toLowerCase ( ) ) {
513+ case 'base64' :
514+ return 'ZXhhbXBsZQ==' ; // 'example' base64 encoded
515+ case 'binary' :
516+ case '7bit' :
517+ case '8bit' :
518+ case 'quoted-printable' :
519+ return 'string' ;
520+ }
521+ }
522+ if ( schemaObj . contentMediaType ) {
523+ if ( schemaObj . contentMediaType . toLowerCase ( ) === 'application/json' ) {
524+ if ( schemaObj . contentSchema ) {
525+ const sample = schemaToSampleObj ( schemaObj . contentSchema ) ;
526+ const sampleVal = sample ?. [ 'example-0' ] ?? sample ;
527+ return JSON . stringify ( sampleVal ) ;
528+ }
529+ return '{}' ;
530+ }
531+ if ( schemaObj . contentMediaType . startsWith ( 'text/' ) ) {
532+ return 'text content' ;
533+ }
534+ }
496535 if ( schemaObj . format ) {
497536 switch ( schemaObj . format . toLowerCase ( ) ) {
498537 case 'url' :
@@ -519,7 +558,10 @@ export function getSampleValueByType(schemaObj) {
519558 case 'uuid' :
520559 return '3fa85f64-5717-4562-b3fc-2c963f66afa6' ;
521560 case 'byte' :
561+ case 'base64' :
522562 return 'ZXhhbXBsZQ==' ; // 'example' base64 encoded. See https://spec.openapis.org/oas/v3.0.0#data-types
563+ case 'binary' :
564+ return 'binary' ;
523565 default :
524566 return '' ;
525567 }
@@ -1022,8 +1064,8 @@ function handleMultiTypeSchema(schema, baseObj = {}, level = 0) {
10221064 typeof subSchema . items ?. type === 'string' &&
10231065 subSchema . items ?. type . match ( / i n t e g e r | n u m b e r | s t r i n g | n u l l | b o o l e a n / g)
10241066 ) {
1025- if ( subSchema . items . type === 'string' && subSchema . items . format ) {
1026- primitiveType . push ( `[${ subSchema . items . format } ]` ) ;
1067+ if ( subSchema . items . type === 'string' && ( subSchema . items . format || subSchema . items . contentMediaType ) ) {
1068+ primitiveType . push ( `[${ subSchema . items . format || subSchema . items . contentMediaType } ]` ) ;
10271069 } else {
10281070 primitiveType . push ( `[${ subSchema . items . type } ]` ) ;
10291071 }
@@ -1161,6 +1203,9 @@ function createPrimitiveAST(schema, name, isRequired) {
11611203 name,
11621204 type : typeInfo . type || schema . type || '' ,
11631205 format : typeInfo . format || schema . format || '' ,
1206+ contentMediaType : typeInfo . contentMediaType || schema . contentMediaType || '' ,
1207+ contentEncoding : typeInfo . contentEncoding || schema . contentEncoding || '' ,
1208+ contentSchema : typeInfo . contentSchema || schema . contentSchema || null ,
11641209 pattern : typeInfo . pattern || schema . pattern || '' ,
11651210 constraints : typeInfo . constrain || '' ,
11661211 defaultValue : typeInfo . default !== undefined && typeInfo . default !== '' ? String ( typeInfo . default ) : '' ,
@@ -1339,8 +1384,8 @@ export function schemaToAST(schema, level = 0, name = '', isRequired = false, su
13391384 typeof subSchema . items ?. type === 'string' &&
13401385 subSchema . items ?. type . match ( / i n t e g e r | n u m b e r | s t r i n g | n u l l | b o o l e a n / g)
13411386 ) {
1342- if ( subSchema . items . type === 'string' && subSchema . items . format ) {
1343- primitiveType . push ( `[${ subSchema . items . format } ]` ) ;
1387+ if ( subSchema . items . type === 'string' && ( subSchema . items . format || subSchema . items . contentMediaType ) ) {
1388+ primitiveType . push ( `[${ subSchema . items . format || subSchema . items . contentMediaType } ]` ) ;
13441389 } else {
13451390 primitiveType . push ( `[${ subSchema . items . type } ]` ) ;
13461391 }
0 commit comments