[BUG] Foreign key marked as required in generated openapi spec
I've set up a new project based on an existing Prisma schema. I use the RestApiHandler and openapi plugin with rest flavor.
My (simplified) models look like this:
model Client extends Base {
id Int @id @default(autoincrement())
ClientConfig ClientConfig?
}
model ClientConfig extends Base {
id Int @id @default(autoincrement())
clientId Int @unique
Client Client @relation(fields: [clientId], references: [id])
}
In the generated openapi spec, clientId is marked as required. But if clientId is included in the attributes list, the request is rejected as invalid (since you're supposed to send it in the relationships object).
Here's a sample query that the generated client thinks is valid:
const res = await clientConfigApi.createClientConfig({
clientConfigCreateRequest: {
data: {
type: "clientConfig",
attributes: {
clientId: Number(client.id), // This shouldn't be here
},
relationships: {
client: {
data: {
type: "client",
id: client.id,
},
},
},
},
},
})
This will fail, since the clientId attribute is invalid.
I have a workaround for now:
const res = await clientConfigApi.createClientConfig({
clientConfigCreateRequest: {
data: {
type: "clientConfig",
attributes: {} as any, // Not providing clientId is a type error
relationships: {
client: {
data: {
type: "client",
id: client.id,
},
},
},
},
},
})
As far as I can tell there is no way to mark the clientId attribute as optional or ignorable for the openapi plugin without making the field itself optional in the db. And in any case, I think it makes sense for the default to be that any field that's a foreign key for a relationship is ignored by the openapi plugin.
Let me know if I'm missing something. If someone can point me in the correct direction I may be able to create a PR to fix the issue.