From cbab1c412f6590eab3a06f60377c1f417fe54830 Mon Sep 17 00:00:00 2001 From: Jonathan Sawyer Date: Fri, 28 Jun 2024 02:20:30 +0200 Subject: [PATCH] Fix JsonSchemaGenerator to handle StructInfo with same alias and name (#5788) Motivation: - The `StructInfo` `alias` has the same value as the `name` causing a duplicate key exception when building `typeSignatureToStructMappingBuilder`. - Occurred when setting up a HTTP service which consumes protobuf messages Modifications: - Checks that the `struct` and `alias` don't have the same name to avoid duplicate key exception (alias is created here https://github.com/line/armeria/blob/main/protobuf/src/main/java/com/linecorp/armeria/server/protobuf/ProtobufDescriptiveTypeInfoProvider.java#L106) Result: - Improves the `JsonSchemaGenerator.java` for the documentation service by allowing resources to have the same alias and name as is the default behavior of https://github.com/line/armeria/blob/main/protobuf/src/main/java/com/linecorp/armeria/server/protobuf/ProtobufDescriptiveTypeInfoProvider.java#L106 --- .../com/linecorp/armeria/server/docs/JsonSchemaGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/com/linecorp/armeria/server/docs/JsonSchemaGenerator.java b/core/src/main/java/com/linecorp/armeria/server/docs/JsonSchemaGenerator.java index 8f81d157347..9796d3d15b2 100644 --- a/core/src/main/java/com/linecorp/armeria/server/docs/JsonSchemaGenerator.java +++ b/core/src/main/java/com/linecorp/armeria/server/docs/JsonSchemaGenerator.java @@ -77,7 +77,7 @@ private JsonSchemaGenerator(ServiceSpecification serviceSpecification) { ImmutableMap.builderWithExpectedSize(serviceSpecification.structs().size()); for (StructInfo struct : serviceSpecification.structs()) { typeSignatureToStructMappingBuilder.put(struct.name(), struct); - if (struct.alias() != null) { + if (struct.alias() != null && !struct.alias().equals(struct.name())) { // TypeSignature.signature() could be StructInfo.alias() if the type is a protobuf Message. typeSignatureToStructMappingBuilder.put(struct.alias(), struct); }