Skip to content

Commit

Permalink
Merge pull request #160 from disneystreaming/revert-proto-filenames
Browse files Browse the repository at this point in the history
revert proto filename change
  • Loading branch information
lewisjkl authored Jul 18, 2023
2 parents 0dd1846 + af8a307 commit e0ce85d
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 41 deletions.
7 changes: 6 additions & 1 deletion modules/proto/core/src/smithyproto/proto3/Namespacing.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,13 @@ object Namespacing {
val parts = ns.split("\\.").toList
if (parts.size == 0) {
Fqn(None, "definitions") // should not happen
} else {
} else if (parts.size == 1) {
Fqn(Some(parts), "definitions")
} else {
// The reason for using the last directory as the filename as well is
// that the filename is used by several of the proto code generators
val last = parts.last
Fqn(Some(parts), last)
}
}
}
58 changes: 29 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/definitions.proto" -> expected))
convertCheck(source, Map("com/example/example.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/definitions.proto" -> expected))
convertCheck(source, Map("com/example/example.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/definitions.proto" -> expected))
convertCheck(source, Map("com/example/example.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/definitions.proto" -> expected))
convertCheck(source, Map("com/example/example.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/definitions.proto" -> expected))
convertCheck(source, Map("com/example/example.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/definitions.proto" -> expected))
convertCheck(source, Map("com/example/example.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/definitions.proto" -> expected))
convertCheck(source, Map("com/example/example.proto" -> expected))
}

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

convertCheck(source, Map("com/example/definitions.proto" -> expected))
convertCheck(source, Map("com/example/example.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/definitions.proto" -> expected))
convertCheck(source, Map("com/example/example.proto" -> expected))

}

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

test("top level - big decimal") {
Expand All @@ -333,7 +333,7 @@ class CompilerRendererSuite extends FunSuite {
|""".stripMargin
convertWithApiCheck(
source,
Map("com/example/definitions.proto" -> expected)
Map("com/example/example.proto" -> expected)
)
}

Expand All @@ -354,7 +354,7 @@ class CompilerRendererSuite extends FunSuite {
|""".stripMargin
convertWithApiCheck(
source,
Map("com/example/definitions.proto" -> expected)
Map("com/example/example.proto" -> expected)
)
}

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

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

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

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

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

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

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

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

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

}

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

test("transitive structure with protoEnabled") {
Expand Down Expand Up @@ -1074,7 +1074,7 @@ class CompilerRendererSuite extends FunSuite {
|}""".stripMargin
convertCheck(
source,
Map("avoid/cyclic/in/namespace/definitions.proto" -> expected)
Map("avoid/cyclic/in/namespace/namespace.proto" -> expected)
)
}

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

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

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

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

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

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

Expand Down
2 changes: 1 addition & 1 deletion modules/proto/examples/protobuf/demo/definitions.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package demo;

import "google/protobuf/empty.proto";

import "demo/common/definitions.proto";
import "demo/common/common.proto";

import "google/protobuf/wrappers.proto";

Expand Down

0 comments on commit e0ce85d

Please sign in to comment.