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

ModelState.IsValid is false when a required property is missing #62

Open
JanneLouw opened this issue Mar 18, 2024 · 2 comments
Open

ModelState.IsValid is false when a required property is missing #62

JanneLouw opened this issue Mar 18, 2024 · 2 comments

Comments

@JanneLouw
Copy link

As this could be considered a breaking change, maybe initially this behaviour should be opt-in.

builder.Add***JsonMergePatch(o => o.InheritRequirementsFromModel = false)

Setting this to false should result in ModelState.IsValue to be true when the only issue is that not all required properties are present in the request body.

To me it would be more logical that eventually this is the default, although the current behaviour could be useful to have in some specific situations, so the option switch seems the best way.

@JanneLouw
Copy link
Author

It's a known issue in the ReadMe. Shouldn't it be an Issue here?

The way I see it the whole point of using the JsonMergePatchDocument is to have patches that don't have to supply values for properties that aren't being changed, so to me this defeats the purpose. I don't want to have the properties on my models be nullable if they always (should) have values.

@Morcatko
Copy link
Owner

I don't think this could work, There is always a whole model in memory and the validator does not know which properties are set. Also Required is not the only attribute.

Anyway if you think you can make it work then feel free to make a PR

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

2 participants