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

Add :min/:max limits to :map validator #1056

Open
irigarae opened this issue May 10, 2024 · 0 comments
Open

Add :min/:max limits to :map validator #1056

irigarae opened this issue May 10, 2024 · 0 comments

Comments

@irigarae
Copy link

Hi, I see :min and :max are not supported on :map. It would be a nice addition. It is already present in :map-of.

We had a use-case in which two fields are mandatory and 5 are optional. And at least an extra field out of the 5 optional is mandatory. In our case it would be simple to just add the :min property.

[:map {:min 3}
 [:mandatory1 :string]
 [:mandatory2 :string]
 [:optional1 {:optional true} :double]
 [:optional2 {:optional true} :double]
 [:optional3 {:optional true} :double]
 [:optional4 {:optional true} :double]
 [:optional5 {:optional true} :double]]

We solved it with [:and ,,, [:fn ,,,]] but I think the min/max make sense even if the map properties have been defined. Don't know the reason why it was not there since the beginning, but in case it was part of some decision, I think it would be nice to revisit. Number of entries is completely orthogonal to wether the keys are explicit or not.

Also, similar to :map-of the properties should be propagated to json-schema with :minProperties, :maxProperties.

Thanks

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

1 participant