Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arrays of objects not supported in references #39

Open
antoineco opened this issue Mar 26, 2018 · 2 comments
Open

Arrays of objects not supported in references #39

antoineco opened this issue Mar 26, 2018 · 2 comments

Comments

@antoineco
Copy link
Contributor

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"`
}

// ...
@WTIGER001
Copy link

Any idea on when the fix for this will be available?

@ClaytonJY
Copy link

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"`
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants