Skip to content

Commit

Permalink
fix(openapi): CreateManyArgs does not take array as input (#1246)
Browse files Browse the repository at this point in the history
  • Loading branch information
ymc9 authored Apr 12, 2024
1 parent 3e3e44c commit 8137481
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 10 deletions.
10 changes: 9 additions & 1 deletion packages/plugins/openapi/src/rpc-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,15 @@ export class RPCOpenAPIGenerator extends OpenAPIGeneratorBase {
type: 'object',
required: ['data'],
properties: {
data: this.ref(`${modelName}CreateManyInput`),
data: this.oneOf(
this.ref(`${modelName}CreateManyInput`),
this.array(this.ref(`${modelName}CreateManyInput`))
),
skipDuplicates: {
type: 'boolean',
description:
'Do not insert records with unique fields or ID fields that already exist.',
},
meta: this.ref('_Meta'),
},
},
Expand Down
30 changes: 27 additions & 3 deletions packages/plugins/openapi/tests/baseline/rpc-3.0.0.baseline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3194,7 +3194,15 @@ components:
- data
properties:
data:
$ref: '#/components/schemas/UserCreateManyInput'
oneOf:
- $ref: '#/components/schemas/UserCreateManyInput'
- type: array
items:
$ref: '#/components/schemas/UserCreateManyInput'
skipDuplicates:
type: boolean
description: Do not insert records with unique fields or ID fields that already
exist.
meta:
$ref: '#/components/schemas/_Meta'
UserFindUniqueArgs:
Expand Down Expand Up @@ -3374,7 +3382,15 @@ components:
- data
properties:
data:
$ref: '#/components/schemas/ProfileCreateManyInput'
oneOf:
- $ref: '#/components/schemas/ProfileCreateManyInput'
- type: array
items:
$ref: '#/components/schemas/ProfileCreateManyInput'
skipDuplicates:
type: boolean
description: Do not insert records with unique fields or ID fields that already
exist.
meta:
$ref: '#/components/schemas/_Meta'
ProfileFindUniqueArgs:
Expand Down Expand Up @@ -3554,7 +3570,15 @@ components:
- data
properties:
data:
$ref: '#/components/schemas/Post_ItemCreateManyInput'
oneOf:
- $ref: '#/components/schemas/Post_ItemCreateManyInput'
- type: array
items:
$ref: '#/components/schemas/Post_ItemCreateManyInput'
skipDuplicates:
type: boolean
description: Do not insert records with unique fields or ID fields that already
exist.
meta:
$ref: '#/components/schemas/_Meta'
Post_ItemFindUniqueArgs:
Expand Down
30 changes: 27 additions & 3 deletions packages/plugins/openapi/tests/baseline/rpc-3.1.0.baseline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3248,7 +3248,15 @@ components:
- data
properties:
data:
$ref: '#/components/schemas/UserCreateManyInput'
oneOf:
- $ref: '#/components/schemas/UserCreateManyInput'
- type: array
items:
$ref: '#/components/schemas/UserCreateManyInput'
skipDuplicates:
type: boolean
description: Do not insert records with unique fields or ID fields that already
exist.
meta:
$ref: '#/components/schemas/_Meta'
UserFindUniqueArgs:
Expand Down Expand Up @@ -3428,7 +3436,15 @@ components:
- data
properties:
data:
$ref: '#/components/schemas/ProfileCreateManyInput'
oneOf:
- $ref: '#/components/schemas/ProfileCreateManyInput'
- type: array
items:
$ref: '#/components/schemas/ProfileCreateManyInput'
skipDuplicates:
type: boolean
description: Do not insert records with unique fields or ID fields that already
exist.
meta:
$ref: '#/components/schemas/_Meta'
ProfileFindUniqueArgs:
Expand Down Expand Up @@ -3608,7 +3624,15 @@ components:
- data
properties:
data:
$ref: '#/components/schemas/Post_ItemCreateManyInput'
oneOf:
- $ref: '#/components/schemas/Post_ItemCreateManyInput'
- type: array
items:
$ref: '#/components/schemas/Post_ItemCreateManyInput'
skipDuplicates:
type: boolean
description: Do not insert records with unique fields or ID fields that already
exist.
meta:
$ref: '#/components/schemas/_Meta'
Post_ItemFindUniqueArgs:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2017,7 +2017,15 @@ components:
- data
properties:
data:
$ref: '#/components/schemas/FooCreateManyInput'
oneOf:
- $ref: '#/components/schemas/FooCreateManyInput'
- type: array
items:
$ref: '#/components/schemas/FooCreateManyInput'
skipDuplicates:
type: boolean
description: Do not insert records with unique fields or ID fields that already
exist.
meta:
$ref: '#/components/schemas/_Meta'
FooFindUniqueArgs:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2049,7 +2049,15 @@ components:
- data
properties:
data:
$ref: '#/components/schemas/FooCreateManyInput'
oneOf:
- $ref: '#/components/schemas/FooCreateManyInput'
- type: array
items:
$ref: '#/components/schemas/FooCreateManyInput'
skipDuplicates:
type: boolean
description: Do not insert records with unique fields or ID fields that already
exist.
meta:
$ref: '#/components/schemas/_Meta'
FooFindUniqueArgs:
Expand Down
2 changes: 1 addition & 1 deletion packages/schema/src/plugins/zod/transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ export const ${this.name}ObjectSchema: SchemaType = ${schema} as SchemaType;`;
imports.push(
`import { ${modelName}CreateManyInputObjectSchema } from '../objects/${modelName}CreateManyInput.schema'`
);
codeBody += `createMany: z.object({ data: z.union([${modelName}CreateManyInputObjectSchema, z.array(${modelName}CreateManyInputObjectSchema)]) }),`;
codeBody += `createMany: z.object({ data: z.union([${modelName}CreateManyInputObjectSchema, z.array(${modelName}CreateManyInputObjectSchema)]), skipDuplicates: z.boolean().optional() }),`;
operations.push(['createMany', origModelName]);
}

Expand Down

0 comments on commit 8137481

Please sign in to comment.