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

Allowing AnyOfField or OneOfField to use schema #1302

Merged
merged 1 commit into from
Jun 3, 2019

Conversation

SlashBin
Copy link
Contributor

Reasons for making this change

I have a use case where I'd like to be able to define an anyOf in the schema (for validation purposes), but still render items from the schema properties. This should be allowable if I create my own AnyOfField, but currently SchemaField doesn't pass through the schema to the custom Field.

I have a use case where I'd like to be able to define an anyOf in the schema, but still render items from the schema. This should be allowable if I create my own AnyOfField, but currently SchemaField doesn't pass through my schema.
@epicfaace
Copy link
Member

hi @SlashBin, can you show me an example of AnyofField/OneofField using a schema, and add some tests, so that I can see what exactly is the use case for this?

@epicfaace
Copy link
Member

Ok, took a look again and this makes sense. Thanks for the PR!

@epicfaace epicfaace merged commit 59f9d26 into rjsf-team:master Jun 3, 2019
@SlashBin
Copy link
Contributor Author

SlashBin commented Jun 4, 2019

Thanks for merging! Sorry I didn't see your reply earlier.

Just for posterity's sake, the use case here would be that I'd like to render an ObjectField from the properties, as normal, and rely on the anyOf only for validation on a subset of the properties.

So, as a simple (untested) example, I could have something like the following, which I believe is valid JSON Schema and AJV seems fine with. However, it requires that I render all properties and validate on the anyOf conditions. I understand that isn't necessarily supported out of the box yet, but we shouldn't preclude someone from creating their own AnyOfField that does this (by omitting schema, as SchemaField was doing)

{
	"type": "object",
	"properties": {
		"is_exempt": {
			"type": "boolean"
		},
		"overtime_hours": {
			"type": "array",
			"items": {
				"type": "number"
			}
		}

	},
	"anyOf": [{
		"properties": {
			"is_exempt": {
				"const": true
			}
		}
	}, {
		"properties": {
			"overtime_hours": {
				"minItems": 1
			}
		}
	}]
}

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

Successfully merging this pull request may close these issues.

2 participants