Skip to content

Conversation

@sigent
Copy link
Contributor

@sigent sigent commented Jun 28, 2018

Closes #252

FEATURE

Addressing Breaking Change - As there are no implicit Validation providers in MVC core, you need to explicitly add validation to the pipeline e.g. services.AddMvcCore().AddDataAnnotations()
Without this ModelState should always be valid.

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<VersionPrefix>2.3.2</VersionPrefix>
<VersionPrefix>2.3.3</VersionPrefix>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if this should be a major version bump. It could break existing apps if they have annotations but aren't currently checking them. We could release this as a patch version behind a feature flag (e.g. options.ValidateModelState) with a default disabled value. Then in the next major release enable it by default. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could argue that if they have annotations already on their entities, then its already invalid and it's now being flagged. However, the feature flag route makes sense for a minor release :-D

Made the changes


if (!_jsonApiContext.Options.AllowClientGeneratedIds && !string.IsNullOrEmpty(entity.StringId))
return Forbidden();
if (!ModelState.IsValid) return BadRequest(ModelState.ConvertToErrorCollection());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: return on newline

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha no problem

ErrorCollection errors = new ErrorCollection();
foreach (var entry in modelState)
{
if (!entry.Value.Errors.Any()) continue;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: continue on newline

Copy link
Contributor

@jaredcnance jaredcnance left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Just some minor comments on style (need a xplat style checker 🤔) and a note on versioning.

@jaredcnance jaredcnance merged commit 390db09 into json-api-dotnet:master Jun 28, 2018
jaredcnance added a commit that referenced this pull request Aug 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants