protoc-gen-jsonschema icon indicating copy to clipboard operation
protoc-gen-jsonschema copied to clipboard

Multiple allowed in oneOf?

Open jscheid opened this issue 1 year ago • 2 comments

Kia Ora, I have a question: why does each member of the generated oneOf specify only what's required -- doesn't it mean that multiple members are allowed (one is required but multiple allowed) which runs counter to the semantics of oneof?

For example it's generating this:

"properties": {
    "event_a": {
        "$ref": "#/definitions/EventA",
    },
    "event_b": {
        "$ref": "#/definitions/EventB",
    }
},
"oneOf": [
    {
        "required": [
            "event_a"
        ]
    },
    {
        "required": [
            "event_b"
        ]
    }
],

... but I would have expected it to generate the following instead, so that only one of event_a or event_b can be present:

"oneOf": [
    {
        "properties": {
            "event_a": {
                "$ref": "#/definitions/EventA",
            },
        },
        "required": ["event_a"]
    },
    {
        "properties": {
            "event_b": {
                "$ref": "#/definitions/EventB",
            }
        },
        "required": ["event_b"]
    }
],

jscheid avatar Feb 02 '24 16:02 jscheid

Hi @jscheid, thanks for your question. I've just merged a PR which changes the behaviour of "oneOf". Would you be able to have a go with the laster master and let me know if it addresses your concerns?

chrusty avatar Feb 12 '24 06:02 chrusty

Thanks, I'll take a look today or tomorrow!

jscheid avatar Feb 13 '24 11:02 jscheid