generate
generate copied to clipboard
Arrays of objects not supported in references
Parking this here until I (or somebody else) look into it.
Given the following JSON schema:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "House",
"type": "object",
"definitions": {
"address": {
"type": "object",
"properties": {
"number": { "type": "integer" },
"postcode": { "type": "string" }
}
},
"owners": {
"type": "array",
"items": {
"type": "object",
"title": "person",
"properties": {
"name": { "type": "string" }
}
}
}
},
"properties": {
"address": { "$ref": "#/definitions/address" },
"owners": { "$ref": "#/definitions/owners" }
}
}
The generated Owners
field is not an array.
Moving definitions directly under properties
almost* yields the expected result.
* minus the pointer symbol
Result:
// ...
// House
type House struct {
Address *Address `json:"address,omitempty"`
Owners *Person `json:"owners,omitempty"` // WRONG
// should be []*Person
}
// ...
Expected:
// ...
// House
type House struct {
Address *Address `json:"address,omitempty"`
Owners []*Person `json:"owners,omitempty"`
}
// ...
Any idea on when the fix for this will be available?
I dug in here because I thought I hit this bug, but it was a user error.
AFACIT, this works correctly now; if I put the OP code into test.schema.json
, I get the following:
➜ schema-generate test.schema.json
// Code generated by schema-generate. DO NOT EDIT.
package main
// Address
type Address struct {
Number int `json:"number,omitempty"`
Postcode string `json:"postcode,omitempty"`
}
// House
type House struct {
Address *Address `json:"address,omitempty"`
Owners []*Person `json:"owners,omitempty"`
}
// Person
type Person struct {
Name string `json:"name,omitempty"`
}