Skip to content

Commit f399910

Browse files
authoredMar 22, 2025··
protobuf import format (#20946)
1 parent f39675b commit f399910

File tree

8 files changed

+24
-4
lines changed

8 files changed

+24
-4
lines changed
 

‎bin/configs/protobuf-schema-config.yaml

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,8 @@ additionalProperties:
77
addJsonNameAnnotation: true
88
numberedFieldNumberList: true
99
startEnumsWithUnspecified: true
10-
wrapComplexType: false
10+
wrapComplexType: false
11+
typeMappings:
12+
object: "google.protobuf.Struct"
13+
importMappings:
14+
google.protobuf.Struct: "google/protobuf/struct"

‎bin/configs/protobuf-schema.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@ inputSpec: modules/openapi-generator/src/test/resources/3_0/protobuf/petstore.ya
44
templateDir: modules/openapi-generator/src/main/resources/protobuf-schema
55
additionalProperties:
66
packageName: petstore
7+
typeMappings:
8+
object: "google.protobuf.Struct"
9+
importMappings:
10+
google.protobuf.Struct: "google/protobuf/struct"

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,11 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
912912

913913
@Override
914914
public String toModelImport(String name) {
915-
return underscore(name);
915+
if ("".equals(modelPackage())) {
916+
return name;
917+
} else {
918+
return modelPackage() + "/" + underscore(name);
919+
}
916920
}
917921

918922
@Override

‎modules/openapi-generator/src/main/resources/protobuf-schema/api.mustache

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package {{#lambda.lowercase}}{{{packageName}}}.{{{apiPackage}}}.{{{classname}}};
66
import "google/protobuf/empty.proto";
77
{{#imports}}
88
{{#import}}
9-
import public "{{{modelPackage}}}/{{{.}}}.proto";
9+
import public "{{{import}}}.proto";
1010
{{/import}}
1111
{{/imports}}
1212

‎modules/openapi-generator/src/main/resources/protobuf-schema/model.mustache

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ package {{#lambda.lowercase}}{{{packageName}}};{{/lambda.lowercase}}
55

66
{{#imports}}
77
{{#import}}
8-
import public "{{{modelPackage}}}/{{{import}}}.proto";
8+
import public "{{{.}}}.proto";
99
{{/import}}
1010
{{/imports}}
1111

‎modules/openapi-generator/src/test/resources/3_0/protobuf/petstore.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,8 @@ components:
669669
complete:
670670
type: boolean
671671
default: false
672+
meta:
673+
type: object
672674
xml:
673675
name: Order
674676
Category:

‎samples/config/petstore/protobuf-schema-config/models/order.proto

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ syntax = "proto3";
1212

1313
package petstore;
1414

15+
import public "google/protobuf/struct.proto";
1516

1617
message Order {
1718

@@ -35,4 +36,6 @@ message Order {
3536

3637
bool complete = 6;
3738

39+
google.protobuf.Struct meta = 7;
40+
3841
}

‎samples/config/petstore/protobuf-schema/models/order.proto

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ syntax = "proto3";
1212

1313
package petstore;
1414

15+
import public "google/protobuf/struct.proto";
1516

1617
message Order {
1718

@@ -34,4 +35,6 @@ message Order {
3435

3536
bool complete = 62574280;
3637

38+
google.protobuf.Struct meta = 3347973;
39+
3740
}

0 commit comments

Comments
 (0)
Please sign in to comment.