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

document union types support #138

Closed
ransomw opened this issue Jan 11, 2014 · 3 comments
Closed

document union types support #138

ransomw opened this issue Jan 11, 2014 · 3 comments

Comments

@ransomw
Copy link

ransomw commented Jan 11, 2014

thanks for this library. i think it has the potential to save a lot of people a lot of time.

this is an issue for the documentation rather than the code. i see there's partial support for union types, but the following snippet

"time": {
        "type": "object",
        "oneOf": [
                {
                        "description": "single class",
                        "properties": {
                                "date": {
                                        "description": "",
                                        "type": "string",
                                        "format": "date-time"
                                },
                                "start_time": {
                                        "description": "",
                                        "type": "string",
                                        "format": "date-time"
                                },
                                "end_time": {
                                        "description": "",
                                        "type": "string",
                                        "format": "date-time"
                                }
                        },
                        "required": ["date", "start_time", "end_time"],
                        "additionalProperties": false
                },
                {
                        "description": "weekly repeat",
                        "properties": {
                                "day_of_week": {
                                        "type": "integer",
                                        "minimum": 0,
                                        "maximum": 6
                                },
                                "start_time": {
                                        "description": "",
                                        "type": "string",
                                        "format": "date-time"
                                },
                                "end_time": {
                                        "description": "",
                                        "type": "string",
                                        "format": "date-time"
                                }
                        },
                        "required": ["day_of_week", "start_time", "end_time"],
                        "additionalProperties": false
                }
        ]
},

produces a Time class with no data elements.

@joelittlejohn
Copy link
Owner

Thanks for raising this. jsonschema2pojo doesn't actually support draft04 so oneOf is currently ignored. All the generator sees is:

"time": {
        "type": "object"
}

which is why you get class with no data elements.

You're right about the documentation though, we should add something to explain what partial support actually means. On reflection, I might actually change 'Partial' to 'None' for union types as I think it might be misleading. jsonschema2pojo does not explode when it sees a union type, it simply chooses the first type it finds. If you have a schema that includes union types but you still (for whatever reason) find it useful to generate some Java from it, then jsonschema2pojo won't break when you try.

I'm interested to know whether this is a problem for you right now. Are you able to using some other manual workaround here? (e.g. merging the fields or hand-coding this specific type).

@ransomw
Copy link
Author

ransomw commented Jan 15, 2014

i wound up hand-coding it. and simplifying the data model.

there's an android client and a play framework server, so keeping the data model definitions in java isn't so bad (for now) as it's a very small project. also, hand-coding allows for inner public static classes, which is helpful both for uncluttered namespaces and for use with gson.

so yeah, just whatever on this issue. #125 is a good idea, though, as is #127. writing Parcelable decorators is getting pretty boring.

@joelittlejohn
Copy link
Owner

I've updated the docs from 'Partial' to 'No' as I think this expresses the current situation more accurately.

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

2 participants