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

Why does a simple element in xsd result in an object in the json schema? #63

Open
smhdfdl opened this issue Jan 26, 2016 · 4 comments
Open
Assignees
Labels
Milestone

Comments

@smhdfdl
Copy link

smhdfdl commented Jan 26, 2016

Example:

`<xsd:element name="MobileAppVer" nillable="true" minOccurs="0" type="xsd:string"/>`

Gives the following. Why is "type" an object and not just the value type:

                    `"mobileAppVer":{
                        "title":"mobileAppVer",
                        "allOf":[
                            {
                                "type":"object",
                                "properties":{
                                    "name":{
                                        "$ref":"http://www.jsonix.org/jsonschemas/w3c/2001/XMLSchema.jsonschema#/definitions/QName"
                                    },
                                    "value":{
                                        "$ref":"http://www.jsonix.org/jsonschemas/w3c/2001/XMLSchema.jsonschema#/definitions/string"
                                    }
                                },
                                "elementName":{
                                    "localPart":"MobileAppVer",
                                    "namespaceURI":""
                                }
                            }
                        ],
                        "propertyType":"elementRef",
                        "elementName":{
                            "localPart":"MobileAppVer",
                            "namespaceURI":""
                        }
                    },`

And for an xsd with no target namespace why is the localPart & namespaceURI needed?

@highsource
Copy link
Owner

Because of the nillable="true". The underlying schema compiler, XJC uses an "element reference" property instead of an "element" property in this case.

You can either remove nillable="true" from the schema or use the jaxb2-simplify-plugin to "simplify" this property as element property. If you need support with this, please commit a (simples possible) test project under https://github.com/highsource/jsonix-support and I'll help you with bindings/configs to make this property simple.

@highsource highsource added this to the 2.3.x milestone Jan 27, 2016
@highsource highsource self-assigned this Jan 27, 2016
@highsource
Copy link
Owner

And for an xsd with no target namespace why is the localPart & namespaceURI needed?

Depends what you are referring to. Jsonix Schema Compiler generates Jsonix Mappings and JSON Schema.

JSON Schema is experimental. It contains a few properties which are not standard JSON Schema properties (like elementName). So since it's not standard, not evaluated by the JSON Schema processors anyway and just added for reference/info/debug purposes, I'm just ouputting it as is.

In the Jsonix Mappings you get string if namespace matches the default namespace and an object with local name and namespace URI if it does not match. So if you have such a structure in the Jsonix Mappingsm, check your defaultElementNamespace.

Default element namespace is calculated based on the most popular namespace of your elements.

@smhdfdl
Copy link
Author

smhdfdl commented Jan 27, 2016

Thanks - I changed to nillable="false" and now I get:

"isDeleted":{ "title":"isDeleted", "allOf":[ { "$ref":"http://www.jsonix.org/jsonschemas/w3c/2001/XMLSchema.jsonschema#/definitions/boolean" } ], "propertyType":"element", "elementName":{ "localPart":"IsDeleted", "namespaceURI":"" } },

This is much closer to what I need. Two issues:

  1. The property name has been given a lower-case starting letter. I need the original case preserved and all my properties start with upper-case. Is that something that can be changed or made an option?

  2. When the allOf array contains a single item, is it possible to flatten it so type: $ref:... appears instead?

With 1) and 2) fixed the output would be:

"IsDeleted":{ "title":"IsDeleted", "type": { "$ref":"http://www.jsonix.org/jsonschemas/w3c/2001/XMLSchema.jsonschema#/definitions/boolean" }, "propertyType":"element", "elementName":{ "localPart":"IsDeleted", "namespaceURI":"" } },

@highsource
Copy link
Owner

  1. Would be nice but is not supported at the moment. I use property names as generated by XJC. File an issue, but I can't promise the implementation too soon.

  2. No, you can't combine $ref with other things, see:

http://stackoverflow.com/questions/29841175/is-it-allowed-to-combine-ref-with-other-keywords-in-json-schema

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

No branches or pull requests

2 participants