File tree Expand file tree Collapse file tree 2 files changed +14
-0
lines changed
Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,8 @@ export type SchemaDefinition = {
77 $ref ?: string ,
88 items ?: SchemaDefinition | SchemaDefinition [ ] ,
99 oneOf ?: SchemaDefinition [ ] ,
10+ minItems ?: number ,
11+ maxItems ?: number ,
1012 enum ?: ( string | null ) [ ] ,
1113 properties ?: Record < string , SchemaDefinition > ,
1214 required ?: string [ ] ,
Original file line number Diff line number Diff line change @@ -18,6 +18,15 @@ function resolveEnumItem(item: string | null) {
1818 return `"${ item } "` ;
1919}
2020
21+ function resolveTuple ( items : SchemaDefinition | SchemaDefinition [ ] , length : number ) {
22+ if ( Array . isArray ( items ) ) {
23+ const names = Array ( length ) . fill ( null ) . map ( ( _ , index ) => resolveSchema ( items [ index % items . length ] ) ) ;
24+ return `[${ names . join ( ", " ) } ]` ;
25+ }
26+ const names = Array ( length ) . fill ( null ) . map ( ( ) => resolveSchema ( items ) ) ;
27+ return `[${ names . join ( ", " ) } ]` ;
28+ }
29+
2130export function resolveSchema ( definition : SchemaDefinition ) : string {
2231 // TODO: handle definition.format === "date"
2332 if ( definition . type ) {
@@ -32,6 +41,9 @@ export function resolveSchema(definition: SchemaDefinition): string {
3241 case "boolean" : return "boolean" ;
3342 case "array" : {
3443 if ( definition . items ) {
44+ if ( definition . maxItems && definition . maxItems === definition . minItems ) {
45+ return resolveTuple ( definition . items , definition . maxItems ) ;
46+ }
3547 if ( Array . isArray ( definition . items ) ) {
3648 return resolveArray ( definition . items , true ) ;
3749 }
You can’t perform that action at this time.
0 commit comments