forked from loafle/openapi-generator-original
fix protobuf variable name (#13296)
This commit is contained in:
parent
62a0878bae
commit
97946e421f
@ -42,8 +42,7 @@ import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
import static org.openapitools.codegen.utils.StringUtils.underscore;
|
||||
import static org.openapitools.codegen.utils.StringUtils.*;
|
||||
|
||||
public class ProtobufSchemaCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
@ -178,8 +177,7 @@ public class ProtobufSchemaCodegen extends DefaultCodegen implements CodegenConf
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.PACKAGE_NAME)) {
|
||||
setPackageName((String) additionalProperties.get(CodegenConstants.PACKAGE_NAME));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
additionalProperties.put(CodegenConstants.PACKAGE_NAME, packageName);
|
||||
}
|
||||
|
||||
@ -304,8 +302,7 @@ public class ProtobufSchemaCodegen extends DefaultCodegen implements CodegenConf
|
||||
// add x-protobuf-type: repeated if it's an array
|
||||
if (Boolean.TRUE.equals(var.isArray)) {
|
||||
var.vendorExtensions.put("x-protobuf-type", "repeated");
|
||||
}
|
||||
else if (Boolean.TRUE.equals(var.isNullable && var.isPrimitiveType)) {
|
||||
} else if (Boolean.TRUE.equals(var.isNullable && var.isPrimitiveType)) {
|
||||
var.vendorExtensions.put("x-protobuf-type", "optional");
|
||||
}
|
||||
|
||||
@ -333,8 +330,7 @@ public class ProtobufSchemaCodegen extends DefaultCodegen implements CodegenConf
|
||||
if (this.numberedFieldNumberList) {
|
||||
var.vendorExtensions.putIfAbsent("x-protobuf-index", index);
|
||||
index++;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
try {
|
||||
var.vendorExtensions.putIfAbsent("x-protobuf-index", generateFieldNumberFromString(var.getName()));
|
||||
} catch (ProtoBufIndexComputationException e) {
|
||||
@ -500,6 +496,11 @@ public class ProtobufSchemaCodegen extends DefaultCodegen implements CodegenConf
|
||||
return underscore(toModelName(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toVarName(final String name) {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelName(String name) {
|
||||
name = sanitizeName(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
@ -558,11 +559,9 @@ public class ProtobufSchemaCodegen extends DefaultCodegen implements CodegenConf
|
||||
|
||||
if (Boolean.TRUE.equals(p.isArray)) {
|
||||
p.vendorExtensions.put("x-protobuf-type", "repeated");
|
||||
}
|
||||
else if (Boolean.TRUE.equals(p.isNullable && p.isPrimitiveType)) {
|
||||
} else if (Boolean.TRUE.equals(p.isNullable && p.isPrimitiveType)) {
|
||||
p.vendorExtensions.put("x-protobuf-type", "optional");
|
||||
}
|
||||
else if (Boolean.TRUE.equals(p.isMap)) {
|
||||
} else if (Boolean.TRUE.equals(p.isMap)) {
|
||||
LOGGER.warn("Map parameter (name: {}, operation ID: {}) not yet supported", p.paramName, op.operationId);
|
||||
}
|
||||
|
||||
@ -649,5 +648,7 @@ public class ProtobufSchemaCodegen extends DefaultCodegen implements CodegenConf
|
||||
}
|
||||
|
||||
@Override
|
||||
public GeneratorLanguage generatorLanguage() { return GeneratorLanguage.PROTOBUF; }
|
||||
public GeneratorLanguage generatorLanguage() {
|
||||
return GeneratorLanguage.PROTOBUF;
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,6 @@ package petstore;
|
||||
|
||||
message OtherTest {
|
||||
|
||||
repeated string setUnderscoretest = 343904081;
|
||||
repeated string set_test = 341814865;
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user