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

Incomplete type definition for array/Collection properties #45

Open
cowtowncoder opened this issue Sep 2, 2014 · 9 comments
Open

Incomplete type definition for array/Collection properties #45

cowtowncoder opened this issue Sep 2, 2014 · 9 comments

Comments

@cowtowncoder
Copy link
Member

NOTE: cleaved off of #34


This bug seems not to be completely fixed. It doesn't throw a NPE anymore, but it doesn't generate the schema correctly either. It just generates:

{
    "type":"array"
}

I extended the test to use a collection of nested beans, and expected to see the schema of the nested items, e.g.:

    {
      "type" : "array",
      "items" : {
        "type" : "object",
        "properties" : {
          "property1" : {
            "type" : "integer"
          },
          "property2" : {
            "type" : "string"
          }
        }
      }
    }

See updated test: greyfairer@2a9b859

@mariepaulsen-sersol
Copy link

What's the status of this? From my experience, it looks like I can successfully create a schema from an object and then turn that into a json string, but then if I use an ObjectMapper to turn that back into a JsonSchema, all of my arrays get messed up. That's a big problem for me.

Is there anything I can do to help fix this or make the fix happen sooner?

@cowtowncoder
Copy link
Member Author

I haven't had time to work on Schema module lately, so any help would be appreciated.
Oftentimes the problem is in databind module, since most information is sent by JsonSerializer that handles the property. It is also possible that information piped through BeanPropertyWriter is incomplete. And of course, finally, it is also possible that JSON Schema visitors could be omitting something; but more commonly it is incoming metadata that is incomplete.

@mariepaulsen-sersol
Copy link

I'm afraid I'm not familiar enough with the code to fix it myself :-(
I did a bit of debugging and comparing, and it certainly seemed like the two JsonSchemas (the original, and the one created from its string output) were different from each other and the second one had the oversimplified array items. So it seems to me that the problem is somewhere in converting the String to a JsonSchema, not in analyzing that JsonSchema.

Best guess is that the problem is in the com.fasterxml.jackson.module.jsonSchema.types.ArraySchema file, in Items.jsonCreator. I see a comment in there about another bug too.

@cowtowncoder
Copy link
Member Author

@mariepaulsen-sersol I'll go and have a look at the updated tests; sometimes there are easy fixes to be found.

@mariepaulsen-sersol
Copy link

Oh . . . you were talking about serializing, I think the problem is in the deserialization of a schema json string into a JsonSchema object. My sequence:

        ObjectMapper mapper = new ObjectMapper();
        SchemaFactoryWrapper visitor = new SchemaFactoryWrapper();
        mapper.acceptJsonFormatVisitor(mapper.constructType(Foo.class), visitor);
        JsonSchema schema = visitor.finalSchema();
        String schemaString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(schema);
        log.debug(schemaString);
  1. Copy/paste that resulting string into a file. It seems to me (I'm not really experienced in this though) that the json at this point is correct. Here's a part of it:
        "foo" : {
            "type" : "array",
            "items" : {
                "type" : "object",
                "id" : "urn:jsonschema:com:company:project:stuff:Bar",
                "properties" : {
                    "baz" : {
                        "type" : "string"
                    }
                }
            }
        }
  1. (I debug in the middle of this, and discover that secondSchema looks like its structure is missing a bunch of definitions, just has plain-looking "object" items in a lot of places).
        ObjectMapper objectMapper = new ObjectMapper();
        JsonSchema secondSchema = objectMapper.readValue(Experiment.class.getResource("/schema.json"), JsonSchema.class);
        ObjectMapper secondMapper = new ObjectMapper();
        String secondSchemaString = secondMapper.writerWithDefaultPrettyPrinter().writeValueAsString(secondSchema);
        log.debug(secondSchemaString);
  1. Then I look at the secondSchemaString and compare it with the original. Here's that same section:
        "foo" : {
            "type" : "array",
            "items" : {
                "type" : "object",
            }
        }

@cowtowncoder
Copy link
Member Author

Ah. This may be different from the original problem then, which was wrt to generation of schema.
I wouldn't be surprised if there were issues with deserialization, as much less effort has been put there.
I'll see if I can figure out the problem, regardless; schema should deserialize back without losing content.

@fkrauthan
Copy link

Any news on this problem? I run into the same issue if it try to parse a ArraySchema all getItems() property fields are null. I am using version 2.6.1

@dazraf
Copy link

dazraf commented Feb 8, 2018

Hi, any progress with this? It's a notable gap in functionality.

@cowtowncoder
Copy link
Member Author

@dazraf This modules does not have maintainer, and unless someone steps up it will probably be dropped from FasterXML repo for 3.0. There are better generators out there.

But if anyone wants to do a PR I can help merge.

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

4 participants