2222import com .samskivert .mustache .Mustache ;
2323import com .samskivert .mustache .Template ;
2424
25- import io .swagger .v3 .oas .models .media .ArraySchema ;
2625import io .swagger .v3 .oas .models .media .Schema ;
2726import org .apache .commons .io .FilenameUtils ;
2827import org .apache .commons .lang3 .StringUtils ;
4746import static org .openapitools .codegen .utils .StringUtils .camelize ;
4847import static org .openapitools .codegen .utils .StringUtils .underscore ;
4948
50- public abstract class AbstractCSharpCodegen extends DefaultCodegen implements CodegenConfig {
49+ public abstract class AbstractCSharpCodegen extends DefaultCodegen {
5150
5251 protected boolean optionalAssemblyInfoFlag = true ;
5352 protected boolean optionalEmitDefaultValuesFlag = false ;
@@ -108,7 +107,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
108107 protected Set <String > propertySpecialKeywords = new HashSet <>(Arrays .asList ("ToString" , "ToJson" , "GetHashCode" , "Equals" , "ShouldSerializeToString" ));
109108
110109 // A cache to efficiently lookup schema `toModelName()` based on the schema Key
111- private Map <String , String > schemaKeyToModelNameCache = new HashMap <>();
110+ private final Map <String , String > schemaKeyToModelNameCache = new HashMap <>();
112111
113112 public AbstractCSharpCodegen () {
114113 super ();
@@ -464,7 +463,7 @@ protected ImmutableMap.Builder<String, Lambda> addMustacheLambdas() {
464463 .put ("uniqueLines" , new UniqueLambda ("\n " , false ))
465464 .put ("unique" , new UniqueLambda ("\n " , true ))
466465 .put ("camel_case" , new CamelCaseLambda ())
467- .put ("escape_reserved_word" , new EscapeKeywordLambda (( val ) -> this . escapeKeyword ( val ) ));
466+ .put ("escape_reserved_word" , new EscapeKeywordLambda (this :: escapeKeyword ));
468467 }
469468
470469 @ Override
@@ -476,14 +475,14 @@ public void postProcessModelProperty(CodegenModel model, CodegenProperty propert
476475 property .dataType = property .datatypeWithEnum ;
477476 }
478477
479- if (property .isEnum && !property .vendorExtensions .containsKey (this .zeroBasedEnumVendorExtension )) {
478+ if (property .isEnum && !property .vendorExtensions .containsKey (AbstractCSharpCodegen .zeroBasedEnumVendorExtension )) {
480479 if (Boolean .TRUE .equals (this .zeroBasedEnums )) {
481- property .vendorExtensions .put (this .zeroBasedEnumVendorExtension , true );
480+ property .vendorExtensions .put (AbstractCSharpCodegen .zeroBasedEnumVendorExtension , true );
482481 } else if (!Boolean .FALSE .equals (this .zeroBasedEnums )) {
483482 if (property .allowableValues .containsKey ("values" )) {
484- final List <Object > allowableValues = (List <Object >) property .allowableValues .get ("values" );
483+ final List <? > allowableValues = (List <? >) property .allowableValues .get ("values" );
485484 boolean isZeroBased = String .valueOf (allowableValues .get (0 )).toLowerCase (Locale .ROOT ).equals ("unknown" );
486- property .vendorExtensions .put (this .zeroBasedEnumVendorExtension , isZeroBased );
485+ property .vendorExtensions .put (AbstractCSharpCodegen .zeroBasedEnumVendorExtension , isZeroBased );
487486 }
488487 }
489488 }
@@ -531,14 +530,14 @@ public ModelsMap postProcessModels(ModelsMap objs) {
531530 }
532531 }
533532
534- if (cm .isEnum && !cm .vendorExtensions .containsKey (this .zeroBasedEnumVendorExtension )) {
533+ if (cm .isEnum && !cm .vendorExtensions .containsKey (AbstractCSharpCodegen .zeroBasedEnumVendorExtension )) {
535534 if (Boolean .TRUE .equals (this .zeroBasedEnums )) {
536- cm .vendorExtensions .put (this .zeroBasedEnumVendorExtension , true );
535+ cm .vendorExtensions .put (AbstractCSharpCodegen .zeroBasedEnumVendorExtension , true );
537536 } else if (!Boolean .FALSE .equals (this .zeroBasedEnums )) {
538537 if (cm .allowableValues .containsKey ("values" )) {
539- final List <Object > allowableValues = (List <Object >) cm .allowableValues .get ("values" );
538+ final List <? > allowableValues = (List <? >) cm .allowableValues .get ("values" );
540539 boolean isZeroBased = String .valueOf (allowableValues .get (0 )).toLowerCase (Locale .ROOT ).equals ("unknown" );
541- cm .vendorExtensions .put (this .zeroBasedEnumVendorExtension , isZeroBased );
540+ cm .vendorExtensions .put (AbstractCSharpCodegen .zeroBasedEnumVendorExtension , isZeroBased );
542541 }
543542 }
544543 }
@@ -560,6 +559,9 @@ public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs)
560559 Map <String , CodegenModel > enumRefs = new HashMap <>();
561560 for (Map .Entry <String , ModelsMap > entry : processed .entrySet ()) {
562561 CodegenModel model = ModelUtils .getModelByName (entry .getKey (), processed );
562+ if (model == null ) {
563+ continue ;
564+ }
563565
564566 // if we don't call setHasDiscriminatorWithNonEmptyMapping then hasDiscriminatorWithNonEmptyMapping will be false, and we need it in the JsonConverter
565567 // the checks on oneOf and anyOf must be there or else hasDiscriminatorWithNonEmptyMapping will be true for GrandparentAnimal.
@@ -578,7 +580,11 @@ public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs)
578580
579581 for (Map .Entry <String , ModelsMap > entry : objs .entrySet ()) {
580582 CodegenModel model = ModelUtils .getModelByName (entry .getKey (), objs );
581- model .vendorExtensions .put ("x-model-is-mutatable" , modelIsMutatable (model , null ));
583+ if (model == null ) {
584+ continue ;
585+ }
586+
587+ model .vendorExtensions .put ("x-model-is-mutable" , modelIsMutable (model , null ));
582588
583589 CodegenComposedSchemas composedSchemas = model .getComposedSchemas ();
584590 if (composedSchemas != null ) {
@@ -648,19 +654,17 @@ public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs)
648654 * can instantiate the object. If false, then the model is only ever given
649655 * to us by the server, so we do not need a public constructor
650656 */
651- private boolean modelIsMutatable (CodegenModel model , Set <String > processed ) {
657+ private boolean modelIsMutable (CodegenModel model , Set <String > processed ) {
652658 if (processed == null ) {
653659 processed = new HashSet <String >();
654660 }
655- Boolean isMutatable = model .allVars .stream ().anyMatch (v -> !v .isReadOnly );
656- if (!isMutatable && !processed .contains (model .classname ) && model .getDiscriminator () != null && model .getDiscriminator ().getMappedModels () != null ) {
661+ boolean isMutable = model .allVars .stream ().anyMatch (v -> !v .isReadOnly );
662+ if (!isMutable && !processed .contains (model .classname ) && model .getDiscriminator () != null && model .getDiscriminator ().getMappedModels () != null ) {
657663 processed .add (model .classname );
658- for (CodegenDiscriminator .MappedModel mappedModel : model .getDiscriminator ().getMappedModels ()) {
659- isMutatable = modelIsMutatable (model , processed );
660- }
664+ isMutable = modelIsMutable (model , processed );
661665 }
662666
663- return isMutatable ;
667+ return isMutable ;
664668 }
665669
666670 protected void removePropertiesDeclaredInComposedTypes (Map <String , ModelsMap > objs , CodegenModel model , List <CodegenProperty > composedProperties ) {
@@ -677,7 +681,7 @@ private String patchPropertyName(CodegenModel model, String value) {
677681 }
678682
679683 private void patchPropertyVendorExtensions (CodegenProperty property ) {
680- Boolean isValueType = isValueType (property );
684+ boolean isValueType = isValueType (property );
681685 property .vendorExtensions .put ("x-is-value-type" , isValueType );
682686 property .vendorExtensions .put ("x-is-reference-type" , !isValueType );
683687 property .vendorExtensions .put ("x-is-nullable-type" , this .getNullableReferencesTypes () || isValueType );
@@ -736,7 +740,7 @@ protected List<Map<String, Object>> buildEnumVars(List<Object> values, String da
736740
737741 String [] numericTypes = {"double" , "double?" , "decimal" , "decimal" , "float" , "float?" , "int" , "int?" , "long" , "long?" , "ulong" , "ulong?" };
738742 enumVars .forEach ((enumVar ) -> {
739- enumVar .put ("isNumeric" , Arrays .stream (numericTypes ).anyMatch (dataType :: equals ));
743+ enumVar .put ("isNumeric" , Arrays .asList (numericTypes ).contains (dataType ));
740744 });
741745
742746 return enumVars ;
@@ -823,7 +827,7 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
823827 case "0" :
824828 postProcessResponseCode (response , "Default" , httpStatusesWithReturn );
825829 response .vendorExtensions .put ("x-http-status-is-default" , true );
826- if (operation .responses .stream (). count () == 1 ) {
830+ if (( long ) operation .responses .size () == 1 ) {
827831 response .vendorExtensions .put ("x-only-default" , true );
828832 }
829833 break ;
@@ -1031,7 +1035,7 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
10311035 }
10321036 } else {
10331037 operation .returnContainer = operation .returnType ;
1034- operation .isMap = this .mapTypes .stream ().anyMatch (t -> typeMapping . startsWith ( t ) );
1038+ operation .isMap = this .mapTypes .stream ().anyMatch (typeMapping :: startsWith );
10351039 }
10361040 }
10371041
@@ -1438,7 +1442,7 @@ private String getArrayTypeDeclaration(Schema arr) {
14381442 // This supports arrays of arrays.
14391443 String arrayType = typeMapping .get ("array" );
14401444 StringBuilder instantiationType = new StringBuilder (arrayType );
1441- Schema items = ModelUtils .getSchemaItems (arr );
1445+ Schema <?> items = ModelUtils .getSchemaItems (arr );
14421446 String nestedType = getTypeDeclaration (items );
14431447 // TODO: We may want to differentiate here between generics and primitive arrays.
14441448 instantiationType .append ("<" ).append (nestedType ).append (">" );
@@ -1459,7 +1463,7 @@ public String getTypeDeclaration(Schema p) {
14591463 return getArrayTypeDeclaration (p );
14601464 } else if (ModelUtils .isMapSchema (p )) {
14611465 // Should we also support maps of maps?
1462- Schema inner = ModelUtils .getAdditionalProperties (p );
1466+ Schema <?> inner = ModelUtils .getAdditionalProperties (p );
14631467 return getSchemaType (p ) + "<string, " + getTypeDeclaration (inner ) + ">" ;
14641468 }
14651469 return super .getTypeDeclaration (p );
@@ -1720,8 +1724,6 @@ public String toEnumVarName(String name, String datatype) {
17201724 private String adjustNamingStyle (String name )
17211725 {
17221726 switch (getEnumPropertyNaming ()) {
1723- case original :
1724- return name ;
17251727 case camelCase :
17261728 // NOTE: Removes hyphens and underscores
17271729 return camelize (name , LOWERCASE_FIRST_LETTER );
@@ -1790,7 +1792,7 @@ public void setParameterExampleValue(CodegenParameter p) {
17901792 boolean hasAllowableValues = p .allowableValues != null && !p .allowableValues .isEmpty ();
17911793 if (hasAllowableValues ) {
17921794 //support examples for inline enums
1793- final List <Object > values = (List <Object >) p .allowableValues .get ("values" );
1795+ final List <? > values = (List <? >) p .allowableValues .get ("values" );
17941796 example = String .valueOf (values .get (0 ));
17951797 } else if (p .defaultValue == null ) {
17961798 example = p .example ;
@@ -1967,7 +1969,7 @@ public void postProcessPattern(String pattern, Map<String, Object> vendorExtensi
19671969 ? 1
19681970 : 0 ;
19691971
1970- Map <Character , String > optionsMap = new HashMap ();
1972+ Map <Character , String > optionsMap = new HashMap < Character , String > ();
19711973 optionsMap .put ('i' , "IgnoreCase" );
19721974 optionsMap .put ('m' , "Multiline" );
19731975 optionsMap .put ('s' , "SingleLine" );
@@ -1987,7 +1989,7 @@ public void postProcessPattern(String pattern, Map<String, Object> vendorExtensi
19871989 }
19881990 }
19891991
1990- String regex = pattern .substring (start , end ).replace ("'" , " \' " ). replace ( " \" " , "\" \" " );
1992+ String regex = pattern .substring (start , end ).replace ("\" " , "\" \" " );
19911993 vendorExtensions .put ("x-regex" , regex );
19921994 vendorExtensions .put ("x-modifiers" , modifiers );
19931995 }
0 commit comments