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

[BUG][csharp-netcore] Compilation-Error if you have a property named Validate in your schema ("already contains a definition for 'Validate'") #14462

Closed
Cyber1000 opened this issue Jan 14, 2023 · 1 comment · Fixed by #15160

Comments

@Cyber1000
Copy link

Description
  • If you have a property named Validate in your schema you end up with two validates (one property "validate" and a method named "Validate" from your side.

image

- Property Validate also generated:

image

openapi-generator version

6.2.1

OpenAPI declaration file content or url

openproject-api (so I can't change it on my own): https://community.openproject.org/api/v3/spec.yml

Generation Details

openapi-generator-cli generate -i https://community.openproject.org/api/v3/spec.yml -g csharp-netcore -o api --additional-properties=sourceFolder=src,optionalProjectFile=false,excludeTests=true

Suggest a fix
  • Maybe rename your Method to Validate1 (or better), if you find a property Validate in a single class
    • no idea how complicated this would be, think you're using a template
@Cyber1000
Copy link
Author

ok seeing an Interface IValidatableObject, which prevents renaming of Validate

the solution then would be to change it to an explicit interface implementation (https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/interfaces/explicit-interface-implementation):

So instead of public IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> Validate(ValidationContext validationContext) change it to IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext) (without public and explicit IValidatableObject)
This compiles and should have no side effects as far as I know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant