Skip to content

Types with explicit defaults on required fields do not implement Default #918

@jasperswallen

Description

@jasperswallen

MRE:

Schema:

{
  "definitions": {
    "Field": {
      "type": "object",
      "properties": {
        "addr": {
          "type": "string",
          "default": "default_string"
        }
      },
      "required": [
        "addr"
      ]
    }
  }
}

Generates:

#[derive(:: serde :: Deserialize, :: serde :: Serialize, Clone, Debug)]
pub struct Field {
    pub addr: ::std::string::String,
}
impl ::std::convert::From<&Field> for Field {
    fn from(value: &Field) -> Self {
        value.clone()
    }
}

However, there should be another impl on Field:

impl Default for Field {
    fn default() -> Self {
        Self {
            addr: "default_string".to_string(),
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions