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.Map.Entry;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
import static org.openapitools.codegen.utils.StringUtils.*;
|
||||||
import static org.openapitools.codegen.utils.StringUtils.underscore;
|
|
||||||
|
|
||||||
public class ProtobufSchemaCodegen extends DefaultCodegen implements CodegenConfig {
|
public class ProtobufSchemaCodegen extends DefaultCodegen implements CodegenConfig {
|
||||||
|
|
||||||
@ -178,8 +177,7 @@ public class ProtobufSchemaCodegen extends DefaultCodegen implements CodegenConf
|
|||||||
|
|
||||||
if (additionalProperties.containsKey(CodegenConstants.PACKAGE_NAME)) {
|
if (additionalProperties.containsKey(CodegenConstants.PACKAGE_NAME)) {
|
||||||
setPackageName((String) additionalProperties.get(CodegenConstants.PACKAGE_NAME));
|
setPackageName((String) additionalProperties.get(CodegenConstants.PACKAGE_NAME));
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
additionalProperties.put(CodegenConstants.PACKAGE_NAME, packageName);
|
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
|
// add x-protobuf-type: repeated if it's an array
|
||||||
if (Boolean.TRUE.equals(var.isArray)) {
|
if (Boolean.TRUE.equals(var.isArray)) {
|
||||||
var.vendorExtensions.put("x-protobuf-type", "repeated");
|
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");
|
var.vendorExtensions.put("x-protobuf-type", "optional");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -333,8 +330,7 @@ public class ProtobufSchemaCodegen extends DefaultCodegen implements CodegenConf
|
|||||||
if (this.numberedFieldNumberList) {
|
if (this.numberedFieldNumberList) {
|
||||||
var.vendorExtensions.putIfAbsent("x-protobuf-index", index);
|
var.vendorExtensions.putIfAbsent("x-protobuf-index", index);
|
||||||
index++;
|
index++;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
try {
|
try {
|
||||||
var.vendorExtensions.putIfAbsent("x-protobuf-index", generateFieldNumberFromString(var.getName()));
|
var.vendorExtensions.putIfAbsent("x-protobuf-index", generateFieldNumberFromString(var.getName()));
|
||||||
} catch (ProtoBufIndexComputationException e) {
|
} catch (ProtoBufIndexComputationException e) {
|
||||||
@ -500,6 +496,11 @@ public class ProtobufSchemaCodegen extends DefaultCodegen implements CodegenConf
|
|||||||
return underscore(toModelName(name));
|
return underscore(toModelName(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toVarName(final String name) {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toModelName(String name) {
|
public String toModelName(String name) {
|
||||||
name = sanitizeName(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
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)) {
|
if (Boolean.TRUE.equals(p.isArray)) {
|
||||||
p.vendorExtensions.put("x-protobuf-type", "repeated");
|
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");
|
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);
|
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
|
@Override
|
||||||
public GeneratorLanguage generatorLanguage() { return GeneratorLanguage.PROTOBUF; }
|
public GeneratorLanguage generatorLanguage() {
|
||||||
|
return GeneratorLanguage.PROTOBUF;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,6 @@ package petstore;
|
|||||||
|
|
||||||
message OtherTest {
|
message OtherTest {
|
||||||
|
|
||||||
repeated string setUnderscoretest = 343904081;
|
repeated string set_test = 341814865;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user