I'm using OpenAPI Generator to generate client libraries for my c# API. I am having issues generating a c# client, because one of my models is called Environment. The generated service code to manipulate this model causes the build of the project to fail because it is an ambiguous reference between it's own model and .Net's System.Environment.
The exact error I'm seeing is
Api/EnvironmentApi.cs(87,42): error CS0104: 'Environment' is an ambiguous reference between 'MyProject.Model.Environment' and 'System.Environment'
Is there some way to tell openapi-generator to fully-qualify the class names in the generated code so that it won't clash? i.e. so it generates something like
DoSomething<MyProject.Model.Environment>(...) instead of DoSomething<Environment>(...)
In a nutshell: --model-name-prefix can save your build.
In more details:
Generating fully-qualified class names does not seems possible (as this feature request is still open), but there is a workaround though, with the option --model-name-prefix that was added in OpenApi-Generator a couple years ago.
To leverage it, add on your command line something like --model-name-prefix SomePrefix.
The impact is that instead of generating the model class Environment it will generate the class SomePrefixEnvironment.
So, sure, you may dislike having this prefix added everywhere, but at least you won't have build conflict anymore
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With