Skip to main content

CodeGenConfig

Struct CodeGenConfig 

Source
pub struct CodeGenConfig {
Show 17 fields pub context_type_path: String, pub result_type_path: String, pub models_path_template: String, pub models_path_crate_template: String, pub output: CodeGenOutput, pub generate_resource_enum: bool, pub generate_store_integration: bool, pub error_type_path: Option<String>, pub generate_object_conversions: bool, pub bindings: Option<BindingsConfig>, pub resource_store_crate_name: String, pub runtime: Runtime, pub transport_type_path: String, pub dual_transport: bool, pub client_protocols: ClientProtocols, pub connect_client_path: Option<String>, pub rest_client: RestClientOptions,
}
Expand description

Configuration for code generation, including import paths and output directories.

Construct this struct directly and set the fields you need.

Fields§

§context_type_path: String

Fully-qualified path to the request context type used in handler methods.

Default: "crate::api::RequestContext"

§result_type_path: String

Fully-qualified path to the Result alias used in generated handler and client code. The clients use the Result of the generated error module instead when RestClientOptions::error_module is set.

Default: "crate::Result"

§models_path_template: String

Template for the external model import path. {service} is replaced with the service’s base path (e.g. "catalogs").

Example: "my_common::models::{service}::v1"

§models_path_crate_template: String

Template for crate-local model import path. {service} is replaced with the service’s base path.

Default: "crate::models::{service}::v1"

§output: CodeGenOutput

Output directory configuration.

§generate_resource_enum: bool

When true, generate labels.rs with Resource / ObjectLabel enums derived from google.api.resource annotations. Requires output.models to be Some.

Store-specific output (Label impl, RESOURCE_DESCRIPTORS) is only emitted when generate_store_integration is also true.

§generate_store_integration: bool

When true (and generate_resource_enum is set), emit the olai_store integration code in labels.rs:

  • impl olai_store::Label for ObjectLabel
  • pub static RESOURCE_DESCRIPTORS: &[olai_store::ResourceTypeDescriptor<ObjectLabel>]

Set to false for crates that use the enums without a store dependency.

§error_type_path: Option<String>

Fully-qualified path to the Error type used in generated TryFrom<Resource> impls.

E.g. "crate::Error". When None, TryFrom impls are not generated.

§generate_object_conversions: bool

When true and generate_resource_enum is set, emit TryFrom<Object>/TryFrom<T> and ResourceExt impl blocks in labels.rs for all resource types that have an IDENTIFIER-annotated field, plus a qualified_name() inherent method on each resource type.

§bindings: Option<BindingsConfig>

Configuration for language-binding generation. Required when output.python, output.node, or output.node_ts is Some.

§resource_store_crate_name: String

Crate name for the resource store types used in generated RESOURCE_DESCRIPTORS.

Default: "olai_store"

§runtime: Runtime

Protobuf runtime the generated code is shaped for. See Runtime.

Defaults to Runtime::Prost for backward compatibility.

§transport_type_path: String

Fully-qualified path to the HTTP transport type that generated clients store and call.

The transport must expose the surface generated client bodies use: per-verb builder methods (get/post/patch/delete/put) returning a request builder with .json(..)/.query(..)/.send(), whose response has .status()/.bytes(). olai_http::CloudClient satisfies this.

Defaults to "olai_http::CloudClient", so native output is unchanged. A WASM/browser client points this at a lightweight reqwest-Fetch transport that has no ring/tokio dependency and lets the browser attach the session.

§dual_transport: bool

Force dual-transport client emission (the cfg-gated CloudClient/WasmClient Transport alias) even when no WASM #[wasm_bindgen] bindings output is configured. See dual_transport.

Defaults to false. Setting output.wasm also turns dual-transport on; this flag exists so a project can build the same client crate for native and wasm32 without pulling in the JS binding layer.

§client_protocols: ClientProtocols

Which client protocol layer(s) to emit. See ClientProtocols.

Defaults to REST only, so existing HTTP/JSON output is unchanged.

§connect_client_path: Option<String>

Import path of the connect-rust (BSR plugin) generated client module, used only when client_protocols includes Connect.

The generated Connect builder layer references the connect-rust client type as <connect_client_path>::{Service}Client. The path should resolve to the module that holds the per-service {Service}Client<T> structs (e.g. "headwaters_proto::connect_gen::headwaters::read::v1").

Required (non-None) whenever Connect is selected and client output is enabled; ignored for REST-only output.

§rest_client: RestClientOptions

Wire-format and error options of the REST client. See RestClientOptions.

Implementations§

Source§

impl CodeGenConfig

Source

pub fn uses_default_transport(&self) -> bool

Whether generated clients use the default cloud transport (olai_http::CloudClient).

Controls emission of cloud-specific aggregate constructors (new_unauthenticated, new_with_token), which only make sense for CloudClient. A custom transport (e.g. the WASM/browser one) gets only the generic new(transport, base_url).

Source

pub fn uses_reqwest_transport(&self) -> bool

Whether generated clients use the generated reqwest transport (REQWEST_TRANSPORT_TYPE_PATH).

Source

pub fn builds_for_wasm(&self) -> bool

Whether the generated client also builds for wasm32, where the transport’s futures are not Send, so the builders box them as Local* there.

Source

pub fn dual_transport(&self) -> bool

Whether the generated client should carry both transports, selected at compile time by cfg(target_arch = "wasm32") — CloudClient for native targets, olai_http_wasm::WasmClient for the browser.

Enabled when WASM bindings output is requested (output.wasm), or when dual_transport is set explicitly: a project that wants a browser client needs the same client crate to build both ways (native for server-side/tests, wasm32 for the frontend). Native-only projects leave both unset and keep the single transport_type_path transport with no WASM dependency.

The explicit flag decouples the transport alias from the JS binding layer: output.wasm additionally emits #[wasm_bindgen] bindings, whereas dual_transport = true alone emits only the cfg-gated Transport alias.

Source

pub fn json_int64_module_path(&self) -> Option<String>

The crate-local path of the json_int64 module (e.g. crate::models::json_int64), for ModelRewrites::int64_module. None unless RestClientOptions::json_int64_as_number is set.

Source

pub fn json_value_module_path(&self) -> Option<String>

The crate-local path of the json_value module (e.g. crate::models::json_value), for ModelRewrites::json_value_module. None unless RestClientOptions::json_int64_as_number is set.

Source

pub fn validate(&self) -> Result<()>

Validate this config without running code generation.

Checks that:

  • models_path_template and models_path_crate_template produce valid Rust paths after {service} substitution.
  • bindings is Some whenever output.python, output.node, output.node_ts, or output.wasm is Some; output.python also needs BindingsConfig::python.
  • the REST client and Python options that need other options have them.

Call this at construction time to surface misconfiguration early, before generation runs.

Trait Implementations§

Source§

impl Clone for CodeGenConfig

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CodeGenConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more