Open mminns opened 7 years ago
@mminns This is probably a silly question, but why not use {{modelPackage}}
as a prefix in code when you're working with a type that is neither primitive nor container type?
Something like this for operation return types:
{{#returnType}}{{#isNotContainer}}{{^isPrimitiveType}}{{modelPackage}}.{{{returnType}}}{{/isPrimitiveType}}{{#isPrimitiveType}}{{{returnType}}}{{/isPrimitiveType}}{{/isNotContainer}}{{#isContainer}}{{{returnType}}}{{/isContainer}{{/returnType}}
It's ugly, but I think this would be simpler than a lot of shuffling code around within the generator. I think you'd only need to have this wacky long string on method inputs/outputs. Model properties should be safe, unless there are models named something likeInt64
or whatever (sorry, I didn't look at the spec you're targeting).
Another option could be to set a vendor extension like I do for some complex tweaks in the finch generator. see FinchServerGenerator#postProcessOperations. This would have to be done for operations.
Also, I did some work on a new Kotlin generator in which I fully qualify kotlin.*
primitives, collections used by the generator, and a handful of common Java types. What I did there may be helpful to you: https://github.com/swagger-api/swagger-codegen/pull/5727/files See getSwaggerType, getTypeDeclaration, needToImport, and toModelImport.
Sorry missed your comment.
I will test that as an alternative see if that works. In effect its not that much different to the solution in https://github.com/swagger-api/swagger-codegen/pull/5682/files which just adds an explicit returnType package value to the data passed tot he template.
+1
Description
The CSharp api..mustache template creates API classes that reference Model objects. However if the Model contains classes with the same name as core C# classes the code will not compile without the references being explicitly specified.
Swagger-codegen version
Built from master @ commit ea16da8
Swagger declaration file content or url
https://api.bitbucket.org/swagger.json
Command line used for generation
java -jar C:\Users\mminn\Source\github.com\mminns\swagger-codegen\modules\swagger-codegen-cli\target\swagger-codegen-cli.jar generate -i swagger.json -l csharp -o client-mminns/csharp
Steps to reproduce
Results:
Compilation fails Open Issue_trackerApi.cs
Listed with multiple errors, e.g.
Severity Code Description Project File Line Suppression State Error CS0104 'Version' is an ambiguous reference between 'IO.Swagger.Model.Version' and 'System.Version' IO.Swagger C:\Users\mminn\Source\bitbucket.org\mminns\bitbuckit.net.swagger\client-mminnns\csharp-debug\src\IO.Swagger\Api\Issue_trackerApi.cs 562 Active
Related issues
https://github.com/swagger-api/swagger-codegen/issues/5576
Suggest a Fix
In https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractCSharpCodegen.java#L310
Add the following method:
And using it in:
The in https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/resources/csharp/api.mustache#L15
Add the following to make use of the new "usings" data
see also https://github.com/mminns/swagger-codegen/tree/issue/fix-csharp-for-bitbucket\
I'd like to submit a PR for the changes