You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
| keepRelationScalarFields | "false" | By default, the JSON Schema that's generated will output only objects for related model records. If set to "true", this will cause the generator to also output foreign key fields for related records |
63
+
| keepRelationFields | "true" | Determines whether to include fields from related models in the generated schema. Setting it to `"false"` allows excluding related model fields from the schema. |
63
64
| schemaId | undefined | Add an id to the generated schema. All references will include the schema id |
64
65
| includeRequiredFields | "false" | If this flag is `"true"` all required scalar prisma fields that do not have a default value, will be added to the `required` properties field for that schema definition. |
65
66
| persistOriginalType | "false" | If this flag is `"true"` the original type will be outputed under the property key "originalType" |
66
-
| forceAnyOf | "false" | If this flag is `"true"` the union types will be forced to use `anyOf`. Check [contradictory types](https://ajv.js.org/strict-mode.html#contradictory-types) for details |
67
+
| forceAnyOf | "false" | If this flag is `"true"` the union types will be forced to use `anyOf`. Check [contradictory types](https://ajv.js.org/strict-mode.html#contradictory-types) for details |
67
68
68
69
**3. Run generation**
69
70
@@ -308,6 +309,118 @@ Output:
308
309
}
309
310
```
310
311
312
+
### No relation fields
313
+
314
+
For some use cases, it might be useful to not include relation fields in the generated schema. This can be achieved by setting the `keepRelationFields` option to `"false"` and the `keepRelationScalarFields` option to `"true"`. For example if you want to use the generated schema to validate POST request object for instance, you might want to use this option.
315
+
316
+
```prisma
317
+
datasource db {
318
+
provider = "postgresql"
319
+
url = env("DATABASE_URL")
320
+
}
321
+
322
+
generator jsonSchema {
323
+
provider = "prisma-json-schema-generator"
324
+
keepRelationScalarFields = "true" // default is "false"
325
+
keepRelationFields = "false" // default is "true"
326
+
}
327
+
328
+
model User {
329
+
id Int @id @default(autoincrement())
330
+
createdAt DateTime @default(now())
331
+
email String @unique
332
+
weight Float?
333
+
is18 Boolean?
334
+
name String?
335
+
number BigInt @default(34534535435353)
336
+
favouriteDecimal Decimal
337
+
bytes Bytes
338
+
successorId Int? @unique
339
+
successor User? @relation("BlogOwnerHistory", fields: [successorId], references: [id])
340
+
predecessor User? @relation("BlogOwnerHistory")
341
+
role Role @default(USER)
342
+
posts Post[]
343
+
keywords String[]
344
+
biography Json
345
+
}
346
+
347
+
model Post {
348
+
id Int @id @default(autoincrement())
349
+
user User? @relation(fields: [userId], references: [id])
0 commit comments