swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
17.04k stars 6.03k forks source link

[C#] Consolidate C# 2.0 generator into C# generator #5138

Open wing328 opened 7 years ago

wing328 commented 7 years ago
Description

Currently, C# (csharp) generator supports the following .net framework/standard:

    targetFramework
        The target .NET framework version. (Default: v4.5)
            v3.5 - .NET Framework 3.5 compatible
            v4.5 - .NET Framework 4.5+ compatible
            v5.0 - .NET Standard 1.3 compatible
            uwp - Universal Windows Platform - beta support

and there's a separate generator for C# 2.0.

We want to consolidate/merge C# 2.0 generator into csharp generator for easier maintenance and support.

Swagger-codegen version

Latest master

If anyone wants to work on the enhancement, please reply to let us know. Thanks!

jimschubert commented 7 years ago

@wing328 I would disagree that merging the C# 2.0 generator into the others will lead to easier maintenance.

The other generators currently use syntax which is unavailable in C# 2.0 (object initialization, default/named parameters, implicit types). As well, there are additional keywords in later versions which are not keywords in C# 2.0. It's been nearly ten years since I last used C# 2.0, but I seem to recall there were issues with the migration of delegates and enumerations to C# 3.0 (really 3.5 since we don't have a 3.0 generator).

Merging them all will create many unnecessary conditional blocks which I think will become difficult to reason about.

One path I think we could take is to merge the generator code in Java, but keep the templates physically separate. However, this could be a breaking change if anyone currently relies on the existing template structure for custom templates.

wing328 commented 7 years ago

@jimschubert fair enough. My goal is to keep the C# 2.0 generator up-to-date with the enhancements, bug fixes we applied to the C# (3.5, 4.5, UWP) generator as I believe C# 2.0 generator is still popular to Unity developers.

jimschubert commented 7 years ago

@wing328 I agree with your points. I was just trying to say I think it'd be more maintainable as a separate generator that extends the other C# generator. However, if you want them all to be executed via -l csharp, I don't think my suggestion is possible (easily) with the current code.

Do you think it would make more sense to push most of the bug fixes into the abstract class? I think this would solve most of the issues.

jimschubert commented 7 years ago

@wing328 I opened a PR to remove a bit of the duplicated code in the C# 2.0 generator in favor of the abstract base class. I explained in the PR why it doesn't consolidate templates, which basically reiterates what I stated above.

Let me know if you have any suggestions about how to merge templates cleanly and in a way that doesn't break current integrations and I'll investigate it further.