Skip to content

Use serde deserialization instead of constructor for defaults #902

@PolyProgrammist

Description

@PolyProgrammist

For the following schema:

"field": {
    "allOf": [
        {
            "$ref": "#/components/schemas/MyStruct"
        }
    ],
    "default": "0",
},

The part of generated code is:

...
pub mod defaults {
    pub(super) fn object_field() -> super::MyStruct {
        super::MyStruct("0".to_string())
    }
}
...

It can be, there is no constructor for MyStruct which accepts string.

So it's better to use serde deserialization rather than using constructor

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions