oxidecomputer / oxidecomputer/typify

Use serde deserialization instead of constructor for defaults

Open
#902 1 comment 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

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

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 schema shown in the issue and inspect the generated defaults module for the allOf reference. Verify that the generated default compiles and deserializes the value for MyStruct rather than calling a constructor.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.