forked from loafle/openapi-generator-original
[Protobuf] Make it possible to override field index using x-protobuf-index (#7002)
This commit is contained in:
parent
9bfd9545cc
commit
8d63f75966
@ -28,7 +28,6 @@ import org.openapitools.codegen.meta.Stability;
|
||||
import org.openapitools.codegen.meta.features.DocumentationFeature;
|
||||
import org.openapitools.codegen.meta.features.SecurityFeature;
|
||||
import org.openapitools.codegen.meta.features.WireFormatFeature;
|
||||
import org.openapitools.codegen.utils.ProcessUtils;
|
||||
import org.openapitools.codegen.utils.ModelUtils;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -216,13 +215,12 @@ public class ProtobufSchemaCodegen extends DefaultCodegen implements CodegenConf
|
||||
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
|
||||
objs = postProcessModelsEnum(objs);
|
||||
List<Object> models = (List<Object>) objs.get("models");
|
||||
// add x-index to properties
|
||||
ProcessUtils.addIndexToProperties(models, 1);
|
||||
|
||||
for (Object _mo : models) {
|
||||
Map<String, Object> mo = (Map<String, Object>) _mo;
|
||||
CodegenModel cm = (CodegenModel) mo.get("model");
|
||||
|
||||
int index = 1;
|
||||
for (CodegenProperty var : cm.vars) {
|
||||
// add x-protobuf-type: repeated if it's an array
|
||||
if (Boolean.TRUE.equals(var.isListContainer)) {
|
||||
@ -247,6 +245,10 @@ public class ProtobufSchemaCodegen extends DefaultCodegen implements CodegenConf
|
||||
enumIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
// Add x-protobuf-index, unless already specified
|
||||
var.vendorExtensions.putIfAbsent("x-protobuf-index", index);
|
||||
index++;
|
||||
}
|
||||
}
|
||||
return objs;
|
||||
@ -422,7 +424,7 @@ public class ProtobufSchemaCodegen extends DefaultCodegen implements CodegenConf
|
||||
}
|
||||
}
|
||||
|
||||
p.vendorExtensions.put("x-index", index);
|
||||
p.vendorExtensions.putIfAbsent("x-protobuf-index", index);
|
||||
index++;
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ message {{operationId}}Request {
|
||||
{{#description}}
|
||||
// {{{.}}}
|
||||
{{/description}}
|
||||
{{#vendorExtensions.x-protobuf-type}}{{.}} {{/vendorExtensions.x-protobuf-type}}{{vendorExtensions.x-protobuf-data-type}} {{paramName}} = {{vendorExtensions.x-index}};
|
||||
{{#vendorExtensions.x-protobuf-type}}{{.}} {{/vendorExtensions.x-protobuf-type}}{{vendorExtensions.x-protobuf-data-type}} {{paramName}} = {{vendorExtensions.x-protobuf-index}};
|
||||
{{/allParams}}
|
||||
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ message {{classname}} {
|
||||
// {{{.}}}
|
||||
{{/description}}
|
||||
{{^isEnum}}
|
||||
{{#vendorExtensions.x-protobuf-type}}{{.}} {{/vendorExtensions.x-protobuf-type}}{{vendorExtensions.x-protobuf-data-type}} {{name}} = {{vendorExtensions.x-index}}{{#vendorExtensions.x-protobuf-packed}} [packed=true]{{/vendorExtensions.x-protobuf-packed}};
|
||||
{{#vendorExtensions.x-protobuf-type}}{{.}} {{/vendorExtensions.x-protobuf-type}}{{vendorExtensions.x-protobuf-data-type}} {{name}} = {{vendorExtensions.x-protobuf-index}}{{#vendorExtensions.x-protobuf-packed}} [packed=true]{{/vendorExtensions.x-protobuf-packed}};
|
||||
{{/isEnum}}
|
||||
{{#isEnum}}
|
||||
enum {{name}} {
|
||||
|
Loading…
x
Reference in New Issue
Block a user