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

Ensure that ValidationIssue.Field respects [JsonPropertyName] #113

Merged
merged 4 commits into from
Dec 13, 2022

Conversation

ivarne
Copy link
Member

@ivarne ivarne commented Dec 13, 2022

When there is a mismatch between the C# property name and the [JsonPropertyName()]
image
And one of the nested [System.ComponentModel.DataAnnotations] rules fails, the Field property of ValidationIssue is wrong, and frontend can't attach the error to the correct component.

Description

Some xsd definitions contain property names with illegal characters that can't be used in properties (without ugly escaping)

To solve that conflict, additional properties is added for json and xml serialziation to include the illegal characters. This needs to be respected everywhere.

In net70, this is easily fixed with a configuration change, https://learn.microsoft.com/en-us/aspnet/core/mvc/models/validation?view=aspnetcore-7.0#use-json-property-names-in-validation-errors, but in net60, we need to manually translate the keys.

Related Issue(s)

  • not sure if this has previously been reported.

Verification

  • Your code builds clean without any errors or warnings
  • Manual testing done (required)
  • Relevant automated test added (if you find this hard, leave it and we'll help out)
  • All tests run green

Documentation

  • User documentation is updated with a separate linked PR in altinn-studio-docs. (if applicable)

Some xsd definitions contain property names with illegal characters
that can't be used in properties (without ugly escaping)

To solve that conflict, additional properties is added for json and xml
serialziation to include the illegal characters. This needs to be respected
everywhere.

In net70, this is easily fixed with a configuration change,
https://learn.microsoft.com/en-us/aspnet/core/mvc/models/validation?view=aspnetcore-7.0#use-json-property-names-in-validation-errors,
but in net60, we need to manually translate the keys.
@tjololo tjololo added external-contribution-❤️ Pull request from a developer outside the Altinn teams. bugfix Label Pull requests with bugfix. Used when generation releasenotes labels Dec 13, 2022
@tjololo tjololo self-assigned this Dec 13, 2022
Copy link
Member

@tjololo tjololo left a comment

Choose a reason for hiding this comment

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

We should change the signature of MapModelStateToIssueList to only require the Type of the data object as we don't need anything else in the method

src/Altinn.App.Core/Features/Validation/ValidationAppSI.cs Outdated Show resolved Hide resolved
@ivarne
Copy link
Member Author

ivarne commented Dec 13, 2022

@tjololo Totally agree ❤️
I just initially thought the logic would be dependent on the value, not just the type, and then I fixed it for only one level up.

Copy link
Member

@tjololo tjololo left a comment

Choose a reason for hiding this comment

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

Looks good 👍

@tjololo tjololo merged commit 13c31f6 into Altinn:main Dec 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix Label Pull requests with bugfix. Used when generation releasenotes external-contribution-❤️ Pull request from a developer outside the Altinn teams.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants