Skip to content

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

Closed

Description

@Cyber1000
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

Activity

  1. Cyber1000 commented on Jan 14, 2023

    @Cyber1000
    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions