Skip to content

Commit

Permalink
Merge pull request #158 from disneystreaming/fix-proto-output-directo…
Browse files Browse the repository at this point in the history
…ries

fix so proto files are output to correct folders
  • Loading branch information
lewisjkl authored Jul 12, 2023
2 parents 6306e77 + de6518d commit 0dd1846
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 57 deletions.
5 changes: 1 addition & 4 deletions modules/proto/core/src/smithyproto/proto3/Namespacing.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,8 @@ object Namespacing {
val parts = ns.split("\\.").toList
if (parts.size == 0) {
Fqn(None, "definitions") // should not happen
} else if (parts.size == 1) {
Fqn(Some(parts), "definitions")
} else {
val last = parts.last
Fqn(Some(parts.init), last)
Fqn(Some(parts), "definitions")
}
}
}
67 changes: 38 additions & 29 deletions modules/proto/core/tests/src/CompilerRendererSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class CompilerRendererSuite extends FunSuite {
| }
|}
|""".stripMargin
convertCheck(source, Map("com/example.proto" -> expected))
convertCheck(source, Map("com/example/definitions.proto" -> expected))
}

test("@protoInlinedOneOf union - used within only one data structure") {
Expand Down Expand Up @@ -79,7 +79,7 @@ class CompilerRendererSuite extends FunSuite {
| string other = 4;
|}
|""".stripMargin
convertCheck(source, Map("com/example.proto" -> expected))
convertCheck(source, Map("com/example/definitions.proto" -> expected))
}

test(
Expand Down Expand Up @@ -146,7 +146,7 @@ class CompilerRendererSuite extends FunSuite {
| google.protobuf.Any value = 1;
|}
|""".stripMargin
convertCheck(source, Map("com/example.proto" -> expected))
convertCheck(source, Map("com/example/definitions.proto" -> expected))
}

test("top level - string") {
Expand All @@ -162,7 +162,7 @@ class CompilerRendererSuite extends FunSuite {
| string value = 1;
|}
|""".stripMargin
convertCheck(source, Map("com/example.proto" -> expected))
convertCheck(source, Map("com/example/definitions.proto" -> expected))
}

test("top level - structure") {
Expand All @@ -181,7 +181,7 @@ class CompilerRendererSuite extends FunSuite {
| string value = 1;
|}
|""".stripMargin
convertCheck(source, Map("com/example.proto" -> expected))
convertCheck(source, Map("com/example/definitions.proto" -> expected))
}

test("top level - int") {
Expand All @@ -197,7 +197,7 @@ class CompilerRendererSuite extends FunSuite {
| int32 value = 1;
|}
|""".stripMargin
convertCheck(source, Map("com/example.proto" -> expected))
convertCheck(source, Map("com/example/definitions.proto" -> expected))
}

test("top level - long") {
Expand All @@ -213,7 +213,7 @@ class CompilerRendererSuite extends FunSuite {
| int64 value = 1;
|}
|""".stripMargin
convertCheck(source, Map("com/example.proto" -> expected))
convertCheck(source, Map("com/example/definitions.proto" -> expected))
}

test("top level - double") {
Expand All @@ -230,7 +230,7 @@ class CompilerRendererSuite extends FunSuite {
|}
|""".stripMargin

convertCheck(source, Map("com/example.proto" -> expected))
convertCheck(source, Map("com/example/definitions.proto" -> expected))
}

test("top level - float") {
Expand All @@ -246,7 +246,7 @@ class CompilerRendererSuite extends FunSuite {
| float value = 1;
|}
|""".stripMargin
convertCheck(source, Map("com/example.proto" -> expected))
convertCheck(source, Map("com/example/definitions.proto" -> expected))

}

Expand All @@ -263,7 +263,7 @@ class CompilerRendererSuite extends FunSuite {
| int32 value = 1;
|}
|""".stripMargin
convertCheck(source, Map("com/example.proto" -> expected))
convertCheck(source, Map("com/example/definitions.proto" -> expected))
}

test("top level - bool") {
Expand All @@ -279,7 +279,7 @@ class CompilerRendererSuite extends FunSuite {
| bool value = 1;
|}
|""".stripMargin
convertCheck(source, Map("com/example.proto" -> expected))
convertCheck(source, Map("com/example/definitions.proto" -> expected))
}

test("top level - bytes") {
Expand All @@ -295,7 +295,7 @@ class CompilerRendererSuite extends FunSuite {
| bytes value = 1;
|}
|""".stripMargin
convertCheck(source, Map("com/example.proto" -> someBlob))
convertCheck(source, Map("com/example/definitions.proto" -> someBlob))
}

