4
4
import com .samskivert .mustache .Mustache ;
5
5
import io .swagger .codegen .*;
6
6
import io .swagger .models .Model ;
7
+ import io .swagger .models .ModelImpl ;
8
+ import io .swagger .models .Swagger ;
7
9
import io .swagger .models .properties .ArrayProperty ;
8
10
import io .swagger .models .properties .Property ;
11
+ import io .swagger .models .properties .PropertyBuilder ;
12
+ import io .swagger .models .properties .RefProperty ;
13
+ import org .apache .commons .lang3 .StringUtils ;
9
14
import org .slf4j .Logger ;
10
15
import org .slf4j .LoggerFactory ;
11
16
@@ -29,6 +34,8 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
29
34
// Defines the sdk option for targeted frameworks, which differs from targetFramework and targetFrameworkNuget
30
35
private static final String MCS_NET_VERSION_KEY = "x-mcs-sdk" ;
31
36
37
+ protected Swagger swagger ;
38
+
32
39
protected String packageGuid = "{" + java .util .UUID .randomUUID ().toString ().toUpperCase () + "}" ;
33
40
protected String clientPackage = "IO.Swagger.Client" ;
34
41
protected String localVariablePrefix = "" ;
@@ -433,6 +440,10 @@ public void processOpts() {
433
440
434
441
additionalProperties .put ("apiDocPath" , apiDocPath );
435
442
additionalProperties .put ("modelDocPath" , modelDocPath );
443
+
444
+ if (skipAliasGeneration == null ) {
445
+ skipAliasGeneration = true ;
446
+ }
436
447
}
437
448
438
449
public void setModelPropertyNaming (String naming ) {
@@ -477,6 +488,26 @@ public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
477
488
return objs ;
478
489
}
479
490
491
+ @ Override
492
+ public String getSwaggerType (Property p ) {
493
+ String swaggerType = super .getSwaggerType (p );
494
+ if (p instanceof RefProperty && this .swagger != null ) {
495
+ final Map <String , Model > allDefinitions = this .swagger .getDefinitions ();
496
+ final Model referencedModel = allDefinitions .get (swaggerType );
497
+ if (referencedModel == null ) {
498
+ return swaggerType ;
499
+ }
500
+ if (referencedModel instanceof ModelImpl ) {
501
+ final ModelImpl model = (ModelImpl ) referencedModel ;
502
+ if (!this .isModelObject (model ) && (model .getEnum () == null || model .getEnum ().isEmpty ())) {
503
+ final Property property = PropertyBuilder .build (model .getType (), model .getFormat (), null );
504
+ swaggerType = getSwaggerType (property );
505
+ }
506
+ }
507
+ }
508
+ return swaggerType ;
509
+ }
510
+
480
511
@ Override
481
512
public CodegenType getTag () {
482
513
return CodegenType .CLIENT ;
@@ -803,4 +834,9 @@ public Mustache.Compiler processCompiler(Mustache.Compiler compiler) {
803
834
// To avoid unexpected behaviors when options are passed programmatically such as { "supportsAsync": "" }
804
835
return super .processCompiler (compiler ).emptyStringIsFalse (true );
805
836
}
837
+
838
+ @ Override
839
+ public void preprocessSwagger (Swagger swagger ) {
840
+ this .swagger = swagger ;
841
+ }
806
842
}
0 commit comments