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

@Valid is not being added to an arrays of objects that are defined using a $ref #97

Closed
joelittlejohn opened this issue Jun 23, 2013 · 3 comments
Milestone

Comments

@joelittlejohn
Copy link
Owner

Original author: b...@hotmail.com (April 01, 2013 20:26:10)

@Valid is not being added to an array of objects that have been defined using a $ref parameter to reference the definition.

Here is a simplified version of the schema in question.

{
"id": "http://www.foo.com/schema",
"$schema": "http://json-schema.org/draft-03/schema#",
"type": "object",
"properties": {
"id" : {
"type": "string"
},
"products": {
"type": "array",
"required": true,
"minItems": 1,
"items": { "$ref": "#definitions/product" },
"uniqueItems": true
}
},
"additionalProperties": false,
"definitions": {
"product": {
"type": "object",
"required": [ "productId" ],
"properties": {
"productId": {
"type": "string",
"pattern": "^\d{6}$"
}
},
"additionalProperties": {
"type": "string"
}
}
},
"links":[
{
"rel": "self",
"href": "{id}"
}, {
"rel": "parent",
"href": "{parent_id}"
}
]
}

My output for the products is this:
/**
*
* (Required)
*
*/
@JsonProperty("products")
@NotNull
@SiZe(min = 1)
private Set<Product> products = new HashSet<Product>();

If this had been defined using the definition in place, it will work correctly:

    &quot;products&quot;: {
        &quot;type&quot;: &quot;array&quot;,
        &quot;required&quot;: true,
        &quot;minItems&quot;: 1,
        &quot;items&quot;: {
            &quot;type&quot;: &quot;object&quot;,
            &quot;required&quot;: [ &quot;productId&quot; ],
            &quot;properties&quot;: {
                &quot;productId&quot;: {
                    &quot;type&quot;: &quot;string&quot;,
                    &quot;pattern&quot;: &quot;^\\d{6}$&quot;
                }
            },
            &quot;additionalProperties&quot;: {
                &quot;type&quot;: &quot;string&quot;
            }
        },
        &quot;uniqueItems&quot;: true
    }

/**
 * 
 * (Required)
 * 
 */
@JsonProperty(&quot;products&quot;)
@NotNull
@Size(min = 1)
@Valid
private Set&lt;Product&gt; products = new HashSet&lt;Product&gt;();

I would expect to be able to get @Valid on the array of objects no matter whether I was using a reference or extending the schema.

I am using version 0.3.6 with Java version 1.6.0_20

If I had to guess the cause, I would look at

Revision: e6415a0
/jsonschema2pojo-core/src/main/java/com/googlecode/jsonschema2pojo/rules/PropertyRule.java

private boolean isArrayOfObjects(JsonNode node)

It doesn't appear to be resolving any referenced or extended schema's before determine if it is an array of objects or not.

Original issue: http://code.google.com/p/jsonschema2pojo/issues/detail?id=97

@joelittlejohn
Copy link
Owner Author

From b...@hotmail.com on April 01, 2013 21:00:38
Apologies for mixing my draft-03 and draft-04 required syntax. It doesn't affect the outcome however.

@joelittlejohn
Copy link
Owner Author

From joelittl...@gmail.com on April 05, 2013 16:35:59
Hi Brenton. Thanks for taking the time to raise this with complete examples. I think your diagnosis is correct :)

I fixed another, similar problem in 0.3.6 and I'm sure there are more. We really need to switch to a process where all these references are resolved before type generation starts. I'm going to try and prove this solution and I'll make sure that one way or another this is fixed in 0.3.7.

@joelittlejohn
Copy link
Owner Author

From joelittl...@gmail.com on June 19, 2013 23:33:35
Fixed and will be released in 0.3.7.

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

No branches or pull requests

1 participant