jsontypedef / json-typedef-codegen

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

Go: support for explicit embedded structs #74

Open BatmanAoD opened 1 year ago

BatmanAoD commented 1 year ago

I would like to generate a Go struct where some of the fields are "embedded" in another struct:

type Inner struct {
    Foo string `json:"foo"`
    Bar string `json:"bar"`
}

type SharedType struct {
    Inner

    Baz string `json:"baz"`
}

This is marshaled and unmarshaled as:

{
    "foo": "<data>",
    "bar": "<data>",
    "baz": "<data>"
}

Would it be feasible to add Go-specific medadata to enable codegen like this? Something like:

{
  "properties": {
    "foo": {
      "metadata": {
        "goEmbedded": "Inner"
      },
      "type": "string"
    },
    "bar": {
      "metadata": {
        "goEmbedded": "Inner"
      },
      "type": "string"
    },
    "baz": {
      "type": "string"
    },
  }
}