From d530d2327a00147bcd9151af1cabfaa51a7a6d19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20M=C3=A9lois?= Date: Thu, 30 May 2024 15:22:05 +0200 Subject: [PATCH 1/2] Bump alloy (and smithy), fix tests in consequence --- buildDeps.sc | 4 ++-- modules/openapi/tests/resources/issue-23.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/buildDeps.sc b/buildDeps.sc index 230b05a..8dbd8b3 100644 --- a/buildDeps.sc +++ b/buildDeps.sc @@ -3,7 +3,7 @@ import mill.define._ import mill.scalalib._ object alloy { - val alloyVersion = "0.3.4" + val alloyVersion = "0.3.9" val core = ivy"com.disneystreaming.alloy:alloy-core:$alloyVersion" val protobuf = @@ -25,7 +25,7 @@ object swagger { ) } object smithy { - val smithyVersion = "1.41.1" + val smithyVersion = "1.49.0" val model = ivy"software.amazon.smithy:smithy-model:$smithyVersion" val build = ivy"software.amazon.smithy:smithy-build:$smithyVersion" val diff = ivy"software.amazon.smithy:smithy-diff:$smithyVersion" diff --git a/modules/openapi/tests/resources/issue-23.json b/modules/openapi/tests/resources/issue-23.json index d35b11b..09b88ef 100644 --- a/modules/openapi/tests/resources/issue-23.json +++ b/modules/openapi/tests/resources/issue-23.json @@ -15,7 +15,7 @@ } ], "paths": { - "/Testers/{id}": { + "/Testers/{id_}": { "get": { "tags": ["Testers"], "summary": "Testers_GetTest", From 2113caa00d25d72ab63417dacc05eef61dbef872 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20M=C3=A9lois?= Date: Thu, 30 May 2024 15:28:28 +0200 Subject: [PATCH 2/2] Consider protoTimestampFormat on union members Adds logic to properly take protoTimestampFormat into consideration when applied on union members --- .../proto3/internals/Compiler.scala | 9 +++++- .../internals/CompilerRendererSuite.scala | 30 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/modules/proto/src/smithytranslate/proto3/internals/Compiler.scala b/modules/proto/src/smithytranslate/proto3/internals/Compiler.scala index 2227f00..e46a1a4 100644 --- a/modules/proto/src/smithytranslate/proto3/internals/Compiler.scala +++ b/modules/proto/src/smithytranslate/proto3/internals/Compiler.scala @@ -452,9 +452,16 @@ private[proto3] class Compiler(model: Model, allShapes: Boolean) { val isMap = targetShape.isMapShape() memberHasWrapped || targetHasWrapped || isList || isMap } + val maybeTimestampFormat = extractTimestampFormat(m) val fieldType = targetShape - .accept(typeVisitor(isWrapped = isWrapped, numType)) + .accept( + typeVisitor( + isWrapped = isWrapped, + numType, + maybeTimestampFormat + ) + ) .get val isDeprecated = m.hasTrait(classOf[DeprecatedTrait]) Field( diff --git a/modules/proto/tests/src/smithytranslate/proto3/internals/CompilerRendererSuite.scala b/modules/proto/tests/src/smithytranslate/proto3/internals/CompilerRendererSuite.scala index 76577a4..ce2695f 100644 --- a/modules/proto/tests/src/smithytranslate/proto3/internals/CompilerRendererSuite.scala +++ b/modules/proto/tests/src/smithytranslate/proto3/internals/CompilerRendererSuite.scala @@ -67,6 +67,36 @@ class CompilerRendererSuite extends FunSuite { convertCheck(source, Map("com/example/example.proto" -> expected)) } + test("top level - union with timestamp formats") { + val source = """|namespace com.example + | + |use alloy.proto#protoTimestampFormat + | + |union MyUnion { + | one: Timestamp + | @protoTimestampFormat("EPOCH_MILLIS") + | two: Timestamp + |} + |""".stripMargin + + val expected = """|syntax = "proto3"; + | + |package com.example; + | + |import "google/protobuf/timestamp.proto"; + | + |import "alloy/protobuf/types.proto"; + | + |message MyUnion { + | oneof definition { + | google.protobuf.Timestamp one = 1; + | alloy.protobuf.EpochMillisTimestamp two = 2; + | } + |} + |""".stripMargin + convertCheck(source, Map("com/example/example.proto" -> expected)) + } + test("@protoInlinedOneOf union - used within only one data structure") { val source = """|namespace com.example |