diff --git a/bin/configs/protobuf-schema-config.yaml b/bin/configs/protobuf-schema-config.yaml index 03df6bce30c..44ae7540fd8 100644 --- a/bin/configs/protobuf-schema-config.yaml +++ b/bin/configs/protobuf-schema-config.yaml @@ -7,4 +7,8 @@ additionalProperties: addJsonNameAnnotation: true numberedFieldNumberList: true startEnumsWithUnspecified: true - wrapComplexType: false \ No newline at end of file + wrapComplexType: false +typeMappings: + object: "google.protobuf.Struct" +importMappings: + google.protobuf.Struct: "google/protobuf/struct" \ No newline at end of file diff --git a/bin/configs/protobuf-schema.yaml b/bin/configs/protobuf-schema.yaml index 30f606c915f..c3947e075dc 100644 --- a/bin/configs/protobuf-schema.yaml +++ b/bin/configs/protobuf-schema.yaml @@ -4,3 +4,7 @@ inputSpec: modules/openapi-generator/src/test/resources/3_0/protobuf/petstore.ya templateDir: modules/openapi-generator/src/main/resources/protobuf-schema additionalProperties: packageName: petstore +typeMappings: + object: "google.protobuf.Struct" +importMappings: + google.protobuf.Struct: "google/protobuf/struct" diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ProtobufSchemaCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ProtobufSchemaCodegen.java index 052d1aa8321..78938f1cacf 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ProtobufSchemaCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ProtobufSchemaCodegen.java @@ -912,7 +912,11 @@ public class ProtobufSchemaCodegen extends DefaultCodegen implements CodegenConf @Override public String toModelImport(String name) { - return underscore(name); + if ("".equals(modelPackage())) { + return name; + } else { + return modelPackage() + "/" + underscore(name); + } } @Override diff --git a/modules/openapi-generator/src/main/resources/protobuf-schema/api.mustache b/modules/openapi-generator/src/main/resources/protobuf-schema/api.mustache index 4e4518615ac..cab1a8ac794 100644 --- a/modules/openapi-generator/src/main/resources/protobuf-schema/api.mustache +++ b/modules/openapi-generator/src/main/resources/protobuf-schema/api.mustache @@ -6,7 +6,7 @@ package {{#lambda.lowercase}}{{{packageName}}}.{{{apiPackage}}}.{{{classname}}}; import "google/protobuf/empty.proto"; {{#imports}} {{#import}} -import public "{{{modelPackage}}}/{{{.}}}.proto"; +import public "{{{import}}}.proto"; {{/import}} {{/imports}} diff --git a/modules/openapi-generator/src/main/resources/protobuf-schema/model.mustache b/modules/openapi-generator/src/main/resources/protobuf-schema/model.mustache index 6872f57f18d..df6b8af644c 100644 --- a/modules/openapi-generator/src/main/resources/protobuf-schema/model.mustache +++ b/modules/openapi-generator/src/main/resources/protobuf-schema/model.mustache @@ -5,7 +5,7 @@ package {{#lambda.lowercase}}{{{packageName}}};{{/lambda.lowercase}} {{#imports}} {{#import}} -import public "{{{modelPackage}}}/{{{import}}}.proto"; +import public "{{{.}}}.proto"; {{/import}} {{/imports}} diff --git a/modules/openapi-generator/src/test/resources/3_0/protobuf/petstore.yaml b/modules/openapi-generator/src/test/resources/3_0/protobuf/petstore.yaml index 2c4ee2647cd..01b109bdad1 100644 --- a/modules/openapi-generator/src/test/resources/3_0/protobuf/petstore.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/protobuf/petstore.yaml @@ -669,6 +669,8 @@ components: complete: type: boolean default: false + meta: + type: object xml: name: Order Category: diff --git a/samples/config/petstore/protobuf-schema-config/models/order.proto b/samples/config/petstore/protobuf-schema-config/models/order.proto index cc93af2330e..7f5283263ed 100644 --- a/samples/config/petstore/protobuf-schema-config/models/order.proto +++ b/samples/config/petstore/protobuf-schema-config/models/order.proto @@ -12,6 +12,7 @@ syntax = "proto3"; package petstore; +import public "google/protobuf/struct.proto"; message Order { @@ -35,4 +36,6 @@ message Order { bool complete = 6; + google.protobuf.Struct meta = 7; + } diff --git a/samples/config/petstore/protobuf-schema/models/order.proto b/samples/config/petstore/protobuf-schema/models/order.proto index cdd08cc15f3..c8df611f89b 100644 --- a/samples/config/petstore/protobuf-schema/models/order.proto +++ b/samples/config/petstore/protobuf-schema/models/order.proto @@ -12,6 +12,7 @@ syntax = "proto3"; package petstore; +import public "google/protobuf/struct.proto"; message Order { @@ -34,4 +35,6 @@ message Order { bool complete = 62574280; + google.protobuf.Struct meta = 3347973; + }