@@ -20,7 +20,7 @@ export function tableFromSchema(allRefs: Refs, schema: JSONSchema6): {content: s
20
20
const description = prepareComplexDescription ( '' , schema ) ;
21
21
const content = table ( [
22
22
[ 'Type' , 'Description' ] ,
23
- [ schema . type , description ] ,
23
+ [ inferType ( schema ) , description ] ,
24
24
] ) ;
25
25
return { content, tableRefs : [ ] } ;
26
26
}
@@ -64,7 +64,7 @@ export function prepareTableRowData(allRefs: Refs, value: JSONSchema6, key?: str
64
64
if ( ref ) {
65
65
return { type : anchor ( ref ) , description, ref} ;
66
66
}
67
- if ( value . type === 'array' ) {
67
+ if ( inferType ( value ) === 'array' ) {
68
68
if ( ! value . items || value . items === true || Array . isArray ( value . items ) ) {
69
69
throw Error ( `unsupported array items for ${ key } ` ) ;
70
70
}
@@ -76,7 +76,7 @@ export function prepareTableRowData(allRefs: Refs, value: JSONSchema6, key?: str
76
76
ref : inner . ref ,
77
77
} ;
78
78
}
79
- return { type : `${ value . type } ` , description : prepareComplexDescription ( description , value ) } ;
79
+ return { type : `${ inferType ( value ) } ` , description : prepareComplexDescription ( description , value ) } ;
80
80
}
81
81
82
82
function prepareComplexDescription ( baseDescription : string , value : JSONSchema6 ) : string {
@@ -108,7 +108,7 @@ function findRef(allRefs: Refs, value: JSONSchema6): string | undefined {
108
108
}
109
109
return undefined ;
110
110
}
111
- type OpenJSONSchema = JSONSchema6 & { example ?: any } ;
111
+ type OpenJSONSchema = Omit < JSONSchema6 , 'enum' > & { example ?: any ; enum ?: Array < any > } ;
112
112
type OpenJSONSchemaDefinition = OpenJSONSchema | boolean ;
113
113
114
114
// sample key-value JSON body
@@ -144,7 +144,7 @@ function prepareSampleElement(key: string, v: OpenJSONSchemaDefinition, required
144
144
return undefined ;
145
145
}
146
146
const downCallstack = callstack . concat ( value ) ;
147
- switch ( value . type ) {
147
+ switch ( inferType ( value ) ) {
148
148
case 'object' :
149
149
return prepareSampleObject ( value , downCallstack ) ;
150
150
case 'array' :
@@ -234,3 +234,18 @@ function merge(value: OpenJSONSchemaDefinition): OpenJSONSchema {
234
234
function isRequired ( key : string , value : JSONSchema6 ) : boolean {
235
235
return value . required ?. includes ( key ) ?? false ;
236
236
}
237
+
238
+ function inferType ( value : OpenJSONSchema ) : JSONSchema6 [ 'type' ] {
239
+ if ( value . type ) {
240
+ return value . type ;
241
+ }
242
+ if ( value . enum && Array . isArray ( value . enum ) ) {
243
+ const enumType = typeof value . enum [ 0 ] ;
244
+ if ( enumType === 'bigint' || enumType === 'symbol' || enumType === 'undefined' || enumType === 'function' ) {
245
+ throw new Error ( 'Not supported type enum' ) ;
246
+ } else {
247
+ return enumType ;
248
+ }
249
+ }
250
+ return value . type ;
251
+ }
0 commit comments