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

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

Open
grmcdorman opened this issue Nov 6, 2018 · 1 comment

Comments

@grmcdorman
Copy link

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
Copy link
Contributor

Starkie commented Oct 31, 2021

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:

  • Set the option sourceFolder to anything other than src.
    • In this case, I left it empty: --additional-properties=sourceFolder=""
  • Generate the client
  • See that the client was generated in the provided sourceFolder... but the tests where generated in src:
    image

In the AbstractCSharpCodegen.java, there is a TODO a few years old saying that a separate option for testFolder could be added:

// TODO: Add option for test folder output location. Nice to allow e.g. ./test instead of ./src.
// This would require updating relative paths (e.g. path to main project file in test project file)
protected String testFolder = sourceFolder;

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.

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

3 participants