Skip to content

Commit 9a9f68f

Browse files
author
andrewwilsonnew
committed
fixing param name
1 parent ea26e96 commit 9a9f68f

4 files changed

Lines changed: 12 additions & 12 deletions

File tree

bin/configs/protobuf-schema-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ additionalProperties:
1010
wrapComplexType: false
1111
supportMultipleResponses: false
1212
aggregateModelsName: data
13-
enumSimpleName: true
13+
useSimplifiedEnumNames: true
1414
typeMappings:
1515
object: "google.protobuf.Struct"
1616
importMappings:

docs/generators/protobuf-schema.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
2020
| ------ | ----------- | ------ | ------- |
2121
|addJsonNameAnnotation|Append "json_name" annotation to message field when the specification name differs from the protobuf field name| |false|
2222
|aggregateModelsName|Aggregated model filename. If set, all generated models will be combined into this single file.| |null|
23-
|enumSimpleName|Use a simple name for enums| |false|
23+
|useSimplifiedEnumNames|Use a simple name for enums| |false|
2424
|numberedFieldNumberList|Field numbers in order.| |false|
2525
|startEnumsWithUnspecified|Introduces "UNSPECIFIED" as the first element of enumerations.| |false|
2626
|supportMultipleResponses|Support multiple responses| |true|

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public class ProtobufSchemaCodegen extends DefaultCodegen implements CodegenConf
6666

6767
public static final String WRAP_COMPLEX_TYPE = "wrapComplexType";
6868

69-
public static final String SIMPLE_ENUM_NAME = "enumSimpleName";
69+
public static final String USE_SIMPLIFIED_ENUM_NAMES = "useSimplifiedEnumNames";
7070

7171
public static final String AGGREGATE_MODELS_NAME = "aggregateModelsName";
7272

@@ -86,7 +86,7 @@ public class ProtobufSchemaCodegen extends DefaultCodegen implements CodegenConf
8686

8787
private boolean wrapComplexType = true;
8888

89-
private boolean simpleEnumName = false;
89+
private boolean useSimplifiedEnumNames = false;
9090

9191
private boolean supportMultipleResponses = true;
9292

@@ -200,7 +200,7 @@ public ProtobufSchemaCodegen() {
200200
addSwitch(START_ENUMS_WITH_UNSPECIFIED, "Introduces \"UNSPECIFIED\" as the first element of enumerations.", startEnumsWithUnspecified);
201201
addSwitch(ADD_JSON_NAME_ANNOTATION, "Append \"json_name\" annotation to message field when the specification name differs from the protobuf field name", addJsonNameAnnotation);
202202
addSwitch(WRAP_COMPLEX_TYPE, "Generate Additional message for complex type", wrapComplexType);
203-
addSwitch(SIMPLE_ENUM_NAME, "Use a simple name for enums", simpleEnumName);
203+
addSwitch(USE_SIMPLIFIED_ENUM_NAMES, "Use a simple name for enums", useSimplifiedEnumNames);
204204
addSwitch(SUPPORT_MULTIPLE_RESPONSES, "Support multiple responses", supportMultipleResponses);
205205
addOption(AGGREGATE_MODELS_NAME, "Aggregated model filename. If set, all generated models will be combined into this single file.", null);
206206
}
@@ -245,8 +245,8 @@ public void processOpts() {
245245
this.wrapComplexType = convertPropertyToBooleanAndWriteBack(WRAP_COMPLEX_TYPE);
246246
}
247247

248-
if (additionalProperties.containsKey(SIMPLE_ENUM_NAME)) {
249-
this.simpleEnumName = convertPropertyToBooleanAndWriteBack(SIMPLE_ENUM_NAME);
248+
if (additionalProperties.containsKey(USE_SIMPLIFIED_ENUM_NAMES)) {
249+
this.useSimplifiedEnumNames = convertPropertyToBooleanAndWriteBack(USE_SIMPLIFIED_ENUM_NAMES);
250250
}
251251

252252
if (additionalProperties.containsKey(AGGREGATE_MODELS_NAME)) {
@@ -507,15 +507,15 @@ public void addEnumValuesPrefix(Map<String, Object> allowableValues, String pref
507507
prefix = CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, prefix);
508508
for (Map<String, Object> value : enumVars) {
509509
String name = (String) value.get("name");
510-
value.put("name", simpleEnumName ? name : prefix + "_" + name);
511-
value.put("value", simpleEnumName ? name : "\"" + prefix + "_" + name + "\"");
510+
value.put("name", useSimplifiedEnumNames ? name : prefix + "_" + name);
511+
value.put("value", useSimplifiedEnumNames ? name : "\"" + prefix + "_" + name + "\"");
512512
}
513513
}
514514

515515
if (allowableValues.containsKey("values")) {
516516
List<Object> values = (List<Object>) allowableValues.get("values");
517517
for (Object value : values) {
518-
value = simpleEnumName ? value : prefix + "_" + value;
518+
value = useSimplifiedEnumNames ? value : prefix + "_" + value;
519519
}
520520
}
521521
}

modules/openapi-generator/src/test/java/org/openapitools/codegen/protobuf/ProtobufSchemaCodegenTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
import java.util.Map;
4444

4545
import static org.openapitools.codegen.TestUtils.createCodegenModelWrapper;
46-
import static org.openapitools.codegen.languages.ProtobufSchemaCodegen.SIMPLE_ENUM_NAME;
46+
import static org.openapitools.codegen.languages.ProtobufSchemaCodegen.USE_SIMPLIFIED_ENUM_NAMES;
4747
import static org.testng.Assert.assertEquals;
4848

4949
public class ProtobufSchemaCodegenTest {
@@ -169,7 +169,7 @@ private void testEnumValues(boolean simpleEnumValue) {
169169
OpenAPI openAPI = TestUtils.createOpenAPIWithOneSchema("sample", model);
170170
codegen.setOpenAPI(openAPI);
171171
final CodegenModel cm = codegen.fromModel("sample", model);
172-
codegen.additionalProperties().put(SIMPLE_ENUM_NAME, simpleEnumValue);
172+
codegen.additionalProperties().put(USE_SIMPLIFIED_ENUM_NAMES, simpleEnumValue);
173173
codegen.processOpts();
174174
codegen.postProcessModels(createCodegenModelWrapper(cm));
175175

0 commit comments

Comments
 (0)