diff --git a/formats/protobuf/commonMain/src/kotlinx/serialization/protobuf/schema/ProtoBufSchemaGenerator.kt b/formats/protobuf/commonMain/src/kotlinx/serialization/protobuf/schema/ProtoBufSchemaGenerator.kt index b22df6267..4f4ca9c42 100644 --- a/formats/protobuf/commonMain/src/kotlinx/serialization/protobuf/schema/ProtoBufSchemaGenerator.kt +++ b/formats/protobuf/commonMain/src/kotlinx/serialization/protobuf/schema/ProtoBufSchemaGenerator.kt @@ -216,29 +216,34 @@ public object ProtoBufSchemaGenerator { val messageDescriptor = messageType.descriptor val fieldDescriptor = messageDescriptor.getElementDescriptor(index) + var unwrappedFieldDescriptor = fieldDescriptor + while (unwrappedFieldDescriptor.isInline) { + unwrappedFieldDescriptor = unwrappedFieldDescriptor.getElementDescriptor(0) + } + val nestedTypes: List val typeName: String = when { messageDescriptor.isSealedPolymorphic && index == 1 -> { appendLine(" // decoded as message with one of these types:") - nestedTypes = fieldDescriptor.elementDescriptors.map { TypeDefinition(it) }.toList() + nestedTypes = unwrappedFieldDescriptor.elementDescriptors.map { TypeDefinition(it) }.toList() nestedTypes.forEachIndexed { _, childType -> append(" // message ").append(childType.descriptor.messageOrEnumName).append(", serial name '") .append(removeLineBreaks(childType.descriptor.serialName)).appendLine('\'') } - fieldDescriptor.scalarTypeName() + unwrappedFieldDescriptor.scalarTypeName() } - fieldDescriptor.isProtobufScalar -> { + unwrappedFieldDescriptor.isProtobufScalar -> { nestedTypes = emptyList() - fieldDescriptor.scalarTypeName(messageDescriptor.getElementAnnotations(index)) + unwrappedFieldDescriptor.scalarTypeName(messageDescriptor.getElementAnnotations(index)) } - fieldDescriptor.isOpenPolymorphic -> { + unwrappedFieldDescriptor.isOpenPolymorphic -> { nestedTypes = listOf(SyntheticPolymorphicType) SyntheticPolymorphicType.descriptor.serialName } else -> { // enum or regular message - nestedTypes = listOf(TypeDefinition(fieldDescriptor)) - fieldDescriptor.messageOrEnumName + nestedTypes = listOf(TypeDefinition(unwrappedFieldDescriptor)) + unwrappedFieldDescriptor.messageOrEnumName } } diff --git a/formats/protobuf/jvmTest/resources/OptionalClass.proto b/formats/protobuf/jvmTest/resources/OptionalClass.proto index 41fdba71f..68fda00af 100644 --- a/formats/protobuf/jvmTest/resources/OptionalClass.proto +++ b/formats/protobuf/jvmTest/resources/OptionalClass.proto @@ -5,9 +5,21 @@ package kotlinx.serialization.protobuf.schema.generator; // serial name 'kotlinx.serialization.protobuf.schema.GenerationTest.OptionalClass' message OptionalClass { required int32 requiredInt = 1; + required int32 requiredUInt = 2; + required int32 requiredWrappedUInt = 3; // WARNING: a default value decoded when value is missing - optional int32 optionalInt = 2; - optional int32 nullableInt = 3; + optional int32 optionalInt = 4; // WARNING: a default value decoded when value is missing - optional int32 nullableOptionalInt = 4; + optional int32 optionalUInt = 5; + // WARNING: a default value decoded when value is missing + optional int32 optionalWrappedUInt = 6; + optional int32 nullableInt = 7; + optional int32 nullableUInt = 8; + optional int32 nullableWrappedUInt = 9; + // WARNING: a default value decoded when value is missing + optional int32 nullableOptionalInt = 10; + // WARNING: a default value decoded when value is missing + optional int32 nullableOptionalUInt = 11; + // WARNING: a default value decoded when value is missing + optional int32 nullableOptionalWrappedUInt = 12; } diff --git a/formats/protobuf/jvmTest/resources/common/schema.proto b/formats/protobuf/jvmTest/resources/common/schema.proto index 79e2d79ed..44b5a181d 100644 --- a/formats/protobuf/jvmTest/resources/common/schema.proto +++ b/formats/protobuf/jvmTest/resources/common/schema.proto @@ -63,11 +63,23 @@ message MapClass { // serial name 'kotlinx.serialization.protobuf.schema.GenerationTest.OptionalClass' message OptionalClass { required int32 requiredInt = 1; + required int32 requiredUInt = 2; + required int32 requiredWrappedUInt = 3; // WARNING: a default value decoded when value is missing - optional int32 optionalInt = 2; - optional int32 nullableInt = 3; + optional int32 optionalInt = 4; // WARNING: a default value decoded when value is missing - optional int32 nullableOptionalInt = 4; + optional int32 optionalUInt = 5; + // WARNING: a default value decoded when value is missing + optional int32 optionalWrappedUInt = 6; + optional int32 nullableInt = 7; + optional int32 nullableUInt = 8; + optional int32 nullableWrappedUInt = 9; + // WARNING: a default value decoded when value is missing + optional int32 nullableOptionalInt = 10; + // WARNING: a default value decoded when value is missing + optional int32 nullableOptionalUInt = 11; + // WARNING: a default value decoded when value is missing + optional int32 nullableOptionalWrappedUInt = 12; } // serial name 'kotlinx.serialization.protobuf.schema.GenerationTest.ContextualHolder' diff --git a/formats/protobuf/jvmTest/src/kotlinx/serialization/protobuf/schema/GenerationTest.kt b/formats/protobuf/jvmTest/src/kotlinx/serialization/protobuf/schema/GenerationTest.kt index 61a2dce55..f2a44234c 100644 --- a/formats/protobuf/jvmTest/src/kotlinx/serialization/protobuf/schema/GenerationTest.kt +++ b/formats/protobuf/jvmTest/src/kotlinx/serialization/protobuf/schema/GenerationTest.kt @@ -61,7 +61,7 @@ class GenerationTest { @ProtoNumber(5) val b: Int, @ProtoNumber(3) - val c: Int + val c: UInt, ) @Serializable @@ -84,6 +84,10 @@ class GenerationTest { @Serializable data class OptionsClass(val i: Int) + @JvmInline + @Serializable + value class WrappedUInt(val i : UInt) + @Serializable class ListClass( val intList: List, @@ -113,9 +117,17 @@ class GenerationTest { @Serializable data class OptionalClass( val requiredInt: Int, + val requiredUInt: UInt, + val requiredWrappedUInt: WrappedUInt, val optionalInt: Int = 5, + val optionalUInt: UInt = 5U, + val optionalWrappedUInt: WrappedUInt = WrappedUInt(5U), val nullableInt: Int?, - val nullableOptionalInt: Int? = 10 + val nullableUInt: UInt?, + val nullableWrappedUInt: WrappedUInt?, + val nullableOptionalInt: Int? = 10, + val nullableOptionalUInt: UInt? = 10U, + val nullableOptionalWrappedUInt: WrappedUInt? = WrappedUInt(10U), ) @Serializable