-
Notifications
You must be signed in to change notification settings - Fork 6k
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
[csharp] Mustache templates do not distinguish generated and native parent classes #7669
Comments
Could anyone please clarify if there is a known fix for this issue? thank you. |
@wickedw You can use the csharp-dotnet2 client code generator. Although it does not respect request content-types, the created code is easy to fix. |
I get an error similar to this on swagger codegen v3 cli. My OpenAPI spec is OpenAPI v 3.0.0. I don't use any additionalProperties, but I do have a few anyOf, allOf's. It appears that this ValidationContext function only shows up where my OpenAPI spec used anyOf. |
Same problem |
Same here. C# .NET Core 2.2, https://app.swaggerhub.com/apis/Billingo/Billingo/3.0.7 |
I've thought that the solution would be to edit A derived class can't get access to the base It is possible to add a new protected IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> BaseValidate(ValidationContext validationContext)
{
return ((IValidatableObject)this).Validate(validationContext);
} However I do not think that implicit public virtual IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> Validate(ValidationContext validationContext)
{
yield break;
} derived public override IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> Validate(ValidationContext validationContext)
{
foreach(var x in base.Validate(validationContext)) yield return x;
yield break;
} What do you think? Which one is better ? I've solved it right now by creating partial class with Regards |
…yModel to True. This change enable the modelGeneric.mustache templates to distinguish between generated type and native dictionary type. "BaseValidate" reference is no longer incorrectly generated in IValidatableObject.Validate(). "Override" keyword is no longer added to the `ToJson()` method.
Please merge PR #10819 to fix this! |
Just want to +1 that this is still an existing issue and a fix would be appreciated. |
Description
The mustache templates do not distinguish generated and native parent classes resulting in invalid code. For example, the
override
modifier is set in themodelGeneric.mustach
template for theToJson
method if a non-array parent exists. But the parent can be a dictionary as well (see Swagger declaration below).Same for the validate method:
BaseValidate
does not exist in the dictionary class.Swagger-codegen version
Version: 2.3.0
Is it a regression? Yes, works well with version 2.3.0-20170713.173236-24.
Swagger declaration file content or url
Generates:
Command line used for generation
Steps to reproduce
java -jar .\swagger-codegen-cli-2.3.0.jar generate -l csharp -i .\swagger.json
Suggest a fix/enhancement
If there would be a template variable like
isArrayModel
but for dictionaries or native parent classes in general, we could adjust the existing templates easily.For example like this:
The text was updated successfully, but these errors were encountered: