-
Notifications
You must be signed in to change notification settings - Fork 14
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
Doesn't Handle RuleSets well #2
Comments
I have the same issue - two different rule sets that are selected using the |
Yes, it currently doesn't handle RuleSets at the moment. I'm trying to think how it would be implemented. From the NSwag schema, we should be able to back into the controller/action that has the The challenge is with the swagger spec, the validation is located on the object itself and not on the endpoint, so even if we could look at the class FooController
{
[CustomizeValidatorAttribute(RuleSet="create")]
public void CreateFooAction(FooModel foo);
[CustomizeValidatorAttribute(RuleSet="update")]
public void UpdateFooAction(FooModel foo);
}
class FooModel
{} NSwag would generate an endpoint for create and update; however, the endpoints in the swagger spec would reference the same FooModel, which is where the swagger spec defines the validation requirements. "requestBody": {
"x-name": "command",
"description": "Create foo command.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/FooModel"
}
}
},
"required": true,
"x-position": 2
}, "FooModel": {
"type": "object",
"description": "Fooo Result",
"additionalProperties": false,
"required": [
"items"
],
"properties": {
"foo": {
"type": "string",
"description": "Foo",
"minLength": 1, // Validations used by both create and update actions due to object reference from action request definition
}
}, Thoughts? |
Thanks, Geoffrey, for your answer! I added two more operations to your example: class FooController
{
[CustomizeValidatorAttribute(RuleSet="create")]
public void CreateFooAction(FooModel foo);
[CustomizeValidatorAttribute(RuleSet="update")]
public void UpdateFooAction(FooModel foo);
[CustomizeValidatorAttribute(RuleSet="another,default")]
public void AnotherFooAction(FooModel foo);
[CustomizeValidatorAttribute(RuleSet="*")]
public void UltimateFooAction(FooModel foo);
}
class FooModel
{} I think it's necessary to generate multiple models/types to support different rule sets. Idea 1 Append the type name with the rule set name(s) Idea 2 Define a type for every operation that needs it Resume So will a combination of both be the best solution? Greetings from Austria! |
While the use of
RuleSets
is probably more on the edge, this doesn't quite support them. I'm getting 2 distinct signs of what validation is, but without the context of whatRuleSet
is being applied. ex.Having 2 different rulesets yields showing 2 different validations for the same property without the context which is slightly confusing. I'm looking at the code to see if I can figure out where to possibly apply this change.
The text was updated successfully, but these errors were encountered: