|
1 | 1 | // Inspired by: https://github.com/omar-dulaimi/prisma-trpc-generator |
2 | 2 |
|
3 | | -import { analyzePolicies, PluginError, requireOption, resolvePath } from '@zenstackhq/sdk'; |
| 3 | +import { PluginError, analyzePolicies, requireOption, resolvePath, supportCreateMany } from '@zenstackhq/sdk'; |
4 | 4 | import { DataModel, isDataModel } from '@zenstackhq/sdk/ast'; |
5 | 5 | import { |
| 6 | + AggregateOperationSupport, |
6 | 7 | addMissingInputObjectTypesForAggregate, |
7 | 8 | addMissingInputObjectTypesForInclude, |
8 | 9 | addMissingInputObjectTypesForModelArgs, |
9 | 10 | addMissingInputObjectTypesForSelect, |
10 | | - AggregateOperationSupport, |
11 | 11 | resolveAggregateOperationSupport, |
12 | 12 | } from '@zenstackhq/sdk/dmmf-helpers'; |
13 | | -import type { DMMF } from '@zenstackhq/sdk/prisma'; |
| 13 | +import { type DMMF } from '@zenstackhq/sdk/prisma'; |
14 | 14 | import * as fs from 'fs'; |
15 | 15 | import { lowerCaseFirst } from 'lower-case-first'; |
16 | 16 | import type { OpenAPIV3_1 as OAPI } from 'openapi-types'; |
17 | 17 | import * as path from 'path'; |
18 | 18 | import invariant from 'tiny-invariant'; |
19 | | -import { match, P } from 'ts-pattern'; |
| 19 | +import { P, match } from 'ts-pattern'; |
20 | 20 | import { upperCaseFirst } from 'upper-case-first'; |
21 | 21 | import YAML from 'yaml'; |
22 | 22 | import { name } from '.'; |
@@ -166,7 +166,7 @@ export class RPCOpenAPIGenerator extends OpenAPIGeneratorBase { |
166 | 166 | }); |
167 | 167 | } |
168 | 168 |
|
169 | | - if (ops['createMany']) { |
| 169 | + if (ops['createMany'] && supportCreateMany(zmodel.$container)) { |
170 | 170 | definitions.push({ |
171 | 171 | method: 'post', |
172 | 172 | operation: 'createMany', |
@@ -704,7 +704,7 @@ export class RPCOpenAPIGenerator extends OpenAPIGeneratorBase { |
704 | 704 | private generateEnumComponent(_enum: DMMF.SchemaEnum): OAPI.SchemaObject { |
705 | 705 | const schema: OAPI.SchemaObject = { |
706 | 706 | type: 'string', |
707 | | - enum: _enum.values, |
| 707 | + enum: _enum.values as string[], |
708 | 708 | }; |
709 | 709 | return schema; |
710 | 710 | } |
@@ -793,17 +793,14 @@ export class RPCOpenAPIGenerator extends OpenAPIGeneratorBase { |
793 | 793 | return result; |
794 | 794 | } |
795 | 795 |
|
796 | | - private setInputRequired(fields: { name: string; isRequired: boolean }[], result: OAPI.NonArraySchemaObject) { |
| 796 | + private setInputRequired(fields: readonly DMMF.SchemaArg[], result: OAPI.NonArraySchemaObject) { |
797 | 797 | const required = fields.filter((f) => f.isRequired).map((f) => f.name); |
798 | 798 | if (required.length > 0) { |
799 | 799 | result.required = required; |
800 | 800 | } |
801 | 801 | } |
802 | 802 |
|
803 | | - private setOutputRequired( |
804 | | - fields: { name: string; isNullable?: boolean; outputType: DMMF.OutputTypeRef }[], |
805 | | - result: OAPI.NonArraySchemaObject |
806 | | - ) { |
| 803 | + private setOutputRequired(fields: readonly DMMF.SchemaField[], result: OAPI.NonArraySchemaObject) { |
807 | 804 | const required = fields.filter((f) => f.isNullable !== true).map((f) => f.name); |
808 | 805 | if (required.length > 0) { |
809 | 806 | result.required = required; |
|
0 commit comments