pub fn generate_code(
metadata: &CodeGenMetadata,
config: &CodeGenConfig,
) -> Result<()>Expand description
Generate all code described by config from metadata.
Writes the following outputs, depending on which CodeGenOutput fields are Some:
| Field | Contents |
|---|---|
output.common | Axum extractor code, per-service mod.rs (always written) |
output.models_gen | labels.rs resource-enum file (falls back to common if None) |
output.server | Handler trait + Axum route wiring per service |
output.client | HTTP client structs and request builders per service |
output.python | PyO3 binding wrappers + .pyi typings stub |
output.node | NAPI binding wrappers |
output.node_ts | TypeScript client (client.ts) |
§Required fields
output.commonis always required.bindingsmust beSomewhen any ofoutput.python,output.node, oroutput.node_tsisSome; otherwise returnsError::MissingBindingsConfig.models_path_templateandmodels_path_crate_templatemust be valid Rust path templates (containing{service}); invalid templates returnError::InvalidModelsPathTemplate.
§Optional fields
Setting generate_resource_enum to false skips labels.rs generation.
Setting bindings to None skips all language-binding output.
Call CodeGenConfig::validate before this function to surface config errors at
construction time rather than mid-generation.
§Errors
Returns:
Error::InvalidModelsPathTemplateifmodels_path_templateormodels_path_crate_templateis not a valid Rust path template.Error::InvalidConfigPathifcontext_type_pathorresult_type_pathis not a valid Rust path.Error::MissingBindingsConfigif any of thepython,node, ornode_tsoutputs is requested without abindingsconfig.Error::MissingAnnotationorError::Buildsurfaced while analyzing the metadata (e.g. a requiredgoogle.apiannotation is missing, or a service cannot be planned).Error::InvalidRustPathif a proto message or field maps to an invalid Rust path, andError::InvalidErrorTypePathif the configurederror_type_pathis not a valid Rust path.Error::GeneratedParseif an internal generator produces tokens that do not parse as a Rust file.Error::Ioif creating the models directory or writing any generated file fails.