Skip to content

Commit 56f3016

Browse files
authored
removed warnings (#18775)
1 parent 1c94576 commit 56f3016

3 files changed

Lines changed: 37 additions & 70 deletions

File tree

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCSharpCodegen.java

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import com.samskivert.mustache.Mustache;
2323
import com.samskivert.mustache.Template;
2424

25-
import io.swagger.v3.oas.models.media.ArraySchema;
2625
import io.swagger.v3.oas.models.media.Schema;
2726
import org.apache.commons.io.FilenameUtils;
2827
import org.apache.commons.lang3.StringUtils;
@@ -47,7 +46,7 @@
4746
import static org.openapitools.codegen.utils.StringUtils.camelize;
4847
import 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
}

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CSharpClientCodegen.java

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,9 @@
1818

1919
import com.google.common.collect.ImmutableMap;
2020
import com.samskivert.mustache.Mustache;
21-
import io.swagger.v3.oas.models.media.ArraySchema;
22-
import io.swagger.v3.oas.models.media.ComposedSchema;
2321
import io.swagger.v3.oas.models.media.Schema;
2422
import io.swagger.v3.oas.models.Operation;
2523
import io.swagger.v3.oas.models.servers.Server;
26-
import org.mozilla.javascript.optimizer.Codegen;
2724
import org.openapitools.codegen.*;
2825
import org.openapitools.codegen.meta.features.*;
2926
import org.openapitools.codegen.model.ModelMap;
@@ -408,7 +405,7 @@ public CodegenModel fromModel(String name, Schema model) {
408405
Map<String, Schema> allDefinitions = ModelUtils.getSchemas(this.openAPI);
409406
CodegenModel codegenModel = super.fromModel(name, model);
410407
if (allDefinitions != null && codegenModel != null && codegenModel.parent != null) {
411-
final Schema parentModel = allDefinitions.get(toModelName(codegenModel.parent));
408+
final Schema<?> parentModel = allDefinitions.get(toModelName(codegenModel.parent));
412409
if (parentModel != null) {
413410
final CodegenModel parentCodegenModel = super.fromModel(codegenModel.parent, parentModel);
414411
if (codegenModel.hasEnums) {
@@ -426,13 +423,11 @@ public CodegenModel fromModel(String name, Schema model) {
426423
}
427424
}
428425

429-
CodegenProperty last = null;
430426
for (final CodegenProperty property : parentCodegenModel.vars) {
431427
// helper list of parentVars simplifies templating
432428
if (!propertyHash.containsKey(property.name)) {
433429
final CodegenProperty parentVar = property.clone();
434430
parentVar.isInherited = true;
435-
last = parentVar;
436431
LOGGER.debug("adding parent variable {}", property.name);
437432
codegenModel.parentVars.add(parentVar);
438433
}
@@ -1067,12 +1062,6 @@ public void setPackageGuid(String packageGuid) {
10671062
this.packageGuid = packageGuid;
10681063
}
10691064

1070-
// TODO: this does the same as super
1071-
@Override
1072-
public void setPackageName(String packageName) {
1073-
this.packageName = packageName;
1074-
}
1075-
10761065
/**
10771066
* Sets the api name. This value must be a valid class name.
10781067
*
@@ -1085,12 +1074,6 @@ public void setApiName(String apiName) {
10851074
this.apiName = apiName;
10861075
}
10871076

1088-
// TODO: this does the same as super
1089-
@Override
1090-
public void setPackageVersion(String packageVersion) {
1091-
this.packageVersion = packageVersion;
1092-
}
1093-
10941077
public void setSupportsAsync(Boolean supportsAsync) {
10951078
this.supportsAsync = supportsAsync;
10961079
}
@@ -1323,8 +1306,6 @@ private void syncStringProperty(final Map<String, Object> additionalProperties,
13231306
@SuppressWarnings("Duplicates")
13241307
private static abstract class FrameworkStrategy {
13251308

1326-
private final Logger LOGGER = LoggerFactory.getLogger(CSharpClientCodegen.class);
1327-
13281309
static FrameworkStrategy NETSTANDARD_1_3 = new FrameworkStrategy("netstandard1.3", ".NET Standard 1.3", "net7.0") {
13291310
};
13301311
static FrameworkStrategy NETSTANDARD_1_4 = new FrameworkStrategy("netstandard1.4", ".NET Standard 1.4", "net7.0") {
@@ -1365,22 +1346,6 @@ private static abstract class FrameworkStrategy {
13651346
this.isNetStandard = isNetStandard;
13661347
}
13671348

1368-
protected void configureAdditionalProperties(final Map<String, Object> properties) {
1369-
properties.putIfAbsent(CodegenConstants.DOTNET_FRAMEWORK, this.name);
1370-
1371-
// not intended to be user-settable
1372-
properties.put(TARGET_FRAMEWORK_IDENTIFIER, this.getTargetFrameworkIdentifier());
1373-
properties.put(TARGET_FRAMEWORK_VERSION, this.getTargetFrameworkVersion());
1374-
properties.putIfAbsent(MCS_NET_VERSION_KEY, "4.6-api");
1375-
1376-
properties.put(NET_STANDARD, this.isNetStandard);
1377-
if (properties.containsKey(SUPPORTS_UWP)) {
1378-
LOGGER.warn(".NET {} generator does not support the UWP option. Use the csharp generator instead.",
1379-
this.name);
1380-
properties.remove(SUPPORTS_UWP);
1381-
}
1382-
}
1383-
13841349
protected String getNugetFrameworkIdentifier() {
13851350
return this.name.toLowerCase(Locale.ROOT);
13861351
}
@@ -1496,7 +1461,7 @@ protected void configureAdditionalPropertiesForFrameworks(final Map<String, Obje
14961461
@Override
14971462
public String toInstantiationType(Schema schema) {
14981463
if (ModelUtils.isMapSchema(schema)) {
1499-
Schema additionalProperties = ModelUtils.getAdditionalProperties(schema);
1464+
Schema<?> additionalProperties = ModelUtils.getAdditionalProperties(schema);
15001465
String inner = getSchemaType(additionalProperties);
15011466
if (ModelUtils.isMapSchema(additionalProperties)) {
15021467
inner = toInstantiationType(additionalProperties);

0 commit comments

Comments
 (0)