From 9d71328af91a580b59ea22068a552d18d2585e39 Mon Sep 17 00:00:00 2001 From: xil Date: Mon, 30 Dec 2024 22:45:52 +0000 Subject: [PATCH] enum zero index is UNSPECIFIED suffix --- docs/generators/protobuf-schema.md | 8 ++--- .../languages/ProtobufSchemaCodegen.java | 32 +++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/docs/generators/protobuf-schema.md b/docs/generators/protobuf-schema.md index 88e54ff6e766..78d55d8c6a1f 100644 --- a/docs/generators/protobuf-schema.md +++ b/docs/generators/protobuf-schema.md @@ -16,10 +16,10 @@ title: Documentation for the protobuf-schema Generator ## CONFIG OPTIONS These options may be applied as additional-properties (cli) or configOptions (plugins). Refer to [configuration docs](https://openapi-generator.tech/docs/configuration) for more details. -| Option | Description | Values | Default | -| ------ | ----------- | ------ | ------- | -|numberedFieldNumberList|Field numbers in order.| |false| -|startEnumsWithUnknown|Introduces "UNKNOWN" as the first element of enumerations.| |false| +| Option | Description | Values | Default | +|---------------------------|--------------------------------------------------------------------------| ------ | ------- | +| numberedFieldNumberList | Field numbers in order. | |false| +| startEnumsWithUnspecified | Introduces "UNSPECIFIED" as the first element of enumerations. | |false| ## IMPORT MAPPING diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ProtobufSchemaCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ProtobufSchemaCodegen.java index bac31f924dd6..e4ede29750ce 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ProtobufSchemaCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ProtobufSchemaCodegen.java @@ -52,7 +52,7 @@ public class ProtobufSchemaCodegen extends DefaultCodegen implements CodegenConf public static final String NUMBERED_FIELD_NUMBER_LIST = "numberedFieldNumberList"; - public static final String START_ENUMS_WITH_UNKNOWN = "startEnumsWithUnknown"; + public static final String START_ENUMS_WITH_UNSPECIFIED = "startEnumsWithUnspecified"; private final Logger LOGGER = LoggerFactory.getLogger(ProtobufSchemaCodegen.class); @@ -60,7 +60,7 @@ public class ProtobufSchemaCodegen extends DefaultCodegen implements CodegenConf private boolean numberedFieldNumberList = false; - private boolean startEnumsWithUnknown = false; + private boolean startEnumsWithUnspecified = false; @Override public CodegenType getTag() { @@ -164,7 +164,7 @@ public ProtobufSchemaCodegen() { cliOptions.clear(); addSwitch(NUMBERED_FIELD_NUMBER_LIST, "Field numbers in order.", numberedFieldNumberList); - addSwitch(START_ENUMS_WITH_UNKNOWN, "Introduces \"UNKNOWN\" as the first element of enumerations.", startEnumsWithUnknown); + addSwitch(START_ENUMS_WITH_UNSPECIFIED, "Introduces \"UNSPECIFIED\" as the first element of enumerations.", startEnumsWithUnspecified); } @Override @@ -195,8 +195,8 @@ public void processOpts() { this.numberedFieldNumberList = convertPropertyToBooleanAndWriteBack(NUMBERED_FIELD_NUMBER_LIST); } - if (additionalProperties.containsKey(this.START_ENUMS_WITH_UNKNOWN)) { - this.startEnumsWithUnknown = convertPropertyToBooleanAndWriteBack(START_ENUMS_WITH_UNKNOWN); + if (additionalProperties.containsKey(this.START_ENUMS_WITH_UNSPECIFIED)) { + this.startEnumsWithUnspecified = convertPropertyToBooleanAndWriteBack(START_ENUMS_WITH_UNSPECIFIED); } supportingFiles.add(new SupportingFile("README.mustache", "", "README.md")); @@ -233,6 +233,7 @@ public void addEnumValuesPrefix(Map allowableValues, String pref String name = (String) value.get("name"); value.put("name", prefix + "_" + name); value.put("value", "\"" + prefix + "_" + name + "\""); + } } @@ -249,22 +250,21 @@ public void addEnumValuesPrefix(Map allowableValues, String pref * * @param allowableValues allowable values */ - public void addUnknownToAllowableValues(Map allowableValues) { - if (startEnumsWithUnknown) { + public void addUnspecifiedToAllowableValues(Map allowableValues) { + if (startEnumsWithUnspecified) { if (allowableValues.containsKey("enumVars")) { List> enumVars = (List>) allowableValues.get("enumVars"); - HashMap unknown = new HashMap(); - unknown.put("name", "UNKNOWN"); - unknown.put("isString", "false"); - unknown.put("value", "\"UNKNOWN\""); - - enumVars.add(0, unknown); + HashMap unspecified = new HashMap(); + unspecified.put("name", "UNSPECIFIED"); + unspecified.put("isString", "false"); + unspecified.put("value", "\"UNSPECIFIED\""); + enumVars.add(0, unspecified); } if (allowableValues.containsKey("values")) { List values = (List) allowableValues.get("values"); - values.add(0, "UNKNOWN"); + values.add(0, "UNSPECIFIED"); } } } @@ -291,7 +291,7 @@ public ModelsMap postProcessModels(ModelsMap objs) { if (cm.isEnum) { Map allowableValues = cm.getAllowableValues(); - addUnknownToAllowableValues(allowableValues); + addUnspecifiedToAllowableValues(allowableValues); addEnumValuesPrefix(allowableValues, cm.getClassname()); if (allowableValues.containsKey("enumVars")) { List> enumVars = (List>) allowableValues.get("enumVars"); @@ -319,7 +319,7 @@ public ModelsMap postProcessModels(ModelsMap objs) { } if (var.isEnum) { - addUnknownToAllowableValues(var.allowableValues); + addUnspecifiedToAllowableValues(var.allowableValues); addEnumValuesPrefix(var.allowableValues, var.getEnumName()); if (var.allowableValues.containsKey("enumVars")) {