Skip to content

fix(stackable-versioned): Use crate override in generated code #1079

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ impl Struct {
// names.
let inserts = self.generate_tracking_inserts(direction, next_version, mod_gen_ctx);
let removals = self.generate_tracking_removals(direction, next_version, mod_gen_ctx);
let json_paths = self.generate_json_paths(next_version);
let json_paths = self.generate_json_paths(next_version, mod_gen_ctx);

// TODO (@Techassi): Re-add support for generics
// TODO (@Techassi): We know the status, so we can hard-code it, but hard to track across structs
Expand Down Expand Up @@ -288,11 +288,15 @@ impl Struct {
}
}

fn generate_json_paths(&self, next_version: &VersionDefinition) -> Option<TokenStream> {
fn generate_json_paths(
&self,
next_version: &VersionDefinition,
mod_gen_ctx: ModuleGenerationContext<'_>,
) -> Option<TokenStream> {
let json_paths = self
.fields
.iter()
.filter_map(|f| f.generate_for_json_path(next_version))
.filter_map(|f| f.generate_for_json_path(next_version, mod_gen_ctx))
.collect();

Some(json_paths)
Expand Down
12 changes: 9 additions & 3 deletions crates/stackable-versioned-macros/src/codegen/item/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,13 @@ impl VersionedField {
}
}

pub fn generate_for_json_path(&self, next_version: &VersionDefinition) -> Option<TokenStream> {
pub fn generate_for_json_path(
&self,
next_version: &VersionDefinition,
mod_gen_ctx: ModuleGenerationContext<'_>,
) -> Option<TokenStream> {
let versioned_path = &*mod_gen_ctx.crates.versioned;

match (&self.changes, self.nested) {
// If there are no changes and the field also not marked as nested, there is no need to
// generate a path variable for that field as no tracked values need to be applied/inserted
Expand All @@ -373,7 +379,7 @@ impl VersionedField {
let field_ident = format_ident!("__sv_{}_path", &self.ident.as_ident());
let child_string = &self.ident.to_string();
Some(quote! {
let #field_ident = ::stackable_versioned::jthong_path(parent, #child_string);
let #field_ident = #versioned_path::jthong_path(parent, #child_string);
})
}
(Some(changes), _) => {
Expand All @@ -385,7 +391,7 @@ impl VersionedField {
let child_string = ident.to_string();

Some(quote! {
let #field_ident = ::stackable_versioned::jthong_path(parent, #child_string);
let #field_ident = #versioned_path::jthong_path(parent, #child_string);
})
}
_ => None,
Expand Down
6 changes: 6 additions & 0 deletions crates/stackable-versioned/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

### Fixed

- Replace the hardcoded `::stackable_versioned` path in the `tracking_from` function with the configurable crate override ([#1079]).

[#1079]: https://github.com/stackabletech/operator-rs/pull/1079

## [0.8.0] - 2025-07-10

### Added
Expand Down