kopium icon indicating copy to clipboard operation
kopium copied to clipboard

handle default field

Open clux opened this issue 3 years ago • 1 comments

Problem

Some schemas can set explicit default: replace to define what defaults are, but we will always just output #[serde(default)] on non-required properties.

Solution

Add an OutputImpls struct and collect things like impl Default for MemberStruct that will ensure #[serde(default)] works and takes into account the correct default values. This is especially important for enums where no default can be derived.

EDIT: This must also handle enums.

clux avatar May 02 '22 19:05 clux

We actually won't need to impl Default for SomeEnum for enums because of the rust 1.62 feature allowing us to do:

#[derive(Default)]
enum Maybe<T> {
    #[default]
    Nothing,

    Something(T),
}

i.e. we just need pushing "#[default]" to the m.extra_annot vec

clux avatar Mar 11 '23 07:03 clux