glideapps / quicktype

Generate types and converters from JSON, Schema, and GraphQL

Home Page:https://app.quicktype.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Generated Rust code overrides `Option` keyword when array key is `options`

ASTRELION opened this issue · comments

Similar to #2385, generated code can still override the built-in Option type when an array field is named options in the JSON data (I'm assuming since it makes the word singular and doesn't recognize the keyword).

Example input:

{
    "options": [
        {
            "name": "test"
        },
        {
            "name": "test2",
            "foo": "bar"
        }
    ]
}

Output:

use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize)]
pub struct Test {
    options: Vec<Option>,
}

#[derive(Serialize, Deserialize)]
pub struct Option {
    name: String,
    foo: Option<String>,
}

Note the now invalid use of Option<String>