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.03k stars 6.03k forks source link

CSharp Import mapping #4483

Open simo9000 opened 7 years ago

simo9000 commented 7 years ago
Description

I submitted #4405 a little while ago with the main aim to allow a derived generator to add .net project references into the packages.config and .csproj files. I just noticed today that the nancyfx generator has an import mapping feature added in c734a216. This solves the same problem of appending dependencies as I was attempting to solve with #4405, however I needed the feature in the csharp client sdk not the nancyfx server stub.

This brings me to two questions:

  1. which method of import mapping is preferred (#4405 or c734a216)

  2. shouldn't the preferred import mapping method be available to all .net generators while keeping the generators DRY as possible? If c734a216 is preferred then should the implementation code be moved to the AbstractCSharpGenerator?

Swagger-codegen version

curent master branch

Swagger declaration file content or url

N/A

Command line used for generation

N/A

Steps to reproduce

N/A

Related issues

N/A

Suggest a Fix

I am willing to do the PRs is necessary to implement whatever is decided. If #4405 is not the preferred method, i will close it.

wing328 commented 7 years ago

@simo9000 I need more time to review in order to answer your question.

As a user of Swagger Codegen, which one do you prefer?

simo9000 commented 7 years ago

I actually prefer the method in c734a216 for import mapping specifically since it uses the importMapping field from DefaultCodegen. I have been tempted to close #4405 and create a PR to move the helper methods to AbstractCSharp as i mentioned before, however, I still feel like the option of inheriting templates when sub-classing a generator is appealing even if the method in c734a216 obviates my immediate need for it.

I would really like to do both options and move some template skeletons to AbstractCSharp to make less duplication of boiler plate code (i.e. .csproj, packages.config, etc).

wing328 commented 7 years ago

I would really like to do both options and move some template skeletons to AbstractCSharp to make less duplication of boiler plate code (i.e. .csproj, packages.config, etc).

Please go for it 👍

wing328 commented 7 years ago

@simo9000 the C# client generator in the latest master has been refactored. Please give it a try.

(we just released stable version v2.2.3 last week)