jsontypedef / json-typedef-codegen

A CLI tool that generates code from JSON Typedef schemas
https://jsontypedef.com/docs/tools/jtd-codegen
MIT License
154 stars 31 forks source link

Rust code generated can't be compiled when there is recursive type #40

Open xli opened 2 years ago

xli commented 2 years ago

example:

{
    "definitions": {
        "node": {
            "properties": {
                "child": {"ref": "node"}
            }
        }
    },
    "properties": {
        "root": {
            "ref": "node"
        }
    }
}

generated code

use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize)]
pub struct Jtd {
    #[serde(rename = "root")]
    pub root: Node,
}

#[derive(Serialize, Deserialize)]
pub struct Node {
    #[serde(rename = "child")]
    pub child: Node,
}

should be boxed

pub child: Box<Node>
ucarion commented 2 years ago

Are there any JSON documents that satisfy the schema in question? I'm not sure this project has a stance on what to generate for uninstantiable schemas. Perhaps a bit more context on your problem would help inform what jtd-codegen ought to do.

ucarion commented 2 years ago

Closed by accident. Sorry.