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][aspnetcore][csharp][csharp-dotnet2] allOf generates source code for *AllOf model #3338

Closed
oleksabor opened this issue Jul 11, 2019 · 8 comments

Comments

@oleksabor
Copy link

oleksabor commented Jul 11, 2019

Description

I've tried to use allOf to check inherited classes case. But the problem is that it generates surplus model class ExtendedErrorModelAllOf.cs among with ErrorModel.cs ExtendedErrorModel.cs
I expect that ExtendedErrorModelAllOf.cs should not be generated.

openapi-generator version

v4.0.3

OpenAPI declaration file content or url

classInherit.yml.zip

Command line used for generation

java -jar D:/os/openapi-generator/modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i classInherit.yml -g aspnetcore -o d:\temp\ErrorMessage

java -jar D:/os/openapi-generator/modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i classInherit.yml -g csharp -o d:\temp\ErrorMessage

java -jar D:/os/openapi-generator/modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i classInherit.yml -g csharp-dotnet2 -o d:\temp\ErrorMessage

Steps to reproduce

clone openapi-generator
checkout v4.0.3
build mvnw package
get classInherit.yml
run commands

Related issues/PRs
Suggest a fix

I suppose the reason is in the AbstractCSharpCodegen since all three c# is affected.

probably it happens because of ExtendedErrorModel has -ref$ and -type

  ExtendedErrorModel:
    allOf:
    - $ref: '#/definitions/ErrorModel'
    - type: object
@auto-labeler
Copy link

auto-labeler bot commented Jul 11, 2019

👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

@thilux
Copy link

thilux commented Jul 11, 2019

This is affecting other clients as well. I see the same problem for Java and Typescript at least.
I am using the same generator version as the reporter (v4.0.3).

@wing328
Copy link
Member

wing328 commented Jul 18, 2019

Thanks for reporting the issue. Can you please check the latest master? if it's still an issue, I'll take a look in the next 2 weeks after I'm back from my trip.

@oleksabor
Copy link
Author

I've just checked with latest master but it generates three files

ErrorModel.cs
ExtendedErrorModel.cs
ExtendedErrorModelAllOf.cs - it should not be generated

and ExtendedErrorModel does not inherit from the ErrorModel:
public partial class ExtendedErrorModel : IEquatable<ExtendedErrorModel>

@edag94
Copy link

edag94 commented Aug 6, 2019

@oleksabor
I seemed to have solved the inheritance issue using a discriminator in the base class (in this case it would be ErrorModel.cs). See if this works for you. (Similar to how its done in the Animal object in the example here)

As to why the *AllOf.cs models are generated, this is a separate issue that should be fixed.

@slemrmartin
Copy link
Contributor

There is the same problem in Ruby client. Tried in version 4.1.1 and 4.2.0

@wing328
Copy link
Member

wing328 commented Sep 24, 2022

I've filed a PR (#13498) related to this.

Please refer to #3100 (comment) for the instruction to try it out.

closing this one as we'll use #3100 to track

@wing328 wing328 closed this as completed Sep 24, 2022
@wing328
Copy link
Member

wing328 commented Jun 11, 2023

Closed via #15682

Please pull the latest master to give it a try.

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

No branches or pull requests

5 participants