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

Feature/customer main #14

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Feature/customer main #14

wants to merge 6 commits into from

Conversation

Wellingtonbsjr
Copy link

@Wellingtonbsjr Wellingtonbsjr commented Nov 2, 2022

Summary

  • Create method WithRuleType in validation, to set type property in response.
  • Change lib to response validation rules with a specific response format, implementing your owner InvalidModelStateResponseFactory.
  • To use this lib, just need to set AddModelValidationAsyncActionFilter in Startup.cs

How to use method WithRuleType in validation?

RuleFor(x => x.Text)
                .NotEmpty()
                .WithMessage("Text can't be null")
                .WithRuleType("SOME_RULE");

How response stay?

{
    "error": {
        "Cnpj": [
            "O CNPJ do cliente é obrigatório"
        ]
    },
    "type": "SOME_RULE"
}

Why use it?
To identify Rules in InvalidModelStateResponseFactory and customize the HTTP response.
Just need to set AddModelValidationAsyncActionFilter in the Startup.cs

      services.AddControllers()
                .AddModelValidationAsyncActionFilter(options => options.OnlyApiController = true)

@sonarcloud
Copy link

sonarcloud bot commented Nov 2, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

Copy link

@nunorelvao nunorelvao left a comment

Choose a reason for hiding this comment

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

👍

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

Successfully merging this pull request may close these issues.

4 participants