Brendonovich / prisma-client-rust

Type-safe database access for Rust
https://prisma.brendonovich.dev
Apache License 2.0
1.74k stars 106 forks source link

Add optional utoipa to generated prisma macro #447

Open askasp opened 3 months ago

askasp commented 3 months ago

I wanted to generate a openapi schema from the prisma types. I tried doing the following, but i cant get the prisma-cli to compile.

quote! {
        #[derive(Debug, Clone, ::serde::Serialize, ::serde::Deserialize, utoipa::ToSchema)]
        #specta_derive
        pub struct Data {
            #(#struct_fields),*
        }

        impl Data {
            #(#relation_accessors)*
        }
    }
}

When i try to do prisma-generate it sais i need cargo to enable postgresql feature.

However, when i try to add postgresql in the dependency list here

[package]
name = "prisma-cli"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
postgresql = ["prisma-client-rust-cli/postgresql"]

[dependencies]
prisma-client-rust-cli = { features = [
  "migrations",
  # "mutation-callbacks",
], default_features = false, path = "../../prisma-client-rust/crates/cli" }

i get an error on

tcp_keepalive = tcp_keepalive.with_interval(interval); ^^^^^^^^^^^^^ method not found in TcpKeepalive

If you can give me a pointer on how to get past this step i'll gladly try to set up a PR for an optional toSchema derivation on the prisma data structures!

Brendonovich commented 2 months ago

I think this is a dependency issue I may have recently resolved, but aside from that I'd recommend applying the utopia::ToSchema conditionally as is done in Specta, unless you don't intend on PRing this change