-
-
Notifications
You must be signed in to change notification settings - Fork 15
[Merged by Bors] - Config fragment/validation #445
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
Conversation
A slightly different take of #425, which uses the existing Atomic infra and some trait magic to determine "complex" types. It also tries to provide nice error messages for validation failures.
There is an example conversion of zookeeper-operator: stackabletech/zookeeper-operator#530 |
This should help improve consistency with serde and derivative
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor comments/questions aimed at clarifying things.
Co-authored-by: Andrew Kenworthy <[email protected]>
This depends on GREsau/schemars#167 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm.
(q: should we refer to a tag rather than a branch - feature/custom-bound
- for schemars_derive
? Or is that going to remain static until the change is merged upstream?)
No, we should probably hold off on merging this until their branch is merged and released. |
OK. |
@adwk67 Are we ok merging this now? |
yes, fine by me. |
bors r+ |
## Description This is an alternate take on #425. Essentially, we define a new macro `Fragment`, which creates a "parallel fragment universe" where everything is optional. For example, given the following types: ```rust #[derive(Fragment)] struct Outer { foo: u32, inner: Inner, } #[derive(Fragment)] struct Inner { required: String, optional: Option<String>, } ``` we generate the following fragment variants: ```rust struct OuterFragment { foo: Option<u32>, inner: InnerFragment, // not an atomic type, so make every subfield optional instead } struct InnerFragment { required: Option<String>, // was non-optional, so make it optional optional: Option<String>, // was already optional, so preserve the type } ``` as well as validation functions that turn `OuterFragment` into `Result<Outer>` (and an equivalent for `Inner`), while giving us the full context when a validation error occurs. This allows us to safely deserialize and merge the fragment variants, and only afterwards validate that all required options are present in the final merged configuration. This is a pretty big and breaking change, since it moves all `Serialize` and `Deserialize` impls on the resources into the fragment variants. Co-authored-by: Teo Klestrup Röijezon <[email protected]>
Pull request successfully merged into main. Build succeeded: |
Looks like the merge went slightly awry...
## Description Looks like the merge went slightly awry... Co-authored-by: Teo Klestrup Röijezon <[email protected]>
Description
This is an alternate take on #425. Essentially, we define a new macro
Fragment
, which creates a "parallel fragment universe" where everything is optional. For example, given the following types:we generate the following fragment variants:
as well as validation functions that turn
OuterFragment
intoResult<Outer>
(and an equivalent forInner
), while giving us the full context when a validation error occurs.This allows us to safely deserialize and merge the fragment variants, and only afterwards validate that all required options are present in the final merged configuration.
This is a pretty big and breaking change, since it moves all
Serialize
andDeserialize
impls on the resources into the fragment variants.Review Checklist
Once the review is done, comment
bors r+
(orbors merge
) to merge. Further information