OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.68k stars 6.55k forks source link

[C#] csharp client generation does not handle "sourceFolder" config setting #1390

Open grmcdorman opened 5 years ago

grmcdorman commented 5 years ago
Description

If the source folder setting is changed via a configuration file, csharp client generation still generates some files with references to 'src'.

openapi-generator version

main

OpenAPI declaration file content or url

Not applicable. Configuration file, for -c option:

{
"sourceFolder":  "."
}

or any sourceFolder setting other than src.

Command line used for generation

java -jar openapi-generator-cli.jar generate -i swagger.json -l csharp -o ClientAPI -c .\openapi-generation-parameters.json

Steps to reproduce

Generate code. Try to build; it will fail.

Related issues/PRs

None.

Suggest a fix/enhancement

There are a significant number of .mustache files which have the literal string src instead of the {{sourceFolder}} macro; replacing these should fix the issue [not tested]:

Search "src" (12 hits in 5 files) compile-mono.sh.mustache (2 hits) Line 43: ${nuget_cmd} install src/{{packageName}}/packages.config -o packages; Line 68: -recurse:'src/{{packageName}}/*.cs' \ compile.mustache (2 hits) Line 14: .\nuget.exe install src{{packageName}}\packages.config -o packages Line 26: %CSCPATH%\csc /reference:bin\Newtonsoft.Json.dll;bin\JsonSubTypes.dll;bin\RestSharp.dll;System.ComponentModel.DataAnnotations.dll {{#generatePropertyChanged}}/r:bin\Fody.dll;bin\PropertyChanged.Fody.dll;bin\PropertyChanged.dll{{/generatePropertyChanged}} /target:library /out:bin{{packageName}}.dll /recurse:src{{packageName}}*.cs /doc:bin{{packageName}}.xml mono_nunit_test.mustache (3 hits) Line 10: rm src/{{{packageName}}}.Test/bin/Debug/{{{packageName}}}.Test.dll 2> /dev/null Line 15: mono nuget.exe install src/{{{packageName}}}.Test/packages.config -o packages Line 22: mono ./packages/NUnit.Runners.2.6.4/tools/nunit-console.exe src/{{{packageName}}}.Test/bin/Debug/{{{packageName}}}.Test.dll nuspec.mustache (3 hits) Line 46: <file src="....\README.md" target="" /> Line 47: <file src="....\docs**." target="docs" /> Line 49: <file src="....\packages\Fody.1.29.4\build\portable-net+sl+win+wpa+wp\Fody.targets" target="build" /> Solution.mustache (2 hits) Line 5: Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "{{packageName}}", "src{{packageName}}{{packageName}}.csproj", "{{packageGuid}}" Line 7: {{^excludeTests}}Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "{{testPackageName}}", "src{{testPackageName}}{{testPackageName}}.csproj", "{19F1DEBC-DE5E-4517-8062-F000CD499087}"

Starkie commented 2 years ago

Hi all!

I found something slightly related to this issue, There is a bit of an inconsistency on how the test folders are generated when the sourceFolder property is provided. For example:

In the AbstractCSharpCodegen.java, there is a TODO a few years old saying that a separate option for testFolder could be added: https://github.com/OpenAPITools/openapi-generator/blob/8551b0af492286a431c95ce3a37d7edf1ef4870a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCSharpCodegen.java#L73-L75

Until that is implemented, I created a little workaround, assigning the provided sourceFolder parameter to the testFolder.

With this change, the projects are generated as expected: image

I'll open a PR with these changes, if you are interested.