From d5979d3180c480965ccdc1ea5faaa9e88ebfd856 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20=C4=8Cerm=C3=A1k?= Date: Tue, 14 Dec 2021 08:44:22 +0100 Subject: [PATCH] [Protobuf-Schema] Added nullable (#11073) --- .../codegen/languages/ProtobufSchemaCodegen.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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 5f55e9d47f0..d842a935a0f 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 @@ -254,6 +254,9 @@ public class ProtobufSchemaCodegen extends DefaultCodegen implements CodegenConf if (Boolean.TRUE.equals(var.isArray)) { var.vendorExtensions.put("x-protobuf-type", "repeated"); } + else if (Boolean.TRUE.equals(var.isNullable && var.isPrimitiveType)) { + var.vendorExtensions.put("x-protobuf-type", "optional"); + } // add x-protobuf-data-type // ref: https://developers.google.com/protocol-buffers/docs/proto3 @@ -500,9 +503,14 @@ public class ProtobufSchemaCodegen extends DefaultCodegen implements CodegenConf int index = 1; for (CodegenParameter p : op.allParams) { // add x-protobuf-type: repeated if it's an array + if (Boolean.TRUE.equals(p.isArray)) { p.vendorExtensions.put("x-protobuf-type", "repeated"); - } else if (Boolean.TRUE.equals(p.isMap)) { + } + else if (Boolean.TRUE.equals(p.isNullable && p.isPrimitiveType)) { + p.vendorExtensions.put("x-protobuf-type", "optional"); + } + else if (Boolean.TRUE.equals(p.isMap)) { LOGGER.warn("Map parameter (name: {}, operation ID: {}) not yet supported", p.paramName, op.operationId); }