@@ -30,40 +30,32 @@ function resolveTuple(items: SchemaObject | SchemaObject[], length: number) {
3030
3131export function resolveSchema ( definition ?: SchemaObject ) : string {
3232 if ( ! definition ) return "unknown" ;
33- if ( definition . $ref ) {
33+ if ( " $ref" in definition ) {
3434 return definition . $ref . replace ( "#/components/schemas/" , "" ) ;
3535 }
36- if ( definition . type ) {
37- switch ( definition . type ) {
38- case "string" : {
39- if ( definition . format === "binary" ) return "File" ;
40- // TODO: handle definition.format === "date"
41- if ( definition . enum ) {
42- return definition . enum . map ( resolveEnumItem ) . join ( " | " ) ;
43- }
44- return "string" ;
36+ switch ( definition . type ) {
37+ case "string" : {
38+ if ( definition . format === "binary" ) return "File" ;
39+ // TODO: handle definition.format === "date"
40+ if ( definition . enum ) {
41+ return definition . enum . map ( resolveEnumItem ) . join ( " | " ) ;
4542 }
46- case "number" : return "number" ;
47- case "boolean" : return "boolean" ;
48- case "array" : {
49- if ( definition . items ) {
50- if ( definition . maxItems && definition . maxItems === definition . minItems ) {
51- return resolveTuple ( definition . items , definition . maxItems ) ;
52- }
53- if ( Array . isArray ( definition . items ) ) {
54- return resolveArray ( definition . items , true ) ;
55- }
56- return `${ resolveSchema ( definition . items ) } []` ;
57- }
58- return "unknown[]" ;
43+ return "string" ;
44+ }
45+ case "number" : return "number" ;
46+ case "boolean" : return "boolean" ;
47+ case "array" : {
48+ if ( definition . maxItems && definition . maxItems === definition . minItems ) {
49+ return resolveTuple ( definition . items , definition . maxItems ) ;
5950 }
60- case "object" : {
61- if ( definition . properties ) {
62- const props = resolveObject ( definition . properties , definition . required ?? [ ] ) ;
63- return `{ ${ props . join ( ", " ) } }` ;
64- }
65- return "unknown" ;
51+ if ( Array . isArray ( definition . items ) ) {
52+ return resolveArray ( definition . items , true ) ;
6653 }
54+ return `${ resolveSchema ( definition . items ) } []` ;
55+ }
56+ case "object" : {
57+ const props = resolveObject ( definition . properties , definition . required ?? [ ] ) ;
58+ return `{ ${ props . join ( ", " ) } }` ;
6759 }
6860 }
6961 if ( definition . oneOf ) {
@@ -73,7 +65,7 @@ export function resolveSchema(definition?: SchemaObject): string {
7365}
7466
7567export function resolveSchemaWithNull ( definition : SchemaObject ) {
76- if ( definition . nullable ) {
68+ if ( "nullable" in definition && definition . nullable ) {
7769 return `${ resolveSchema ( definition ) } | null` ;
7870 }
7971 return resolveSchema ( definition ) ;
0 commit comments