Skip to content

Commit

Permalink
Merge pull request #3129 from alex-statsig/more-schema-option-keys
Browse files Browse the repository at this point in the history
feat: Add schema support for more option keys
  • Loading branch information
kamilmysliwiec authored Oct 29, 2024
2 parents 6132592 + d279a08 commit 81ea4a2
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 3 deletions.
35 changes: 35 additions & 0 deletions e2e/api-spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,26 @@
"type": "number"
}
},
{
"name": "constrainedLimit",
"required": true,
"in": "query",
"schema": {
"oneOf": [
{
"minimum": 0,
"maximum": 10,
"format": "int32"
},
{
"minimum": 100,
"maximum": 100,
"format": "int32"
}
],
"type": "number"
}
},
{
"name": "enum",
"required": true,
Expand Down Expand Up @@ -1535,6 +1555,20 @@
"limit": {
"type": "number"
},
"constrainedLimit": {
"oneOf": [
{
"minimum": 0,
"maximum": 10,
"format": "int32"
},
{
"minimum": 100,
"maximum": 100,
"format": "int32"
}
]
},
"enum": {
"allOf": [
{
Expand Down Expand Up @@ -1575,6 +1609,7 @@
"page",
"_sortBy",
"limit",
"constrainedLimit",
"enum",
"enumArr",
"letters",
Expand Down
20 changes: 18 additions & 2 deletions e2e/src/cats/dto/pagination-query.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@ export class PaginationQuery {
@ApiProperty()
limit: number;

@ApiProperty({
oneOf: [
{
minimum: 0,
maximum: 10,
format: 'int32'
},
{
minimum: 100,
maximum: 100,
format: 'int32'
}
],
})
constrainedLimit?: number;

@ApiProperty({
enum: LettersEnum,
enumName: 'LettersEnum'
Expand All @@ -45,7 +61,7 @@ export class PaginationQuery {
@ApiProperty({
enum: LettersEnum,
enumName: 'Letter',
isArray: true,
isArray: true
})
letters: LettersEnum[];

Expand All @@ -59,7 +75,7 @@ export class PaginationQuery {
type: 'string'
},
age: {
type: 'number',
type: 'number'
}
},
additionalProperties: true
Expand Down
4 changes: 3 additions & 1 deletion lib/services/swagger-types-mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ export class SwaggerTypesMapper {
'pattern',
'nullable',
'default',
'example'
'example',
'oneOf',
'anyOf'
];
}
}
16 changes: 16 additions & 0 deletions test/plugin/fixtures/project/cats/dto/pagination-query.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@ export class PaginationQuery {
@ApiProperty()
limit: number;

@ApiProperty({
oneOf: [
{
minimum: 0,
maximum: 10,
format: 'int32'
},
{
minimum: 100,
maximum: 100,
format: 'int32'
}
],
})
constrainedLimit?: number;

@ApiProperty({
enum: LettersEnum,
enumName: 'LettersEnum'
Expand Down
1 change: 1 addition & 0 deletions test/plugin/fixtures/serialized-meta.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default async () => {
page: { required: true, type: () => Number },
sortBy: { required: true, type: () => [String] },
limit: { required: true, type: () => Number },
constrainedLimit: { required: false, type: () => Number },
enum: {
required: true,
enum: t['./cats/dto/pagination-query.dto'].LettersEnum
Expand Down

0 comments on commit 81ea4a2

Please sign in to comment.