OpenAPITools / OpenAPITools/openapi-generator

[BUG] csharp generator is calling SequenceEqual on properties of type 'object'

Open
#2,800 5 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Client: C-Sharp Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

When I generate csharp code for an object that has a property of type 'object', the Equals method is calling SequenceEquals instead of calling Equals on the generated C# property.

For example,

"Superpower": {
	"properties": {
		"superpowerType": {
			"type": "string",
			"enum": [
				"Foo",
				"Bar"
			]
		},
		"superpowerData": {
			"type": "object"
		}
	},
	"required": [
		"superpowerData"
	]
}

results in:

        public bool Equals(Superpower input)
        {
            if (input == null)
                return false;

            return 
                (
                    this.SuperpowerType == input.SuperpowerType ||
                    (this.SuperpowerType != null &&
                    this.SuperpowerType.Equals(input.SuperpowerType))
                ) && 
                (
                    this.SuperpowerData == input.SuperpowerData ||
                    this.SuperpowerData != null &&
                    this.SuperpowerData.SequenceEqual(input.SuperpowerData)
                );
        }

This doesn't compile because Superpower.Data above is of type object and does not have a SequenceEquals member.

openapi-generator version

I am using openapi-generator-cli-3.3.4. I wanted to try 4.0.0-beta3 but it doesn't seem to support C#.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with the supplied OpenAPI schema using the C# generator, then inspect the generated Equals method for the object-typed property. Done means the generated C# compares that property with Equals rather than SequenceEqual and compiles successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.