Skip to content

Commit e3ad312

Browse files
Merge pull request #839 from BitGo/DX-602-min-max-in-array
feat: support `minItem` and `maxItem` for array types
2 parents 497dc9f + 179bf7b commit e3ad312

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

packages/openapi-generator/src/openapi.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,12 @@ function schemaToOpenAPI(
5555
return undefined;
5656
}
5757

58-
const { arrayExample, ...rest } = defaultOpenAPIObject;
58+
const { arrayExample, minItems, maxItems, ...rest } = defaultOpenAPIObject;
5959

6060
return {
6161
type: 'array',
62+
...(minItems ? { minItems } : {}),
63+
...(maxItems ? { maxItems } : {}),
6264
...(arrayExample ? { example: JSON.parse(arrayExample) } : {}), // Add example to array if it exists
6365
items: { ...innerSchema, ...rest },
6466
};

packages/openapi-generator/test/openapi.test.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3588,6 +3588,11 @@ export const route = h.httpRoute({
35883588
* @arrayExample ["btc", "eth"]
35893589
*/
35903590
array2: t.array(t.string),
3591+
/**
3592+
* @minItems 1
3593+
* @maxItems 5
3594+
*/
3595+
array3: t.array(t.number),
35913596
objectWithArray: t.type({
35923597
/**
35933598
* @arrayExample ["btc", "eth"]
@@ -3632,6 +3637,14 @@ testCase("route with array examples", ROUTE_WITH_ARRAY_EXAMPLE, {
36323637
example: '"btc"'
36333638
},
36343639
},
3640+
array3: {
3641+
items: {
3642+
type: 'number'
3643+
},
3644+
maxItems: 5,
3645+
minItems: 1,
3646+
type: 'array'
3647+
},
36353648
objectWithArray: {
36363649
properties: {
36373650
nestedArray: {
@@ -3651,7 +3664,7 @@ testCase("route with array examples", ROUTE_WITH_ARRAY_EXAMPLE, {
36513664
type: 'object'
36523665
},
36533666
},
3654-
required: [ 'array1', 'array2', 'objectWithArray' ],
3667+
required: [ 'array1', 'array2', 'array3', 'objectWithArray' ],
36553668
},
36563669
}
36573670
}

0 commit comments

Comments
 (0)