Skip to content

Conversation

Techassi
Copy link
Contributor

@Techassi Techassi commented May 26, 2025

Motivation

The JsonSchema derive macro will use an incorrect import of schemars which does not match the customized import via #[kube(crates(schemars = ...))]. In my case, this was undiscovered until now, because previously, schemars was available at the top-level through a dependency declaration in Cargo.toml.

Solution

This PR simply adds the #[schemars(crate = ...)] attribute to the generated CRD struct.

This fixes errors which occur when the schemars crate is not
available at the top level (at (::)schemars). This is the case
when users use custom imports via #[kube(crates(schemars))].
The JsonSchema derive macro then wrongly uses the top-level
import. Adding this attribute will instruct JsonSchema to use
the correct custom import instead.

Signed-off-by: Techassi <git@techassi.dev>
@Techassi
Copy link
Contributor Author

Techassi commented May 26, 2025

Alright, I have noticed that we have to be a little cleverer and conditionally emit the attribute only when the schema mode is Derived.

Copy link

codecov bot commented May 26, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 76.5%. Comparing base (83f5fe8) to head (864738a).
Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##           main   #1764      +/-   ##
=======================================
+ Coverage      0   76.5%   +76.5%     
=======================================
  Files         0      84      +84     
  Lines         0    7893    +7893     
=======================================
+ Hits          0    6032    +6032     
- Misses        0    1861    +1861     
Files with missing lines Coverage Δ
kube-derive/src/custom_resource.rs 84.2% <100.0%> (ø)

... and 83 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Signed-off-by: Techassi <git@techassi.dev>
@Techassi
Copy link
Contributor Author

Both CI failures seem unrelated to my change... Let me know if there is anything I need to fix.

@Techassi Techassi marked this pull request as ready for review May 26, 2025 14:46
Copy link
Member

@clux clux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks all very reasonable to me. Thank you!

@clux clux added the changelog-fix changelog fix category for prs label May 26, 2025
@clux clux added this to the 1.1.0 milestone May 26, 2025
@clux
Copy link
Member

clux commented May 26, 2025

Integration test failure (clearly unrelated) seems to have become flaky somehow. The latter* test failure is my own fault for dropping openssl support in muslrust :/

Merging and fixing up CI after.

@clux clux merged commit e82f2db into kube-rs:main May 26, 2025
32 of 37 checks passed
@clux clux changed the title fix(derive): Emit schemars crate attribute Emit #[schemars(crate)] attribute May 26, 2025
@Techassi Techassi deleted the fix/schemars-crate-override branch May 28, 2025 06:46
@Techassi
Copy link
Contributor Author

Thank you for the quick merge!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog-fix changelog fix category for prs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants