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

anyOf fields with empty required arrays are treated as required #919

Closed
alexkreidler opened this issue Apr 1, 2021 · 2 comments · Fixed by #936
Closed

anyOf fields with empty required arrays are treated as required #919

alexkreidler opened this issue Apr 1, 2021 · 2 comments · Fixed by #936
Assignees
Labels
Type: Bug Bug reports and their fixes
Milestone

Comments

@alexkreidler
Copy link

alexkreidler commented Apr 1, 2021

I have a JSON Schema:

"TextBaseline": {
    "anyOf": [
        {
            "const": "alphabetic",
            "type": "string"
        },
        {
            "$ref": "#/definitions/Baseline"
        },
        {
            "const": "line-top",
            "type": "string"
        },
        {
            "const": "line-bottom",
            "type": "string"
        }
    ]
}

Which becomes

"TextBaseline": {
    "anyOf": [
        {
            "const": "alphabetic",
            "type": "string"
        },
        {
            "enum": [
                "top",
                "middle",
                "bottom"
            ],
            "type": "string"
        }
        {
            "const": "line-top",
            "type": "string"
        },
        {
            "const": "line-bottom",
            "type": "string"
        }
    ]
}

and then the compiled schema becomes:

{
    "anyOf": [
        {
            "const": "alphabetic",
            "type": "string"
        },
        {
            "enum": [
                "top",
                "middle",
                "bottom"
            ],
            "type": "string"
        },
        {
            "const": "line-top",
            "type": "string"
        },
        {
            "const": "line-bottom",
            "type": "string"
        }
    ],
    "properties": {},
    "required": [],
    "type": "string",
    "isRequired": false
}

Now a string Field is rendered, but with the property required set to an empty array. Surprisingly, this results in the field being required.

The interface shows the required asterisk, and I cannot submit the form because it doesn't validate.

uniforms_required
uniforms_devtools

Please fix so an empty array means the field is not required.

Thanks for this great library!

@alexkreidler alexkreidler changed the title Random anyOf fields are treated as required anyOf fields with empty required arrays are treated as required Apr 1, 2021
@radekmie radekmie self-assigned this Apr 6, 2021
@radekmie radekmie added the Type: Bug Bug reports and their fixes label Apr 6, 2021
@radekmie
Copy link
Contributor

radekmie commented Apr 6, 2021

Hi @alexkreidler. I see where the problem is (field receives required: []), but I'm not sure how to proceed here. Technically, required should be ignored for non-objects. Maybe changing this condition to include non-booleans would be enough. If you'd like to, give it a try. If not, we'll look into it.

@alexkreidler
Copy link
Author

Thanks, that's very helpful.

I'll try that change out within this week hopefully. I'll report back here if it works, then maybe send a PR.

@radekmie radekmie assigned Monteth and unassigned radekmie Apr 21, 2021
radekmie pushed a commit that referenced this issue Apr 22, 2021
@radekmie radekmie added this to the v3.4 milestone Apr 22, 2022
@radekmie radekmie moved this to Closed in Open Source Nov 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Bug reports and their fixes
Projects
Archived in project
3 participants