This repository was archived by the owner on Sep 27, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +12
-2
lines changed
Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ export type SchemaDefinition = {
1111 readOnly : boolean ,
1212 $ref ?: string ,
1313 items ?: SchemaDefinition | SchemaDefinition [ ] ,
14+ oneOf ?: SchemaDefinition [ ] ,
1415} ;
1516
1617export type PathParameter = {
Original file line number Diff line number Diff line change 11import type { SchemaDefinition } from "./openapi" ;
22
3+ function resolveArray ( items : SchemaDefinition [ ] , isArray : boolean ) {
4+ const schemas = items . map ( resolveSchema ) ;
5+ const names = schemas . join ( " | " ) ;
6+ return isArray ? `(${ names } )[]` : names ;
7+ }
8+
39export function resolveSchema ( definition : SchemaDefinition ) : string {
410 // TODO: handle definition.format === "date"
511 if ( definition . type ) {
@@ -9,8 +15,7 @@ export function resolveSchema(definition: SchemaDefinition): string {
915 case "array" : {
1016 if ( definition . items ) {
1117 if ( Array . isArray ( definition . items ) ) {
12- const schemas = definition . items . map ( resolveSchema ) ;
13- return `(${ schemas . join ( " | " ) } )[]` ;
18+ return resolveArray ( definition . items , true ) ;
1419 }
1520 return `${ resolveSchema ( definition . items ) } []` ;
1621 }
@@ -22,6 +27,9 @@ export function resolveSchema(definition: SchemaDefinition): string {
2227 if ( definition . $ref ) {
2328 return definition . $ref . replace ( "#/components/schemas/" , "" ) ;
2429 }
30+ if ( definition . oneOf ) {
31+ return resolveArray ( definition . oneOf , false ) ;
32+ }
2533 return "unknown" ;
2634}
2735
@@ -33,6 +41,7 @@ export function filterGenericSchemas(resolvedSchemas: string[]) {
3341 const genericSchemas = [
3442 "string" ,
3543 "number" ,
44+ "unknown" ,
3645 ] ;
3746 return resolvedSchemas . filter ( s => ! genericSchemas . includes ( s ) ) ;
3847}
You can’t perform that action at this time.
0 commit comments