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.DocumentationFeature;
|
||||||
import org.openapitools.codegen.meta.features.SecurityFeature;
|
import org.openapitools.codegen.meta.features.SecurityFeature;
|
||||||
import org.openapitools.codegen.meta.features.WireFormatFeature;
|
import org.openapitools.codegen.meta.features.WireFormatFeature;
|
||||||
import org.openapitools.codegen.utils.ProcessUtils;
|
|
||||||
import org.openapitools.codegen.utils.ModelUtils;
|
import org.openapitools.codegen.utils.ModelUtils;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
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) {
|
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
|
||||||
objs = postProcessModelsEnum(objs);
|
objs = postProcessModelsEnum(objs);
|
||||||
List<Object> models = (List<Object>) objs.get("models");
|
List<Object> models = (List<Object>) objs.get("models");
|
||||||
// add x-index to properties
|
|
||||||
ProcessUtils.addIndexToProperties(models, 1);
|
|
||||||
|
|
||||||
for (Object _mo : models) {
|
for (Object _mo : models) {
|
||||||
Map<String, Object> mo = (Map<String, Object>) _mo;
|
Map<String, Object> mo = (Map<String, Object>) _mo;
|
||||||
CodegenModel cm = (CodegenModel) mo.get("model");
|
CodegenModel cm = (CodegenModel) mo.get("model");
|
||||||
|
|
||||||
|
int index = 1;
|
||||||
for (CodegenProperty var : cm.vars) {
|
for (CodegenProperty var : cm.vars) {
|
||||||
// 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.isListContainer)) {
|
if (Boolean.TRUE.equals(var.isListContainer)) {
|
||||||
@ -247,6 +245,10 @@ public class ProtobufSchemaCodegen extends DefaultCodegen implements CodegenConf
|
|||||||
enumIndex++;
|
enumIndex++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add x-protobuf-index, unless already specified
|
||||||
|
var.vendorExtensions.putIfAbsent("x-protobuf-index", index);
|
||||||
|
index++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return objs;
|
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++;
|
index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ message {{operationId}}Request {
|
|||||||
{{#description}}
|
{{#description}}
|
||||||
// {{{.}}}
|
// {{{.}}}
|
||||||
{{/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}}
|
{{/allParams}}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ message {{classname}} {
|
|||||||
// {{{.}}}
|
// {{{.}}}
|
||||||
{{/description}}
|
{{/description}}
|
||||||
{{^isEnum}}
|
{{^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}}
|
||||||
{{#isEnum}}
|
{{#isEnum}}
|
||||||
enum {{name}} {
|
enum {{name}} {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user