test("top level - big integer") {
Expand All @@ -313,7 +313,7 @@ class CompilerRendererSuite extends FunSuite {
| smithytranslate.BigInteger value = 1;
|}
|""".stripMargin
convertCheck(source, Map("com/example.proto" -> expected))
convertCheck(source, Map("com/example/definitions.proto" -> expected))
}

test("top level - big decimal") {
Expand All @@ -331,7 +331,10 @@ class CompilerRendererSuite extends FunSuite {
| smithytranslate.BigDecimal value = 1;
|}
|""".stripMargin
convertWithApiCheck(source, Map("com/example.proto" -> expected))
convertWithApiCheck(
source,
Map("com/example/definitions.proto" -> expected)
)
}

test("top level - timestamp") {
Expand All @@ -349,7 +352,10 @@ class CompilerRendererSuite extends FunSuite {
| smithytranslate.Timestamp value = 1;
|}
|""".stripMargin
convertWithApiCheck(source, Map("com/example.proto" -> expected))
convertWithApiCheck(
source,
Map("com/example/definitions.proto" -> expected)
)
}

test("proto top-level deprecated") {
Expand All @@ -368,7 +374,7 @@ class CompilerRendererSuite extends FunSuite {
| string value = 1 [deprecated = true];
|}
|""".stripMargin
convertCheck(source, Map("another/namespace.proto" -> expected))
convertCheck(source, Map("another/namespace/definitions.proto" -> expected))
}

test("proto structure deprecated") {
Expand All @@ -390,7 +396,7 @@ class CompilerRendererSuite extends FunSuite {
| string value = 1 [deprecated = true];
|}
|""".stripMargin
convertCheck(source, Map("another/namespace.proto" -> expected))
convertCheck(source, Map("another/namespace/definitions.proto" -> expected))
}

test("protoNumType") {
Expand Down Expand Up @@ -498,7 +504,7 @@ class CompilerRendererSuite extends FunSuite {
|}""".stripMargin
convertCheck(
source,
Map("com/example.proto" -> expected)
Map("com/example/definitions.proto" -> expected)
)
}

Expand All @@ -525,7 +531,7 @@ class CompilerRendererSuite extends FunSuite {
| map<string, google.protobuf.StringValue> object = 1;
|}
|""".stripMargin
convertCheck(source, Map("com/example.proto" -> expected))
convertCheck(source, Map("com/example/definitions.proto" -> expected))
}

test("inlined maps message") {
Expand Down Expand Up @@ -557,7 +563,7 @@ class CompilerRendererSuite extends FunSuite {
| map<string, com.example.MapItem> values = 1;
|}
|""".stripMargin
convertCheck(source, Map("com/example.proto" -> expected))
convertCheck(source, Map("com/example/definitions.proto" -> expected))
}

test("inlined maps") {
Expand All @@ -580,7 +586,7 @@ class CompilerRendererSuite extends FunSuite {
| map<string, int32> strings = 1;
|}
|""".stripMargin
convertCheck(source, Map("com/example.proto" -> expected))
convertCheck(source, Map("com/example/definitions.proto" -> expected))
}

test("inlined lists") {
Expand All @@ -602,7 +608,7 @@ class CompilerRendererSuite extends FunSuite {
| repeated string strings = 1;
|}
|""".stripMargin
convertCheck(source, Map("com/example.proto" -> expected))
convertCheck(source, Map("com/example/definitions.proto" -> expected))
}

test("inlined sparse lists") {
Expand All @@ -627,7 +633,7 @@ class CompilerRendererSuite extends FunSuite {
| repeated google.protobuf.StringValue strings = 1;
|}
|""".stripMargin
convertCheck(source, Map("com/example.proto" -> expected))
convertCheck(source, Map("com/example/definitions.proto" -> expected))
}

test("inlined lists message") {
Expand Down Expand Up @@ -659,7 +665,7 @@ class CompilerRendererSuite extends FunSuite {
| repeated com.example.ListItem strings = 1;
|}
|""".stripMargin
convertCheck(source, Map("com/example.proto" -> expected))
convertCheck(source, Map("com/example/definitions.proto" -> expected))

}

Expand Down Expand Up @@ -703,7 +709,7 @@ class CompilerRendererSuite extends FunSuite {
|message Unions {
| repeated com.example.UnionStruct values = 1;
|}""".stripMargin
convertCheck(source, Map("com/example.proto" -> expected))
convertCheck(source, Map("com/example/definitions.proto" -> expected))
}

test("transitive structure with protoEnabled") {
Expand Down Expand Up @@ -1066,7 +1072,10 @@ class CompilerRendererSuite extends FunSuite {
|message Two {
| avoid.cyclic.in.namespace.One one = 1;
|}""".stripMargin
convertCheck(source, Map("avoid/cyclic/in/namespace.proto" -> expected))
convertCheck(
source,
Map("avoid/cyclic/in/namespace/definitions.proto" -> expected)
)
}

