Emit #[schemars(crate)] attribute#1764
Merged
Merged
Conversation
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 <[email protected]>
Contributor
Author
|
Alright, I have noticed that we have to be a little cleverer and conditionally emit the attribute only when the schema mode is |
Codecov ReportAll modified and coverable lines are covered by tests ✅
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
🚀 New features to boost your workflow:
|
Signed-off-by: Techassi <[email protected]>
Contributor
Author
|
Both CI failures seem unrelated to my change... Let me know if there is anything I need to fix. |
clux
approved these changes
May 26, 2025
Member
clux
left a comment
There was a problem hiding this comment.
Looks all very reasonable to me. Thank you!
Member
|
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. |
#[schemars(crate)] attribute
Contributor
Author
|
Thank you for the quick merge! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
The
JsonSchemaderive macro will use an incorrect import ofschemarswhich does not match the customized import via#[kube(crates(schemars = ...))]. In my case, this was undiscovered until now, because previously,schemarswas available at the top-level through a dependency declaration inCargo.toml.Solution
This PR simply adds the
#[schemars(crate = ...)]attribute to the generated CRD struct.