oxidecomputer / oxidecomputer/typify

Types with explicit defaults on required fields do not implement Default

Open
#918 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
898
Forks
114
Avg merge
4h 18m
Merged PRs (30d)
14

Description

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(),
        }
    }
}

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the provided JSON Schema example and inspecting the generated Rust Field output. Trace how explicit defaults on required properties are handled, then verify that the generated type includes a Default implementation returning addr as "default_string".

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.