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

OneOf playground sample with maxLength generating wrong validation message #4427

Open
4 tasks done
DharamveerYadav opened this issue Dec 19, 2024 · 2 comments
Open
4 tasks done
Labels
any-one-all-of Related to fixing anyOf, oneOf or allOf question validation

Comments

@DharamveerYadav
Copy link

DharamveerYadav commented Dec 19, 2024

Prerequisites

What theme are you using?

core

Version

5.x

Current Behavior

Using sample JSON for oneOf given on RJSF playground,

{
	"type": "object",
	"oneOf": [
		{
			"properties": {
				"lorem": {
					"type": "string",
					"maxLength": 50
				}
			},
			"required": [
				"lorem"
			]
		},
		{
			"properties": {
				"ipsum": {
					"type": "string",
					"maxLength": 50
				}
			},
			"required": [
				"ipsum"
			]
		}
	]
}

I have just inserted maxLength attribute to both of the properties to validate the max length.

validation message thrown is:
image

Expected Behavior

It should throw only : "must NOT have more than 50 characters".

Should not throw : "must match exactly one schema in oneOf".

Steps To Reproduce

try above mentioned JSON schema on rjsf playground and validate the form

Environment

- OS:
- Node:
- npm:

Anything else?

(https://rjsf-team.github.io/react-jsonschema-form/)

@DharamveerYadav DharamveerYadav added bug needs triage Initial label given, to be assigned correct labels and assigned labels Dec 19, 2024
@DharamveerYadav
Copy link
Author

Any update on this

@nickgros
Copy link
Contributor

@DharamveerYadav The validator implementation, AJV, just looks at your form data and it has no idea that you picked option 2, so it validates against option 1. You could refactor your schema to make your form data include the option type using conditionals or a discriminator. You can find some more information in #4252, where another person had the same issue.

@nickgros nickgros added question any-one-all-of Related to fixing anyOf, oneOf or allOf validation and removed bug labels Jan 17, 2025
@heath-freenome heath-freenome removed the needs triage Initial label given, to be assigned correct labels and assigned label Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
any-one-all-of Related to fixing anyOf, oneOf or allOf question validation
Projects
None yet
Development

No branches or pull requests

3 participants