Skip to content

Commit 60053a0

Browse files
fix(registry): drop Deserialize derive on structs with &'static fields
The generated `ParamDef`, `BodyDef`, and `OperationDef` derive both `Serialize` and `Deserialize` but contain `&'static str` and `&'static [ParamDef]` fields. `Deserialize` cannot reconstruct references to baked-in static data, so consumers of the generated `registry.rs` failed to compile with: the trait bound `&'static [ParamDef]: serde::Deserialize<'de>` is not satisfied The data is only ever produced at codegen time and read at runtime, so `Serialize`-only is the correct shape. Drop `Deserialize` from the three relevant structs and add a docstring noting why. Caught while wiring `enable_registry = true` for the virgil walking skeleton's github-mini integration crate.
1 parent 782ccf7 commit 60053a0

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

src/registry_generator.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,12 @@ impl CodeGenerator {
9090
TextPlain,
9191
}
9292

93-
/// Definition of an operation parameter
94-
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
93+
/// Definition of an operation parameter.
94+
///
95+
/// Only `Serialize` is derived: this struct holds `&'static`
96+
/// references to data baked into the binary, which cannot be
97+
/// reconstructed by `Deserialize`.
98+
#[derive(Debug, Clone, serde::Serialize)]
9599
pub struct ParamDef {
96100
pub name: &'static str,
97101
pub location: ParamLocation,
@@ -100,16 +104,20 @@ impl CodeGenerator {
100104
pub description: Option<&'static str>,
101105
}
102106

103-
/// Definition of a request body
104-
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
107+
/// Definition of a request body.
108+
///
109+
/// `Serialize`-only for the same reason as [`ParamDef`].
110+
#[derive(Debug, Clone, serde::Serialize)]
105111
pub struct BodyDef {
106112
pub content_type: BodyContentType,
107113
/// Name of the schema type (for JSON/form bodies)
108114
pub schema_name: Option<&'static str>,
109115
}
110116

111-
/// A single operation in the registry
112-
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
117+
/// A single operation in the registry.
118+
///
119+
/// `Serialize`-only because of the `&'static` fields.
120+
#[derive(Debug, Clone, serde::Serialize)]
113121
pub struct OperationDef {
114122
/// Unique operation identifier (e.g. "repos/get", "issues/create-comment")
115123
pub id: &'static str,

0 commit comments

Comments
 (0)