test("multiple namespaces") {
Expand All @@ -1085,8 +1094,8 @@ class CompilerRendererSuite extends FunSuite {
convertChecks(
Map("ns1.smithy" -> src("ns1"), "ns2.smithy" -> src("ns2")),
Map(
"com/ns1.proto" -> expected("ns1"),
"com/ns2.proto" -> expected("ns2")
"com/ns1/definitions.proto" -> expected("ns1"),
"com/ns2/definitions.proto" -> expected("ns2")
)
)
}
Expand Down Expand Up @@ -1116,7 +1125,7 @@ class CompilerRendererSuite extends FunSuite {
| string value = 1;
|}
|""".stripMargin
convertCheck(source, Map("another/namespace.proto" -> expected))
convertCheck(source, Map("another/namespace/definitions.proto" -> expected))
}

/** Perform the same check as convertCheck but include the smithytranslate
Expand Down
33 changes: 23 additions & 10 deletions modules/proto/core/tests/src/CompilerSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ class CompilerSuite extends FunSuite {
OutputFile(
List(
"com",
"example.proto"
"example",
"definitions.proto"
),
CompilationUnit(
Some(
Expand All @@ -75,26 +76,38 @@ class CompilerSuite extends FunSuite {
}

test("correctly choose file name - all caps") {
namespaceTest("com.EXAMPLE", List("com", "example.proto"))
namespaceTest("com.EXAMPLE", List("com", "EXAMPLE", "definitions.proto"))
}

test("correctly choose file name - underscore") {
namespaceTest("com.some_example", List("com", "some_example.proto"))
namespaceTest(
"com.some_example",
List("com", "some_example", "definitions.proto")
)
}

test("correctly choose file name - leading underscore") {
namespaceTest("com._example", List("com", "_example.proto"))
namespaceTest("com._EXAMPLE", List("com", "_example.proto"))
namespaceTest("com._Example", List("com", "_example.proto"))
namespaceTest("com._example", List("com", "_example", "definitions.proto"))
namespaceTest("com._EXAMPLE", List("com", "_EXAMPLE", "definitions.proto"))
namespaceTest("com._Example", List("com", "_Example", "definitions.proto"))
}

test("correctly choose file name - underscore and caps") {
namespaceTest("com.some_EXAMPLE", List("com", "some_example.proto"))
namespaceTest("com.SOME_EXAMPLE", List("com", "some_example.proto"))
namespaceTest("com.Some_Example", List("com", "some_example.proto"))
namespaceTest(
"com.some_EXAMPLE",
List("com", "some_EXAMPLE", "definitions.proto")
)
namespaceTest(
"com.SOME_EXAMPLE",
List("com", "SOME_EXAMPLE", "definitions.proto")
)
namespaceTest(
"com.Some_Example",
List("com", "Some_Example", "definitions.proto")
)
namespaceTest(
"com.Some_OTHER_Example",
List("com", "some_other_example.proto")
List("com", "Some_OTHER_Example", "definitions.proto")
)
}

Expand Down
8 changes: 8 additions & 0 deletions modules/proto/examples/protobuf/demo/common/definitions.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
syntax = "proto3";

package demo.common;

enum Language {
FRENCH = 0;
ENGLISH = 1;
}
9 changes: 3 additions & 6 deletions modules/proto/examples/protobuf/demo/definitions.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ package demo;

import "google/protobuf/empty.proto";

import "demo/common/definitions.proto";

import "google/protobuf/wrappers.proto";

import "smithytranslate/definitions.proto";
Expand All @@ -13,15 +15,10 @@ service Hello {
rpc Greet(google.protobuf.Empty) returns (demo.HelloResponse);
}

enum Language {
FRENCH = 0;
ENGLISH = 1;
}

message HelloRequest {
reserved 3;
string name = 1;
demo.Language lang = 2;
demo.common.Language lang = 2;
int32 requiredInt = 4;
google.protobuf.Int32Value int = 5;
smithytranslate.UUID id = 6;
Expand Down
13 changes: 13 additions & 0 deletions modules/proto/examples/smithy/common.smithy
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
$version: "2"

namespace demo.common

use alloy.proto#protoIndex

// protoindex is not necessary , this is just for demo purposes
enum Language{
@protoIndex(0)
FRENCH
@protoIndex(1)
ENGLISH
}
Loading

0 comments on commit 0dd1846

Please sign in to comment.