From a4c1b660e4e37cf9ea2585eb0cbef5158ef82da2 Mon Sep 17 00:00:00 2001 From: Stephan Behnke Date: Fri, 20 Nov 2026 08:36:48 -0700 Subject: [PATCH 01/20] generate-stable-protos: turn draft schema validation cases into fixtures What Moves draft schema validation cases into fixture directories with their own inputs and expected diagnostics. Why Each validation rule can be read and exercised directly through the common fixture runner. Co-Authored-By: Claude Opus 5.5 --- .../schema/missing-extension/expected.json | 3 ++ .../api_next/protometa/v1/draft.proto | 2 + .../input/temporal/api_next/fixture.proto | 3 ++ .../api_next/protometa/v1/draft.proto | 13 ++++++ .../schema/wrong-extendee/expected.json | 3 ++ .../api_next/protometa/v1/draft.proto | 11 +++++ .../testdata/schema/wrong-type/expected.json | 3 ++ .../api_next/protometa/v1/draft.proto | 11 +++++ cmd/generate-stable-protos/walk_test.go | 45 ------------------- 9 files changed, 49 insertions(+), 45 deletions(-) create mode 100644 cmd/generate-stable-protos/testdata/schema/missing-extension/expected.json create mode 100644 cmd/generate-stable-protos/testdata/schema/missing-extension/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/schema/unrelated-extension/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/schema/unrelated-extension/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/schema/wrong-extendee/expected.json create mode 100644 cmd/generate-stable-protos/testdata/schema/wrong-extendee/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/schema/wrong-type/expected.json create mode 100644 cmd/generate-stable-protos/testdata/schema/wrong-type/input/temporal/api_next/protometa/v1/draft.proto delete mode 100644 cmd/generate-stable-protos/walk_test.go diff --git a/cmd/generate-stable-protos/testdata/schema/missing-extension/expected.json b/cmd/generate-stable-protos/testdata/schema/missing-extension/expected.json new file mode 100644 index 000000000..5d56824f1 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/schema/missing-extension/expected.json @@ -0,0 +1,3 @@ +{ + "error": "temporal.api.protometa.v1.draft not found in temporal/api_next/protometa/v1/draft.proto" +} diff --git a/cmd/generate-stable-protos/testdata/schema/missing-extension/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/schema/missing-extension/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..150a05051 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/schema/missing-extension/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,2 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; diff --git a/cmd/generate-stable-protos/testdata/schema/unrelated-extension/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/schema/unrelated-extension/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..522fe91cb --- /dev/null +++ b/cmd/generate-stable-protos/testdata/schema/unrelated-extension/input/temporal/api_next/fixture.proto @@ -0,0 +1,3 @@ +syntax = "proto3"; +package fixture; +message Stable {} diff --git a/cmd/generate-stable-protos/testdata/schema/unrelated-extension/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/schema/unrelated-extension/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..9be4b3dea --- /dev/null +++ b/cmd/generate-stable-protos/testdata/schema/unrelated-extension/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,13 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98111; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.FileOptions { string draft_file = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98008; } +// An extension outside the draft name table is not a draft option and needs no schema check. +extend google.protobuf.FileOptions { bool draft_notes = 98112; } diff --git a/cmd/generate-stable-protos/testdata/schema/wrong-extendee/expected.json b/cmd/generate-stable-protos/testdata/schema/wrong-extendee/expected.json new file mode 100644 index 000000000..8d63acef6 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/schema/wrong-extendee/expected.json @@ -0,0 +1,3 @@ +{ + "error": "invalid draft option schema for temporal.api.protometa.v1.draft: want singular string extending google.protobuf.FieldOptions" +} diff --git a/cmd/generate-stable-protos/testdata/schema/wrong-extendee/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/schema/wrong-extendee/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..6ddd4255e --- /dev/null +++ b/cmd/generate-stable-protos/testdata/schema/wrong-extendee/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.OneofOptions { string draft = 98111; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.FileOptions { string draft_file = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98008; } diff --git a/cmd/generate-stable-protos/testdata/schema/wrong-type/expected.json b/cmd/generate-stable-protos/testdata/schema/wrong-type/expected.json new file mode 100644 index 000000000..8d63acef6 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/schema/wrong-type/expected.json @@ -0,0 +1,3 @@ +{ + "error": "invalid draft option schema for temporal.api.protometa.v1.draft: want singular string extending google.protobuf.FieldOptions" +} diff --git a/cmd/generate-stable-protos/testdata/schema/wrong-type/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/schema/wrong-type/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..83f5b25e3 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/schema/wrong-type/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { bool draft = 98111; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.FileOptions { string draft_file = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98008; } diff --git a/cmd/generate-stable-protos/walk_test.go b/cmd/generate-stable-protos/walk_test.go deleted file mode 100644 index 243fdf638..000000000 --- a/cmd/generate-stable-protos/walk_test.go +++ /dev/null @@ -1,45 +0,0 @@ -package main - -import ( - "os" - "path/filepath" - "strings" - "testing" -) - -func TestDraftSchemaValidation(t *testing.T) { - t.Parallel() - schema, err := os.ReadFile("testdata/classification/valid/input/temporal/api_next/protometa/v1/draft.proto") - if err != nil { - t.Fatal(err) - } - for _, tc := range []struct{ name, schema, want string }{ - {"wrong type", strings.Replace(string(schema), "string draft =", "bool draft =", 1), "invalid draft option schema"}, - {"wrong extendee", strings.Replace(string(schema), "FieldOptions", "OneofOptions", 1), "invalid draft option schema"}, - {"missing extension", `syntax = "proto3"; package temporal.api.protometa.v1;`, "not found"}, - // An extension outside the draft name table is not a draft option and needs no schema check. - {"unrelated extension", string(schema) + "extend google.protobuf.FileOptions { bool draft_notes = 98112; }\n", ""}, - } { - t.Run(tc.name, func(t *testing.T) { - t.Parallel() - root := t.TempDir() - path := filepath.Join(root, draftTagsPath) - if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil { - t.Fatal(err) - } - if err := os.WriteFile(path, []byte(tc.schema), 0600); err != nil { - t.Fatal(err) - } - err := stableProtosGenerator(t.Context(), root, t.TempDir()) - if tc.want == "" { - if err != nil { - t.Fatal(err) - } - return - } - if err == nil || !strings.Contains(err.Error(), tc.want) { - t.Fatalf("want %q, got %v", tc.want, err) - } - }) - } -} From fa437510d945e248b47fcb5e2a23d5fe480d5925 Mon Sep 17 00:00:00 2001 From: Stephan Behnke Date: Fri, 20 Nov 2026 08:37:18 -0700 Subject: [PATCH 02/20] generate-stable-protos: turn comment ownership cases into fixtures What Moves accepted and rejected draft comment placements into standalone fixtures. Why Reviewers can see the exact comment placement that produces each expected result. Co-Authored-By: Claude Opus 5.5 --- cmd/generate-stable-protos/comments_test.go | 96 ------------------- .../testdata/comments/README.md | 9 ++ .../after-nested-draft-message/expected.json | 3 + .../input/temporal/api_next/fixture.proto | 43 +++++++++ .../api_next/protometa/v1/draft.proto | 0 .../comments/{ => attached}/expected.json | 0 .../expected/temporal/api/fixture.proto | 0 .../input/temporal/api_next/fixture.proto | 0 .../api_next/protometa/v1/draft.proto | 11 +++ .../expected.json | 3 + .../input/temporal/api_next/fixture.proto | 41 ++++++++ .../api_next/protometa/v1/draft.proto | 11 +++ .../expected.json | 3 + .../input/temporal/api_next/fixture.proto | 40 ++++++++ .../api_next/protometa/v1/draft.proto | 11 +++ .../detached-section-header/expected.json | 3 + .../input/temporal/api_next/fixture.proto | 40 ++++++++ .../api_next/protometa/v1/draft.proto | 11 +++ .../expected.json | 3 + .../input/temporal/api_next/fixture.proto | 43 +++++++++ .../api_next/protometa/v1/draft.proto | 11 +++ .../comments/next-line-trailing/expected.json | 3 + .../input/temporal/api_next/fixture.proto | 39 ++++++++ .../api_next/protometa/v1/draft.proto | 11 +++ 24 files changed, 339 insertions(+), 96 deletions(-) delete mode 100644 cmd/generate-stable-protos/comments_test.go create mode 100644 cmd/generate-stable-protos/testdata/comments/README.md create mode 100644 cmd/generate-stable-protos/testdata/comments/after-nested-draft-message/expected.json create mode 100644 cmd/generate-stable-protos/testdata/comments/after-nested-draft-message/input/temporal/api_next/fixture.proto rename cmd/generate-stable-protos/testdata/comments/{ => after-nested-draft-message}/input/temporal/api_next/protometa/v1/draft.proto (100%) rename cmd/generate-stable-protos/testdata/comments/{ => attached}/expected.json (100%) rename cmd/generate-stable-protos/testdata/comments/{ => attached}/expected/temporal/api/fixture.proto (100%) rename cmd/generate-stable-protos/testdata/comments/{ => attached}/input/temporal/api_next/fixture.proto (100%) create mode 100644 cmd/generate-stable-protos/testdata/comments/attached/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/comments/dangling-after-last-draft-field/expected.json create mode 100644 cmd/generate-stable-protos/testdata/comments/dangling-after-last-draft-field/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/comments/dangling-after-last-draft-field/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/comments/detached-before-stable-field/expected.json create mode 100644 cmd/generate-stable-protos/testdata/comments/detached-before-stable-field/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/comments/detached-before-stable-field/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/comments/detached-section-header/expected.json create mode 100644 cmd/generate-stable-protos/testdata/comments/detached-section-header/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/comments/detached-section-header/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/comments/end-of-file-after-draft-message/expected.json create mode 100644 cmd/generate-stable-protos/testdata/comments/end-of-file-after-draft-message/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/comments/end-of-file-after-draft-message/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/comments/next-line-trailing/expected.json create mode 100644 cmd/generate-stable-protos/testdata/comments/next-line-trailing/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/comments/next-line-trailing/input/temporal/api_next/protometa/v1/draft.proto diff --git a/cmd/generate-stable-protos/comments_test.go b/cmd/generate-stable-protos/comments_test.go deleted file mode 100644 index 37e2590bb..000000000 --- a/cmd/generate-stable-protos/comments_test.go +++ /dev/null @@ -1,96 +0,0 @@ -package main - -import ( - "os" - "path/filepath" - "strings" - "testing" -) - -// TestDraftCommentOwnership checks that no comment belonging to a removed draft -// declaration survives in the stable output: neither one protoc attributes to it, nor one -// after it that protoc attaches to nothing. The passing case also pins the raw printer -// output, which TestStableProjection cannot see because it runs buf format first. -func TestDraftCommentOwnership(t *testing.T) { - t.Parallel() - const fixture = "temporal/api_next/fixture.proto" - const after = `after a removed draft declaration would survive in the stable output; move it directly above a declaration, or delete it` - input, err := os.ReadFile(filepath.Join("testdata/comments/input", fixture)) - if err != nil { - t.Fatal(err) - } - for _, tc := range []struct{ name, old, new, want string }{ - {"attached comments are removed", "", "", ""}, - { - "next-line trailing comment", - "= \"f\"];\n", - "= \"f\"];\n // Next-line trailing comment of f.\n", - `temporal/api_next/fixture.proto:16: comment "// Next-line trailing comment of f." ` + after, - }, - { - "detached comment before the next stable field", - "= \"f\"];\n", - "= \"f\"];\n\n // Detached comment before d.\n", - `temporal/api_next/fixture.proto:17: comment "// Detached comment before d." ` + after, - }, - { - "comment after a nested draft message", - " // leading h shares the word DRAFT\n", - " message Inner {\n option (temporal.api.protometa.v1.draft_message) = \"inner\";\n }\n // Note after Inner.\n\n // leading h shares the word DRAFT\n", - `temporal/api_next/fixture.proto:30: comment "// Note after Inner." ` + after, - }, - { - "dangling comment after the last draft field", - " string h = 9;\n}", - " string h = 9;\n string z = 10 [(temporal.api.protometa.v1.draft) = \"z\"];\n\n // Note about z.\n}", - `temporal/api_next/fixture.proto:31: comment "// Note about z." ` + after, - }, - { - "comment at end of file after a draft message", - "message Flat { string x = 1; }\n", - "message Flat { string x = 1; }\n\nmessage Tail {\n option (temporal.api.protometa.v1.draft_message) = \"tail\";\n}\n// Note after Tail.\n", - `temporal/api_next/fixture.proto:43: comment "// Note after Tail." ` + after, - }, - { - "detached section header", - "}\n\n// DRAFT leading comment of draft message.", - "}\n\n// Section header: draft messages follow.\n\n// DRAFT leading comment of draft message.", - `comment "Section header: draft messages follow." of a removed draft declaration survives`, - }, - } { - t.Run(tc.name, func(t *testing.T) { - t.Parallel() - root, out := t.TempDir(), t.TempDir() - if err := os.CopyFS(root, os.DirFS("testdata/comments/input")); err != nil { - t.Fatal(err) - } - if tc.old != "" && strings.Count(string(input), tc.old) != 1 { - t.Fatalf("fixture must contain %q once", tc.old) - } - if err := os.WriteFile(filepath.Join(root, fixture), []byte(strings.Replace(string(input), tc.old, tc.new, 1)), 0600); err != nil { - t.Fatal(err) - } - err := stableProtosGenerator(t.Context(), root, out) - if tc.want != "" { - if err == nil || !strings.Contains(err.Error(), tc.want) { - t.Fatalf("want %q, got %v", tc.want, err) - } - return - } - if err != nil { - t.Fatal(err) - } - expected, err := os.ReadFile("testdata/comments/expected/temporal/api/fixture.proto") - if err != nil { - t.Fatal(err) - } - actual, err := os.ReadFile(filepath.Join(out, "temporal/api/fixture.proto")) - if err != nil { - t.Fatal(err) - } - if body, ok := strings.CutPrefix(string(actual), generatedHeader); !ok || body != string(expected) { - t.Fatalf("raw printer output differs\nexpected:\n%s\nactual:\n%s", expected, actual) - } - }) - } -} diff --git a/cmd/generate-stable-protos/testdata/comments/README.md b/cmd/generate-stable-protos/testdata/comments/README.md new file mode 100644 index 000000000..b15930924 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/comments/README.md @@ -0,0 +1,9 @@ +# Comment ownership fixtures + +No comment belonging to a removed draft declaration may survive in the stable output: +neither one protoc attributes to it, nor one after it that protoc attaches to nothing. + +- `attached`: comments attached to removed declarations are removed; its golden pins the + raw printer output. +- Every other case adds one comment the generator must reject, because it would + otherwise survive next to where a draft declaration was removed. diff --git a/cmd/generate-stable-protos/testdata/comments/after-nested-draft-message/expected.json b/cmd/generate-stable-protos/testdata/comments/after-nested-draft-message/expected.json new file mode 100644 index 000000000..7cde9b617 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/comments/after-nested-draft-message/expected.json @@ -0,0 +1,3 @@ +{ + "error": "temporal/api_next/fixture.proto:30: comment \"// Note after Inner.\" after a removed draft declaration would survive in the stable output; move it directly above a declaration, or delete it" +} diff --git a/cmd/generate-stable-protos/testdata/comments/after-nested-draft-message/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/comments/after-nested-draft-message/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..8675696cf --- /dev/null +++ b/cmd/generate-stable-protos/testdata/comments/after-nested-draft-message/input/temporal/api_next/fixture.proto @@ -0,0 +1,43 @@ +syntax = "proto3"; + +package fixture; + +import "temporal/api_next/protometa/v1/draft.proto"; + +// Stable doc. +message Keeper { + string a = 1; // trailing a + string b = 2 [(temporal.api.protometa.v1.draft) = "b"]; // DRAFT same-line trailing b + // DRAFT leading c + string c = 3 [(temporal.api.protometa.v1.draft) = "c"]; + // DRAFT wrapped leading doc of f, + // DRAFT continued on a second line. + string f = 4 [(temporal.api.protometa.v1.draft) = "f"]; + + // leading d + string d=5 ; + Thing t = 6; /* DRAFT block trailing t */ + string e = 7 [ + // DRAFT inside options + (temporal.api.protometa.v1.draft) = "e" /* DRAFT inside options block */ + ]; + /* DRAFT block leading g + * continued */ + string g = 8 [(temporal.api.protometa.v1.draft) = "g"]; + message Inner { + option (temporal.api.protometa.v1.draft_message) = "inner"; + } + // Note after Inner. + + // leading h shares the word DRAFT + string h = 9; +} + +// DRAFT leading comment of draft message. +message Thing { + option (temporal.api.protometa.v1.draft_message) = "thing"; + // DRAFT nested leading + string v = 1; // DRAFT nested trailing +} // DRAFT trailing on draft message close + +message Flat { string x = 1; } diff --git a/cmd/generate-stable-protos/testdata/comments/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/comments/after-nested-draft-message/input/temporal/api_next/protometa/v1/draft.proto similarity index 100% rename from cmd/generate-stable-protos/testdata/comments/input/temporal/api_next/protometa/v1/draft.proto rename to cmd/generate-stable-protos/testdata/comments/after-nested-draft-message/input/temporal/api_next/protometa/v1/draft.proto diff --git a/cmd/generate-stable-protos/testdata/comments/expected.json b/cmd/generate-stable-protos/testdata/comments/attached/expected.json similarity index 100% rename from cmd/generate-stable-protos/testdata/comments/expected.json rename to cmd/generate-stable-protos/testdata/comments/attached/expected.json diff --git a/cmd/generate-stable-protos/testdata/comments/expected/temporal/api/fixture.proto b/cmd/generate-stable-protos/testdata/comments/attached/expected/temporal/api/fixture.proto similarity index 100% rename from cmd/generate-stable-protos/testdata/comments/expected/temporal/api/fixture.proto rename to cmd/generate-stable-protos/testdata/comments/attached/expected/temporal/api/fixture.proto diff --git a/cmd/generate-stable-protos/testdata/comments/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/comments/attached/input/temporal/api_next/fixture.proto similarity index 100% rename from cmd/generate-stable-protos/testdata/comments/input/temporal/api_next/fixture.proto rename to cmd/generate-stable-protos/testdata/comments/attached/input/temporal/api_next/fixture.proto diff --git a/cmd/generate-stable-protos/testdata/comments/attached/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/comments/attached/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..03c5c5701 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/comments/attached/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98111; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.FileOptions { string draft_file = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98008; } diff --git a/cmd/generate-stable-protos/testdata/comments/dangling-after-last-draft-field/expected.json b/cmd/generate-stable-protos/testdata/comments/dangling-after-last-draft-field/expected.json new file mode 100644 index 000000000..bf8b77cd5 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/comments/dangling-after-last-draft-field/expected.json @@ -0,0 +1,3 @@ +{ + "error": "temporal/api_next/fixture.proto:31: comment \"// Note about z.\" after a removed draft declaration would survive in the stable output; move it directly above a declaration, or delete it" +} diff --git a/cmd/generate-stable-protos/testdata/comments/dangling-after-last-draft-field/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/comments/dangling-after-last-draft-field/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..3930a3ee7 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/comments/dangling-after-last-draft-field/input/temporal/api_next/fixture.proto @@ -0,0 +1,41 @@ +syntax = "proto3"; + +package fixture; + +import "temporal/api_next/protometa/v1/draft.proto"; + +// Stable doc. +message Keeper { + string a = 1; // trailing a + string b = 2 [(temporal.api.protometa.v1.draft) = "b"]; // DRAFT same-line trailing b + // DRAFT leading c + string c = 3 [(temporal.api.protometa.v1.draft) = "c"]; + // DRAFT wrapped leading doc of f, + // DRAFT continued on a second line. + string f = 4 [(temporal.api.protometa.v1.draft) = "f"]; + + // leading d + string d=5 ; + Thing t = 6; /* DRAFT block trailing t */ + string e = 7 [ + // DRAFT inside options + (temporal.api.protometa.v1.draft) = "e" /* DRAFT inside options block */ + ]; + /* DRAFT block leading g + * continued */ + string g = 8 [(temporal.api.protometa.v1.draft) = "g"]; + // leading h shares the word DRAFT + string h = 9; + string z = 10 [(temporal.api.protometa.v1.draft) = "z"]; + + // Note about z. +} + +// DRAFT leading comment of draft message. +message Thing { + option (temporal.api.protometa.v1.draft_message) = "thing"; + // DRAFT nested leading + string v = 1; // DRAFT nested trailing +} // DRAFT trailing on draft message close + +message Flat { string x = 1; } diff --git a/cmd/generate-stable-protos/testdata/comments/dangling-after-last-draft-field/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/comments/dangling-after-last-draft-field/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..03c5c5701 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/comments/dangling-after-last-draft-field/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98111; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.FileOptions { string draft_file = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98008; } diff --git a/cmd/generate-stable-protos/testdata/comments/detached-before-stable-field/expected.json b/cmd/generate-stable-protos/testdata/comments/detached-before-stable-field/expected.json new file mode 100644 index 000000000..f2a613edc --- /dev/null +++ b/cmd/generate-stable-protos/testdata/comments/detached-before-stable-field/expected.json @@ -0,0 +1,3 @@ +{ + "error": "temporal/api_next/fixture.proto:17: comment \"// Detached comment before d.\" after a removed draft declaration would survive in the stable output; move it directly above a declaration, or delete it" +} diff --git a/cmd/generate-stable-protos/testdata/comments/detached-before-stable-field/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/comments/detached-before-stable-field/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..e0176368d --- /dev/null +++ b/cmd/generate-stable-protos/testdata/comments/detached-before-stable-field/input/temporal/api_next/fixture.proto @@ -0,0 +1,40 @@ +syntax = "proto3"; + +package fixture; + +import "temporal/api_next/protometa/v1/draft.proto"; + +// Stable doc. +message Keeper { + string a = 1; // trailing a + string b = 2 [(temporal.api.protometa.v1.draft) = "b"]; // DRAFT same-line trailing b + // DRAFT leading c + string c = 3 [(temporal.api.protometa.v1.draft) = "c"]; + // DRAFT wrapped leading doc of f, + // DRAFT continued on a second line. + string f = 4 [(temporal.api.protometa.v1.draft) = "f"]; + + // Detached comment before d. + + // leading d + string d=5 ; + Thing t = 6; /* DRAFT block trailing t */ + string e = 7 [ + // DRAFT inside options + (temporal.api.protometa.v1.draft) = "e" /* DRAFT inside options block */ + ]; + /* DRAFT block leading g + * continued */ + string g = 8 [(temporal.api.protometa.v1.draft) = "g"]; + // leading h shares the word DRAFT + string h = 9; +} + +// DRAFT leading comment of draft message. +message Thing { + option (temporal.api.protometa.v1.draft_message) = "thing"; + // DRAFT nested leading + string v = 1; // DRAFT nested trailing +} // DRAFT trailing on draft message close + +message Flat { string x = 1; } diff --git a/cmd/generate-stable-protos/testdata/comments/detached-before-stable-field/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/comments/detached-before-stable-field/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..03c5c5701 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/comments/detached-before-stable-field/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98111; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.FileOptions { string draft_file = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98008; } diff --git a/cmd/generate-stable-protos/testdata/comments/detached-section-header/expected.json b/cmd/generate-stable-protos/testdata/comments/detached-section-header/expected.json new file mode 100644 index 000000000..fadd94071 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/comments/detached-section-header/expected.json @@ -0,0 +1,3 @@ +{ + "error": "comment \"Section header: draft messages follow.\" of a removed draft declaration survives" +} diff --git a/cmd/generate-stable-protos/testdata/comments/detached-section-header/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/comments/detached-section-header/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..6ecd6d257 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/comments/detached-section-header/input/temporal/api_next/fixture.proto @@ -0,0 +1,40 @@ +syntax = "proto3"; + +package fixture; + +import "temporal/api_next/protometa/v1/draft.proto"; + +// Stable doc. +message Keeper { + string a = 1; // trailing a + string b = 2 [(temporal.api.protometa.v1.draft) = "b"]; // DRAFT same-line trailing b + // DRAFT leading c + string c = 3 [(temporal.api.protometa.v1.draft) = "c"]; + // DRAFT wrapped leading doc of f, + // DRAFT continued on a second line. + string f = 4 [(temporal.api.protometa.v1.draft) = "f"]; + + // leading d + string d=5 ; + Thing t = 6; /* DRAFT block trailing t */ + string e = 7 [ + // DRAFT inside options + (temporal.api.protometa.v1.draft) = "e" /* DRAFT inside options block */ + ]; + /* DRAFT block leading g + * continued */ + string g = 8 [(temporal.api.protometa.v1.draft) = "g"]; + // leading h shares the word DRAFT + string h = 9; +} + +// Section header: draft messages follow. + +// DRAFT leading comment of draft message. +message Thing { + option (temporal.api.protometa.v1.draft_message) = "thing"; + // DRAFT nested leading + string v = 1; // DRAFT nested trailing +} // DRAFT trailing on draft message close + +message Flat { string x = 1; } diff --git a/cmd/generate-stable-protos/testdata/comments/detached-section-header/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/comments/detached-section-header/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..03c5c5701 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/comments/detached-section-header/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98111; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.FileOptions { string draft_file = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98008; } diff --git a/cmd/generate-stable-protos/testdata/comments/end-of-file-after-draft-message/expected.json b/cmd/generate-stable-protos/testdata/comments/end-of-file-after-draft-message/expected.json new file mode 100644 index 000000000..401b2bf4d --- /dev/null +++ b/cmd/generate-stable-protos/testdata/comments/end-of-file-after-draft-message/expected.json @@ -0,0 +1,3 @@ +{ + "error": "temporal/api_next/fixture.proto:43: comment \"// Note after Tail.\" after a removed draft declaration would survive in the stable output; move it directly above a declaration, or delete it" +} diff --git a/cmd/generate-stable-protos/testdata/comments/end-of-file-after-draft-message/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/comments/end-of-file-after-draft-message/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..7fba453b7 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/comments/end-of-file-after-draft-message/input/temporal/api_next/fixture.proto @@ -0,0 +1,43 @@ +syntax = "proto3"; + +package fixture; + +import "temporal/api_next/protometa/v1/draft.proto"; + +// Stable doc. +message Keeper { + string a = 1; // trailing a + string b = 2 [(temporal.api.protometa.v1.draft) = "b"]; // DRAFT same-line trailing b + // DRAFT leading c + string c = 3 [(temporal.api.protometa.v1.draft) = "c"]; + // DRAFT wrapped leading doc of f, + // DRAFT continued on a second line. + string f = 4 [(temporal.api.protometa.v1.draft) = "f"]; + + // leading d + string d=5 ; + Thing t = 6; /* DRAFT block trailing t */ + string e = 7 [ + // DRAFT inside options + (temporal.api.protometa.v1.draft) = "e" /* DRAFT inside options block */ + ]; + /* DRAFT block leading g + * continued */ + string g = 8 [(temporal.api.protometa.v1.draft) = "g"]; + // leading h shares the word DRAFT + string h = 9; +} + +// DRAFT leading comment of draft message. +message Thing { + option (temporal.api.protometa.v1.draft_message) = "thing"; + // DRAFT nested leading + string v = 1; // DRAFT nested trailing +} // DRAFT trailing on draft message close + +message Flat { string x = 1; } + +message Tail { + option (temporal.api.protometa.v1.draft_message) = "tail"; +} +// Note after Tail. diff --git a/cmd/generate-stable-protos/testdata/comments/end-of-file-after-draft-message/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/comments/end-of-file-after-draft-message/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..03c5c5701 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/comments/end-of-file-after-draft-message/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98111; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.FileOptions { string draft_file = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98008; } diff --git a/cmd/generate-stable-protos/testdata/comments/next-line-trailing/expected.json b/cmd/generate-stable-protos/testdata/comments/next-line-trailing/expected.json new file mode 100644 index 000000000..08c9620a2 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/comments/next-line-trailing/expected.json @@ -0,0 +1,3 @@ +{ + "error": "temporal/api_next/fixture.proto:16: comment \"// Next-line trailing comment of f.\" after a removed draft declaration would survive in the stable output; move it directly above a declaration, or delete it" +} diff --git a/cmd/generate-stable-protos/testdata/comments/next-line-trailing/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/comments/next-line-trailing/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..a8f50958e --- /dev/null +++ b/cmd/generate-stable-protos/testdata/comments/next-line-trailing/input/temporal/api_next/fixture.proto @@ -0,0 +1,39 @@ +syntax = "proto3"; + +package fixture; + +import "temporal/api_next/protometa/v1/draft.proto"; + +// Stable doc. +message Keeper { + string a = 1; // trailing a + string b = 2 [(temporal.api.protometa.v1.draft) = "b"]; // DRAFT same-line trailing b + // DRAFT leading c + string c = 3 [(temporal.api.protometa.v1.draft) = "c"]; + // DRAFT wrapped leading doc of f, + // DRAFT continued on a second line. + string f = 4 [(temporal.api.protometa.v1.draft) = "f"]; + // Next-line trailing comment of f. + + // leading d + string d=5 ; + Thing t = 6; /* DRAFT block trailing t */ + string e = 7 [ + // DRAFT inside options + (temporal.api.protometa.v1.draft) = "e" /* DRAFT inside options block */ + ]; + /* DRAFT block leading g + * continued */ + string g = 8 [(temporal.api.protometa.v1.draft) = "g"]; + // leading h shares the word DRAFT + string h = 9; +} + +// DRAFT leading comment of draft message. +message Thing { + option (temporal.api.protometa.v1.draft_message) = "thing"; + // DRAFT nested leading + string v = 1; // DRAFT nested trailing +} // DRAFT trailing on draft message close + +message Flat { string x = 1; } diff --git a/cmd/generate-stable-protos/testdata/comments/next-line-trailing/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/comments/next-line-trailing/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..03c5c5701 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/comments/next-line-trailing/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98111; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.FileOptions { string draft_file = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98008; } From 1664ed5aedcd31407e1c0d8c1ee844221bb392d9 Mon Sep 17 00:00:00 2001 From: Stephan Behnke Date: Fri, 20 Nov 2026 08:38:13 -0700 Subject: [PATCH 03/20] generate-stable-protos: cover import path rewriting in the imports fixture MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit What Runs import path rewriting cases through the generator’s imports fixture. Why The test checks how real imports, comments, and option strings behave through projection and printing. Co-Authored-By: Claude Opus 5.5 --- cmd/generate-stable-protos/main_test.go | 25 ------------------- .../expected/temporal/api/consumer.proto | 8 ++++++ .../expected/temporal/api/reexported.proto | 3 +++ .../imports/expected/temporal/api/root.proto | 11 ++++++++ .../imports/expected/temporal/api/split.proto | 3 +++ .../input/temporal/api_next/consumer.proto | 5 ++++ .../input/temporal/api_next/reexported.proto | 1 + .../input/temporal/api_next/root.proto | 7 ++++++ .../input/temporal/api_next/split.proto | 1 + 9 files changed, 39 insertions(+), 25 deletions(-) create mode 100644 cmd/generate-stable-protos/testdata/imports/expected/temporal/api/consumer.proto create mode 100644 cmd/generate-stable-protos/testdata/imports/expected/temporal/api/reexported.proto create mode 100644 cmd/generate-stable-protos/testdata/imports/expected/temporal/api/split.proto create mode 100644 cmd/generate-stable-protos/testdata/imports/input/temporal/api_next/consumer.proto create mode 100644 cmd/generate-stable-protos/testdata/imports/input/temporal/api_next/reexported.proto create mode 100644 cmd/generate-stable-protos/testdata/imports/input/temporal/api_next/split.proto diff --git a/cmd/generate-stable-protos/main_test.go b/cmd/generate-stable-protos/main_test.go index 5907d57ae..011ead47f 100644 --- a/cmd/generate-stable-protos/main_test.go +++ b/cmd/generate-stable-protos/main_test.go @@ -9,31 +9,6 @@ import ( "testing" ) -func TestRewriteImportPaths(t *testing.T) { - t.Parallel() - input := `syntax = "proto3"; -import public /* before */ 'temporal/api_next/used.proto' /* after */; -import "google/protobuf/any.proto"; -import "temporal/api_n" /* internal comment */ "ext/another.proto"; -option java_package = "temporal/api_next/used.proto"; -// import "temporal/api_next/used.proto"; -` - expected := `syntax = "proto3"; -import public /* before */ 'temporal/api/used.proto' /* after */; -import "google/protobuf/any.proto"; -import "temporal/api" /* internal comment */ "/another.proto"; -option java_package = "temporal/api_next/used.proto"; -// import "temporal/api_next/used.proto"; -` - actual, err := rewriteImportPaths(input) - if err != nil { - t.Fatal(err) - } - if actual != expected { - t.Fatalf("expected %q, got %q", expected, actual) - } -} - func TestStableReplacement(t *testing.T) { t.Parallel() script, err := filepath.Abs("../../scripts/stable-api.sh") diff --git a/cmd/generate-stable-protos/testdata/imports/expected/temporal/api/consumer.proto b/cmd/generate-stable-protos/testdata/imports/expected/temporal/api/consumer.proto new file mode 100644 index 000000000..f88c9c04e --- /dev/null +++ b/cmd/generate-stable-protos/testdata/imports/expected/temporal/api/consumer.proto @@ -0,0 +1,8 @@ +syntax = "proto3"; +package fixture; + +import "temporal/api/root.proto"; +// Reexported reaches this file only through the public import in root.proto. +message Consumer { + Reexported reexported = 1; +} diff --git a/cmd/generate-stable-protos/testdata/imports/expected/temporal/api/reexported.proto b/cmd/generate-stable-protos/testdata/imports/expected/temporal/api/reexported.proto new file mode 100644 index 000000000..fecaf42d8 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/imports/expected/temporal/api/reexported.proto @@ -0,0 +1,3 @@ +syntax = "proto3"; +package fixture; +message Reexported {} diff --git a/cmd/generate-stable-protos/testdata/imports/expected/temporal/api/root.proto b/cmd/generate-stable-protos/testdata/imports/expected/temporal/api/root.proto index 084261d12..f671db272 100644 --- a/cmd/generate-stable-protos/testdata/imports/expected/temporal/api/root.proto +++ b/cmd/generate-stable-protos/testdata/imports/expected/temporal/api/root.proto @@ -1,8 +1,19 @@ syntax = "proto3"; package fixture; +import "google/protobuf/any.proto"; +import +"temporal/api" +/* internal comment */ +"/split.proto"; import "temporal/api/used.proto"; +import public /* before */ 'temporal/api/reexported.proto' /* after */; + +option java_package = "temporal/api_next/used.proto"; // Keep the literal "temporal/api_next/used.proto" in comments and options. +// import "temporal/api_next/used.proto"; message Root { Used stable = 1 [json_name = "temporal/api_next/used.proto"]; + google.protobuf.Any any = 3; + Split split = 4; } diff --git a/cmd/generate-stable-protos/testdata/imports/expected/temporal/api/split.proto b/cmd/generate-stable-protos/testdata/imports/expected/temporal/api/split.proto new file mode 100644 index 000000000..6444f6e24 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/imports/expected/temporal/api/split.proto @@ -0,0 +1,3 @@ +syntax = "proto3"; +package fixture; +message Split {} diff --git a/cmd/generate-stable-protos/testdata/imports/input/temporal/api_next/consumer.proto b/cmd/generate-stable-protos/testdata/imports/input/temporal/api_next/consumer.proto new file mode 100644 index 000000000..eb11a40ff --- /dev/null +++ b/cmd/generate-stable-protos/testdata/imports/input/temporal/api_next/consumer.proto @@ -0,0 +1,5 @@ +syntax = "proto3"; +package fixture; +import "temporal/api_next/root.proto"; +// Reexported reaches this file only through the public import in root.proto. +message Consumer { Reexported reexported = 1; } diff --git a/cmd/generate-stable-protos/testdata/imports/input/temporal/api_next/reexported.proto b/cmd/generate-stable-protos/testdata/imports/input/temporal/api_next/reexported.proto new file mode 100644 index 000000000..e7f222e9b --- /dev/null +++ b/cmd/generate-stable-protos/testdata/imports/input/temporal/api_next/reexported.proto @@ -0,0 +1 @@ +syntax = "proto3"; package fixture; message Reexported {} diff --git a/cmd/generate-stable-protos/testdata/imports/input/temporal/api_next/root.proto b/cmd/generate-stable-protos/testdata/imports/input/temporal/api_next/root.proto index 24fe33f6f..1e6c07d32 100644 --- a/cmd/generate-stable-protos/testdata/imports/input/temporal/api_next/root.proto +++ b/cmd/generate-stable-protos/testdata/imports/input/temporal/api_next/root.proto @@ -3,8 +3,15 @@ package fixture; import "temporal/api_next/protometa/v1/draft.proto"; import "temporal/api_next/used.proto"; import "temporal/api_next/unused.proto"; +import public /* before */ 'temporal/api_next/reexported.proto' /* after */; +import "google/protobuf/any.proto"; +import "temporal/api_n" /* internal comment */ "ext/split.proto"; +option java_package = "temporal/api_next/used.proto"; // Keep the literal "temporal/api_next/used.proto" in comments and options. +// import "temporal/api_next/used.proto"; message Root { Used stable = 1 [json_name = "temporal/api_next/used.proto"]; Unused draft = 2 [(temporal.api.protometa.v1.draft) = "feature-a"]; + google.protobuf.Any any = 3; + Split split = 4; } diff --git a/cmd/generate-stable-protos/testdata/imports/input/temporal/api_next/split.proto b/cmd/generate-stable-protos/testdata/imports/input/temporal/api_next/split.proto new file mode 100644 index 000000000..1030167a3 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/imports/input/temporal/api_next/split.proto @@ -0,0 +1 @@ +syntax = "proto3"; package fixture; message Split {} From 68592779bf277b80d928b8ef885d69fd0e1c02e9 Mon Sep 17 00:00:00 2001 From: Stephan Behnke Date: Sat, 21 Nov 2026 09:41:24 -0700 Subject: [PATCH 04/20] generate-stable-protos: check the generator is idempotent What Checks that regenerating a projected tree produces byte-identical output. Why A second pass should preserve the stable declarations, comments, and import order from the first pass. Co-Authored-By: Claude Opus 5.5 --- cmd/generate-stable-protos/corpus_test.go | 15 +++++ cmd/generate-stable-protos/fixtures_test.go | 64 +++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 cmd/generate-stable-protos/corpus_test.go diff --git a/cmd/generate-stable-protos/corpus_test.go b/cmd/generate-stable-protos/corpus_test.go new file mode 100644 index 000000000..a7660ef0e --- /dev/null +++ b/cmd/generate-stable-protos/corpus_test.go @@ -0,0 +1,15 @@ +package main + +import "testing" + +// TestRepoAPINextIdempotent checks that the stable tree generated from the repository's +// api_next tree is a fixed point of the generator. +func TestRepoAPINextIdempotent(t *testing.T) { + t.Parallel() + const root = "../.." + first := t.TempDir() + if err := stableProtosGenerator(t.Context(), root, first); err != nil { + t.Fatal(err) + } + checkIdempotent(t, root, first) +} diff --git a/cmd/generate-stable-protos/fixtures_test.go b/cmd/generate-stable-protos/fixtures_test.go index df70164c3..9d2c1fe63 100644 --- a/cmd/generate-stable-protos/fixtures_test.go +++ b/cmd/generate-stable-protos/fixtures_test.go @@ -8,6 +8,7 @@ import ( "os" "path/filepath" "reflect" + "regexp" "slices" "strings" "testing" @@ -98,6 +99,7 @@ func runFixture(t *testing.T, dir string) { if !reflect.DeepEqual(actual, readTree(t, again)) { t.Fatal("generator output is not deterministic") } + checkIdempotent(t, root, out) paths, err := getAPINextPaths(root) if err != nil { @@ -134,3 +136,65 @@ func sortedKeys(a, b map[string]string) []string { maps.Copy(keys, b) return slices.Sorted(maps.Keys(keys)) } + +// checkIdempotent feeds the stable tree the generator wrote from root into first back in +// as an api_next tree without drafts. The generator must then reproduce it byte for +// byte: removing nothing, keeping every comment, and printing its own output unchanged. +func checkIdempotent(t *testing.T, root, first string) { + t.Helper() + next := t.TempDir() + // An import may have comments before its path, and the first literal of a path split + // across literals is "temporal/api" on its own. + stableImport := regexp.MustCompile(`(?m)^(import\b(?:\s+|/\*[^*]*\*/|public|weak)*["'])` + regexp.QuoteMeta(strings.TrimSuffix(stableAPIPrefix, "/")) + `(["'/])`) + for path, text := range readTree(t, first) { + body, ok := strings.CutPrefix(text, generatedHeader) + if !ok { + t.Fatalf("%s: missing generated header", path) + } + body = stableImport.ReplaceAllString(body, `${1}`+strings.TrimSuffix(apiNextPrefix, "/")+`$2`) + writeFile(t, filepath.Join(next, apiNextPrefix, strings.TrimPrefix(path, stableAPIPrefix)), body) + } + draft, err := os.ReadFile(filepath.Join(root, draftTagsPath)) + if err != nil { + t.Fatal(err) + } + writeFile(t, filepath.Join(next, draftTagsPath), string(draft)) + // Imports outside temporal/, such as google/ and nexusannotations/, resolve as before. + entries, err := os.ReadDir(root) + if err != nil { + t.Fatal(err) + } + for _, entry := range entries { + if entry.Name() == "temporal" { + continue + } + target, err := filepath.Abs(filepath.Join(root, entry.Name())) + if err != nil { + t.Fatal(err) + } + if err := os.Symlink(target, filepath.Join(next, entry.Name())); err != nil { + t.Fatal(err) + } + } + + second := t.TempDir() + if err := stableProtosGenerator(t.Context(), next, second); err != nil { + t.Fatalf("second pass: %v", err) + } + want, got := readTree(t, first), readTree(t, second) + for _, path := range sortedKeys(want, got) { + if want[path] != got[path] { + t.Errorf("%s changed on the second pass\nfirst:\n%s\nsecond:\n%s", path, want[path], got[path]) + } + } +} + +func writeFile(t *testing.T, path, text string) { + t.Helper() + if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(path, []byte(text), 0o644); err != nil { + t.Fatal(err) + } +} From ff2c0caae2e35421e6c7d1054bfc6684b5ee96bc Mon Sep 17 00:00:00 2001 From: Stephan Behnke Date: Fri, 20 Nov 2026 09:37:23 -0700 Subject: [PATCH 05/20] generate-stable-protos: check random schemas with rapid What Uses Rapid to generate small draft schemas and checks that generation is idempotent. Why Generated schemas exercise combinations that the handwritten fixtures may miss, and Rapid can shrink failures. Co-Authored-By: Claude Opus 5.5 --- cmd/generate-stable-protos/corpus_test.go | 2 +- cmd/generate-stable-protos/fixtures_test.go | 22 ++- cmd/generate-stable-protos/go.mod | 7 +- cmd/generate-stable-protos/go.sum | 8 +- cmd/generate-stable-protos/main_test.go | 2 +- cmd/generate-stable-protos/random_test.go | 155 ++++++++++++++++++++ 6 files changed, 180 insertions(+), 16 deletions(-) create mode 100644 cmd/generate-stable-protos/random_test.go diff --git a/cmd/generate-stable-protos/corpus_test.go b/cmd/generate-stable-protos/corpus_test.go index a7660ef0e..07fbe5570 100644 --- a/cmd/generate-stable-protos/corpus_test.go +++ b/cmd/generate-stable-protos/corpus_test.go @@ -11,5 +11,5 @@ func TestRepoAPINextIdempotent(t *testing.T) { if err := stableProtosGenerator(t.Context(), root, first); err != nil { t.Fatal(err) } - checkIdempotent(t, root, first) + checkIdempotent(t.Context(), t, root, first, t.TempDir()) } diff --git a/cmd/generate-stable-protos/fixtures_test.go b/cmd/generate-stable-protos/fixtures_test.go index 9d2c1fe63..58f05100c 100644 --- a/cmd/generate-stable-protos/fixtures_test.go +++ b/cmd/generate-stable-protos/fixtures_test.go @@ -1,6 +1,7 @@ package main import ( + "context" "encoding/json" "errors" "io/fs" @@ -99,7 +100,7 @@ func runFixture(t *testing.T, dir string) { if !reflect.DeepEqual(actual, readTree(t, again)) { t.Fatal("generator output is not deterministic") } - checkIdempotent(t, root, out) + checkIdempotent(t.Context(), t, root, out, t.TempDir()) paths, err := getAPINextPaths(root) if err != nil { @@ -140,9 +141,10 @@ func sortedKeys(a, b map[string]string) []string { // checkIdempotent feeds the stable tree the generator wrote from root into first back in // as an api_next tree without drafts. The generator must then reproduce it byte for // byte: removing nothing, keeping every comment, and printing its own output unchanged. -func checkIdempotent(t *testing.T, root, first string) { +// scratch is an empty directory for the second pass. +func checkIdempotent(ctx context.Context, t testingT, root, first, scratch string) { t.Helper() - next := t.TempDir() + next := filepath.Join(scratch, "next") // An import may have comments before its path, and the first literal of a path split // across literals is "temporal/api" on its own. stableImport := regexp.MustCompile(`(?m)^(import\b(?:\s+|/\*[^*]*\*/|public|weak)*["'])` + regexp.QuoteMeta(strings.TrimSuffix(stableAPIPrefix, "/")) + `(["'/])`) @@ -177,8 +179,8 @@ func checkIdempotent(t *testing.T, root, first string) { } } - second := t.TempDir() - if err := stableProtosGenerator(t.Context(), next, second); err != nil { + second := filepath.Join(scratch, "second") + if err := stableProtosGenerator(ctx, next, second); err != nil { t.Fatalf("second pass: %v", err) } want, got := readTree(t, first), readTree(t, second) @@ -189,7 +191,15 @@ func checkIdempotent(t *testing.T, root, first string) { } } -func writeFile(t *testing.T, path, text string) { +// testingT is the part of testing.TB the fixture helpers use, which *rapid.T also has. +type testingT interface { + Helper() + Errorf(format string, args ...any) + Fatal(args ...any) + Fatalf(format string, args ...any) +} + +func writeFile(t testingT, path, text string) { t.Helper() if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil { t.Fatal(err) diff --git a/cmd/generate-stable-protos/go.mod b/cmd/generate-stable-protos/go.mod index 518ffcfa5..55e1495ba 100644 --- a/cmd/generate-stable-protos/go.mod +++ b/cmd/generate-stable-protos/go.mod @@ -2,7 +2,11 @@ module github.com/temporalio/api/cmd/generate-stable-protos go 1.26.7 -require github.com/bufbuild/protocompile v0.14.2-0.20260825174057-3dfa26e2df9b +require ( + github.com/bufbuild/protocompile v0.14.2-0.20260825174057-3dfa26e2df9b + google.golang.org/protobuf v1.36.12 + pgregory.net/rapid v1.3.0 +) require ( buf.build/gen/go/bufbuild/protodescriptor/protocolbuffers/go v1.36.12-20250109164928-1da0de137947.1 // indirect @@ -12,5 +16,4 @@ require ( github.com/tidwall/btree v1.8.1 // indirect golang.org/x/exp v0.0.0-20260709172345-9ea1abe57597 // indirect golang.org/x/sync v0.22.0 // indirect - google.golang.org/protobuf v1.36.12 // indirect ) diff --git a/cmd/generate-stable-protos/go.sum b/cmd/generate-stable-protos/go.sum index 92f2f8031..83654acf7 100644 --- a/cmd/generate-stable-protos/go.sum +++ b/cmd/generate-stable-protos/go.sum @@ -2,8 +2,6 @@ buf.build/gen/go/bufbuild/protodescriptor/protocolbuffers/go v1.36.12-2025010916 buf.build/gen/go/bufbuild/protodescriptor/protocolbuffers/go v1.36.12-20250109164928-1da0de137947.1/go.mod h1:jMWijYwl5JMuBr0OqOy5wSWh2mkSIfkMlwNsSY1aL6w= buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.12-20260709200747-435963d16310.1 h1:6nlcxMOui23ZRVAfJM451duu79P1npA5JRdZqMilrrQ= buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.12-20260709200747-435963d16310.1/go.mod h1:TCt1lluMFnctISJXvkIQ4x3ABrPuUKCWKyjKdkJNBpw= -buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.12-20260825204119-511051f7f437.1 h1:Slv0uGxx219srASyiaI5C9cDlyG8kNDcXpTSYcuAeE4= -buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.12-20260825204119-511051f7f437.1/go.mod h1:TCt1lluMFnctISJXvkIQ4x3ABrPuUKCWKyjKdkJNBpw= github.com/bmatcuk/doublestar/v4 v4.10.0 h1:zU9WiOla1YA122oLM6i4EXvGW62DvKZVxIe6TYWexEs= github.com/bmatcuk/doublestar/v4 v4.10.0/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc= github.com/bufbuild/protocompile v0.14.2-0.20260825174057-3dfa26e2df9b h1:SGNT4/0br4KW4yQe3COGJH7WK/1XBtknsea73KQWzdE= @@ -14,8 +12,6 @@ github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/petermattis/goid v0.0.0-20260716134002-a9b348f0a2b9 h1:UyKlK0Ke63afxhHrgJAk8KlCt+kP9KYBRUsWG6lK2WM= github.com/petermattis/goid v0.0.0-20260716134002-a9b348f0a2b9/go.mod h1:pxMtw7cyUw6B2bRH0ZBANSPg+AoSud1I1iyJHI69jH4= -github.com/petermattis/goid v0.0.0-20260820044319-269ab09b5261 h1:lcWAnrqr2nNfDiArwFNHCE4787Mw2tCdVSOXCru0/0E= -github.com/petermattis/goid v0.0.0-20260820044319-269ab09b5261/go.mod h1:pxMtw7cyUw6B2bRH0ZBANSPg+AoSud1I1iyJHI69jH4= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/protocolbuffers/protoscope v0.0.0-20221109213918-8e7a6aafa2c9 h1:arwj11zP0yJIxIRiDn22E0H8PxfF7TsTrc2wIPFIsf4= @@ -28,11 +24,11 @@ github.com/tidwall/btree v1.8.1 h1:27ehoXvm5AG/g+1VxLS1SD3vRhp/H7LuEfwNvddEdmA= github.com/tidwall/btree v1.8.1/go.mod h1:jBbTdUWhSZClZWoDg54VnvV7/54modSOzDN7VXftj1A= golang.org/x/exp v0.0.0-20260709172345-9ea1abe57597 h1:qLvzZeaANDgyVOA8pyHCOStGlXn0rseXma+GQjeuv2g= golang.org/x/exp v0.0.0-20260709172345-9ea1abe57597/go.mod h1:EdfpwwqSu+0Li0mzskwHU6FWDV3t9Q+RZDo3QMUtL3Q= -golang.org/x/exp v0.0.0-20260824195058-e88cd73687aa h1:QSyA8ishJCyT21kER9KwNt0b7BM3iRK4x9QXhjN5Fdk= -golang.org/x/exp v0.0.0-20260824195058-e88cd73687aa/go.mod h1:zeBbvyFKDaLwa7CH/zI8KXt7gTl14SF7sO08Pl5jBCM= golang.org/x/sync v0.22.0 h1:SZjpbeLmrCk4xhRSZFNZW5gFUeCeFgjekvI/+gfScek= golang.org/x/sync v0.22.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0= google.golang.org/protobuf v1.36.12 h1:pJOKDDOyeXErUroCihFAd5LQuwXBSpVnKGrj5o/fwxc= google.golang.org/protobuf v1.36.12/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +pgregory.net/rapid v1.3.0 h1:vBvO0VSqti75J1jjYqpgPNBLKMd1+gxa9fYo7vk/Exc= +pgregory.net/rapid v1.3.0/go.mod h1:dPlE4OBBxgXPqkP79flB6sJL1dx5azpI7HQ9MY9Z7uk= diff --git a/cmd/generate-stable-protos/main_test.go b/cmd/generate-stable-protos/main_test.go index 011ead47f..aefa7254e 100644 --- a/cmd/generate-stable-protos/main_test.go +++ b/cmd/generate-stable-protos/main_test.go @@ -65,7 +65,7 @@ exec /bin/mv "$@" } } -func readTree(t *testing.T, root string) map[string]string { +func readTree(t testingT, root string) map[string]string { t.Helper() files := map[string]string{} if err := filepath.WalkDir(root, func(path string, entry fs.DirEntry, err error) error { diff --git a/cmd/generate-stable-protos/random_test.go b/cmd/generate-stable-protos/random_test.go new file mode 100644 index 000000000..1d3324e60 --- /dev/null +++ b/cmd/generate-stable-protos/random_test.go @@ -0,0 +1,155 @@ +package main + +import ( + "fmt" + "path/filepath" + "strings" + "testing" + + "pgregory.net/rapid" +) + +// TestRandomSchemas generates random api_next trees with draft fields and messages and +// requires the generator to accept each one and a +// second pass to reproduce it. Comments only sit where the generator accepts them: +// directly above a declaration or after it on the same line. +func TestRandomSchemas(t *testing.T) { + t.Parallel() + rapid.Check(t, func(rt *rapid.T) { + root := t.TempDir() + writeFile(rt, filepath.Join(root, draftTagsPath), randomDraftSchema) + for path, text := range newSchemaGen(rt).files() { + rt.Logf("%s:\n%s", path, text) + writeFile(rt, filepath.Join(root, path), text) + } + out := t.TempDir() + if err := stableProtosGenerator(t.Context(), root, out); err != nil { + rt.Fatalf("generator rejected the schema: %v", err) + } + checkIdempotent(t.Context(), rt, root, out, t.TempDir()) + }) +} + +const randomDraftSchema = `syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98111; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +` + +// schemaGen writes a base file and a dependent file, so that references, and the +// imports they need, can cross files. +type schemaGen struct { + rt *rapid.T + b *strings.Builder + comments int + // types are the message names fields in the current file may reference. + types []string +} + +func newSchemaGen(rt *rapid.T) *schemaGen { return &schemaGen{rt: rt} } + +func (g *schemaGen) files() map[string]string { + base := g.file("base", rapid.IntRange(1, 4).Draw(g.rt, "base messages"), nil) + dependent := g.file("dependent", rapid.IntRange(0, 3).Draw(g.rt, "dependent messages"), g.types) + return map[string]string{ + apiNextPrefix + "base.proto": base, + apiNextPrefix + "dependent.proto": dependent, + } +} + +func (g *schemaGen) file(name string, messages int, imported []string) string { + g.b = &strings.Builder{} + g.b.WriteString("syntax = \"proto3\";\npackage fixture;\n") + g.b.WriteString("import \"" + draftTagsPath + "\";\n") + if name == "dependent" { + g.b.WriteString("import \"" + apiNextPrefix + "base.proto\";\n") + } + names := make([]string, messages) + for i := range names { + names[i] = fmt.Sprintf("%s%d", strings.ToUpper(name[:1]), i) + } + g.types = append(append([]string{}, imported...), names...) + for _, n := range names { + g.message(n, "", 0) + } + return g.b.String() +} + +// comment returns a comment with a word no other comment has, so a leak is visible. +func (g *schemaGen) comment() string { + g.comments++ + return fmt.Sprintf("// note%d", g.comments) +} + +func (g *schemaGen) leading(indent string) { + if rapid.Bool().Draw(g.rt, "leading comment") { + g.b.WriteString(indent + g.comment() + "\n") + } +} + +func (g *schemaGen) trailing() string { + if rapid.Bool().Draw(g.rt, "trailing comment") { + return " " + g.comment() + } + return "" +} + +func (g *schemaGen) draft(what string) bool { + return rapid.IntRange(0, 3).Draw(g.rt, "draft "+what) == 0 +} + +func (g *schemaGen) message(name, indent string, depth int) { + g.leading(indent) + g.b.WriteString(indent + "message " + name + " {" + g.trailing() + "\n") + inner := indent + " " + if g.draft("message") { + g.b.WriteString(inner + `option (temporal.api.protometa.v1.draft_message) = "feature";` + "\n") + } + number := 0 + field := func(typ string) { + number++ + g.leading(inner) + g.b.WriteString(fmt.Sprintf("%s%s f%d = %d", inner, typ, number, number)) + if g.draft("field") { + g.b.WriteString(` [(temporal.api.protometa.v1.draft) = "feature"]`) + } + g.b.WriteString(";" + g.trailing() + "\n") + } + for i := range rapid.IntRange(0, 5).Draw(g.rt, "members") { + switch rapid.IntRange(0, 6).Draw(g.rt, "member kind") { + case 0: + field(g.fieldType()) + case 1: + field("repeated " + g.fieldType()) + case 2: + field("optional " + g.fieldType()) + case 3: + field("map") + case 4: + g.leading(inner) + g.b.WriteString(fmt.Sprintf("%soneof o%d {%s\n", inner, i, g.trailing())) + saved := inner + inner += " " + for range rapid.IntRange(1, 3).Draw(g.rt, "branches") { + field(g.fieldType()) + } + inner = saved + g.b.WriteString(inner + "}" + g.trailing() + "\n") + case 5: + if depth < 2 { + g.message(fmt.Sprintf("N%d", i), inner, depth+1) + } + default: + field("string") + } + } + g.b.WriteString(indent + "}" + g.trailing() + "\n") +} + +func (g *schemaGen) fieldType() string { + if len(g.types) > 0 && rapid.Bool().Draw(g.rt, "message type") { + return rapid.SampledFrom(g.types).Draw(g.rt, "type") + } + return rapid.SampledFrom([]string{"string", "int32", "bool", "bytes"}).Draw(g.rt, "scalar") +} From 0e785ae3e8ca8fe1e45089faee437538c7697bd9 Mon Sep 17 00:00:00 2001 From: Stephan Behnke Date: Fri, 20 Nov 2026 15:16:34 -0700 Subject: [PATCH 06/20] generate-stable-protos: reject RPC options that name draft fields What Rejects HTTP mappings and request-header templates on retained RPCs that refer to draft fields. Why Those mappings would otherwise point to fields that disappear from the stable schema. Co-Authored-By: Claude Opus 5.5 --- cmd/generate-stable-protos/tags.go | 96 +++++ .../rpc-http-additional-binding/expected.json | 3 + .../input/google/api/annotations.proto | 31 ++ .../input/google/api/http.proto | 379 ++++++++++++++++++ .../input/temporal/api_next/fixture.proto | 15 + .../api_next/protometa/v1/draft.proto | 11 + .../rpc-http-body/expected.json | 3 + .../input/google/api/annotations.proto | 31 ++ .../rpc-http-body/input/google/api/http.proto | 379 ++++++++++++++++++ .../input/temporal/api_next/fixture.proto | 12 + .../api_next/protometa/v1/draft.proto | 11 + .../rpc-http-nested/expected.json | 3 + .../input/google/api/annotations.proto | 31 ++ .../input/google/api/http.proto | 379 ++++++++++++++++++ .../input/temporal/api_next/fixture.proto | 15 + .../api_next/protometa/v1/draft.proto | 11 + .../rpc-http-path/expected.json | 3 + .../input/google/api/annotations.proto | 31 ++ .../rpc-http-path/input/google/api/http.proto | 379 ++++++++++++++++++ .../input/temporal/api_next/fixture.proto | 11 + .../api_next/protometa/v1/draft.proto | 11 + .../rpc-http-response-body/expected.json | 3 + .../input/google/api/annotations.proto | 31 ++ .../input/google/api/http.proto | 379 ++++++++++++++++++ .../input/temporal/api_next/fixture.proto | 11 + .../api_next/protometa/v1/draft.proto | 11 + .../rpc-http-stable/expected.json | 5 + .../input/google/api/annotations.proto | 31 ++ .../input/google/api/http.proto | 379 ++++++++++++++++++ .../input/temporal/api_next/fixture.proto | 19 + .../api_next/protometa/v1/draft.proto | 11 + .../rpc-request-header/expected.json | 3 + .../input/temporal/api_next/fixture.proto | 19 + .../api_next/protometa/v1/annotations.proto | 37 ++ .../api_next/protometa/v1/draft.proto | 11 + 35 files changed, 2795 insertions(+) create mode 100644 cmd/generate-stable-protos/testdata/classification/rpc-http-additional-binding/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/rpc-http-additional-binding/input/google/api/annotations.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/rpc-http-additional-binding/input/google/api/http.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/rpc-http-additional-binding/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/rpc-http-additional-binding/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/rpc-http-body/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/rpc-http-body/input/google/api/annotations.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/rpc-http-body/input/google/api/http.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/rpc-http-body/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/rpc-http-body/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/rpc-http-nested/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/rpc-http-nested/input/google/api/annotations.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/rpc-http-nested/input/google/api/http.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/rpc-http-nested/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/rpc-http-nested/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/rpc-http-path/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/rpc-http-path/input/google/api/annotations.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/rpc-http-path/input/google/api/http.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/rpc-http-path/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/rpc-http-path/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/rpc-http-response-body/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/rpc-http-response-body/input/google/api/annotations.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/rpc-http-response-body/input/google/api/http.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/rpc-http-response-body/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/rpc-http-response-body/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/rpc-http-stable/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/rpc-http-stable/input/google/api/annotations.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/rpc-http-stable/input/google/api/http.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/rpc-http-stable/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/rpc-http-stable/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/rpc-request-header/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/rpc-request-header/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/rpc-request-header/input/temporal/api_next/protometa/v1/annotations.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/rpc-request-header/input/temporal/api_next/protometa/v1/draft.proto diff --git a/cmd/generate-stable-protos/tags.go b/cmd/generate-stable-protos/tags.go index 9fde947e5..fdca016b0 100644 --- a/cmd/generate-stable-protos/tags.go +++ b/cmd/generate-stable-protos/tags.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "regexp" "strings" "unicode" @@ -131,11 +132,106 @@ func validateDraftAnnotations(tags draftTags, f *ir.File) (draftAnnotations, err return nil, fmt.Errorf("%s: RPC references draft type %s unavailable in the stable API", m.FullName(), t.FullName()) } } + if err := validateMethodFieldReferences(tags, m, input, output); err != nil { + return nil, err + } } } return accepted, nil } +const fieldPathPattern = `([a-zA-Z_][a-zA-Z_0-9]*(?:\.[a-zA-Z_][a-zA-Z_0-9]*)*)` + +var ( + httpPathVariable = regexp.MustCompile(`\{` + fieldPathPattern + `(?:=[^{}]+)?\}`) + headerVariable = regexp.MustCompile(`\{` + fieldPathPattern + `\}`) +) + +func validateMethodFieldReferences(tags draftTags, method ir.Method, input, output ir.Type) error { + for option := range method.Options().Fields() { + switch option.Field().FullName() { + case "google.api.http": + if path := draftHTTPField(tags, option.AsMessage(), input, output); path != "" { + return fmt.Errorf("%s: http rule references draft field %s", method.FullName(), path) + } + case "temporal.api.protometa.v1.request_header": + for header := range seq.Values(option.Elements()) { + template := messageString(header.AsMessage(), "value") + if path := draftTemplateField(tags, input, template, headerVariable); path != "" { + return fmt.Errorf("%s: request header references draft field %s", method.FullName(), path) + } + } + } + } + return nil +} + +func draftHTTPField(tags draftTags, rule ir.MessageValue, input, output ir.Type) string { + for field := range rule.Fields() { + var draftPath string + switch field.Field().Name() { + case "get", "put", "post", "delete", "patch": + template, _ := field.AsString() + draftPath = draftTemplateField(tags, input, template, httpPathVariable) + case "custom": + template := messageString(field.AsMessage(), "path") + draftPath = draftTemplateField(tags, input, template, httpPathVariable) + case "body": + path, _ := field.AsString() + if referencesDraftField(tags, input, path) { + draftPath = path + } + case "response_body": + path, _ := field.AsString() + if referencesDraftField(tags, output, path) { + draftPath = path + } + case "additional_bindings": + for binding := range seq.Values(field.Elements()) { + if path := draftHTTPField(tags, binding.AsMessage(), input, output); path != "" { + return path + } + } + } + if draftPath != "" { + return draftPath + } + } + return "" +} + +func messageString(value ir.MessageValue, name string) string { + text, _ := value.Field(value.Type().MemberByName(name)).AsString() + return text +} + +func draftTemplateField(tags draftTags, message ir.Type, template string, variable *regexp.Regexp) string { + for _, match := range variable.FindAllStringSubmatch(template, -1) { + path := match[1] + if referencesDraftField(tags, message, path) { + return path + } + } + return "" +} + +func referencesDraftField(tags draftTags, message ir.Type, path string) bool { + for name := range strings.SplitSeq(path, ".") { + if !message.IsMessage() { + return false + } + field := message.MemberByName(name) + if field.IsZero() { + return false + } + if isDraftMember(tags, field) { + return true + } + message = field.Element() + } + return false +} + func isDraftType(tags draftTags, t ir.Type) bool { if t.IsZero() || t.IsPredeclared() { return false diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-http-additional-binding/expected.json b/cmd/generate-stable-protos/testdata/classification/rpc-http-additional-binding/expected.json new file mode 100644 index 000000000..93717c15c --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/rpc-http-additional-binding/expected.json @@ -0,0 +1,3 @@ +{ + "error": "fixture.Service.Call: http rule references draft field item.draft_id" +} diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-http-additional-binding/input/google/api/annotations.proto b/cmd/generate-stable-protos/testdata/classification/rpc-http-additional-binding/input/google/api/annotations.proto new file mode 100644 index 000000000..efdab3db6 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/rpc-http-additional-binding/input/google/api/annotations.proto @@ -0,0 +1,31 @@ +// Copyright 2015 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package google.api; + +import "google/api/http.proto"; +import "google/protobuf/descriptor.proto"; + +option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations"; +option java_multiple_files = true; +option java_outer_classname = "AnnotationsProto"; +option java_package = "com.google.api"; +option objc_class_prefix = "GAPI"; + +extend google.protobuf.MethodOptions { + // See `HttpRule`. + HttpRule http = 72295728; +} diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-http-additional-binding/input/google/api/http.proto b/cmd/generate-stable-protos/testdata/classification/rpc-http-additional-binding/input/google/api/http.proto new file mode 100644 index 000000000..31d867a27 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/rpc-http-additional-binding/input/google/api/http.proto @@ -0,0 +1,379 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package google.api; + +option cc_enable_arenas = true; +option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations"; +option java_multiple_files = true; +option java_outer_classname = "HttpProto"; +option java_package = "com.google.api"; +option objc_class_prefix = "GAPI"; + +// Defines the HTTP configuration for an API service. It contains a list of +// [HttpRule][google.api.HttpRule], each specifying the mapping of an RPC method +// to one or more HTTP REST API methods. +message Http { + // A list of HTTP configuration rules that apply to individual API methods. + // + // **NOTE:** All service configuration rules follow "last one wins" order. + repeated HttpRule rules = 1; + + // When set to true, URL path parameters will be fully URI-decoded except in + // cases of single segment matches in reserved expansion, where "%2F" will be + // left encoded. + // + // The default behavior is to not decode RFC 6570 reserved characters in multi + // segment matches. + bool fully_decode_reserved_expansion = 2; +} + +// # gRPC Transcoding +// +// gRPC Transcoding is a feature for mapping between a gRPC method and one or +// more HTTP REST endpoints. It allows developers to build a single API service +// that supports both gRPC APIs and REST APIs. Many systems, including [Google +// APIs](https://github.com/googleapis/googleapis), +// [Cloud Endpoints](https://cloud.google.com/endpoints), [gRPC +// Gateway](https://github.com/grpc-ecosystem/grpc-gateway), +// and [Envoy](https://github.com/envoyproxy/envoy) proxy support this feature +// and use it for large scale production services. +// +// `HttpRule` defines the schema of the gRPC/REST mapping. The mapping specifies +// how different portions of the gRPC request message are mapped to the URL +// path, URL query parameters, and HTTP request body. It also controls how the +// gRPC response message is mapped to the HTTP response body. `HttpRule` is +// typically specified as an `google.api.http` annotation on the gRPC method. +// +// Each mapping specifies a URL path template and an HTTP method. The path +// template may refer to one or more fields in the gRPC request message, as long +// as each field is a non-repeated field with a primitive (non-message) type. +// The path template controls how fields of the request message are mapped to +// the URL path. +// +// Example: +// +// service Messaging { +// rpc GetMessage(GetMessageRequest) returns (Message) { +// option (google.api.http) = { +// get: "/v1/{name=messages/*}" +// }; +// } +// } +// message GetMessageRequest { +// string name = 1; // Mapped to URL path. +// } +// message Message { +// string text = 1; // The resource content. +// } +// +// This enables an HTTP REST to gRPC mapping as below: +// +// HTTP | gRPC +// -----|----- +// `GET /v1/messages/123456` | `GetMessage(name: "messages/123456")` +// +// Any fields in the request message which are not bound by the path template +// automatically become HTTP query parameters if there is no HTTP request body. +// For example: +// +// service Messaging { +// rpc GetMessage(GetMessageRequest) returns (Message) { +// option (google.api.http) = { +// get:"/v1/messages/{message_id}" +// }; +// } +// } +// message GetMessageRequest { +// message SubMessage { +// string subfield = 1; +// } +// string message_id = 1; // Mapped to URL path. +// int64 revision = 2; // Mapped to URL query parameter `revision`. +// SubMessage sub = 3; // Mapped to URL query parameter `sub.subfield`. +// } +// +// This enables a HTTP JSON to RPC mapping as below: +// +// HTTP | gRPC +// -----|----- +// `GET /v1/messages/123456?revision=2&sub.subfield=foo` | +// `GetMessage(message_id: "123456" revision: 2 sub: SubMessage(subfield: +// "foo"))` +// +// Note that fields which are mapped to URL query parameters must have a +// primitive type or a repeated primitive type or a non-repeated message type. +// In the case of a repeated type, the parameter can be repeated in the URL +// as `...?param=A¶m=B`. In the case of a message type, each field of the +// message is mapped to a separate parameter, such as +// `...?foo.a=A&foo.b=B&foo.c=C`. +// +// For HTTP methods that allow a request body, the `body` field +// specifies the mapping. Consider a REST update method on the +// message resource collection: +// +// service Messaging { +// rpc UpdateMessage(UpdateMessageRequest) returns (Message) { +// option (google.api.http) = { +// patch: "/v1/messages/{message_id}" +// body: "message" +// }; +// } +// } +// message UpdateMessageRequest { +// string message_id = 1; // mapped to the URL +// Message message = 2; // mapped to the body +// } +// +// The following HTTP JSON to RPC mapping is enabled, where the +// representation of the JSON in the request body is determined by +// protos JSON encoding: +// +// HTTP | gRPC +// -----|----- +// `PATCH /v1/messages/123456 { "text": "Hi!" }` | `UpdateMessage(message_id: +// "123456" message { text: "Hi!" })` +// +// The special name `*` can be used in the body mapping to define that +// every field not bound by the path template should be mapped to the +// request body. This enables the following alternative definition of +// the update method: +// +// service Messaging { +// rpc UpdateMessage(Message) returns (Message) { +// option (google.api.http) = { +// patch: "/v1/messages/{message_id}" +// body: "*" +// }; +// } +// } +// message Message { +// string message_id = 1; +// string text = 2; +// } +// +// +// The following HTTP JSON to RPC mapping is enabled: +// +// HTTP | gRPC +// -----|----- +// `PATCH /v1/messages/123456 { "text": "Hi!" }` | `UpdateMessage(message_id: +// "123456" text: "Hi!")` +// +// Note that when using `*` in the body mapping, it is not possible to +// have HTTP parameters, as all fields not bound by the path end in +// the body. This makes this option more rarely used in practice when +// defining REST APIs. The common usage of `*` is in custom methods +// which don't use the URL at all for transferring data. +// +// It is possible to define multiple HTTP methods for one RPC by using +// the `additional_bindings` option. Example: +// +// service Messaging { +// rpc GetMessage(GetMessageRequest) returns (Message) { +// option (google.api.http) = { +// get: "/v1/messages/{message_id}" +// additional_bindings { +// get: "/v1/users/{user_id}/messages/{message_id}" +// } +// }; +// } +// } +// message GetMessageRequest { +// string message_id = 1; +// string user_id = 2; +// } +// +// This enables the following two alternative HTTP JSON to RPC mappings: +// +// HTTP | gRPC +// -----|----- +// `GET /v1/messages/123456` | `GetMessage(message_id: "123456")` +// `GET /v1/users/me/messages/123456` | `GetMessage(user_id: "me" message_id: +// "123456")` +// +// ## Rules for HTTP mapping +// +// 1. Leaf request fields (recursive expansion nested messages in the request +// message) are classified into three categories: +// - Fields referred by the path template. They are passed via the URL path. +// - Fields referred by the [HttpRule.body][google.api.HttpRule.body]. They +// are passed via the HTTP +// request body. +// - All other fields are passed via the URL query parameters, and the +// parameter name is the field path in the request message. A repeated +// field can be represented as multiple query parameters under the same +// name. +// 2. If [HttpRule.body][google.api.HttpRule.body] is "*", there is no URL +// query parameter, all fields +// are passed via URL path and HTTP request body. +// 3. If [HttpRule.body][google.api.HttpRule.body] is omitted, there is no HTTP +// request body, all +// fields are passed via URL path and URL query parameters. +// +// ### Path template syntax +// +// Template = "/" Segments [ Verb ] ; +// Segments = Segment { "/" Segment } ; +// Segment = "*" | "**" | LITERAL | Variable ; +// Variable = "{" FieldPath [ "=" Segments ] "}" ; +// FieldPath = IDENT { "." IDENT } ; +// Verb = ":" LITERAL ; +// +// The syntax `*` matches a single URL path segment. The syntax `**` matches +// zero or more URL path segments, which must be the last part of the URL path +// except the `Verb`. +// +// The syntax `Variable` matches part of the URL path as specified by its +// template. A variable template must not contain other variables. If a variable +// matches a single path segment, its template may be omitted, e.g. `{var}` +// is equivalent to `{var=*}`. +// +// The syntax `LITERAL` matches literal text in the URL path. If the `LITERAL` +// contains any reserved character, such characters should be percent-encoded +// before the matching. +// +// If a variable contains exactly one path segment, such as `"{var}"` or +// `"{var=*}"`, when such a variable is expanded into a URL path on the client +// side, all characters except `[-_.~0-9a-zA-Z]` are percent-encoded. The +// server side does the reverse decoding. Such variables show up in the +// [Discovery +// Document](https://developers.google.com/discovery/v1/reference/apis) as +// `{var}`. +// +// If a variable contains multiple path segments, such as `"{var=foo/*}"` +// or `"{var=**}"`, when such a variable is expanded into a URL path on the +// client side, all characters except `[-_.~/0-9a-zA-Z]` are percent-encoded. +// The server side does the reverse decoding, except "%2F" and "%2f" are left +// unchanged. Such variables show up in the +// [Discovery +// Document](https://developers.google.com/discovery/v1/reference/apis) as +// `{+var}`. +// +// ## Using gRPC API Service Configuration +// +// gRPC API Service Configuration (service config) is a configuration language +// for configuring a gRPC service to become a user-facing product. The +// service config is simply the YAML representation of the `google.api.Service` +// proto message. +// +// As an alternative to annotating your proto file, you can configure gRPC +// transcoding in your service config YAML files. You do this by specifying a +// `HttpRule` that maps the gRPC method to a REST endpoint, achieving the same +// effect as the proto annotation. This can be particularly useful if you +// have a proto that is reused in multiple services. Note that any transcoding +// specified in the service config will override any matching transcoding +// configuration in the proto. +// +// Example: +// +// http: +// rules: +// # Selects a gRPC method and applies HttpRule to it. +// - selector: example.v1.Messaging.GetMessage +// get: /v1/messages/{message_id}/{sub.subfield} +// +// ## Special notes +// +// When gRPC Transcoding is used to map a gRPC to JSON REST endpoints, the +// proto to JSON conversion must follow the [proto3 +// specification](https://developers.google.com/protocol-buffers/docs/proto3#json). +// +// While the single segment variable follows the semantics of +// [RFC 6570](https://tools.ietf.org/html/rfc6570) Section 3.2.2 Simple String +// Expansion, the multi segment variable **does not** follow RFC 6570 Section +// 3.2.3 Reserved Expansion. The reason is that the Reserved Expansion +// does not expand special characters like `?` and `#`, which would lead +// to invalid URLs. As the result, gRPC Transcoding uses a custom encoding +// for multi segment variables. +// +// The path variables **must not** refer to any repeated or mapped field, +// because client libraries are not capable of handling such variable expansion. +// +// The path variables **must not** capture the leading "/" character. The reason +// is that the most common use case "{var}" does not capture the leading "/" +// character. For consistency, all path variables must share the same behavior. +// +// Repeated message fields must not be mapped to URL query parameters, because +// no client library can support such complicated mapping. +// +// If an API needs to use a JSON array for request or response body, it can map +// the request or response body to a repeated field. However, some gRPC +// Transcoding implementations may not support this feature. +message HttpRule { + // Selects a method to which this rule applies. + // + // Refer to [selector][google.api.DocumentationRule.selector] for syntax + // details. + string selector = 1; + + // Determines the URL pattern is matched by this rules. This pattern can be + // used with any of the {get|put|post|delete|patch} methods. A custom method + // can be defined using the 'custom' field. + oneof pattern { + // Maps to HTTP GET. Used for listing and getting information about + // resources. + string get = 2; + + // Maps to HTTP PUT. Used for replacing a resource. + string put = 3; + + // Maps to HTTP POST. Used for creating a resource or performing an action. + string post = 4; + + // Maps to HTTP DELETE. Used for deleting a resource. + string delete = 5; + + // Maps to HTTP PATCH. Used for updating a resource. + string patch = 6; + + // The custom pattern is used for specifying an HTTP method that is not + // included in the `pattern` field, such as HEAD, or "*" to leave the + // HTTP method unspecified for this rule. The wild-card rule is useful + // for services that provide content to Web (HTML) clients. + CustomHttpPattern custom = 8; + } + + // The name of the request field whose value is mapped to the HTTP request + // body, or `*` for mapping all request fields not captured by the path + // pattern to the HTTP body, or omitted for not having any HTTP request body. + // + // NOTE: the referred field must be present at the top-level of the request + // message type. + string body = 7; + + // Optional. The name of the response field whose value is mapped to the HTTP + // response body. When omitted, the entire response message will be used + // as the HTTP response body. + // + // NOTE: The referred field must be present at the top-level of the response + // message type. + string response_body = 12; + + // Additional HTTP bindings for the selector. Nested bindings must + // not contain an `additional_bindings` field themselves (that is, + // the nesting may only be one level deep). + repeated HttpRule additional_bindings = 11; +} + +// A custom pattern is used for defining custom HTTP verb. +message CustomHttpPattern { + // The name of this custom HTTP verb. + string kind = 1; + + // The path matched by this custom verb. + string path = 2; +} diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-http-additional-binding/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/rpc-http-additional-binding/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..2c7454d45 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/rpc-http-additional-binding/input/temporal/api_next/fixture.proto @@ -0,0 +1,15 @@ +syntax = "proto3"; +package fixture; +import "google/api/annotations.proto"; +import "temporal/api_next/protometa/v1/draft.proto"; +message Request { Item item = 1; } +message Item { string draft_id = 1 [(temporal.api.protometa.v1.draft) = "feature-a"]; } +message Response {} +service Service { + rpc Call (Request) returns (Response) { + option (google.api.http) = { + get: "/item" + additional_bindings { custom { kind: "REPORT" path: "/items/{item.draft_id}" } } + }; + } +} diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-http-additional-binding/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/rpc-http-additional-binding/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..03c5c5701 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/rpc-http-additional-binding/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98111; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.FileOptions { string draft_file = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98008; } diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-http-body/expected.json b/cmd/generate-stable-protos/testdata/classification/rpc-http-body/expected.json new file mode 100644 index 000000000..7ffa481d0 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/rpc-http-body/expected.json @@ -0,0 +1,3 @@ +{ + "error": "fixture.Service.Call: http rule references draft field payload" +} diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-http-body/input/google/api/annotations.proto b/cmd/generate-stable-protos/testdata/classification/rpc-http-body/input/google/api/annotations.proto new file mode 100644 index 000000000..efdab3db6 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/rpc-http-body/input/google/api/annotations.proto @@ -0,0 +1,31 @@ +// Copyright 2015 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package google.api; + +import "google/api/http.proto"; +import "google/protobuf/descriptor.proto"; + +option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations"; +option java_multiple_files = true; +option java_outer_classname = "AnnotationsProto"; +option java_package = "com.google.api"; +option objc_class_prefix = "GAPI"; + +extend google.protobuf.MethodOptions { + // See `HttpRule`. + HttpRule http = 72295728; +} diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-http-body/input/google/api/http.proto b/cmd/generate-stable-protos/testdata/classification/rpc-http-body/input/google/api/http.proto new file mode 100644 index 000000000..31d867a27 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/rpc-http-body/input/google/api/http.proto @@ -0,0 +1,379 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package google.api; + +option cc_enable_arenas = true; +option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations"; +option java_multiple_files = true; +option java_outer_classname = "HttpProto"; +option java_package = "com.google.api"; +option objc_class_prefix = "GAPI"; + +// Defines the HTTP configuration for an API service. It contains a list of +// [HttpRule][google.api.HttpRule], each specifying the mapping of an RPC method +// to one or more HTTP REST API methods. +message Http { + // A list of HTTP configuration rules that apply to individual API methods. + // + // **NOTE:** All service configuration rules follow "last one wins" order. + repeated HttpRule rules = 1; + + // When set to true, URL path parameters will be fully URI-decoded except in + // cases of single segment matches in reserved expansion, where "%2F" will be + // left encoded. + // + // The default behavior is to not decode RFC 6570 reserved characters in multi + // segment matches. + bool fully_decode_reserved_expansion = 2; +} + +// # gRPC Transcoding +// +// gRPC Transcoding is a feature for mapping between a gRPC method and one or +// more HTTP REST endpoints. It allows developers to build a single API service +// that supports both gRPC APIs and REST APIs. Many systems, including [Google +// APIs](https://github.com/googleapis/googleapis), +// [Cloud Endpoints](https://cloud.google.com/endpoints), [gRPC +// Gateway](https://github.com/grpc-ecosystem/grpc-gateway), +// and [Envoy](https://github.com/envoyproxy/envoy) proxy support this feature +// and use it for large scale production services. +// +// `HttpRule` defines the schema of the gRPC/REST mapping. The mapping specifies +// how different portions of the gRPC request message are mapped to the URL +// path, URL query parameters, and HTTP request body. It also controls how the +// gRPC response message is mapped to the HTTP response body. `HttpRule` is +// typically specified as an `google.api.http` annotation on the gRPC method. +// +// Each mapping specifies a URL path template and an HTTP method. The path +// template may refer to one or more fields in the gRPC request message, as long +// as each field is a non-repeated field with a primitive (non-message) type. +// The path template controls how fields of the request message are mapped to +// the URL path. +// +// Example: +// +// service Messaging { +// rpc GetMessage(GetMessageRequest) returns (Message) { +// option (google.api.http) = { +// get: "/v1/{name=messages/*}" +// }; +// } +// } +// message GetMessageRequest { +// string name = 1; // Mapped to URL path. +// } +// message Message { +// string text = 1; // The resource content. +// } +// +// This enables an HTTP REST to gRPC mapping as below: +// +// HTTP | gRPC +// -----|----- +// `GET /v1/messages/123456` | `GetMessage(name: "messages/123456")` +// +// Any fields in the request message which are not bound by the path template +// automatically become HTTP query parameters if there is no HTTP request body. +// For example: +// +// service Messaging { +// rpc GetMessage(GetMessageRequest) returns (Message) { +// option (google.api.http) = { +// get:"/v1/messages/{message_id}" +// }; +// } +// } +// message GetMessageRequest { +// message SubMessage { +// string subfield = 1; +// } +// string message_id = 1; // Mapped to URL path. +// int64 revision = 2; // Mapped to URL query parameter `revision`. +// SubMessage sub = 3; // Mapped to URL query parameter `sub.subfield`. +// } +// +// This enables a HTTP JSON to RPC mapping as below: +// +// HTTP | gRPC +// -----|----- +// `GET /v1/messages/123456?revision=2&sub.subfield=foo` | +// `GetMessage(message_id: "123456" revision: 2 sub: SubMessage(subfield: +// "foo"))` +// +// Note that fields which are mapped to URL query parameters must have a +// primitive type or a repeated primitive type or a non-repeated message type. +// In the case of a repeated type, the parameter can be repeated in the URL +// as `...?param=A¶m=B`. In the case of a message type, each field of the +// message is mapped to a separate parameter, such as +// `...?foo.a=A&foo.b=B&foo.c=C`. +// +// For HTTP methods that allow a request body, the `body` field +// specifies the mapping. Consider a REST update method on the +// message resource collection: +// +// service Messaging { +// rpc UpdateMessage(UpdateMessageRequest) returns (Message) { +// option (google.api.http) = { +// patch: "/v1/messages/{message_id}" +// body: "message" +// }; +// } +// } +// message UpdateMessageRequest { +// string message_id = 1; // mapped to the URL +// Message message = 2; // mapped to the body +// } +// +// The following HTTP JSON to RPC mapping is enabled, where the +// representation of the JSON in the request body is determined by +// protos JSON encoding: +// +// HTTP | gRPC +// -----|----- +// `PATCH /v1/messages/123456 { "text": "Hi!" }` | `UpdateMessage(message_id: +// "123456" message { text: "Hi!" })` +// +// The special name `*` can be used in the body mapping to define that +// every field not bound by the path template should be mapped to the +// request body. This enables the following alternative definition of +// the update method: +// +// service Messaging { +// rpc UpdateMessage(Message) returns (Message) { +// option (google.api.http) = { +// patch: "/v1/messages/{message_id}" +// body: "*" +// }; +// } +// } +// message Message { +// string message_id = 1; +// string text = 2; +// } +// +// +// The following HTTP JSON to RPC mapping is enabled: +// +// HTTP | gRPC +// -----|----- +// `PATCH /v1/messages/123456 { "text": "Hi!" }` | `UpdateMessage(message_id: +// "123456" text: "Hi!")` +// +// Note that when using `*` in the body mapping, it is not possible to +// have HTTP parameters, as all fields not bound by the path end in +// the body. This makes this option more rarely used in practice when +// defining REST APIs. The common usage of `*` is in custom methods +// which don't use the URL at all for transferring data. +// +// It is possible to define multiple HTTP methods for one RPC by using +// the `additional_bindings` option. Example: +// +// service Messaging { +// rpc GetMessage(GetMessageRequest) returns (Message) { +// option (google.api.http) = { +// get: "/v1/messages/{message_id}" +// additional_bindings { +// get: "/v1/users/{user_id}/messages/{message_id}" +// } +// }; +// } +// } +// message GetMessageRequest { +// string message_id = 1; +// string user_id = 2; +// } +// +// This enables the following two alternative HTTP JSON to RPC mappings: +// +// HTTP | gRPC +// -----|----- +// `GET /v1/messages/123456` | `GetMessage(message_id: "123456")` +// `GET /v1/users/me/messages/123456` | `GetMessage(user_id: "me" message_id: +// "123456")` +// +// ## Rules for HTTP mapping +// +// 1. Leaf request fields (recursive expansion nested messages in the request +// message) are classified into three categories: +// - Fields referred by the path template. They are passed via the URL path. +// - Fields referred by the [HttpRule.body][google.api.HttpRule.body]. They +// are passed via the HTTP +// request body. +// - All other fields are passed via the URL query parameters, and the +// parameter name is the field path in the request message. A repeated +// field can be represented as multiple query parameters under the same +// name. +// 2. If [HttpRule.body][google.api.HttpRule.body] is "*", there is no URL +// query parameter, all fields +// are passed via URL path and HTTP request body. +// 3. If [HttpRule.body][google.api.HttpRule.body] is omitted, there is no HTTP +// request body, all +// fields are passed via URL path and URL query parameters. +// +// ### Path template syntax +// +// Template = "/" Segments [ Verb ] ; +// Segments = Segment { "/" Segment } ; +// Segment = "*" | "**" | LITERAL | Variable ; +// Variable = "{" FieldPath [ "=" Segments ] "}" ; +// FieldPath = IDENT { "." IDENT } ; +// Verb = ":" LITERAL ; +// +// The syntax `*` matches a single URL path segment. The syntax `**` matches +// zero or more URL path segments, which must be the last part of the URL path +// except the `Verb`. +// +// The syntax `Variable` matches part of the URL path as specified by its +// template. A variable template must not contain other variables. If a variable +// matches a single path segment, its template may be omitted, e.g. `{var}` +// is equivalent to `{var=*}`. +// +// The syntax `LITERAL` matches literal text in the URL path. If the `LITERAL` +// contains any reserved character, such characters should be percent-encoded +// before the matching. +// +// If a variable contains exactly one path segment, such as `"{var}"` or +// `"{var=*}"`, when such a variable is expanded into a URL path on the client +// side, all characters except `[-_.~0-9a-zA-Z]` are percent-encoded. The +// server side does the reverse decoding. Such variables show up in the +// [Discovery +// Document](https://developers.google.com/discovery/v1/reference/apis) as +// `{var}`. +// +// If a variable contains multiple path segments, such as `"{var=foo/*}"` +// or `"{var=**}"`, when such a variable is expanded into a URL path on the +// client side, all characters except `[-_.~/0-9a-zA-Z]` are percent-encoded. +// The server side does the reverse decoding, except "%2F" and "%2f" are left +// unchanged. Such variables show up in the +// [Discovery +// Document](https://developers.google.com/discovery/v1/reference/apis) as +// `{+var}`. +// +// ## Using gRPC API Service Configuration +// +// gRPC API Service Configuration (service config) is a configuration language +// for configuring a gRPC service to become a user-facing product. The +// service config is simply the YAML representation of the `google.api.Service` +// proto message. +// +// As an alternative to annotating your proto file, you can configure gRPC +// transcoding in your service config YAML files. You do this by specifying a +// `HttpRule` that maps the gRPC method to a REST endpoint, achieving the same +// effect as the proto annotation. This can be particularly useful if you +// have a proto that is reused in multiple services. Note that any transcoding +// specified in the service config will override any matching transcoding +// configuration in the proto. +// +// Example: +// +// http: +// rules: +// # Selects a gRPC method and applies HttpRule to it. +// - selector: example.v1.Messaging.GetMessage +// get: /v1/messages/{message_id}/{sub.subfield} +// +// ## Special notes +// +// When gRPC Transcoding is used to map a gRPC to JSON REST endpoints, the +// proto to JSON conversion must follow the [proto3 +// specification](https://developers.google.com/protocol-buffers/docs/proto3#json). +// +// While the single segment variable follows the semantics of +// [RFC 6570](https://tools.ietf.org/html/rfc6570) Section 3.2.2 Simple String +// Expansion, the multi segment variable **does not** follow RFC 6570 Section +// 3.2.3 Reserved Expansion. The reason is that the Reserved Expansion +// does not expand special characters like `?` and `#`, which would lead +// to invalid URLs. As the result, gRPC Transcoding uses a custom encoding +// for multi segment variables. +// +// The path variables **must not** refer to any repeated or mapped field, +// because client libraries are not capable of handling such variable expansion. +// +// The path variables **must not** capture the leading "/" character. The reason +// is that the most common use case "{var}" does not capture the leading "/" +// character. For consistency, all path variables must share the same behavior. +// +// Repeated message fields must not be mapped to URL query parameters, because +// no client library can support such complicated mapping. +// +// If an API needs to use a JSON array for request or response body, it can map +// the request or response body to a repeated field. However, some gRPC +// Transcoding implementations may not support this feature. +message HttpRule { + // Selects a method to which this rule applies. + // + // Refer to [selector][google.api.DocumentationRule.selector] for syntax + // details. + string selector = 1; + + // Determines the URL pattern is matched by this rules. This pattern can be + // used with any of the {get|put|post|delete|patch} methods. A custom method + // can be defined using the 'custom' field. + oneof pattern { + // Maps to HTTP GET. Used for listing and getting information about + // resources. + string get = 2; + + // Maps to HTTP PUT. Used for replacing a resource. + string put = 3; + + // Maps to HTTP POST. Used for creating a resource or performing an action. + string post = 4; + + // Maps to HTTP DELETE. Used for deleting a resource. + string delete = 5; + + // Maps to HTTP PATCH. Used for updating a resource. + string patch = 6; + + // The custom pattern is used for specifying an HTTP method that is not + // included in the `pattern` field, such as HEAD, or "*" to leave the + // HTTP method unspecified for this rule. The wild-card rule is useful + // for services that provide content to Web (HTML) clients. + CustomHttpPattern custom = 8; + } + + // The name of the request field whose value is mapped to the HTTP request + // body, or `*` for mapping all request fields not captured by the path + // pattern to the HTTP body, or omitted for not having any HTTP request body. + // + // NOTE: the referred field must be present at the top-level of the request + // message type. + string body = 7; + + // Optional. The name of the response field whose value is mapped to the HTTP + // response body. When omitted, the entire response message will be used + // as the HTTP response body. + // + // NOTE: The referred field must be present at the top-level of the response + // message type. + string response_body = 12; + + // Additional HTTP bindings for the selector. Nested bindings must + // not contain an `additional_bindings` field themselves (that is, + // the nesting may only be one level deep). + repeated HttpRule additional_bindings = 11; +} + +// A custom pattern is used for defining custom HTTP verb. +message CustomHttpPattern { + // The name of this custom HTTP verb. + string kind = 1; + + // The path matched by this custom verb. + string path = 2; +} diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-http-body/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/rpc-http-body/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..41d04bdcc --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/rpc-http-body/input/temporal/api_next/fixture.proto @@ -0,0 +1,12 @@ +syntax = "proto3"; +package fixture; +import "google/api/annotations.proto"; +import "temporal/api_next/protometa/v1/draft.proto"; +message Request { Payload payload = 1 [(temporal.api.protometa.v1.draft) = "feature-a"]; } +message Payload { string name = 1; } +message Response {} +service Service { + rpc Call (Request) returns (Response) { + option (google.api.http) = { post: "/items" body: "payload" }; + } +} diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-http-body/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/rpc-http-body/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..03c5c5701 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/rpc-http-body/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98111; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.FileOptions { string draft_file = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98008; } diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-http-nested/expected.json b/cmd/generate-stable-protos/testdata/classification/rpc-http-nested/expected.json new file mode 100644 index 000000000..07b74a13d --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/rpc-http-nested/expected.json @@ -0,0 +1,3 @@ +{ + "error": "fixture.Service.Call: http rule references draft field item.id" +} diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-http-nested/input/google/api/annotations.proto b/cmd/generate-stable-protos/testdata/classification/rpc-http-nested/input/google/api/annotations.proto new file mode 100644 index 000000000..efdab3db6 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/rpc-http-nested/input/google/api/annotations.proto @@ -0,0 +1,31 @@ +// Copyright 2015 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package google.api; + +import "google/api/http.proto"; +import "google/protobuf/descriptor.proto"; + +option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations"; +option java_multiple_files = true; +option java_outer_classname = "AnnotationsProto"; +option java_package = "com.google.api"; +option objc_class_prefix = "GAPI"; + +extend google.protobuf.MethodOptions { + // See `HttpRule`. + HttpRule http = 72295728; +} diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-http-nested/input/google/api/http.proto b/cmd/generate-stable-protos/testdata/classification/rpc-http-nested/input/google/api/http.proto new file mode 100644 index 000000000..31d867a27 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/rpc-http-nested/input/google/api/http.proto @@ -0,0 +1,379 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package google.api; + +option cc_enable_arenas = true; +option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations"; +option java_multiple_files = true; +option java_outer_classname = "HttpProto"; +option java_package = "com.google.api"; +option objc_class_prefix = "GAPI"; + +// Defines the HTTP configuration for an API service. It contains a list of +// [HttpRule][google.api.HttpRule], each specifying the mapping of an RPC method +// to one or more HTTP REST API methods. +message Http { + // A list of HTTP configuration rules that apply to individual API methods. + // + // **NOTE:** All service configuration rules follow "last one wins" order. + repeated HttpRule rules = 1; + + // When set to true, URL path parameters will be fully URI-decoded except in + // cases of single segment matches in reserved expansion, where "%2F" will be + // left encoded. + // + // The default behavior is to not decode RFC 6570 reserved characters in multi + // segment matches. + bool fully_decode_reserved_expansion = 2; +} + +// # gRPC Transcoding +// +// gRPC Transcoding is a feature for mapping between a gRPC method and one or +// more HTTP REST endpoints. It allows developers to build a single API service +// that supports both gRPC APIs and REST APIs. Many systems, including [Google +// APIs](https://github.com/googleapis/googleapis), +// [Cloud Endpoints](https://cloud.google.com/endpoints), [gRPC +// Gateway](https://github.com/grpc-ecosystem/grpc-gateway), +// and [Envoy](https://github.com/envoyproxy/envoy) proxy support this feature +// and use it for large scale production services. +// +// `HttpRule` defines the schema of the gRPC/REST mapping. The mapping specifies +// how different portions of the gRPC request message are mapped to the URL +// path, URL query parameters, and HTTP request body. It also controls how the +// gRPC response message is mapped to the HTTP response body. `HttpRule` is +// typically specified as an `google.api.http` annotation on the gRPC method. +// +// Each mapping specifies a URL path template and an HTTP method. The path +// template may refer to one or more fields in the gRPC request message, as long +// as each field is a non-repeated field with a primitive (non-message) type. +// The path template controls how fields of the request message are mapped to +// the URL path. +// +// Example: +// +// service Messaging { +// rpc GetMessage(GetMessageRequest) returns (Message) { +// option (google.api.http) = { +// get: "/v1/{name=messages/*}" +// }; +// } +// } +// message GetMessageRequest { +// string name = 1; // Mapped to URL path. +// } +// message Message { +// string text = 1; // The resource content. +// } +// +// This enables an HTTP REST to gRPC mapping as below: +// +// HTTP | gRPC +// -----|----- +// `GET /v1/messages/123456` | `GetMessage(name: "messages/123456")` +// +// Any fields in the request message which are not bound by the path template +// automatically become HTTP query parameters if there is no HTTP request body. +// For example: +// +// service Messaging { +// rpc GetMessage(GetMessageRequest) returns (Message) { +// option (google.api.http) = { +// get:"/v1/messages/{message_id}" +// }; +// } +// } +// message GetMessageRequest { +// message SubMessage { +// string subfield = 1; +// } +// string message_id = 1; // Mapped to URL path. +// int64 revision = 2; // Mapped to URL query parameter `revision`. +// SubMessage sub = 3; // Mapped to URL query parameter `sub.subfield`. +// } +// +// This enables a HTTP JSON to RPC mapping as below: +// +// HTTP | gRPC +// -----|----- +// `GET /v1/messages/123456?revision=2&sub.subfield=foo` | +// `GetMessage(message_id: "123456" revision: 2 sub: SubMessage(subfield: +// "foo"))` +// +// Note that fields which are mapped to URL query parameters must have a +// primitive type or a repeated primitive type or a non-repeated message type. +// In the case of a repeated type, the parameter can be repeated in the URL +// as `...?param=A¶m=B`. In the case of a message type, each field of the +// message is mapped to a separate parameter, such as +// `...?foo.a=A&foo.b=B&foo.c=C`. +// +// For HTTP methods that allow a request body, the `body` field +// specifies the mapping. Consider a REST update method on the +// message resource collection: +// +// service Messaging { +// rpc UpdateMessage(UpdateMessageRequest) returns (Message) { +// option (google.api.http) = { +// patch: "/v1/messages/{message_id}" +// body: "message" +// }; +// } +// } +// message UpdateMessageRequest { +// string message_id = 1; // mapped to the URL +// Message message = 2; // mapped to the body +// } +// +// The following HTTP JSON to RPC mapping is enabled, where the +// representation of the JSON in the request body is determined by +// protos JSON encoding: +// +// HTTP | gRPC +// -----|----- +// `PATCH /v1/messages/123456 { "text": "Hi!" }` | `UpdateMessage(message_id: +// "123456" message { text: "Hi!" })` +// +// The special name `*` can be used in the body mapping to define that +// every field not bound by the path template should be mapped to the +// request body. This enables the following alternative definition of +// the update method: +// +// service Messaging { +// rpc UpdateMessage(Message) returns (Message) { +// option (google.api.http) = { +// patch: "/v1/messages/{message_id}" +// body: "*" +// }; +// } +// } +// message Message { +// string message_id = 1; +// string text = 2; +// } +// +// +// The following HTTP JSON to RPC mapping is enabled: +// +// HTTP | gRPC +// -----|----- +// `PATCH /v1/messages/123456 { "text": "Hi!" }` | `UpdateMessage(message_id: +// "123456" text: "Hi!")` +// +// Note that when using `*` in the body mapping, it is not possible to +// have HTTP parameters, as all fields not bound by the path end in +// the body. This makes this option more rarely used in practice when +// defining REST APIs. The common usage of `*` is in custom methods +// which don't use the URL at all for transferring data. +// +// It is possible to define multiple HTTP methods for one RPC by using +// the `additional_bindings` option. Example: +// +// service Messaging { +// rpc GetMessage(GetMessageRequest) returns (Message) { +// option (google.api.http) = { +// get: "/v1/messages/{message_id}" +// additional_bindings { +// get: "/v1/users/{user_id}/messages/{message_id}" +// } +// }; +// } +// } +// message GetMessageRequest { +// string message_id = 1; +// string user_id = 2; +// } +// +// This enables the following two alternative HTTP JSON to RPC mappings: +// +// HTTP | gRPC +// -----|----- +// `GET /v1/messages/123456` | `GetMessage(message_id: "123456")` +// `GET /v1/users/me/messages/123456` | `GetMessage(user_id: "me" message_id: +// "123456")` +// +// ## Rules for HTTP mapping +// +// 1. Leaf request fields (recursive expansion nested messages in the request +// message) are classified into three categories: +// - Fields referred by the path template. They are passed via the URL path. +// - Fields referred by the [HttpRule.body][google.api.HttpRule.body]. They +// are passed via the HTTP +// request body. +// - All other fields are passed via the URL query parameters, and the +// parameter name is the field path in the request message. A repeated +// field can be represented as multiple query parameters under the same +// name. +// 2. If [HttpRule.body][google.api.HttpRule.body] is "*", there is no URL +// query parameter, all fields +// are passed via URL path and HTTP request body. +// 3. If [HttpRule.body][google.api.HttpRule.body] is omitted, there is no HTTP +// request body, all +// fields are passed via URL path and URL query parameters. +// +// ### Path template syntax +// +// Template = "/" Segments [ Verb ] ; +// Segments = Segment { "/" Segment } ; +// Segment = "*" | "**" | LITERAL | Variable ; +// Variable = "{" FieldPath [ "=" Segments ] "}" ; +// FieldPath = IDENT { "." IDENT } ; +// Verb = ":" LITERAL ; +// +// The syntax `*` matches a single URL path segment. The syntax `**` matches +// zero or more URL path segments, which must be the last part of the URL path +// except the `Verb`. +// +// The syntax `Variable` matches part of the URL path as specified by its +// template. A variable template must not contain other variables. If a variable +// matches a single path segment, its template may be omitted, e.g. `{var}` +// is equivalent to `{var=*}`. +// +// The syntax `LITERAL` matches literal text in the URL path. If the `LITERAL` +// contains any reserved character, such characters should be percent-encoded +// before the matching. +// +// If a variable contains exactly one path segment, such as `"{var}"` or +// `"{var=*}"`, when such a variable is expanded into a URL path on the client +// side, all characters except `[-_.~0-9a-zA-Z]` are percent-encoded. The +// server side does the reverse decoding. Such variables show up in the +// [Discovery +// Document](https://developers.google.com/discovery/v1/reference/apis) as +// `{var}`. +// +// If a variable contains multiple path segments, such as `"{var=foo/*}"` +// or `"{var=**}"`, when such a variable is expanded into a URL path on the +// client side, all characters except `[-_.~/0-9a-zA-Z]` are percent-encoded. +// The server side does the reverse decoding, except "%2F" and "%2f" are left +// unchanged. Such variables show up in the +// [Discovery +// Document](https://developers.google.com/discovery/v1/reference/apis) as +// `{+var}`. +// +// ## Using gRPC API Service Configuration +// +// gRPC API Service Configuration (service config) is a configuration language +// for configuring a gRPC service to become a user-facing product. The +// service config is simply the YAML representation of the `google.api.Service` +// proto message. +// +// As an alternative to annotating your proto file, you can configure gRPC +// transcoding in your service config YAML files. You do this by specifying a +// `HttpRule` that maps the gRPC method to a REST endpoint, achieving the same +// effect as the proto annotation. This can be particularly useful if you +// have a proto that is reused in multiple services. Note that any transcoding +// specified in the service config will override any matching transcoding +// configuration in the proto. +// +// Example: +// +// http: +// rules: +// # Selects a gRPC method and applies HttpRule to it. +// - selector: example.v1.Messaging.GetMessage +// get: /v1/messages/{message_id}/{sub.subfield} +// +// ## Special notes +// +// When gRPC Transcoding is used to map a gRPC to JSON REST endpoints, the +// proto to JSON conversion must follow the [proto3 +// specification](https://developers.google.com/protocol-buffers/docs/proto3#json). +// +// While the single segment variable follows the semantics of +// [RFC 6570](https://tools.ietf.org/html/rfc6570) Section 3.2.2 Simple String +// Expansion, the multi segment variable **does not** follow RFC 6570 Section +// 3.2.3 Reserved Expansion. The reason is that the Reserved Expansion +// does not expand special characters like `?` and `#`, which would lead +// to invalid URLs. As the result, gRPC Transcoding uses a custom encoding +// for multi segment variables. +// +// The path variables **must not** refer to any repeated or mapped field, +// because client libraries are not capable of handling such variable expansion. +// +// The path variables **must not** capture the leading "/" character. The reason +// is that the most common use case "{var}" does not capture the leading "/" +// character. For consistency, all path variables must share the same behavior. +// +// Repeated message fields must not be mapped to URL query parameters, because +// no client library can support such complicated mapping. +// +// If an API needs to use a JSON array for request or response body, it can map +// the request or response body to a repeated field. However, some gRPC +// Transcoding implementations may not support this feature. +message HttpRule { + // Selects a method to which this rule applies. + // + // Refer to [selector][google.api.DocumentationRule.selector] for syntax + // details. + string selector = 1; + + // Determines the URL pattern is matched by this rules. This pattern can be + // used with any of the {get|put|post|delete|patch} methods. A custom method + // can be defined using the 'custom' field. + oneof pattern { + // Maps to HTTP GET. Used for listing and getting information about + // resources. + string get = 2; + + // Maps to HTTP PUT. Used for replacing a resource. + string put = 3; + + // Maps to HTTP POST. Used for creating a resource or performing an action. + string post = 4; + + // Maps to HTTP DELETE. Used for deleting a resource. + string delete = 5; + + // Maps to HTTP PATCH. Used for updating a resource. + string patch = 6; + + // The custom pattern is used for specifying an HTTP method that is not + // included in the `pattern` field, such as HEAD, or "*" to leave the + // HTTP method unspecified for this rule. The wild-card rule is useful + // for services that provide content to Web (HTML) clients. + CustomHttpPattern custom = 8; + } + + // The name of the request field whose value is mapped to the HTTP request + // body, or `*` for mapping all request fields not captured by the path + // pattern to the HTTP body, or omitted for not having any HTTP request body. + // + // NOTE: the referred field must be present at the top-level of the request + // message type. + string body = 7; + + // Optional. The name of the response field whose value is mapped to the HTTP + // response body. When omitted, the entire response message will be used + // as the HTTP response body. + // + // NOTE: The referred field must be present at the top-level of the response + // message type. + string response_body = 12; + + // Additional HTTP bindings for the selector. Nested bindings must + // not contain an `additional_bindings` field themselves (that is, + // the nesting may only be one level deep). + repeated HttpRule additional_bindings = 11; +} + +// A custom pattern is used for defining custom HTTP verb. +message CustomHttpPattern { + // The name of this custom HTTP verb. + string kind = 1; + + // The path matched by this custom verb. + string path = 2; +} diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-http-nested/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/rpc-http-nested/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..a3a669069 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/rpc-http-nested/input/temporal/api_next/fixture.proto @@ -0,0 +1,15 @@ +syntax = "proto3"; +package fixture; +import "google/api/annotations.proto"; +import "temporal/api_next/protometa/v1/draft.proto"; +message Request { Draft item = 1; } +message Draft { + option (temporal.api.protometa.v1.draft_message) = "feature-a"; + string id = 1; +} +message Response {} +service Service { + rpc Call (Request) returns (Response) { + option (google.api.http) = { get: "/items/{item.id}" }; + } +} diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-http-nested/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/rpc-http-nested/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..03c5c5701 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/rpc-http-nested/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98111; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.FileOptions { string draft_file = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98008; } diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-http-path/expected.json b/cmd/generate-stable-protos/testdata/classification/rpc-http-path/expected.json new file mode 100644 index 000000000..43ce3f360 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/rpc-http-path/expected.json @@ -0,0 +1,3 @@ +{ + "error": "fixture.Service.Call: http rule references draft field draft_id" +} diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-http-path/input/google/api/annotations.proto b/cmd/generate-stable-protos/testdata/classification/rpc-http-path/input/google/api/annotations.proto new file mode 100644 index 000000000..efdab3db6 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/rpc-http-path/input/google/api/annotations.proto @@ -0,0 +1,31 @@ +// Copyright 2015 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package google.api; + +import "google/api/http.proto"; +import "google/protobuf/descriptor.proto"; + +option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations"; +option java_multiple_files = true; +option java_outer_classname = "AnnotationsProto"; +option java_package = "com.google.api"; +option objc_class_prefix = "GAPI"; + +extend google.protobuf.MethodOptions { + // See `HttpRule`. + HttpRule http = 72295728; +} diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-http-path/input/google/api/http.proto b/cmd/generate-stable-protos/testdata/classification/rpc-http-path/input/google/api/http.proto new file mode 100644 index 000000000..31d867a27 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/rpc-http-path/input/google/api/http.proto @@ -0,0 +1,379 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package google.api; + +option cc_enable_arenas = true; +option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations"; +option java_multiple_files = true; +option java_outer_classname = "HttpProto"; +option java_package = "com.google.api"; +option objc_class_prefix = "GAPI"; + +// Defines the HTTP configuration for an API service. It contains a list of +// [HttpRule][google.api.HttpRule], each specifying the mapping of an RPC method +// to one or more HTTP REST API methods. +message Http { + // A list of HTTP configuration rules that apply to individual API methods. + // + // **NOTE:** All service configuration rules follow "last one wins" order. + repeated HttpRule rules = 1; + + // When set to true, URL path parameters will be fully URI-decoded except in + // cases of single segment matches in reserved expansion, where "%2F" will be + // left encoded. + // + // The default behavior is to not decode RFC 6570 reserved characters in multi + // segment matches. + bool fully_decode_reserved_expansion = 2; +} + +// # gRPC Transcoding +// +// gRPC Transcoding is a feature for mapping between a gRPC method and one or +// more HTTP REST endpoints. It allows developers to build a single API service +// that supports both gRPC APIs and REST APIs. Many systems, including [Google +// APIs](https://github.com/googleapis/googleapis), +// [Cloud Endpoints](https://cloud.google.com/endpoints), [gRPC +// Gateway](https://github.com/grpc-ecosystem/grpc-gateway), +// and [Envoy](https://github.com/envoyproxy/envoy) proxy support this feature +// and use it for large scale production services. +// +// `HttpRule` defines the schema of the gRPC/REST mapping. The mapping specifies +// how different portions of the gRPC request message are mapped to the URL +// path, URL query parameters, and HTTP request body. It also controls how the +// gRPC response message is mapped to the HTTP response body. `HttpRule` is +// typically specified as an `google.api.http` annotation on the gRPC method. +// +// Each mapping specifies a URL path template and an HTTP method. The path +// template may refer to one or more fields in the gRPC request message, as long +// as each field is a non-repeated field with a primitive (non-message) type. +// The path template controls how fields of the request message are mapped to +// the URL path. +// +// Example: +// +// service Messaging { +// rpc GetMessage(GetMessageRequest) returns (Message) { +// option (google.api.http) = { +// get: "/v1/{name=messages/*}" +// }; +// } +// } +// message GetMessageRequest { +// string name = 1; // Mapped to URL path. +// } +// message Message { +// string text = 1; // The resource content. +// } +// +// This enables an HTTP REST to gRPC mapping as below: +// +// HTTP | gRPC +// -----|----- +// `GET /v1/messages/123456` | `GetMessage(name: "messages/123456")` +// +// Any fields in the request message which are not bound by the path template +// automatically become HTTP query parameters if there is no HTTP request body. +// For example: +// +// service Messaging { +// rpc GetMessage(GetMessageRequest) returns (Message) { +// option (google.api.http) = { +// get:"/v1/messages/{message_id}" +// }; +// } +// } +// message GetMessageRequest { +// message SubMessage { +// string subfield = 1; +// } +// string message_id = 1; // Mapped to URL path. +// int64 revision = 2; // Mapped to URL query parameter `revision`. +// SubMessage sub = 3; // Mapped to URL query parameter `sub.subfield`. +// } +// +// This enables a HTTP JSON to RPC mapping as below: +// +// HTTP | gRPC +// -----|----- +// `GET /v1/messages/123456?revision=2&sub.subfield=foo` | +// `GetMessage(message_id: "123456" revision: 2 sub: SubMessage(subfield: +// "foo"))` +// +// Note that fields which are mapped to URL query parameters must have a +// primitive type or a repeated primitive type or a non-repeated message type. +// In the case of a repeated type, the parameter can be repeated in the URL +// as `...?param=A¶m=B`. In the case of a message type, each field of the +// message is mapped to a separate parameter, such as +// `...?foo.a=A&foo.b=B&foo.c=C`. +// +// For HTTP methods that allow a request body, the `body` field +// specifies the mapping. Consider a REST update method on the +// message resource collection: +// +// service Messaging { +// rpc UpdateMessage(UpdateMessageRequest) returns (Message) { +// option (google.api.http) = { +// patch: "/v1/messages/{message_id}" +// body: "message" +// }; +// } +// } +// message UpdateMessageRequest { +// string message_id = 1; // mapped to the URL +// Message message = 2; // mapped to the body +// } +// +// The following HTTP JSON to RPC mapping is enabled, where the +// representation of the JSON in the request body is determined by +// protos JSON encoding: +// +// HTTP | gRPC +// -----|----- +// `PATCH /v1/messages/123456 { "text": "Hi!" }` | `UpdateMessage(message_id: +// "123456" message { text: "Hi!" })` +// +// The special name `*` can be used in the body mapping to define that +// every field not bound by the path template should be mapped to the +// request body. This enables the following alternative definition of +// the update method: +// +// service Messaging { +// rpc UpdateMessage(Message) returns (Message) { +// option (google.api.http) = { +// patch: "/v1/messages/{message_id}" +// body: "*" +// }; +// } +// } +// message Message { +// string message_id = 1; +// string text = 2; +// } +// +// +// The following HTTP JSON to RPC mapping is enabled: +// +// HTTP | gRPC +// -----|----- +// `PATCH /v1/messages/123456 { "text": "Hi!" }` | `UpdateMessage(message_id: +// "123456" text: "Hi!")` +// +// Note that when using `*` in the body mapping, it is not possible to +// have HTTP parameters, as all fields not bound by the path end in +// the body. This makes this option more rarely used in practice when +// defining REST APIs. The common usage of `*` is in custom methods +// which don't use the URL at all for transferring data. +// +// It is possible to define multiple HTTP methods for one RPC by using +// the `additional_bindings` option. Example: +// +// service Messaging { +// rpc GetMessage(GetMessageRequest) returns (Message) { +// option (google.api.http) = { +// get: "/v1/messages/{message_id}" +// additional_bindings { +// get: "/v1/users/{user_id}/messages/{message_id}" +// } +// }; +// } +// } +// message GetMessageRequest { +// string message_id = 1; +// string user_id = 2; +// } +// +// This enables the following two alternative HTTP JSON to RPC mappings: +// +// HTTP | gRPC +// -----|----- +// `GET /v1/messages/123456` | `GetMessage(message_id: "123456")` +// `GET /v1/users/me/messages/123456` | `GetMessage(user_id: "me" message_id: +// "123456")` +// +// ## Rules for HTTP mapping +// +// 1. Leaf request fields (recursive expansion nested messages in the request +// message) are classified into three categories: +// - Fields referred by the path template. They are passed via the URL path. +// - Fields referred by the [HttpRule.body][google.api.HttpRule.body]. They +// are passed via the HTTP +// request body. +// - All other fields are passed via the URL query parameters, and the +// parameter name is the field path in the request message. A repeated +// field can be represented as multiple query parameters under the same +// name. +// 2. If [HttpRule.body][google.api.HttpRule.body] is "*", there is no URL +// query parameter, all fields +// are passed via URL path and HTTP request body. +// 3. If [HttpRule.body][google.api.HttpRule.body] is omitted, there is no HTTP +// request body, all +// fields are passed via URL path and URL query parameters. +// +// ### Path template syntax +// +// Template = "/" Segments [ Verb ] ; +// Segments = Segment { "/" Segment } ; +// Segment = "*" | "**" | LITERAL | Variable ; +// Variable = "{" FieldPath [ "=" Segments ] "}" ; +// FieldPath = IDENT { "." IDENT } ; +// Verb = ":" LITERAL ; +// +// The syntax `*` matches a single URL path segment. The syntax `**` matches +// zero or more URL path segments, which must be the last part of the URL path +// except the `Verb`. +// +// The syntax `Variable` matches part of the URL path as specified by its +// template. A variable template must not contain other variables. If a variable +// matches a single path segment, its template may be omitted, e.g. `{var}` +// is equivalent to `{var=*}`. +// +// The syntax `LITERAL` matches literal text in the URL path. If the `LITERAL` +// contains any reserved character, such characters should be percent-encoded +// before the matching. +// +// If a variable contains exactly one path segment, such as `"{var}"` or +// `"{var=*}"`, when such a variable is expanded into a URL path on the client +// side, all characters except `[-_.~0-9a-zA-Z]` are percent-encoded. The +// server side does the reverse decoding. Such variables show up in the +// [Discovery +// Document](https://developers.google.com/discovery/v1/reference/apis) as +// `{var}`. +// +// If a variable contains multiple path segments, such as `"{var=foo/*}"` +// or `"{var=**}"`, when such a variable is expanded into a URL path on the +// client side, all characters except `[-_.~/0-9a-zA-Z]` are percent-encoded. +// The server side does the reverse decoding, except "%2F" and "%2f" are left +// unchanged. Such variables show up in the +// [Discovery +// Document](https://developers.google.com/discovery/v1/reference/apis) as +// `{+var}`. +// +// ## Using gRPC API Service Configuration +// +// gRPC API Service Configuration (service config) is a configuration language +// for configuring a gRPC service to become a user-facing product. The +// service config is simply the YAML representation of the `google.api.Service` +// proto message. +// +// As an alternative to annotating your proto file, you can configure gRPC +// transcoding in your service config YAML files. You do this by specifying a +// `HttpRule` that maps the gRPC method to a REST endpoint, achieving the same +// effect as the proto annotation. This can be particularly useful if you +// have a proto that is reused in multiple services. Note that any transcoding +// specified in the service config will override any matching transcoding +// configuration in the proto. +// +// Example: +// +// http: +// rules: +// # Selects a gRPC method and applies HttpRule to it. +// - selector: example.v1.Messaging.GetMessage +// get: /v1/messages/{message_id}/{sub.subfield} +// +// ## Special notes +// +// When gRPC Transcoding is used to map a gRPC to JSON REST endpoints, the +// proto to JSON conversion must follow the [proto3 +// specification](https://developers.google.com/protocol-buffers/docs/proto3#json). +// +// While the single segment variable follows the semantics of +// [RFC 6570](https://tools.ietf.org/html/rfc6570) Section 3.2.2 Simple String +// Expansion, the multi segment variable **does not** follow RFC 6570 Section +// 3.2.3 Reserved Expansion. The reason is that the Reserved Expansion +// does not expand special characters like `?` and `#`, which would lead +// to invalid URLs. As the result, gRPC Transcoding uses a custom encoding +// for multi segment variables. +// +// The path variables **must not** refer to any repeated or mapped field, +// because client libraries are not capable of handling such variable expansion. +// +// The path variables **must not** capture the leading "/" character. The reason +// is that the most common use case "{var}" does not capture the leading "/" +// character. For consistency, all path variables must share the same behavior. +// +// Repeated message fields must not be mapped to URL query parameters, because +// no client library can support such complicated mapping. +// +// If an API needs to use a JSON array for request or response body, it can map +// the request or response body to a repeated field. However, some gRPC +// Transcoding implementations may not support this feature. +message HttpRule { + // Selects a method to which this rule applies. + // + // Refer to [selector][google.api.DocumentationRule.selector] for syntax + // details. + string selector = 1; + + // Determines the URL pattern is matched by this rules. This pattern can be + // used with any of the {get|put|post|delete|patch} methods. A custom method + // can be defined using the 'custom' field. + oneof pattern { + // Maps to HTTP GET. Used for listing and getting information about + // resources. + string get = 2; + + // Maps to HTTP PUT. Used for replacing a resource. + string put = 3; + + // Maps to HTTP POST. Used for creating a resource or performing an action. + string post = 4; + + // Maps to HTTP DELETE. Used for deleting a resource. + string delete = 5; + + // Maps to HTTP PATCH. Used for updating a resource. + string patch = 6; + + // The custom pattern is used for specifying an HTTP method that is not + // included in the `pattern` field, such as HEAD, or "*" to leave the + // HTTP method unspecified for this rule. The wild-card rule is useful + // for services that provide content to Web (HTML) clients. + CustomHttpPattern custom = 8; + } + + // The name of the request field whose value is mapped to the HTTP request + // body, or `*` for mapping all request fields not captured by the path + // pattern to the HTTP body, or omitted for not having any HTTP request body. + // + // NOTE: the referred field must be present at the top-level of the request + // message type. + string body = 7; + + // Optional. The name of the response field whose value is mapped to the HTTP + // response body. When omitted, the entire response message will be used + // as the HTTP response body. + // + // NOTE: The referred field must be present at the top-level of the response + // message type. + string response_body = 12; + + // Additional HTTP bindings for the selector. Nested bindings must + // not contain an `additional_bindings` field themselves (that is, + // the nesting may only be one level deep). + repeated HttpRule additional_bindings = 11; +} + +// A custom pattern is used for defining custom HTTP verb. +message CustomHttpPattern { + // The name of this custom HTTP verb. + string kind = 1; + + // The path matched by this custom verb. + string path = 2; +} diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-http-path/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/rpc-http-path/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..70c32437b --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/rpc-http-path/input/temporal/api_next/fixture.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; +package fixture; +import "google/api/annotations.proto"; +import "temporal/api_next/protometa/v1/draft.proto"; +message Request { string draft_id = 1 [(temporal.api.protometa.v1.draft) = "feature-a"]; } +message Response {} +service Service { + rpc Call (Request) returns (Response) { + option (google.api.http) = { get: "/items/{draft_id=items/*}" }; + } +} diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-http-path/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/rpc-http-path/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..03c5c5701 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/rpc-http-path/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98111; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.FileOptions { string draft_file = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98008; } diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-http-response-body/expected.json b/cmd/generate-stable-protos/testdata/classification/rpc-http-response-body/expected.json new file mode 100644 index 000000000..474329e5d --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/rpc-http-response-body/expected.json @@ -0,0 +1,3 @@ +{ + "error": "fixture.Service.Call: http rule references draft field draft_result" +} diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-http-response-body/input/google/api/annotations.proto b/cmd/generate-stable-protos/testdata/classification/rpc-http-response-body/input/google/api/annotations.proto new file mode 100644 index 000000000..efdab3db6 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/rpc-http-response-body/input/google/api/annotations.proto @@ -0,0 +1,31 @@ +// Copyright 2015 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package google.api; + +import "google/api/http.proto"; +import "google/protobuf/descriptor.proto"; + +option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations"; +option java_multiple_files = true; +option java_outer_classname = "AnnotationsProto"; +option java_package = "com.google.api"; +option objc_class_prefix = "GAPI"; + +extend google.protobuf.MethodOptions { + // See `HttpRule`. + HttpRule http = 72295728; +} diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-http-response-body/input/google/api/http.proto b/cmd/generate-stable-protos/testdata/classification/rpc-http-response-body/input/google/api/http.proto new file mode 100644 index 000000000..31d867a27 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/rpc-http-response-body/input/google/api/http.proto @@ -0,0 +1,379 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package google.api; + +option cc_enable_arenas = true; +option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations"; +option java_multiple_files = true; +option java_outer_classname = "HttpProto"; +option java_package = "com.google.api"; +option objc_class_prefix = "GAPI"; + +// Defines the HTTP configuration for an API service. It contains a list of +// [HttpRule][google.api.HttpRule], each specifying the mapping of an RPC method +// to one or more HTTP REST API methods. +message Http { + // A list of HTTP configuration rules that apply to individual API methods. + // + // **NOTE:** All service configuration rules follow "last one wins" order. + repeated HttpRule rules = 1; + + // When set to true, URL path parameters will be fully URI-decoded except in + // cases of single segment matches in reserved expansion, where "%2F" will be + // left encoded. + // + // The default behavior is to not decode RFC 6570 reserved characters in multi + // segment matches. + bool fully_decode_reserved_expansion = 2; +} + +// # gRPC Transcoding +// +// gRPC Transcoding is a feature for mapping between a gRPC method and one or +// more HTTP REST endpoints. It allows developers to build a single API service +// that supports both gRPC APIs and REST APIs. Many systems, including [Google +// APIs](https://github.com/googleapis/googleapis), +// [Cloud Endpoints](https://cloud.google.com/endpoints), [gRPC +// Gateway](https://github.com/grpc-ecosystem/grpc-gateway), +// and [Envoy](https://github.com/envoyproxy/envoy) proxy support this feature +// and use it for large scale production services. +// +// `HttpRule` defines the schema of the gRPC/REST mapping. The mapping specifies +// how different portions of the gRPC request message are mapped to the URL +// path, URL query parameters, and HTTP request body. It also controls how the +// gRPC response message is mapped to the HTTP response body. `HttpRule` is +// typically specified as an `google.api.http` annotation on the gRPC method. +// +// Each mapping specifies a URL path template and an HTTP method. The path +// template may refer to one or more fields in the gRPC request message, as long +// as each field is a non-repeated field with a primitive (non-message) type. +// The path template controls how fields of the request message are mapped to +// the URL path. +// +// Example: +// +// service Messaging { +// rpc GetMessage(GetMessageRequest) returns (Message) { +// option (google.api.http) = { +// get: "/v1/{name=messages/*}" +// }; +// } +// } +// message GetMessageRequest { +// string name = 1; // Mapped to URL path. +// } +// message Message { +// string text = 1; // The resource content. +// } +// +// This enables an HTTP REST to gRPC mapping as below: +// +// HTTP | gRPC +// -----|----- +// `GET /v1/messages/123456` | `GetMessage(name: "messages/123456")` +// +// Any fields in the request message which are not bound by the path template +// automatically become HTTP query parameters if there is no HTTP request body. +// For example: +// +// service Messaging { +// rpc GetMessage(GetMessageRequest) returns (Message) { +// option (google.api.http) = { +// get:"/v1/messages/{message_id}" +// }; +// } +// } +// message GetMessageRequest { +// message SubMessage { +// string subfield = 1; +// } +// string message_id = 1; // Mapped to URL path. +// int64 revision = 2; // Mapped to URL query parameter `revision`. +// SubMessage sub = 3; // Mapped to URL query parameter `sub.subfield`. +// } +// +// This enables a HTTP JSON to RPC mapping as below: +// +// HTTP | gRPC +// -----|----- +// `GET /v1/messages/123456?revision=2&sub.subfield=foo` | +// `GetMessage(message_id: "123456" revision: 2 sub: SubMessage(subfield: +// "foo"))` +// +// Note that fields which are mapped to URL query parameters must have a +// primitive type or a repeated primitive type or a non-repeated message type. +// In the case of a repeated type, the parameter can be repeated in the URL +// as `...?param=A¶m=B`. In the case of a message type, each field of the +// message is mapped to a separate parameter, such as +// `...?foo.a=A&foo.b=B&foo.c=C`. +// +// For HTTP methods that allow a request body, the `body` field +// specifies the mapping. Consider a REST update method on the +// message resource collection: +// +// service Messaging { +// rpc UpdateMessage(UpdateMessageRequest) returns (Message) { +// option (google.api.http) = { +// patch: "/v1/messages/{message_id}" +// body: "message" +// }; +// } +// } +// message UpdateMessageRequest { +// string message_id = 1; // mapped to the URL +// Message message = 2; // mapped to the body +// } +// +// The following HTTP JSON to RPC mapping is enabled, where the +// representation of the JSON in the request body is determined by +// protos JSON encoding: +// +// HTTP | gRPC +// -----|----- +// `PATCH /v1/messages/123456 { "text": "Hi!" }` | `UpdateMessage(message_id: +// "123456" message { text: "Hi!" })` +// +// The special name `*` can be used in the body mapping to define that +// every field not bound by the path template should be mapped to the +// request body. This enables the following alternative definition of +// the update method: +// +// service Messaging { +// rpc UpdateMessage(Message) returns (Message) { +// option (google.api.http) = { +// patch: "/v1/messages/{message_id}" +// body: "*" +// }; +// } +// } +// message Message { +// string message_id = 1; +// string text = 2; +// } +// +// +// The following HTTP JSON to RPC mapping is enabled: +// +// HTTP | gRPC +// -----|----- +// `PATCH /v1/messages/123456 { "text": "Hi!" }` | `UpdateMessage(message_id: +// "123456" text: "Hi!")` +// +// Note that when using `*` in the body mapping, it is not possible to +// have HTTP parameters, as all fields not bound by the path end in +// the body. This makes this option more rarely used in practice when +// defining REST APIs. The common usage of `*` is in custom methods +// which don't use the URL at all for transferring data. +// +// It is possible to define multiple HTTP methods for one RPC by using +// the `additional_bindings` option. Example: +// +// service Messaging { +// rpc GetMessage(GetMessageRequest) returns (Message) { +// option (google.api.http) = { +// get: "/v1/messages/{message_id}" +// additional_bindings { +// get: "/v1/users/{user_id}/messages/{message_id}" +// } +// }; +// } +// } +// message GetMessageRequest { +// string message_id = 1; +// string user_id = 2; +// } +// +// This enables the following two alternative HTTP JSON to RPC mappings: +// +// HTTP | gRPC +// -----|----- +// `GET /v1/messages/123456` | `GetMessage(message_id: "123456")` +// `GET /v1/users/me/messages/123456` | `GetMessage(user_id: "me" message_id: +// "123456")` +// +// ## Rules for HTTP mapping +// +// 1. Leaf request fields (recursive expansion nested messages in the request +// message) are classified into three categories: +// - Fields referred by the path template. They are passed via the URL path. +// - Fields referred by the [HttpRule.body][google.api.HttpRule.body]. They +// are passed via the HTTP +// request body. +// - All other fields are passed via the URL query parameters, and the +// parameter name is the field path in the request message. A repeated +// field can be represented as multiple query parameters under the same +// name. +// 2. If [HttpRule.body][google.api.HttpRule.body] is "*", there is no URL +// query parameter, all fields +// are passed via URL path and HTTP request body. +// 3. If [HttpRule.body][google.api.HttpRule.body] is omitted, there is no HTTP +// request body, all +// fields are passed via URL path and URL query parameters. +// +// ### Path template syntax +// +// Template = "/" Segments [ Verb ] ; +// Segments = Segment { "/" Segment } ; +// Segment = "*" | "**" | LITERAL | Variable ; +// Variable = "{" FieldPath [ "=" Segments ] "}" ; +// FieldPath = IDENT { "." IDENT } ; +// Verb = ":" LITERAL ; +// +// The syntax `*` matches a single URL path segment. The syntax `**` matches +// zero or more URL path segments, which must be the last part of the URL path +// except the `Verb`. +// +// The syntax `Variable` matches part of the URL path as specified by its +// template. A variable template must not contain other variables. If a variable +// matches a single path segment, its template may be omitted, e.g. `{var}` +// is equivalent to `{var=*}`. +// +// The syntax `LITERAL` matches literal text in the URL path. If the `LITERAL` +// contains any reserved character, such characters should be percent-encoded +// before the matching. +// +// If a variable contains exactly one path segment, such as `"{var}"` or +// `"{var=*}"`, when such a variable is expanded into a URL path on the client +// side, all characters except `[-_.~0-9a-zA-Z]` are percent-encoded. The +// server side does the reverse decoding. Such variables show up in the +// [Discovery +// Document](https://developers.google.com/discovery/v1/reference/apis) as +// `{var}`. +// +// If a variable contains multiple path segments, such as `"{var=foo/*}"` +// or `"{var=**}"`, when such a variable is expanded into a URL path on the +// client side, all characters except `[-_.~/0-9a-zA-Z]` are percent-encoded. +// The server side does the reverse decoding, except "%2F" and "%2f" are left +// unchanged. Such variables show up in the +// [Discovery +// Document](https://developers.google.com/discovery/v1/reference/apis) as +// `{+var}`. +// +// ## Using gRPC API Service Configuration +// +// gRPC API Service Configuration (service config) is a configuration language +// for configuring a gRPC service to become a user-facing product. The +// service config is simply the YAML representation of the `google.api.Service` +// proto message. +// +// As an alternative to annotating your proto file, you can configure gRPC +// transcoding in your service config YAML files. You do this by specifying a +// `HttpRule` that maps the gRPC method to a REST endpoint, achieving the same +// effect as the proto annotation. This can be particularly useful if you +// have a proto that is reused in multiple services. Note that any transcoding +// specified in the service config will override any matching transcoding +// configuration in the proto. +// +// Example: +// +// http: +// rules: +// # Selects a gRPC method and applies HttpRule to it. +// - selector: example.v1.Messaging.GetMessage +// get: /v1/messages/{message_id}/{sub.subfield} +// +// ## Special notes +// +// When gRPC Transcoding is used to map a gRPC to JSON REST endpoints, the +// proto to JSON conversion must follow the [proto3 +// specification](https://developers.google.com/protocol-buffers/docs/proto3#json). +// +// While the single segment variable follows the semantics of +// [RFC 6570](https://tools.ietf.org/html/rfc6570) Section 3.2.2 Simple String +// Expansion, the multi segment variable **does not** follow RFC 6570 Section +// 3.2.3 Reserved Expansion. The reason is that the Reserved Expansion +// does not expand special characters like `?` and `#`, which would lead +// to invalid URLs. As the result, gRPC Transcoding uses a custom encoding +// for multi segment variables. +// +// The path variables **must not** refer to any repeated or mapped field, +// because client libraries are not capable of handling such variable expansion. +// +// The path variables **must not** capture the leading "/" character. The reason +// is that the most common use case "{var}" does not capture the leading "/" +// character. For consistency, all path variables must share the same behavior. +// +// Repeated message fields must not be mapped to URL query parameters, because +// no client library can support such complicated mapping. +// +// If an API needs to use a JSON array for request or response body, it can map +// the request or response body to a repeated field. However, some gRPC +// Transcoding implementations may not support this feature. +message HttpRule { + // Selects a method to which this rule applies. + // + // Refer to [selector][google.api.DocumentationRule.selector] for syntax + // details. + string selector = 1; + + // Determines the URL pattern is matched by this rules. This pattern can be + // used with any of the {get|put|post|delete|patch} methods. A custom method + // can be defined using the 'custom' field. + oneof pattern { + // Maps to HTTP GET. Used for listing and getting information about + // resources. + string get = 2; + + // Maps to HTTP PUT. Used for replacing a resource. + string put = 3; + + // Maps to HTTP POST. Used for creating a resource or performing an action. + string post = 4; + + // Maps to HTTP DELETE. Used for deleting a resource. + string delete = 5; + + // Maps to HTTP PATCH. Used for updating a resource. + string patch = 6; + + // The custom pattern is used for specifying an HTTP method that is not + // included in the `pattern` field, such as HEAD, or "*" to leave the + // HTTP method unspecified for this rule. The wild-card rule is useful + // for services that provide content to Web (HTML) clients. + CustomHttpPattern custom = 8; + } + + // The name of the request field whose value is mapped to the HTTP request + // body, or `*` for mapping all request fields not captured by the path + // pattern to the HTTP body, or omitted for not having any HTTP request body. + // + // NOTE: the referred field must be present at the top-level of the request + // message type. + string body = 7; + + // Optional. The name of the response field whose value is mapped to the HTTP + // response body. When omitted, the entire response message will be used + // as the HTTP response body. + // + // NOTE: The referred field must be present at the top-level of the response + // message type. + string response_body = 12; + + // Additional HTTP bindings for the selector. Nested bindings must + // not contain an `additional_bindings` field themselves (that is, + // the nesting may only be one level deep). + repeated HttpRule additional_bindings = 11; +} + +// A custom pattern is used for defining custom HTTP verb. +message CustomHttpPattern { + // The name of this custom HTTP verb. + string kind = 1; + + // The path matched by this custom verb. + string path = 2; +} diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-http-response-body/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/rpc-http-response-body/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..5427d9c4d --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/rpc-http-response-body/input/temporal/api_next/fixture.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; +package fixture; +import "google/api/annotations.proto"; +import "temporal/api_next/protometa/v1/draft.proto"; +message Request {} +message Response { string draft_result = 1 [(temporal.api.protometa.v1.draft) = "feature-a"]; } +service Service { + rpc Call (Request) returns (Response) { + option (google.api.http) = { get: "/item" response_body: "draft_result" }; + } +} diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-http-response-body/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/rpc-http-response-body/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..03c5c5701 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/rpc-http-response-body/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98111; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.FileOptions { string draft_file = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98008; } diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-http-stable/expected.json b/cmd/generate-stable-protos/testdata/classification/rpc-http-stable/expected.json new file mode 100644 index 000000000..fb15f9e40 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/rpc-http-stable/expected.json @@ -0,0 +1,5 @@ +{ + "annotations": { + "fixture.Request.draft_result": "feature-a" + } +} diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-http-stable/input/google/api/annotations.proto b/cmd/generate-stable-protos/testdata/classification/rpc-http-stable/input/google/api/annotations.proto new file mode 100644 index 000000000..efdab3db6 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/rpc-http-stable/input/google/api/annotations.proto @@ -0,0 +1,31 @@ +// Copyright 2015 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package google.api; + +import "google/api/http.proto"; +import "google/protobuf/descriptor.proto"; + +option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations"; +option java_multiple_files = true; +option java_outer_classname = "AnnotationsProto"; +option java_package = "com.google.api"; +option objc_class_prefix = "GAPI"; + +extend google.protobuf.MethodOptions { + // See `HttpRule`. + HttpRule http = 72295728; +} diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-http-stable/input/google/api/http.proto b/cmd/generate-stable-protos/testdata/classification/rpc-http-stable/input/google/api/http.proto new file mode 100644 index 000000000..31d867a27 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/rpc-http-stable/input/google/api/http.proto @@ -0,0 +1,379 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package google.api; + +option cc_enable_arenas = true; +option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations"; +option java_multiple_files = true; +option java_outer_classname = "HttpProto"; +option java_package = "com.google.api"; +option objc_class_prefix = "GAPI"; + +// Defines the HTTP configuration for an API service. It contains a list of +// [HttpRule][google.api.HttpRule], each specifying the mapping of an RPC method +// to one or more HTTP REST API methods. +message Http { + // A list of HTTP configuration rules that apply to individual API methods. + // + // **NOTE:** All service configuration rules follow "last one wins" order. + repeated HttpRule rules = 1; + + // When set to true, URL path parameters will be fully URI-decoded except in + // cases of single segment matches in reserved expansion, where "%2F" will be + // left encoded. + // + // The default behavior is to not decode RFC 6570 reserved characters in multi + // segment matches. + bool fully_decode_reserved_expansion = 2; +} + +// # gRPC Transcoding +// +// gRPC Transcoding is a feature for mapping between a gRPC method and one or +// more HTTP REST endpoints. It allows developers to build a single API service +// that supports both gRPC APIs and REST APIs. Many systems, including [Google +// APIs](https://github.com/googleapis/googleapis), +// [Cloud Endpoints](https://cloud.google.com/endpoints), [gRPC +// Gateway](https://github.com/grpc-ecosystem/grpc-gateway), +// and [Envoy](https://github.com/envoyproxy/envoy) proxy support this feature +// and use it for large scale production services. +// +// `HttpRule` defines the schema of the gRPC/REST mapping. The mapping specifies +// how different portions of the gRPC request message are mapped to the URL +// path, URL query parameters, and HTTP request body. It also controls how the +// gRPC response message is mapped to the HTTP response body. `HttpRule` is +// typically specified as an `google.api.http` annotation on the gRPC method. +// +// Each mapping specifies a URL path template and an HTTP method. The path +// template may refer to one or more fields in the gRPC request message, as long +// as each field is a non-repeated field with a primitive (non-message) type. +// The path template controls how fields of the request message are mapped to +// the URL path. +// +// Example: +// +// service Messaging { +// rpc GetMessage(GetMessageRequest) returns (Message) { +// option (google.api.http) = { +// get: "/v1/{name=messages/*}" +// }; +// } +// } +// message GetMessageRequest { +// string name = 1; // Mapped to URL path. +// } +// message Message { +// string text = 1; // The resource content. +// } +// +// This enables an HTTP REST to gRPC mapping as below: +// +// HTTP | gRPC +// -----|----- +// `GET /v1/messages/123456` | `GetMessage(name: "messages/123456")` +// +// Any fields in the request message which are not bound by the path template +// automatically become HTTP query parameters if there is no HTTP request body. +// For example: +// +// service Messaging { +// rpc GetMessage(GetMessageRequest) returns (Message) { +// option (google.api.http) = { +// get:"/v1/messages/{message_id}" +// }; +// } +// } +// message GetMessageRequest { +// message SubMessage { +// string subfield = 1; +// } +// string message_id = 1; // Mapped to URL path. +// int64 revision = 2; // Mapped to URL query parameter `revision`. +// SubMessage sub = 3; // Mapped to URL query parameter `sub.subfield`. +// } +// +// This enables a HTTP JSON to RPC mapping as below: +// +// HTTP | gRPC +// -----|----- +// `GET /v1/messages/123456?revision=2&sub.subfield=foo` | +// `GetMessage(message_id: "123456" revision: 2 sub: SubMessage(subfield: +// "foo"))` +// +// Note that fields which are mapped to URL query parameters must have a +// primitive type or a repeated primitive type or a non-repeated message type. +// In the case of a repeated type, the parameter can be repeated in the URL +// as `...?param=A¶m=B`. In the case of a message type, each field of the +// message is mapped to a separate parameter, such as +// `...?foo.a=A&foo.b=B&foo.c=C`. +// +// For HTTP methods that allow a request body, the `body` field +// specifies the mapping. Consider a REST update method on the +// message resource collection: +// +// service Messaging { +// rpc UpdateMessage(UpdateMessageRequest) returns (Message) { +// option (google.api.http) = { +// patch: "/v1/messages/{message_id}" +// body: "message" +// }; +// } +// } +// message UpdateMessageRequest { +// string message_id = 1; // mapped to the URL +// Message message = 2; // mapped to the body +// } +// +// The following HTTP JSON to RPC mapping is enabled, where the +// representation of the JSON in the request body is determined by +// protos JSON encoding: +// +// HTTP | gRPC +// -----|----- +// `PATCH /v1/messages/123456 { "text": "Hi!" }` | `UpdateMessage(message_id: +// "123456" message { text: "Hi!" })` +// +// The special name `*` can be used in the body mapping to define that +// every field not bound by the path template should be mapped to the +// request body. This enables the following alternative definition of +// the update method: +// +// service Messaging { +// rpc UpdateMessage(Message) returns (Message) { +// option (google.api.http) = { +// patch: "/v1/messages/{message_id}" +// body: "*" +// }; +// } +// } +// message Message { +// string message_id = 1; +// string text = 2; +// } +// +// +// The following HTTP JSON to RPC mapping is enabled: +// +// HTTP | gRPC +// -----|----- +// `PATCH /v1/messages/123456 { "text": "Hi!" }` | `UpdateMessage(message_id: +// "123456" text: "Hi!")` +// +// Note that when using `*` in the body mapping, it is not possible to +// have HTTP parameters, as all fields not bound by the path end in +// the body. This makes this option more rarely used in practice when +// defining REST APIs. The common usage of `*` is in custom methods +// which don't use the URL at all for transferring data. +// +// It is possible to define multiple HTTP methods for one RPC by using +// the `additional_bindings` option. Example: +// +// service Messaging { +// rpc GetMessage(GetMessageRequest) returns (Message) { +// option (google.api.http) = { +// get: "/v1/messages/{message_id}" +// additional_bindings { +// get: "/v1/users/{user_id}/messages/{message_id}" +// } +// }; +// } +// } +// message GetMessageRequest { +// string message_id = 1; +// string user_id = 2; +// } +// +// This enables the following two alternative HTTP JSON to RPC mappings: +// +// HTTP | gRPC +// -----|----- +// `GET /v1/messages/123456` | `GetMessage(message_id: "123456")` +// `GET /v1/users/me/messages/123456` | `GetMessage(user_id: "me" message_id: +// "123456")` +// +// ## Rules for HTTP mapping +// +// 1. Leaf request fields (recursive expansion nested messages in the request +// message) are classified into three categories: +// - Fields referred by the path template. They are passed via the URL path. +// - Fields referred by the [HttpRule.body][google.api.HttpRule.body]. They +// are passed via the HTTP +// request body. +// - All other fields are passed via the URL query parameters, and the +// parameter name is the field path in the request message. A repeated +// field can be represented as multiple query parameters under the same +// name. +// 2. If [HttpRule.body][google.api.HttpRule.body] is "*", there is no URL +// query parameter, all fields +// are passed via URL path and HTTP request body. +// 3. If [HttpRule.body][google.api.HttpRule.body] is omitted, there is no HTTP +// request body, all +// fields are passed via URL path and URL query parameters. +// +// ### Path template syntax +// +// Template = "/" Segments [ Verb ] ; +// Segments = Segment { "/" Segment } ; +// Segment = "*" | "**" | LITERAL | Variable ; +// Variable = "{" FieldPath [ "=" Segments ] "}" ; +// FieldPath = IDENT { "." IDENT } ; +// Verb = ":" LITERAL ; +// +// The syntax `*` matches a single URL path segment. The syntax `**` matches +// zero or more URL path segments, which must be the last part of the URL path +// except the `Verb`. +// +// The syntax `Variable` matches part of the URL path as specified by its +// template. A variable template must not contain other variables. If a variable +// matches a single path segment, its template may be omitted, e.g. `{var}` +// is equivalent to `{var=*}`. +// +// The syntax `LITERAL` matches literal text in the URL path. If the `LITERAL` +// contains any reserved character, such characters should be percent-encoded +// before the matching. +// +// If a variable contains exactly one path segment, such as `"{var}"` or +// `"{var=*}"`, when such a variable is expanded into a URL path on the client +// side, all characters except `[-_.~0-9a-zA-Z]` are percent-encoded. The +// server side does the reverse decoding. Such variables show up in the +// [Discovery +// Document](https://developers.google.com/discovery/v1/reference/apis) as +// `{var}`. +// +// If a variable contains multiple path segments, such as `"{var=foo/*}"` +// or `"{var=**}"`, when such a variable is expanded into a URL path on the +// client side, all characters except `[-_.~/0-9a-zA-Z]` are percent-encoded. +// The server side does the reverse decoding, except "%2F" and "%2f" are left +// unchanged. Such variables show up in the +// [Discovery +// Document](https://developers.google.com/discovery/v1/reference/apis) as +// `{+var}`. +// +// ## Using gRPC API Service Configuration +// +// gRPC API Service Configuration (service config) is a configuration language +// for configuring a gRPC service to become a user-facing product. The +// service config is simply the YAML representation of the `google.api.Service` +// proto message. +// +// As an alternative to annotating your proto file, you can configure gRPC +// transcoding in your service config YAML files. You do this by specifying a +// `HttpRule` that maps the gRPC method to a REST endpoint, achieving the same +// effect as the proto annotation. This can be particularly useful if you +// have a proto that is reused in multiple services. Note that any transcoding +// specified in the service config will override any matching transcoding +// configuration in the proto. +// +// Example: +// +// http: +// rules: +// # Selects a gRPC method and applies HttpRule to it. +// - selector: example.v1.Messaging.GetMessage +// get: /v1/messages/{message_id}/{sub.subfield} +// +// ## Special notes +// +// When gRPC Transcoding is used to map a gRPC to JSON REST endpoints, the +// proto to JSON conversion must follow the [proto3 +// specification](https://developers.google.com/protocol-buffers/docs/proto3#json). +// +// While the single segment variable follows the semantics of +// [RFC 6570](https://tools.ietf.org/html/rfc6570) Section 3.2.2 Simple String +// Expansion, the multi segment variable **does not** follow RFC 6570 Section +// 3.2.3 Reserved Expansion. The reason is that the Reserved Expansion +// does not expand special characters like `?` and `#`, which would lead +// to invalid URLs. As the result, gRPC Transcoding uses a custom encoding +// for multi segment variables. +// +// The path variables **must not** refer to any repeated or mapped field, +// because client libraries are not capable of handling such variable expansion. +// +// The path variables **must not** capture the leading "/" character. The reason +// is that the most common use case "{var}" does not capture the leading "/" +// character. For consistency, all path variables must share the same behavior. +// +// Repeated message fields must not be mapped to URL query parameters, because +// no client library can support such complicated mapping. +// +// If an API needs to use a JSON array for request or response body, it can map +// the request or response body to a repeated field. However, some gRPC +// Transcoding implementations may not support this feature. +message HttpRule { + // Selects a method to which this rule applies. + // + // Refer to [selector][google.api.DocumentationRule.selector] for syntax + // details. + string selector = 1; + + // Determines the URL pattern is matched by this rules. This pattern can be + // used with any of the {get|put|post|delete|patch} methods. A custom method + // can be defined using the 'custom' field. + oneof pattern { + // Maps to HTTP GET. Used for listing and getting information about + // resources. + string get = 2; + + // Maps to HTTP PUT. Used for replacing a resource. + string put = 3; + + // Maps to HTTP POST. Used for creating a resource or performing an action. + string post = 4; + + // Maps to HTTP DELETE. Used for deleting a resource. + string delete = 5; + + // Maps to HTTP PATCH. Used for updating a resource. + string patch = 6; + + // The custom pattern is used for specifying an HTTP method that is not + // included in the `pattern` field, such as HEAD, or "*" to leave the + // HTTP method unspecified for this rule. The wild-card rule is useful + // for services that provide content to Web (HTML) clients. + CustomHttpPattern custom = 8; + } + + // The name of the request field whose value is mapped to the HTTP request + // body, or `*` for mapping all request fields not captured by the path + // pattern to the HTTP body, or omitted for not having any HTTP request body. + // + // NOTE: the referred field must be present at the top-level of the request + // message type. + string body = 7; + + // Optional. The name of the response field whose value is mapped to the HTTP + // response body. When omitted, the entire response message will be used + // as the HTTP response body. + // + // NOTE: The referred field must be present at the top-level of the response + // message type. + string response_body = 12; + + // Additional HTTP bindings for the selector. Nested bindings must + // not contain an `additional_bindings` field themselves (that is, + // the nesting may only be one level deep). + repeated HttpRule additional_bindings = 11; +} + +// A custom pattern is used for defining custom HTTP verb. +message CustomHttpPattern { + // The name of this custom HTTP verb. + string kind = 1; + + // The path matched by this custom verb. + string path = 2; +} diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-http-stable/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/rpc-http-stable/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..e20c6e59b --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/rpc-http-stable/input/temporal/api_next/fixture.proto @@ -0,0 +1,19 @@ +syntax = "proto3"; +package fixture; +import "google/api/annotations.proto"; +import "temporal/api_next/protometa/v1/draft.proto"; +message Request { + Item item = 1; + string draft_result = 2 [(temporal.api.protometa.v1.draft) = "feature-a"]; +} +message Item { string id = 1; } +message Response { string draft_result = 1; } +service Service { + rpc Call (Request) returns (Response) { + option (google.api.http) = { + get: "/items/{item.id}" + response_body: "draft_result" + additional_bindings { post: "/items" body: "item" } + }; + } +} diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-http-stable/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/rpc-http-stable/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..03c5c5701 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/rpc-http-stable/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98111; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.FileOptions { string draft_file = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98008; } diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-request-header/expected.json b/cmd/generate-stable-protos/testdata/classification/rpc-request-header/expected.json new file mode 100644 index 000000000..efc7cba1a --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/rpc-request-header/expected.json @@ -0,0 +1,3 @@ +{ + "error": "fixture.Service.Call: request header references draft field item.draft_id" +} diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-request-header/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/rpc-request-header/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..533645c38 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/rpc-request-header/input/temporal/api_next/fixture.proto @@ -0,0 +1,19 @@ +syntax = "proto3"; +package fixture; +import "temporal/api_next/protometa/v1/annotations.proto"; +import "temporal/api_next/protometa/v1/draft.proto"; +message Request { Item item = 1; } +message Item { + string id = 1; + string draft_id = 2 [(temporal.api.protometa.v1.draft) = "feature-a"]; +} +message Response {} +service Service { + rpc Call (Request) returns (Response) { + option (temporal.api.protometa.v1.request_header) = { header: "item-kind" value: "item" }; + option (temporal.api.protometa.v1.request_header) = { + header: "item-id" + value: "{item.id}/{item.draft_id}" + }; + } +} diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-request-header/input/temporal/api_next/protometa/v1/annotations.proto b/cmd/generate-stable-protos/testdata/classification/rpc-request-header/input/temporal/api_next/protometa/v1/annotations.proto new file mode 100644 index 000000000..483ffd676 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/rpc-request-header/input/temporal/api_next/protometa/v1/annotations.proto @@ -0,0 +1,37 @@ +syntax = "proto3"; + +package temporal.api.protometa.v1; + +option go_package = "go.temporal.io/api/protometa/v1;protometa"; +option java_package = "io.temporal.api.protometa.v1"; +option java_multiple_files = true; +option java_outer_classname = "AnnotationsProto"; +option ruby_package = "Temporalio::Api::Protometa::V1"; +option csharp_namespace = "Temporalio.Api.Protometa.V1"; + +import "google/protobuf/descriptor.proto"; + +// RequestHeaderAnnotation allows specifying that field values from a request +// should be propagated as outbound headers. +// +// The value field supports template interpolation where field paths enclosed +// in braces will be replaced with the actual field values from the request. +// For example: +// value: "{workflow_execution.workflow_id}" +// value: "workflow-{workflow_execution.workflow_id}" +// value: "{namespace}/{workflow_execution.workflow_id}" +message RequestHeaderAnnotation { + // The name of the header to set (e.g., "temporal-resource-id") + string header = 1; + + // A template string that may contain field paths in braces. + // Field paths use dot notation to traverse nested messages. + // Example: "{workflow_execution.workflow_id}" + string value = 2; +} + +// Extension to add request-header annotations to RPC methods. +// Multiple headers can be set by repeating this option. +extend google.protobuf.MethodOptions { + repeated RequestHeaderAnnotation request_header = 7234001; +} \ No newline at end of file diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-request-header/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/rpc-request-header/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..03c5c5701 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/rpc-request-header/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98111; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.FileOptions { string draft_file = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98008; } From 16ef18bef80aafba1efdf3f26741cc1ed87484af Mon Sep 17 00:00:00 2001 From: Stephan Behnke Date: Sat, 21 Nov 2026 09:43:45 -0700 Subject: [PATCH 07/20] generate-stable-protos: take the draft option package from the schema file What Resolves draft option names from the package declared in the draft schema. Why The generator can read a relocated draft schema without hard-coding its protobuf package. Co-Authored-By: Claude Opus 5.5 --- cmd/generate-stable-protos/main.go | 14 ++++++------- cmd/generate-stable-protos/tags.go | 33 +++++++++++++++++------------- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/cmd/generate-stable-protos/main.go b/cmd/generate-stable-protos/main.go index cc647934c..b3e459189 100644 --- a/cmd/generate-stable-protos/main.go +++ b/cmd/generate-stable-protos/main.go @@ -102,23 +102,23 @@ func loadAPINext(ctx context.Context, root string, paths []string) (map[string]* // First, lower the api_next corpus into IR. results, err := lowerFiles(ctx, baseOpener(root), paths) if err != nil { - return nil, nil, nil, fmt.Errorf("lower api_next corpus: %w", err) + return nil, draftTags{}, nil, fmt.Errorf("lower api_next corpus: %w", err) } // Check for errors while indexing files by path so we can look up the draft proto in one pass. byPath := make(map[string]*ir.File, len(paths)) for i, p := range paths { if results[i].Fatal != nil { - return nil, nil, nil, fmt.Errorf("%s: %w", p, results[i].Fatal) + return nil, draftTags{}, nil, fmt.Errorf("%s: %w", p, results[i].Fatal) } irFile := results[i].Value if got := irFile.Path(); got != p { - return nil, nil, nil, fmt.Errorf("internal error: incremental.Run result %d has path %q, expected %q", i, got, p) + return nil, draftTags{}, nil, fmt.Errorf("internal error: incremental.Run result %d has path %q, expected %q", i, got, p) } for imp := range seq.Values(irFile.Imports()) { // A public re-export of the draft options proto would leak it into the stable tree. if imp.Direct && imp.Public && imp.Path() == draftTagsPath { - return nil, nil, nil, fmt.Errorf("%s: public import of %s is not supported; import it directly", p, draftTagsPath) + return nil, draftTags{}, nil, fmt.Errorf("%s: public import of %s is not supported; import it directly", p, draftTagsPath) } } byPath[p] = irFile @@ -126,17 +126,17 @@ func loadAPINext(ctx context.Context, root string, paths []string) (map[string]* draftFile, ok := byPath[draftTagsPath] if !ok { - return nil, nil, nil, fmt.Errorf("%s not found in the corpus; cannot discover the draft-tag extension set", draftTagsPath) + return nil, draftTags{}, nil, fmt.Errorf("%s not found in the corpus; cannot discover the draft-tag extension set", draftTagsPath) } tags, err := getDraftTags(draftFile) if err != nil { - return nil, nil, nil, err + return nil, draftTags{}, nil, err } annotations := draftAnnotations{} for _, p := range paths { accepted, err := validateDraftAnnotations(tags, byPath[p]) if err != nil { - return nil, nil, nil, err + return nil, draftTags{}, nil, err } maps.Copy(annotations, accepted) } diff --git a/cmd/generate-stable-protos/tags.go b/cmd/generate-stable-protos/tags.go index fdca016b0..9dfda6c88 100644 --- a/cmd/generate-stable-protos/tags.go +++ b/cmd/generate-stable-protos/tags.go @@ -11,15 +11,13 @@ import ( "google.golang.org/protobuf/types/descriptorpb" ) -const ( - draftFieldName ir.FullName = "temporal.api.protometa.v1.draft" - draftMessageName ir.FullName = "temporal.api.protometa.v1.draft_message" -) - -type draftTags map[ir.FullName]struct{} +type draftTags struct { + packageName ir.FullName + names map[ir.FullName]struct{} +} func getDraftTags(file *ir.File) (draftTags, error) { - tags := make(draftTags) + tags := draftTags{packageName: file.Package(), names: make(map[ir.FullName]struct{})} extendees := map[string]string{ "draft": "FieldOptions", "draft_message": "MessageOptions", @@ -33,23 +31,28 @@ func getDraftTags(file *ir.File) (draftTags, error) { } for ext := range seq.Values(file.AllExtensions()) { name, known := extendees[ext.Name()] - if !known || ext.FullName() != ir.FullName("temporal.api.protometa.v1."+ext.Name()) { + if !known || ext.FullName() != tags.packageName.Append(ext.Name()) { continue } if ext.Container().FullName() != ir.FullName("google.protobuf."+name) || ext.FDPType() != descriptorpb.FieldDescriptorProto_TYPE_STRING || ext.IsRepeated() { - return nil, fmt.Errorf("invalid draft option schema for %s: want singular string extending google.protobuf.%s", ext.FullName(), name) + return draftTags{}, fmt.Errorf("invalid draft option schema for %s: want singular string extending google.protobuf.%s", ext.FullName(), name) } - tags[ext.FullName()] = struct{}{} + tags.names[ext.FullName()] = struct{}{} } - if _, ok := tags[draftFieldName]; !ok { - return nil, fmt.Errorf("%s not found in %s", draftFieldName, draftTagsPath) + if name := tags.packageName.Append("draft"); !tags.contains(name) { + return draftTags{}, fmt.Errorf("%s not found in %s", name, file.Path()) } return tags, nil } +func (tags draftTags) contains(name ir.FullName) bool { + _, ok := tags.names[name] + return ok +} + func (tags draftTags) has(opts ir.MessageValue) bool { for v := range opts.Fields() { - if _, ok := tags[v.Field().FullName()]; ok { + if tags.contains(v.Field().FullName()) { return true } } @@ -64,9 +67,11 @@ type draftFeature = string // returns the accepted ones. func validateDraftAnnotations(tags draftTags, f *ir.File) (draftAnnotations, error) { accepted := draftAnnotations{} + draftFieldName := tags.packageName.Append("draft") + draftMessageName := tags.packageName.Append("draft_message") check := func(name string, placement string, opts ir.MessageValue) error { for v := range opts.Fields() { - if _, ok := tags[v.Field().FullName()]; !ok { + if !tags.contains(v.Field().FullName()) { continue } if !((placement == "field" && v.Field().FullName() == draftFieldName) || From a900e8901e3cdc7abe556766f80ef58630a0ea68 Mon Sep 17 00:00:00 2001 From: Stephan Behnke Date: Sat, 21 Nov 2026 09:50:07 -0700 Subject: [PATCH 08/20] generate-stable-protos: make the source, stable and schema paths flags What Adds flags for the source tree, stable tree, and draft schema paths while keeping the existing defaults. Why Alternate layouts need configurable paths for both schema discovery and import rewriting. Co-Authored-By: Claude Opus 5.5 --- cmd/generate-stable-protos/corpus_test.go | 2 +- cmd/generate-stable-protos/fixtures_test.go | 24 +- cmd/generate-stable-protos/main.go | 141 +++++++---- cmd/generate-stable-protos/main_test.go | 244 ++++++++++++++++---- cmd/generate-stable-protos/random_test.go | 12 +- 5 files changed, 311 insertions(+), 112 deletions(-) diff --git a/cmd/generate-stable-protos/corpus_test.go b/cmd/generate-stable-protos/corpus_test.go index 07fbe5570..057c8d312 100644 --- a/cmd/generate-stable-protos/corpus_test.go +++ b/cmd/generate-stable-protos/corpus_test.go @@ -8,7 +8,7 @@ func TestRepoAPINextIdempotent(t *testing.T) { t.Parallel() const root = "../.." first := t.TempDir() - if err := stableProtosGenerator(t.Context(), root, first); err != nil { + if err := testConfig.stableProtosGenerator(t.Context(), root, first); err != nil { t.Fatal(err) } checkIdempotent(t.Context(), t, root, first, t.TempDir()) diff --git a/cmd/generate-stable-protos/fixtures_test.go b/cmd/generate-stable-protos/fixtures_test.go index 58f05100c..2d007a614 100644 --- a/cmd/generate-stable-protos/fixtures_test.go +++ b/cmd/generate-stable-protos/fixtures_test.go @@ -79,7 +79,7 @@ func runFixture(t *testing.T, dir string) { if err := os.WriteFile(filepath.Join(out, "retained"), []byte("old"), 0o600); err != nil { t.Fatal(err) } - err := stableProtosGenerator(t.Context(), root, out) + err := testConfig.stableProtosGenerator(t.Context(), root, out) if err == nil || !strings.Contains(err.Error(), expected.Error) { t.Fatalf("want error %q, got %v", expected.Error, err) } @@ -89,12 +89,12 @@ func runFixture(t *testing.T, dir string) { return } - if err := stableProtosGenerator(t.Context(), root, out); err != nil { + if err := testConfig.stableProtosGenerator(t.Context(), root, out); err != nil { t.Fatal(err) } actual := readTree(t, out) again := t.TempDir() - if err := stableProtosGenerator(t.Context(), root, again); err != nil { + if err := testConfig.stableProtosGenerator(t.Context(), root, again); err != nil { t.Fatal(err) } if !reflect.DeepEqual(actual, readTree(t, again)) { @@ -102,11 +102,11 @@ func runFixture(t *testing.T, dir string) { } checkIdempotent(t.Context(), t, root, out, t.TempDir()) - paths, err := getAPINextPaths(root) + paths, err := testConfig.getAPINextPaths(root) if err != nil { t.Fatal(err) } - _, _, annotations, err := loadAPINext(t.Context(), root, paths) + _, _, annotations, err := testConfig.loadAPINext(t.Context(), root, paths) if err != nil { t.Fatal(err) } @@ -132,6 +132,8 @@ func runFixture(t *testing.T, dir string) { } } +var testConfig = defaultConfig() + func sortedKeys(a, b map[string]string) []string { keys := maps.Clone(a) maps.Copy(keys, b) @@ -147,20 +149,20 @@ func checkIdempotent(ctx context.Context, t testingT, root, first, scratch strin next := filepath.Join(scratch, "next") // An import may have comments before its path, and the first literal of a path split // across literals is "temporal/api" on its own. - stableImport := regexp.MustCompile(`(?m)^(import\b(?:\s+|/\*[^*]*\*/|public|weak)*["'])` + regexp.QuoteMeta(strings.TrimSuffix(stableAPIPrefix, "/")) + `(["'/])`) + stableImport := regexp.MustCompile(`(?m)^(import\b(?:\s+|/\*[^*]*\*/|public|weak)*["'])` + regexp.QuoteMeta(testConfig.stableDir) + `(["'/])`) for path, text := range readTree(t, first) { body, ok := strings.CutPrefix(text, generatedHeader) if !ok { t.Fatalf("%s: missing generated header", path) } - body = stableImport.ReplaceAllString(body, `${1}`+strings.TrimSuffix(apiNextPrefix, "/")+`$2`) - writeFile(t, filepath.Join(next, apiNextPrefix, strings.TrimPrefix(path, stableAPIPrefix)), body) + body = stableImport.ReplaceAllString(body, `${1}`+testConfig.nextDir+`$2`) + writeFile(t, filepath.Join(next, testConfig.nextDir, strings.TrimPrefix(path, testConfig.stableDir+"/")), body) } - draft, err := os.ReadFile(filepath.Join(root, draftTagsPath)) + draft, err := os.ReadFile(filepath.Join(root, testConfig.draftSchema)) if err != nil { t.Fatal(err) } - writeFile(t, filepath.Join(next, draftTagsPath), string(draft)) + writeFile(t, filepath.Join(next, testConfig.draftSchema), string(draft)) // Imports outside temporal/, such as google/ and nexusannotations/, resolve as before. entries, err := os.ReadDir(root) if err != nil { @@ -180,7 +182,7 @@ func checkIdempotent(ctx context.Context, t testingT, root, first, scratch strin } second := filepath.Join(scratch, "second") - if err := stableProtosGenerator(ctx, next, second); err != nil { + if err := testConfig.stableProtosGenerator(ctx, next, second); err != nil { t.Fatalf("second pass: %v", err) } want, got := readTree(t, first), readTree(t, second) diff --git a/cmd/generate-stable-protos/main.go b/cmd/generate-stable-protos/main.go index b3e459189..055241889 100644 --- a/cmd/generate-stable-protos/main.go +++ b/cmd/generate-stable-protos/main.go @@ -28,18 +28,47 @@ import ( "google.golang.org/protobuf/types/known/wrapperspb" ) -const ( - apiNextPrefix = "temporal/api_next/" - stableAPIPrefix = "temporal/api/" +const generatedHeader = "// Code generated by generate-stable-protos. DO NOT EDIT. \n // @generated \n\n" - draftTagsPath = apiNextPrefix + "protometa/v1/draft.proto" +type config struct { + nextDir string + stableDir string + draftSchema string +} - generatedHeader = "// Code generated by generate-stable-protos. DO NOT EDIT. \n // @generated \n\n" -) +func defaultConfig() config { + return config{ + nextDir: "temporal/api_next", + stableDir: "temporal/api", + draftSchema: "temporal/api_next/protometa/v1/draft.proto", + } +} + +func (cfg config) validatePaths() error { + for _, arg := range []struct{ flag, path string }{ + {"-next", cfg.nextDir}, + {"-stable", cfg.stableDir}, + {"-draft-schema", cfg.draftSchema}, + } { + if arg.path == "." || !fs.ValidPath(arg.path) || !filepath.IsLocal(arg.path) || strings.ContainsRune(arg.path, '\\') { + return fmt.Errorf("%s %q must be a clean, local relative path", arg.flag, arg.path) + } + } + if cfg.nextDir == cfg.stableDir || + strings.HasPrefix(cfg.nextDir, cfg.stableDir+"/") || + strings.HasPrefix(cfg.stableDir, cfg.nextDir+"/") { + return fmt.Errorf("-next %q and -stable %q overlap", cfg.nextDir, cfg.stableDir) + } + return nil +} func main() { root := flag.String("root", ".", "directory holding the proto tree; also the sole import path") outDir := flag.String("out", "", "directory to write the projected tree into (defaults to -root/ as api is still different from api_next)") + cfg := defaultConfig() + flag.StringVar(&cfg.nextDir, "next", cfg.nextDir, "source proto subdirectory relative to -root") + flag.StringVar(&cfg.stableDir, "stable", cfg.stableDir, "stable proto subdirectory relative to -out") + flag.StringVar(&cfg.draftSchema, "draft-schema", cfg.draftSchema, "draft option schema path relative to -root") flag.Parse() if info, err := os.Stat(*root); err != nil || !info.IsDir() { @@ -50,36 +79,40 @@ func main() { *outDir = *root } - if err := stableProtosGenerator(context.Background(), *root, *outDir); err != nil { + if err := cfg.stableProtosGenerator(context.Background(), *root, *outDir); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } } -func stableProtosGenerator(ctx context.Context, root, outDir string) error { - paths, err := getAPINextPaths(root) +func (cfg config) stableProtosGenerator(ctx context.Context, root, outDir string) error { + if err := cfg.validatePaths(); err != nil { + return err + } + + paths, err := cfg.getAPINextPaths(root) if err != nil { return err } if len(paths) == 0 { - return fmt.Errorf("no protos found under %q", filepath.Join(root, apiNextPrefix)) + return fmt.Errorf("no protos found under %q", filepath.Join(root, cfg.nextDir)) } - strippedOrder, strippedProtos, comments, err := stripDrafts(ctx, root, paths) + strippedOrder, strippedProtos, comments, err := cfg.stripDrafts(ctx, root, paths) if err != nil { return err } // Strip unused imports after deleting draft-tagged declarations and re-rendering the protos, // because only then can we detect which imports are unused. - stableProtos, err := organizeImports(ctx, root, strippedOrder, strippedProtos) + stableProtos, err := cfg.organizeImports(ctx, root, strippedOrder, strippedProtos) if err != nil { return err } for _, p := range strippedOrder { var diagnostics report.Report - file, _ := parser.Parse(p, source.NewFile(p, stableProtos[stablePath(p)]), &diagnostics) + file, _ := parser.Parse(p, source.NewFile(p, stableProtos[cfg.stablePath(p)]), &diagnostics) if err := comments[p].check(file.Stream()); err != nil { return err } @@ -96,13 +129,16 @@ func stableProtosGenerator(ctx context.Context, root, outDir string) error { return writeFiles(outDir, stableProtos) } -// loadAPINext lowers the api_next corpus, discovers the draft-tag extension set and +// loadAPINext lowers the configured source tree, discovers the draft-tag extension set and // validates every draft annotation, returning the annotations it accepted. -func loadAPINext(ctx context.Context, root string, paths []string) (map[string]*ir.File, draftTags, draftAnnotations, error) { - // First, lower the api_next corpus into IR. +func (cfg config) loadAPINext(ctx context.Context, root string, paths []string) (map[string]*ir.File, draftTags, draftAnnotations, error) { + if !slices.Contains(paths, cfg.draftSchema) { + paths = slices.Concat(paths, []string{cfg.draftSchema}) + } + // First, lower the source tree and configured draft schema into IR. results, err := lowerFiles(ctx, baseOpener(root), paths) if err != nil { - return nil, draftTags{}, nil, fmt.Errorf("lower api_next corpus: %w", err) + return nil, draftTags{}, nil, fmt.Errorf("lower %s corpus: %w", cfg.nextDir, err) } // Check for errors while indexing files by path so we can look up the draft proto in one pass. @@ -117,18 +153,14 @@ func loadAPINext(ctx context.Context, root string, paths []string) (map[string]* } for imp := range seq.Values(irFile.Imports()) { // A public re-export of the draft options proto would leak it into the stable tree. - if imp.Direct && imp.Public && imp.Path() == draftTagsPath { - return nil, draftTags{}, nil, fmt.Errorf("%s: public import of %s is not supported; import it directly", p, draftTagsPath) + if imp.Direct && imp.Public && imp.Path() == cfg.draftSchema { + return nil, draftTags{}, nil, fmt.Errorf("%s: public import of %s is not supported; import it directly", p, cfg.draftSchema) } } byPath[p] = irFile } - draftFile, ok := byPath[draftTagsPath] - if !ok { - return nil, draftTags{}, nil, fmt.Errorf("%s not found in the corpus; cannot discover the draft-tag extension set", draftTagsPath) - } - tags, err := getDraftTags(draftFile) + tags, err := getDraftTags(byPath[cfg.draftSchema]) if err != nil { return nil, draftTags{}, nil, err } @@ -143,8 +175,8 @@ func loadAPINext(ctx context.Context, root string, paths []string) (map[string]* return byPath, tags, annotations, nil } -func stripDrafts(ctx context.Context, root string, paths []string) ([]string, map[string]string, map[string]draftComments, error) { - byPath, tags, _, err := loadAPINext(ctx, root, paths) +func (cfg config) stripDrafts(ctx context.Context, root string, paths []string) ([]string, map[string]string, map[string]draftComments, error) { + byPath, tags, _, err := cfg.loadAPINext(ctx, root, paths) if err != nil { return nil, nil, nil, err } @@ -153,8 +185,8 @@ func stripDrafts(ctx context.Context, root string, paths []string) ([]string, ma comments := make(map[string]draftComments, len(paths)) for _, p := range paths { irFile := byPath[p] - // Skip draft.proto itself. - if p == draftTagsPath { + // Omit the configured draft schema from the destination tree. + if p == cfg.draftSchema { continue } @@ -179,8 +211,8 @@ func stripDrafts(ctx context.Context, root string, paths []string) ([]string, ma return slices.Sorted(maps.Keys(protoTexts)), protoTexts, comments, nil } -// organizeImports removes unused imports and rewrites api_next import paths to their stable api paths. -func organizeImports(ctx context.Context, root string, order []string, texts map[string]string) (map[string]string, error) { +// organizeImports removes unused imports and rewrites source tree imports to destination tree paths. +func (cfg config) organizeImports(ctx context.Context, root string, order []string, texts map[string]string) (map[string]string, error) { results, err := lowerFiles(ctx, memOpener(root, texts), order) if err != nil { return nil, fmt.Errorf("re-lower draft-stripped corpus: %w", err) @@ -207,7 +239,7 @@ func organizeImports(ctx context.Context, root string, order []string, texts map if err != nil { return nil, fmt.Errorf("print %s: %w", p, err) } - stableTexts[stablePath(p)], err = rewriteImportPaths(protoText) + stableTexts[cfg.stablePath(p)], err = cfg.rewriteImportPaths(protoText) if err != nil { return nil, fmt.Errorf("rewrite imports in %s: %w", p, err) } @@ -269,9 +301,9 @@ func errorDiagnostics(r *report.Report) (renderText string, hasErrors bool) { return text, true } -func stablePath(path string) string { - if rest, ok := strings.CutPrefix(path, apiNextPrefix); ok { - return stableAPIPrefix + rest +func (cfg config) stablePath(path string) string { + if rest, ok := strings.CutPrefix(path, cfg.nextDir+"/"); ok { + return cfg.stableDir + "/" + rest } return path } @@ -289,13 +321,22 @@ func writeFiles(dir string, files map[string]string) error { return nil } -func getAPINextPaths(root string) ([]string, error) { +func (cfg config) getAPINextPaths(root string) ([]string, error) { var sources []string - dir := filepath.Join(root, filepath.FromSlash(apiNextPrefix)) + dir := filepath.Join(root, filepath.FromSlash(cfg.nextDir)) if err := filepath.WalkDir(dir, func(path string, entry fs.DirEntry, err error) error { - if err != nil || entry.IsDir() || filepath.Ext(path) != ".proto" { + if err != nil { return err } + if entry.IsDir() { + return nil + } + if path == dir { + return fmt.Errorf("-next %q must be a directory", cfg.nextDir) + } + if filepath.Ext(path) != ".proto" { + return nil + } relative, err := filepath.Rel(root, path) if err != nil { return err @@ -309,18 +350,23 @@ func getAPINextPaths(root string) ([]string, error) { return sources, nil } -func rewriteImportPaths(text string) (string, error) { +func (cfg config) rewriteImportPaths(text string) (string, error) { var diagnostics report.Report file, _ := parser.Parse("projected.proto", source.NewFile("projected.proto", text), &diagnostics) if diagnostic, hasErrors := errorDiagnostics(&diagnostics); hasErrors { return "", fmt.Errorf("parse projected imports: %s", diagnostic) } + common := 0 + for common < min(len(cfg.nextDir), len(cfg.stableDir)) && cfg.nextDir[common] == cfg.stableDir[common] { + common++ + } + replacement := cfg.stableDir[common:] // Splice only import-expression spans, preserving option values and comments. var out strings.Builder start := 0 for imp := range file.Imports() { path := imp.ImportPath().AsLiteral().Token.AsString().Text() - if !strings.HasPrefix(path, apiNextPrefix) { + if cfg.stablePath(path) == path { continue } span := imp.ImportPath().Span() @@ -334,15 +380,20 @@ func rewriteImportPaths(text string) (string, error) { if err := prototext.Unmarshal([]byte("value: "+partSpan.Text()), &part); err != nil { return "", fmt.Errorf("decode import literal: %w", err) } - // The _next suffix can straddle concatenated literals. Preserve their comments. - from := max(len(stableAPIPrefix)-1-offset, 0) - to := min(len(apiNextPrefix)-1-offset, len(part.Value)) - offset += len(part.Value) - if from >= to { + // The changed directory segment can straddle concatenated literals. Preserve their comments. + end := offset + len(part.Value) + from := max(common-offset, 0) + to := min(len(cfg.nextDir)-offset, len(part.Value)) + insert := "" + if offset <= common && common < end { + insert = replacement + } + offset = end + if from >= to && insert == "" { continue } out.WriteString(text[start:partSpan.Start]) - out.WriteString(quoteLike(partSpan.Text(), part.Value[:from]+part.Value[to:])) + out.WriteString(quoteLike(partSpan.Text(), part.Value[:from]+insert+part.Value[to:])) start = partSpan.End } } diff --git a/cmd/generate-stable-protos/main_test.go b/cmd/generate-stable-protos/main_test.go index aefa7254e..cc05f0f0c 100644 --- a/cmd/generate-stable-protos/main_test.go +++ b/cmd/generate-stable-protos/main_test.go @@ -2,13 +2,205 @@ package main import ( "io/fs" + "maps" "os" "os/exec" "path/filepath" - "reflect" + "slices" + "strings" "testing" + + "github.com/bufbuild/protocompile/experimental/parser" + "github.com/bufbuild/protocompile/experimental/report" + "github.com/bufbuild/protocompile/experimental/source" ) +func TestGeneratorWithCustomPaths(t *testing.T) { + t.Parallel() + root, out := t.TempDir(), t.TempDir() + writeFile(t, filepath.Join(root, "next/meta/options.proto"), `syntax = "proto3"; +package example.meta; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 50000; } +extend google.protobuf.MessageOptions { string draft_message = 50000; } +`) + writeFile(t, filepath.Join(root, "next/shared.proto"), `syntax = "proto3"; +package example.api; +message Shared {} +`) + writeFile(t, filepath.Join(root, "next/service.proto"), `syntax = "proto3"; +package example.api; +import "ne" /* Keep this comment. */ "xt/shared.proto"; +import "next/meta/options.proto"; +message Request { + Shared shared = 1; + string draft_field = 2 [(example.meta.draft) = "feature"]; +} +message DraftMessage { + option (example.meta.draft_message) = "feature"; +} +`) + + cmd := exec.Command("go", "run", ".", "-root", root, "-out", out, + "-next", "next", "-stable", "stable", "-draft-schema", "next/meta/options.proto") + if output, err := cmd.CombinedOutput(); err != nil { + t.Fatalf("generate with custom paths: %v\n%s", err, output) + } + files := readTree(t, out) + if paths := slices.Sorted(maps.Keys(files)); !slices.Equal(paths, []string{"stable/service.proto", "stable/shared.proto"}) { + t.Fatalf("unexpected generated files: %v", paths) + } + service := files["stable/service.proto"] + var diagnostics report.Report + file, _ := parser.Parse("stable/service.proto", source.NewFile("stable/service.proto", service), &diagnostics) + if errs, hasErrors := errorDiagnostics(&diagnostics); hasErrors { + t.Fatalf("parse generated service: %v\n%s", errs, service) + } + var imports []string + for imp := range file.Imports() { + imports = append(imports, imp.ImportPath().AsLiteral().Token.AsString().Text()) + } + if !slices.Equal(imports, []string{"stable/shared.proto"}) { + t.Fatalf("unexpected generated imports: %v\n%s", imports, service) + } + for _, want := range []string{"Keep this comment.", "Shared shared = 1;"} { + if !strings.Contains(service, want) { + t.Errorf("missing %q in generated service:\n%s", want, service) + } + } + for _, draft := range []string{"draft_field", "DraftMessage"} { + if strings.Contains(service, draft) { + t.Errorf("found %q in generated service:\n%s", draft, service) + } + } +} + +func TestGeneratorRejectsInvalidPaths(t *testing.T) { + t.Parallel() + generator := filepath.Join(t.TempDir(), "generate-stable-protos") + if output, err := exec.Command("go", "build", "-o", generator, ".").CombinedOutput(); err != nil { + t.Fatalf("build generator: %v\n%s", err, output) + } + for _, tc := range []struct { + name, next, stable, source, schema, wantError string + }{ + {"root source", ".", "stable", "./service.proto", "meta/draft.proto", "-next"}, + {"root destination", "next", ".", "next/service.proto", "meta/draft.proto", "-stable"}, + {"source traversal", "../next", "stable", "../next/service.proto", "meta/draft.proto", "-next"}, + {"destination traversal", "next", "../outside", "next/service.proto", "meta/draft.proto", "-stable"}, + {"absolute source", "$ROOT/next", "stable", "next/service.proto", "meta/draft.proto", "-next"}, + {"absolute destination", "next", "$ROOT/stable", "next/service.proto", "meta/draft.proto", "-stable"}, + {"unclean source", "./next", "stable", "next/service.proto", "meta/draft.proto", "-next"}, + {"unclean destination", "next", "stable/../output", "next/service.proto", "meta/draft.proto", "-stable"}, + {"absolute schema", "next", "stable", "next/service.proto", "$ROOT/meta/draft.proto", "-draft-schema"}, + {"schema traversal", "next", "stable", "next/service.proto", "../draft.proto", "-draft-schema"}, + {"unclean schema", "next", "stable", "next/service.proto", "./meta/draft.proto", "-draft-schema"}, + {"equal directories", "next", "next", "next/service.proto", "meta/draft.proto", "overlap"}, + {"destination within source", "next", "next/stable", "next/service.proto", "meta/draft.proto", "overlap"}, + {"source within destination", "stable/next", "stable", "stable/next/service.proto", "meta/draft.proto", "overlap"}, + {"source file", "source.proto", "stable", "source.proto", "meta/draft.proto", "-next \"source.proto\" must be a directory"}, + } { + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + workspace := t.TempDir() + root := filepath.Join(workspace, "root") + writeFile(t, filepath.Join(root, tc.source), `syntax = "proto3"; +package example.api; +message Request {} +`) + writeFile(t, filepath.Join(root, "meta/draft.proto"), `syntax = "proto3"; +package example.meta; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 50000; } +`) + before := readTree(t, workspace) + next := strings.ReplaceAll(tc.next, "$ROOT", filepath.ToSlash(root)) + stable := strings.ReplaceAll(tc.stable, "$ROOT", filepath.ToSlash(root)) + schema := strings.ReplaceAll(tc.schema, "$ROOT", filepath.ToSlash(root)) + cmd := exec.Command(generator, "-root", root, "-out", filepath.Join(workspace, "out"), + "-next", next, "-stable", stable, "-draft-schema", schema) + output, err := cmd.CombinedOutput() + if err == nil || !strings.Contains(string(output), tc.wantError) { + t.Errorf("expected rejection mentioning %q, got %v\n%s", tc.wantError, err, output) + } + after := readTree(t, workspace) + if !maps.Equal(before, after) { + t.Errorf("tree changed after rejected generation\nbefore: %v\nafter: %v", before, after) + } + }) + } +} + +func TestStableAPIBufGuards(t *testing.T) { + t.Parallel() + toolDir := t.TempDir() + for name, script := range map[string]string{ + "go": "exit 0", + "buf": `if [[ "$*" == "ls-files --config buf.next.yaml" ]]; then + printf '%s\n' "$NEXT_FILES" + exit "$NEXT_STATUS" +fi +printf '%s\n' "$DEFAULT_FILES" +exit "$DEFAULT_STATUS"`, + "grep": `if [[ "$FILTER_FAIL" == 1 ]]; then exit 2; fi +exec /usr/bin/grep "$@"`, + "awk": `if [[ "$FILTER_FAIL" == 1 ]]; then exit 2; fi +exec /usr/bin/awk "$@"`, + } { + if err := os.WriteFile(filepath.Join(toolDir, name), []byte("#!/bin/bash\n"+script+"\n"), 0o755); err != nil { + t.Fatal(err) + } + } + for _, tc := range []struct { + name, defaultFiles, nextFiles, defaultStatus, nextStatus, filterFail string + wantFailure bool + }{ + {"clean listings", "temporal/api/service.proto", "temporal/api_next/service.proto", "0", "0", "0", false}, + {"preview file in default listing", "temporal/api_next/service.proto", "", "0", "0", "0", true}, + {"stable file in preview listing", "", "temporal/api/service.proto", "0", "0", "0", true}, + {"fixture in default listing", "cmd/fixture.proto", "", "0", "0", "0", true}, + {"fixture in preview listing", "", "cmd/fixture.proto", "0", "0", "0", true}, + {"default Buf failure", "", "", "2", "0", "0", true}, + {"preview Buf failure", "", "", "0", "2", "0", true}, + {"filter failure", "", "", "0", "0", "1", true}, + } { + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + cmd := exec.Command("make", "-C", "../..", "stable-api-test", "PATH="+toolDir+string(os.PathListSeparator)+os.Getenv("PATH")) + cmd.Env = append(os.Environ(), "DEFAULT_FILES="+tc.defaultFiles, "NEXT_FILES="+tc.nextFiles, + "DEFAULT_STATUS="+tc.defaultStatus, "NEXT_STATUS="+tc.nextStatus, "FILTER_FAIL="+tc.filterFail) + output, err := cmd.CombinedOutput() + if (err != nil) != tc.wantFailure { + t.Fatalf("want failure %t, got %v\n%s", tc.wantFailure, err, output) + } + }) + } +} + +func TestGeneratorValidatesRequestHeaderWithRelocatedDraftSchema(t *testing.T) { + t.Parallel() + root, out := t.TempDir(), t.TempDir() + const schema = "temporal/api_next/custom/options.proto" + for path, body := range readTree(t, "testdata/classification/rpc-request-header/input") { + if path == testConfig.draftSchema { + path = schema + body = strings.Replace(body, "package temporal.api.protometa.v1;", "package example.meta;", 1) + } else { + body = strings.NewReplacer( + testConfig.draftSchema, schema, + "temporal.api.protometa.v1.draft", "example.meta.draft", + ).Replace(body) + } + writeFile(t, filepath.Join(root, path), body) + } + + cmd := exec.Command("go", "run", ".", "-root", root, "-out", out, "-draft-schema", schema) + output, err := cmd.CombinedOutput() + if err == nil || !strings.Contains(string(output), "fixture.Service.Call: request header references draft field item.draft_id") { + t.Fatalf("expected rejection of the draft header field reference, got %v\n%s", err, output) + } +} + func TestStableReplacement(t *testing.T) { t.Parallel() script, err := filepath.Abs("../../scripts/stable-api.sh") @@ -50,14 +242,14 @@ exec /bin/mv "$@" if err != nil { t.Fatalf("%v: %s", err, output) } - if !reflect.DeepEqual(readTree(t, filepath.Join(root, "temporal/api")), map[string]string{"new.proto": "generated"}) { + if !maps.Equal(readTree(t, filepath.Join(root, "temporal/api")), map[string]string{"new.proto": "generated"}) { t.Fatal("new tree was nested or old files survived") } } else { if err == nil { t.Fatal("expected injected failure") } - if !reflect.DeepEqual(before, readTree(t, filepath.Join(root, "temporal/api"))) { + if !maps.Equal(before, readTree(t, filepath.Join(root, "temporal/api"))) { t.Fatalf("%s failure modified old tree: %s", failure, output) } } @@ -90,49 +282,3 @@ func readTree(t testingT, root string) map[string]string { } return files } - -func TestStableAPIBufGuards(t *testing.T) { - t.Parallel() - toolDir := t.TempDir() - for name, script := range map[string]string{ - "go": "exit 0", - "buf": `if [[ "$*" == "ls-files --config buf.next.yaml" ]]; then - printf '%s\n' "$NEXT_FILES" - exit "$NEXT_STATUS" -fi -printf '%s\n' "$DEFAULT_FILES" -exit "$DEFAULT_STATUS"`, - "grep": `if [[ "$FILTER_FAIL" == 1 ]]; then exit 2; fi -exec /usr/bin/grep "$@"`, - "awk": `if [[ "$FILTER_FAIL" == 1 ]]; then exit 2; fi -exec /usr/bin/awk "$@"`, - } { - if err := os.WriteFile(filepath.Join(toolDir, name), []byte("#!/bin/bash\n"+script+"\n"), 0o755); err != nil { - t.Fatal(err) - } - } - for _, tc := range []struct { - name, defaultFiles, nextFiles, defaultStatus, nextStatus, filterFail string - wantFailure bool - }{ - {"clean listings", "temporal/api/service.proto", "temporal/api_next/service.proto", "0", "0", "0", false}, - {"preview file in default listing", "temporal/api_next/service.proto", "", "0", "0", "0", true}, - {"stable file in preview listing", "", "temporal/api/service.proto", "0", "0", "0", true}, - {"fixture in default listing", "cmd/fixture.proto", "", "0", "0", "0", true}, - {"fixture in preview listing", "", "cmd/fixture.proto", "0", "0", "0", true}, - {"default Buf failure", "", "", "2", "0", "0", true}, - {"preview Buf failure", "", "", "0", "2", "0", true}, - {"filter failure", "", "", "0", "0", "1", true}, - } { - t.Run(tc.name, func(t *testing.T) { - t.Parallel() - cmd := exec.Command("make", "-C", "../..", "stable-api-test", "PATH="+toolDir+string(os.PathListSeparator)+os.Getenv("PATH")) - cmd.Env = append(os.Environ(), "DEFAULT_FILES="+tc.defaultFiles, "NEXT_FILES="+tc.nextFiles, - "DEFAULT_STATUS="+tc.defaultStatus, "NEXT_STATUS="+tc.nextStatus, "FILTER_FAIL="+tc.filterFail) - output, err := cmd.CombinedOutput() - if (err != nil) != tc.wantFailure { - t.Fatalf("want failure %t, got %v\n%s", tc.wantFailure, err, output) - } - }) - } -} diff --git a/cmd/generate-stable-protos/random_test.go b/cmd/generate-stable-protos/random_test.go index 1d3324e60..c4ccfb481 100644 --- a/cmd/generate-stable-protos/random_test.go +++ b/cmd/generate-stable-protos/random_test.go @@ -17,13 +17,13 @@ func TestRandomSchemas(t *testing.T) { t.Parallel() rapid.Check(t, func(rt *rapid.T) { root := t.TempDir() - writeFile(rt, filepath.Join(root, draftTagsPath), randomDraftSchema) + writeFile(rt, filepath.Join(root, testConfig.draftSchema), randomDraftSchema) for path, text := range newSchemaGen(rt).files() { rt.Logf("%s:\n%s", path, text) writeFile(rt, filepath.Join(root, path), text) } out := t.TempDir() - if err := stableProtosGenerator(t.Context(), root, out); err != nil { + if err := testConfig.stableProtosGenerator(t.Context(), root, out); err != nil { rt.Fatalf("generator rejected the schema: %v", err) } checkIdempotent(t.Context(), rt, root, out, t.TempDir()) @@ -53,17 +53,17 @@ func (g *schemaGen) files() map[string]string { base := g.file("base", rapid.IntRange(1, 4).Draw(g.rt, "base messages"), nil) dependent := g.file("dependent", rapid.IntRange(0, 3).Draw(g.rt, "dependent messages"), g.types) return map[string]string{ - apiNextPrefix + "base.proto": base, - apiNextPrefix + "dependent.proto": dependent, + testConfig.nextDir + "/base.proto": base, + testConfig.nextDir + "/dependent.proto": dependent, } } func (g *schemaGen) file(name string, messages int, imported []string) string { g.b = &strings.Builder{} g.b.WriteString("syntax = \"proto3\";\npackage fixture;\n") - g.b.WriteString("import \"" + draftTagsPath + "\";\n") + g.b.WriteString("import \"" + testConfig.draftSchema + "\";\n") if name == "dependent" { - g.b.WriteString("import \"" + apiNextPrefix + "base.proto\";\n") + g.b.WriteString("import \"" + testConfig.nextDir + "/base.proto\";\n") } names := make([]string, messages) for i := range names { From 4a2907b8aa034d1de8f707aff4b6f02eb3a14282 Mon Sep 17 00:00:00 2001 From: Stephan Behnke Date: Sat, 21 Nov 2026 09:54:11 -0700 Subject: [PATCH 09/20] generate-stable-protos: require an empty -out and create files exclusively What Requires an empty or nonexistent output directory and creates generated files exclusively through `os.Root`. Why The generator needs to avoid overwriting existing files or writing outside its designated output directory. Co-Authored-By: Claude Opus 5.5 --- cmd/generate-stable-protos/fixtures_test.go | 10 +-- cmd/generate-stable-protos/main.go | 55 ++++++++---- cmd/generate-stable-protos/main_test.go | 94 +++++++++++++++++++++ 3 files changed, 135 insertions(+), 24 deletions(-) diff --git a/cmd/generate-stable-protos/fixtures_test.go b/cmd/generate-stable-protos/fixtures_test.go index 2d007a614..10e4f25af 100644 --- a/cmd/generate-stable-protos/fixtures_test.go +++ b/cmd/generate-stable-protos/fixtures_test.go @@ -8,7 +8,6 @@ import ( "maps" "os" "path/filepath" - "reflect" "regexp" "slices" "strings" @@ -75,15 +74,12 @@ func runFixture(t *testing.T, dir string) { out := t.TempDir() if expected.Error != "" { - sentinel := map[string]string{"retained": "old"} - if err := os.WriteFile(filepath.Join(out, "retained"), []byte("old"), 0o600); err != nil { - t.Fatal(err) - } + before := readTree(t, out) err := testConfig.stableProtosGenerator(t.Context(), root, out) if err == nil || !strings.Contains(err.Error(), expected.Error) { t.Fatalf("want error %q, got %v", expected.Error, err) } - if !reflect.DeepEqual(sentinel, readTree(t, out)) { + if !maps.Equal(before, readTree(t, out)) { t.Fatal("generation failure modified output") } return @@ -97,7 +93,7 @@ func runFixture(t *testing.T, dir string) { if err := testConfig.stableProtosGenerator(t.Context(), root, again); err != nil { t.Fatal(err) } - if !reflect.DeepEqual(actual, readTree(t, again)) { + if !maps.Equal(actual, readTree(t, again)) { t.Fatal("generator output is not deterministic") } checkIdempotent(t.Context(), t, root, out, t.TempDir()) diff --git a/cmd/generate-stable-protos/main.go b/cmd/generate-stable-protos/main.go index 055241889..77432c83f 100644 --- a/cmd/generate-stable-protos/main.go +++ b/cmd/generate-stable-protos/main.go @@ -64,21 +64,12 @@ func (cfg config) validatePaths() error { func main() { root := flag.String("root", ".", "directory holding the proto tree; also the sole import path") - outDir := flag.String("out", "", "directory to write the projected tree into (defaults to -root/ as api is still different from api_next)") + outDir := flag.String("out", "", "required output directory (must be empty or nonexistent)") cfg := defaultConfig() flag.StringVar(&cfg.nextDir, "next", cfg.nextDir, "source proto subdirectory relative to -root") flag.StringVar(&cfg.stableDir, "stable", cfg.stableDir, "stable proto subdirectory relative to -out") flag.StringVar(&cfg.draftSchema, "draft-schema", cfg.draftSchema, "draft option schema path relative to -root") flag.Parse() - - if info, err := os.Stat(*root); err != nil || !info.IsDir() { - fmt.Fprintf(os.Stderr, "-root %q must be an existing directory\n", *root) - os.Exit(1) - } - if *outDir == "" { - *outDir = *root - } - if err := cfg.stableProtosGenerator(context.Background(), *root, *outDir); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) @@ -86,9 +77,34 @@ func main() { } func (cfg config) stableProtosGenerator(ctx context.Context, root, outDir string) error { + if outDir == "" { + return errors.New("-out is required") + } if err := cfg.validatePaths(); err != nil { return err } + if err := os.MkdirAll(outDir, 0o755); err != nil { + return fmt.Errorf("prepare -out %q: %w", outDir, err) + } + out, err := os.OpenRoot(outDir) + if err != nil { + return fmt.Errorf("open -out %q: %w", outDir, err) + } + defer out.Close() + entries, err := fs.ReadDir(out.FS(), ".") + if err != nil { + return fmt.Errorf("read -out %q: %w", outDir, err) + } + if len(entries) != 0 { + return fmt.Errorf("-out %q must be empty", outDir) + } + info, err := os.Stat(root) + if err != nil { + return fmt.Errorf("inspect -root %q: %w", root, err) + } + if !info.IsDir() { + return fmt.Errorf("-root %q must be an existing directory", root) + } paths, err := cfg.getAPINextPaths(root) if err != nil { @@ -126,7 +142,7 @@ func (cfg config) stableProtosGenerator(ctx context.Context, root, outDir string return err } - return writeFiles(outDir, stableProtos) + return writeFiles(out, stableProtos) } // loadAPINext lowers the configured source tree, discovers the draft-tag extension set and @@ -308,14 +324,19 @@ func (cfg config) stablePath(path string) string { return path } -func writeFiles(dir string, files map[string]string) error { - for path, text := range files { - dest := filepath.Join(dir, filepath.FromSlash(path)) - if err := os.MkdirAll(filepath.Dir(dest), 0o755); err != nil { +func writeFiles(out *os.Root, files map[string]string) error { + for _, path := range slices.Sorted(maps.Keys(files)) { + dest := filepath.FromSlash(path) + if err := out.MkdirAll(filepath.Dir(dest), 0o755); err != nil { + return err + } + file, err := out.OpenFile(dest, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0o644) + if err != nil { return err } - if err := os.WriteFile(dest, []byte(text), 0o644); err != nil { - return fmt.Errorf("write %q: %w", dest, err) + _, writeErr := file.WriteString(files[path]) + if err := errors.Join(writeErr, file.Close()); err != nil { + return fmt.Errorf("write %q: %w", file.Name(), err) } } return nil diff --git a/cmd/generate-stable-protos/main_test.go b/cmd/generate-stable-protos/main_test.go index cc05f0f0c..57a8c41f7 100644 --- a/cmd/generate-stable-protos/main_test.go +++ b/cmd/generate-stable-protos/main_test.go @@ -1,6 +1,7 @@ package main import ( + "errors" "io/fs" "maps" "os" @@ -131,6 +132,99 @@ extend google.protobuf.FieldOptions { string draft = 50000; } } } +func TestGeneratorOutputDirectory(t *testing.T) { + t.Parallel() + for _, tc := range []struct { + name, state, wantError string + invalidSource bool + }{ + {"missing flag", "omitted", "-out is required", false}, + {"nonempty output", "nonempty", "must be empty", false}, + {"nonempty output before input validation", "nonempty", "must be empty", true}, + {"regular file", "file", "not a directory", false}, + {"stable path is a file", "stable file", "must be empty", false}, + {"empty output", "empty", "", false}, + {"nonexistent output", "nonexistent", "", false}, + } { + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + workspace := t.TempDir() + root, out := filepath.Join(workspace, "source"), filepath.Join(workspace, "out") + source := `syntax = "proto3"; package example.api; message Request {}` + if tc.invalidSource { + source = "invalid protobuf" + } + writeFile(t, filepath.Join(root, "next/service.proto"), source) + writeFile(t, filepath.Join(root, "meta/draft.proto"), `syntax = "proto3"; +package example.meta; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 50000; } +`) + switch tc.state { + case "nonempty": + writeFile(t, filepath.Join(out, "retained"), "") + case "file": + writeFile(t, out, "") + case "stable file": + writeFile(t, filepath.Join(out, "stable"), "retained") + case "empty": + if err := os.Mkdir(out, 0o755); err != nil { + t.Fatal(err) + } + } + before := readTree(t, workspace) + args := []string{"run", ".", "-root", root, "-next", "next", "-stable", "stable", + "-draft-schema", "meta/draft.proto"} + if tc.state != "omitted" { + args = append(args, "-out", out) + } + output, err := exec.Command("go", args...).CombinedOutput() + if tc.wantError != "" { + if err == nil || !strings.Contains(string(output), tc.wantError) { + t.Errorf("expected rejection mentioning %q, got %v\n%s", tc.wantError, err, output) + } + } else { + if err != nil { + t.Fatalf("generate with %s: %v\n%s", tc.state, err, output) + } + const generated = "out/stable/service.proto" + body, err := os.ReadFile(filepath.Join(workspace, generated)) + if err != nil || !strings.Contains(string(body), "message Request") { + t.Fatalf("read generated proto: %v\n%s", err, body) + } + before[generated] = string(body) + } + if after := readTree(t, workspace); !maps.Equal(before, after) { + t.Errorf("unexpected tree changes\nwant: %v\ngot: %v", before, after) + } + }) + } +} + +func TestWriteFilesRejectsExistingFile(t *testing.T) { + t.Parallel() + dir := t.TempDir() + const dest = "stable/service.proto" + const original = "original proto bytes\n" + writeFile(t, filepath.Join(dir, dest), original) + out, err := os.OpenRoot(dir) + if err != nil { + t.Fatal(err) + } + defer out.Close() + + if err := writeFiles(out, map[string]string{dest: "replacement"}); !errors.Is(err, fs.ErrExist) { + t.Errorf("expected file-exists error, got %v", err) + } + contents, err := out.ReadFile(dest) + if err != nil { + t.Fatal(err) + } + if string(contents) != original { + t.Errorf("destination contents changed to %q", contents) + } +} + func TestStableAPIBufGuards(t *testing.T) { t.Parallel() toolDir := t.TempDir() From aee5a016b89527957ae42acb4390f866fb9130c3 Mon Sep 17 00:00:00 2001 From: Stephan Behnke Date: Sat, 21 Nov 2026 10:01:23 -0700 Subject: [PATCH 10/20] docs: specify draft annotations for every proto placement What Documents the draft annotations, validation rules, and expected behavior across the API generator, Go bindings, and server. Why The three implementations need one shared reference for how draft declarations are gated and removed. Co-Authored-By: Claude Opus 5.5 --- README.md | 1 + docs/draft-apis.md | 184 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 185 insertions(+) create mode 100644 docs/draft-apis.md diff --git a/README.md b/README.md index bab1af338..2d940f829 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ Use the `draft` field option or the `draft_message` message option from [`temporal/api_next/protometa/v1/draft.proto`](temporal/api_next/protometa/v1/draft.proto) to mark draft declarations. For example, `string user = 7 [(temporal.api.protometa.v1.draft) = "update-user-tagging"];` is a draft field. The generator removes annotated declarations from the stable tree. +See the [draft API specification](docs/draft-apis.md) for annotation rules, runtime behavior, and implementation gaps. Rust is also required because `make` installs and runs `nex-gen` when regenerating system Nexus WIT files. diff --git a/docs/draft-apis.md b/docs/draft-apis.md new file mode 100644 index 000000000..0bf2db109 --- /dev/null +++ b/docs/draft-apis.md @@ -0,0 +1,184 @@ +# Draft API annotations + +This specification defines how `api` generates the stable proto tree, how `api-go` generates draft filtering helpers for `api_next`, and how the Temporal server gates, filters, and analyzes draft APIs. The [implementation status](#implementation-status) records what the current branches support. + +## Placements and effects + +The options live in [`temporal/api_next/protometa/v1/draft.proto`](../temporal/api_next/protometa/v1/draft.proto) in the `temporal.api.protometa.v1` package. Import that proto directly. Each option is a singular string containing one nonempty, whitespace-free, case-sensitive feature name. For example, `priority` and `Priority` are distinct names. `""` and `"high priority"` are invalid. + +| Declaration | Option and placement | Stable tree | `api_next` Go helpers and server runtime when disabled | Server analyzer | +| --- | --- | --- | --- | --- | +| Field, including a new member of a stable oneof | `draft` (`FieldOptions`) | Remove the field. | Clear the field or unset the active oneof member. | Require acknowledgment for the field, its getter, and its oneof wrapper where applicable. | +| Message | `draft_message` (`MessageOptions`) | Remove the message and its contents. | Clear fields that use the type. RPC endpoint types must match their method or service annotation. | Require acknowledgment for the type, its draft contents, and references that use them. | +| New enum | `draft_enum` (`EnumOptions`) | Remove the enum and its values. | Clear fields that use the enum type. | Require acknowledgment for the enum and its values. | +| New value of a stable enum | `draft_enum_value` (`EnumValueOptions`) | Remove the value and retain the enum. | Clear singular fields, drop repeated elements, and delete map entries containing the value. Reject a request with `codes.InvalidArgument` if this removes a value from a retained field. | Require acknowledgment for the value. | +| New oneof | `draft_oneof` (`OneofOptions`) | Remove the oneof and its members. | Unset the oneof. | Require acknowledgment for the oneof and its member getters and wrappers. | +| New service | `draft_service` (`ServiceOptions`) | Remove the service and its RPCs. | For a covered service, gate every RPC. A disabled RPC returns `codes.Unimplemented`. | Require acknowledgment for generated service and method symbols. | +| RPC in a stable service | `draft_method` (`MethodOptions`) | Remove the RPC and retain the service. | For a covered service, a disabled RPC returns `codes.Unimplemented`. | Require acknowledgment for generated symbols that name the draft RPC. | + +These seven annotations are the complete set. The removed options are `draft_file` and `draft_extension`. Protobuf extension declarations have no draft annotation placement. + +## Declaration rules + +Every proto file in `api_next` must declare `syntax = "proto3";`. This rule applies to the source tree. External imports may use other syntax versions or editions. + +### Containers and nesting + +Before projection, check source declarations, excluding synthetic oneofs for proto3 `optional` fields. A nonempty enum, oneof, or service that has no draft annotation and does not inherit draft status from an enclosing declaration is a schema error if all its members are annotated as draft. It must carry `draft_enum`, `draft_oneof`, or `draft_service`, respectively. A service declared with zero RPCs is stable unless it carries `draft_service`. + +Members of draft containers, including enums and oneofs nested in a `draft_message`, inherit the container's feature and must carry no draft annotation of their own, even for the same feature. + +Messages are exempt from the all-members rule. A stable message, including a previously empty message, may gain only draft fields and remain stable after those fields are removed. + +```proto +// Valid: keep the stable enum and oneof, and remove their draft members. +enum Priority { + PRIORITY_UNSPECIFIED = 0; + PRIORITY_HIGH = 1 [(temporal.api.protometa.v1.draft_enum_value) = "priority"]; +} +message Selector { + oneof key { + string id = 1; + string alias = 2 [(temporal.api.protometa.v1.draft) = "aliases"]; + } +} + +// Valid: annotate the new containers and leave their members unannotated. +enum PreviewMode { + option (temporal.api.protometa.v1.draft_enum) = "preview"; + PREVIEW_MODE_UNSPECIFIED = 0; +} +message Routing { + oneof destination { + option (temporal.api.protometa.v1.draft_oneof) = "preview"; + PreviewConfig.Nested target = 1; + } +} + +// Valid: stable projection leaves OptionalSettings empty. +message OptionalSettings { + bool precise = 1 [(temporal.api.protometa.v1.draft) = "precision"]; +} +``` + +`Routing.destination.target` inherits `preview` from its oneof, matching the feature of its type (`PreviewConfig.Nested`, defined below). Adding `draft_enum_value` to `PREVIEW_MODE_UNSPECIFIED` or `draft` to `target` is a nesting error. Removing `draft_oneof` from `Routing.destination` leaves `target` without the required annotation. Marking both branches of `Selector.key` with `draft` is a container error. + +In a stable enum, a draft value cannot have number zero. A draft value must have a unique number within its enum. Aliasing involving a draft value is a schema error, even with `allow_alias = true`, so each wire number in an enum maps to at most one draft feature. For example, adding `PRIORITY_PREVIEW = 1` as an alias of `PRIORITY_HIGH` is invalid whether `PRIORITY_PREVIEW` is stable or draft. + +### RPC signatures and services + +In a stable service, an RPC with a draft request or response must carry `draft_method`. Both endpoint types must explicitly carry `draft_message` with the method's feature. An unannotated RPC using draft types, an annotated RPC with a stable endpoint, or a mismatch between feature names is a schema error. Inherited draft status alone cannot satisfy the endpoint requirement. No RPC becomes draft implicitly through its types. + +In a service with `draft_service`, every RPC is covered by the service annotation and must omit `draft_method`. Both endpoint types of every RPC must explicitly carry `draft_message` with the service's feature. + +A draft endpoint type may occupy only one request or response position across the entire `api_next` tree, so using it in both positions of one RPC is invalid. The generator checks all services and files without a historical baseline. Stable RPCs may share endpoint types, such as `google.protobuf.Empty`, and may use one type in both positions; they cannot use draft types at all. + +```proto +message PreviewRequest { + option (temporal.api.protometa.v1.draft_message) = "preview"; +} +message PreviewResponse { + option (temporal.api.protometa.v1.draft_message) = "preview"; +} +service PreviewService { + option (temporal.api.protometa.v1.draft_service) = "preview"; + rpc Preview(PreviewRequest) returns (PreviewResponse); +} +``` + +Alternatively, `Preview` can be added to an existing service alongside its stable RPCs: + +```proto +rpc Preview(PreviewRequest) returns (PreviewResponse) { + option (temporal.api.protometa.v1.draft_method) = "preview"; +} +``` + +Removing the annotation from `PreviewResponse`, changing its feature, reusing `PreviewRequest` in another RPC, or writing `rpc Preview(PreviewRequest) returns (PreviewRequest)` is invalid. A service containing only methods marked `draft_method` requires `draft_service` and must remove the method annotations. + +### Containment and type references + +Every draft declaration has exactly one feature. Containment is the only source of implicit draft status. A field in a stable parent that uses a draft message or enum must carry `draft` with the type's feature. This includes the element type of a repeated field, the value type of a map, and nested types that inherit a feature. A field inside a draft container inherits that container's feature and can reference draft types only if they have the same feature. Missing annotations and feature mismatches are validation errors that identify the field and the referenced draft type. + +A message with draft fields and an enum with draft values can each remain stable. Fields that use those stable types can remain stable, and runtime filtering visits the draft contents recursively. + +```proto +message PreviewConfig { + option (temporal.api.protometa.v1.draft_message) = "preview"; + // Nested inherits "preview" without an annotation. + message Nested {} +} +message Config { + PreviewConfig.Nested defaults = 1 [(temporal.api.protometa.v1.draft) = "preview"]; + map profiles = 2 [(temporal.api.protometa.v1.draft) = "preview"]; + PreviewMode mode = 3 [(temporal.api.protometa.v1.draft) = "preview"]; + PreviewConfig override = 4 [(temporal.api.protometa.v1.draft) = "preview"]; +} +``` + +All four fields are explicitly draft and are removed from the stable tree. Changing the feature of `override` to `overrides` is a validation error because `PreviewConfig` has feature `preview`. + +### Field removal and numbers + +Draft field numbers may change before the field first lands in `api_next`. When removing a landed draft field from `api_next`, reserve both its number and its name in the containing message. `buf breaking` with [`buf.next.yaml`](../buf.next.yaml) enforces both reservations against the previous preview schema. For example, after deleting `precise` from `OptionalSettings`: + +```proto +message OptionalSettings { + reserved 1; + reserved "precise"; +} +``` + +## Stable tree generation + +`cmd/generate-stable-protos` validates the source schema before projection, including the all-draft container rule. For valid input, it removes explicitly and implicitly draft declarations and their comments, including whole draft containers. Retain stable containers, including services declared with zero RPCs. + +Place comments meant to disappear inside the draft declaration, directly above it without a blank line, or on its last line. The generator rejects next-line trailing comments and detached comments that would survive removal. A comment between a removed declaration and the next retained declaration can stay when it is part of the doc block directly above the retained declaration. Move a comment away from the gap before a closing brace or end of file to place it with the declaration it describes. + +For retained RPCs, reject reference paths in `google.api.http` and `request_header` that name removed fields, including nested paths. For example, if `LookupRequest.alias` is a draft field, `option (google.api.http) = { get: "/v1/{alias}" };` is invalid on a retained RPC. Removed draft RPCs skip these stable-projection reference checks and remain subject to normal protobuf compilation and draft signature validation. + +Option literals on retained declarations must reference only retained declarations, including fields and enum values in aggregates and typed `Any` payloads. The generator recompiles the projection before writing output and reports the compiler diagnostic for dangling references. Open proto3 enum numbers can still compile as unknown values, so recompilation cannot identify every numeric encoding of a removed enum value. Options on removed declarations may reference draft declarations. + +Reject any protobuf extension declaration whose value type, extendee, or declaring parent is a draft type. + +## Runtime filtering + +`api-go` generates a single method, `OmitDraftFields(enabled func(string) bool) (removedEnumValue bool)`, for affected `api_next` Go types. Determine reachability statically through singular fields, oneof members, repeated elements, and map values. Generate the method for roots that reach draft fields or containers and for roots that reach only individually annotated draft enum values. + +In one traversal, the method clears fields and oneofs whose features are disabled and skips their contents. In retained fields, it clears singular occurrences of disabled draft enum values, drops matching repeated elements, and deletes map entries containing a matching value. Clearing a singular field also removes explicit presence or unsets its active oneof member where applicable. The return value is true if the traversal removed at least one disabled draft enum value from a retained field, including in a nested message. Removing an entire disabled field or container leaves the return value false unless the traversal finds a disabled enum value elsewhere. + +On requests, the server rejects a true result with `codes.InvalidArgument` and a generic message such as “Request contains a disabled draft enum value.” The message never names the enum, value, or field. On responses and outbound protobuf error details, the server applies the same method and ignores its result. For example, with `priority` disabled, a request that includes `PRIORITY_HIGH` in a retained `repeated Priority priorities` field is rejected. The same element is dropped from a response, preserving the other elements. + +The server reads draft RPC features from method and service descriptors. On public Temporal API services registered by the frontend, a draft RPC returns `codes.Unimplemented` before dispatch if its feature is disabled. This scope includes `WorkflowService`, `OperatorService`, and future public Temporal API services registered by the frontend. + +The RPC gate and payload filters share one feature selection per invocation. Use the namespace-filtered dynamic config value for the supplied namespace name. If the request supplies only a namespace ID, resolve it to a name and use that namespace's value. If the lookup fails, disable all draft features. Requests without a namespace name or ID use the global default feature set, the dynamic config value without a namespace filter. + +Payload filtering covers requests, responses, and protobuf error details on unary calls to those public Temporal API services, and in the Nexus handlers. Invoke `OmitDraftFields` on affected roots, including those whose only draft contents are enum values. + +Both the RPC gate and payload filtering exclude `AdminService`, internal services such as `HistoryService` and `MatchingService`, and infrastructure services such as gRPC health and reflection. A guard test enumerates the frontend's actual service registrations and requires each service to have both kinds of coverage or appear on an explicit infrastructure/internal exclusion list, which includes `AdminService`, health, and reflection. A separate guard test fails if a covered service adds a streaming RPC. Payload filtering covers unary RPCs and leaves streaming payloads out of scope. + +The server unwraps recognized protobuf status details from their `google.protobuf.Any` envelopes and applies outbound filtering to each decoded detail as a root. Unrecognized envelopes pass through, and `Any` fields inside decoded details or other message roots remain opaque. + +Payload filtering preserves unknown fields on retained messages. When a disabled draft message is passed directly to `OmitDraftFields` as the root, `proto.Reset` clears the whole message, including its unknown fields. This whole-root reset is an exception to unknown-field preservation. + +## Server analyzer + +`draftapi` requires a `temporal:allow-draft-api` acknowledgment for named Go references to declarations that are explicitly draft or inherit draft status from a container. This includes enum types and values, oneof wrappers, and generated service and method symbols for draft RPCs. The acknowledgment covers the feature of each referenced draft declaration. It does not enable features at runtime. + +```go +_ = cfg.GetOverride() // temporal:allow-draft-api preview +``` + +## Implementation status + +| Repository | Implemented today | Required by this specification | +| --- | --- | --- | +| `api` | `draft.proto` declares `draft`, `draft_message`, `draft_enum`, `draft_enum_value`, `draft_service`, and `draft_method`. The generator accepts field and message annotations only, strips their comments, removes references to draft messages and to types that inherit draft status from enclosing messages, including nested enums and map value types, and drops emptied oneofs. It rejects RPCs and extensions using draft types and HTTP or request-header options naming removed fields. Buf checks preview reservations. | Add `draft_oneof` and remove recognition of `draft_file` and `draft_extension`. Validate before projection and support all seven placements, including explicit `draft_enum`. Limit RPC option reference checks to retained RPCs and continue rejecting extensions that reference draft types. Infer draft status only through containment, with one feature per declaration. | +| `api-go` | `protoc-gen-go-helpers` accepts field and message annotations and generates recursive omission through affected messages, including message-valued maps. It infers draft status through type references and clears draft members of stable oneofs. It resets a disabled draft root with `proto.Reset`, clearing unknown fields. It rejects RPC signatures and extensions using draft types and checks HTTP and request-header references to removed fields. | Accept all seven placements, enforce one feature per declaration with implicit draft status only through containment, and accept valid draft RPC signatures. Remove recognition of `draft_file` and `draft_extension`. Limit RPC option reference checks to retained RPCs and keep the extension checks. Extend `OmitDraftFields` to cover whole draft oneofs and reachable draft enum values, and return whether it removed a disabled enum value from a retained field. | +| Temporal server | `draftapi` accepts field and message placements and tracks their generated Go references, including affected oneof wrappers and enums and values inherited from draft messages. The runtime omits fields in covered unary requests, responses, error details, and Nexus paths. The unary-only guard test exists. | Remove recognition of `draft_file` and `draft_extension`. Extend the analyzer to the new placements and generated RPC and service symbols, using a single feature per declaration. Add descriptor-based RPC gating in covered public Temporal services and the frontend registration guard. Invoke the unified `OmitDraftFields` on affected roots and use its result to reject requests with a generic `codes.InvalidArgument` error. | + +### PR order and verification + +1. **`api`** supplies the annotation schema, stable projection, and shared classification fixtures for valid and invalid declarations, including field type references, all-draft containers, endpoint reuse, enum aliases, and retained versus removed RPC option references. The independent descriptor oracle compares the projected schema and surviving comments for all placements. +2. **`api-go`** takes the updated `api` revision, consumes the shared classification fixtures, and regenerates the Go trees and helper fixtures. Extend `draftwire` to check that field and enum omission with features disabled matches the stable projection and that enabling all features preserves the input. Build the expected result independently of the generated helper. Walk a copy of the original payload using the `api_next` descriptors. Clear disabled fields and containers and skip their contents. From retained fields, remove enum occurrences whose numbers have a `draft_enum_value` annotation with a disabled feature. Clear singular fields, drop matching repeated elements and map entries, and preserve all other values, including unrecognized enum numbers. Check that the helper's result reports whether the walk removed an enum value from a retained field. Marshal the copy, decode it against stable descriptors with `DiscardUnknown`, and compare it with the filtered output decoded against the same descriptors. `DiscardUnknown` alone preserves unrecognized proto3 enum numbers in known fields, including numbers of projected-out enum values. +3. **Temporal server** takes the regenerated `api-go/api_next` revision. Extend the `draftapi` contract test to cover the new generated symbols and their features. Extend the descriptor-based filter properties to cover RPC gating and enum-only roots, including generic request rejection and omission from responses and error details. Check that enum values inside disabled fields do not trigger rejection and that the frontend registration guard accounts for every registered service. From 3b525b8e6a2bd4c666200208de81c71ee867ff47 Mon Sep 17 00:00:00 2001 From: Stephan Behnke Date: Sat, 21 Nov 2026 10:04:04 -0700 Subject: [PATCH 11/20] generate-stable-protos: validate draft annotations on every placement What Validates the supported draft annotations across declarations, including container rules, RPC endpoint constraints, and draft references. Why The generator needs to reject schemas it cannot safely project to the stable API. Co-Authored-By: Claude Opus 5.5 --- cmd/generate-stable-protos/fixtures_test.go | 33 +- cmd/generate-stable-protos/main.go | 19 +- cmd/generate-stable-protos/random_test.go | 29 +- cmd/generate-stable-protos/rules.go | 187 +++++++++ cmd/generate-stable-protos/tags.go | 87 ++-- .../container-all-draft-enum/expected.json | 3 + .../input/temporal/api_next/fixture.proto | 4 + .../api_next/protometa/v1/draft.proto | 3 +- .../expected.json | 3 + .../input/temporal/api_next/fixture.proto | 9 + .../api_next/protometa/v1/draft.proto | 3 +- .../expected.json | 3 + .../input/temporal/api_next/fixture.proto | 14 + .../api_next/protometa/v1/draft.proto | 3 +- .../expected.json | 3 + .../input/temporal/api_next/fixture.proto | 12 + .../api_next/protometa/v1/draft.proto | 10 + .../container-all-draft-service/expected.json | 3 + .../input/temporal/api_next/fixture.proto | 11 + .../api_next/protometa/v1/draft.proto | 10 + .../draft-empty-service/expected.json | 6 + .../input/temporal/api_next/fixture.proto | 2 +- .../api_next/protometa/v1/draft.proto | 10 + .../draft-enum-value/expected.json | 6 + .../input/temporal/api_next/fixture.proto | 11 + .../api_next/protometa/v1/draft.proto | 10 + .../classification/draft-enum/expected.json | 6 + .../input/temporal/api_next/fixture.proto | 8 + .../api_next/protometa/v1/draft.proto | 10 + .../classification/draft-method/expected.json | 8 + .../input/temporal/api_next/fixture.proto | 11 + .../api_next/protometa/v1/draft.proto | 10 + .../classification/draft-oneof/expected.json | 7 + .../input/temporal/api_next/fixture.proto | 10 + .../api_next/protometa/v1/draft.proto | 10 + .../draft-optional-only/expected.json | 5 + .../input/temporal/api_next/fixture.proto | 4 + .../api_next/protometa/v1/draft.proto | 10 + .../draft-service/expected.json | 8 + .../input/temporal/api_next/fixture.proto | 9 + .../api_next/protometa/v1/draft.proto | 10 + .../empty-service/expected.json | 3 + .../input/temporal/api_next/fixture.proto | 3 + .../api_next/protometa/v1/draft.proto | 10 + .../api_next/protometa/v1/draft.proto | 3 +- .../enum-value-alias-both-draft/expected.json | 3 + .../input/temporal/api_next/fixture.proto | 4 + .../api_next/protometa/v1/draft.proto | 10 + .../expected.json | 3 + .../input/temporal/api_next/fixture.proto | 4 + .../api_next/protometa/v1/draft.proto | 10 + .../expected.json | 3 + .../input/temporal/api_next/fixture.proto | 4 + .../api_next/protometa/v1/draft.proto | 10 + .../enum-value-zero/expected.json | 3 + .../input/temporal/api_next/fixture.proto | 4 + .../api_next/protometa/v1/draft.proto | 10 + .../extension-enum-value-type/expected.json | 3 + .../input/temporal/api_next/fixture.proto | 6 + .../api_next/protometa/v1/draft.proto | 10 + .../api_next/protometa/v1/draft.proto | 3 +- .../api_next/protometa/v1/draft.proto | 3 +- .../external-public-import/expected.json | 3 + .../input/bridge/pub.proto | 3 + .../input/temporal/api_next/fixture.proto | 4 + .../api_next/protometa/v1/draft.proto | 10 + .../inherit-draft-message/expected.json | 5 + .../input/temporal/api_next/fixture.proto | 9 + .../api_next/protometa/v1/draft.proto | 10 + .../api_next/protometa/v1/draft.proto | 3 +- .../message-types/expected.json | 5 +- .../input/temporal/api_next/fixture.proto | 4 - .../api_next/protometa/v1/draft.proto | 3 +- .../input/temporal/api_next/types.proto | 1 - .../api_next/protometa/v1/draft.proto | 3 +- .../method-inherited-endpoint/expected.json | 3 + .../input/temporal/api_next/fixture.proto | 11 + .../api_next/protometa/v1/draft.proto | 10 + .../expected.json | 3 + .../input/temporal/api_next/fixture.proto | 11 + .../api_next/protometa/v1/draft.proto | 10 + .../expected.json | 3 + .../input/temporal/api_next/fixture.proto | 11 + .../api_next/protometa/v1/draft.proto | 10 + .../method-stable-request/expected.json | 3 + .../input/temporal/api_next/fixture.proto | 11 + .../api_next/protometa/v1/draft.proto | 10 + .../method-stable-response/expected.json | 3 + .../input/temporal/api_next/fixture.proto | 11 + .../api_next/protometa/v1/draft.proto | 10 + .../api_next/protometa/v1/draft.proto | 3 +- .../nesting-enum-in-message/expected.json | 3 + .../input/temporal/api_next/fixture.proto | 4 + .../api_next/protometa/v1/draft.proto | 10 + .../nesting-enum-value/expected.json | 3 + .../input/temporal/api_next/fixture.proto | 4 + .../api_next/protometa/v1/draft.proto | 10 + .../nesting-field-in-message/expected.json | 3 + .../input/temporal/api_next/fixture.proto | 4 + .../api_next/protometa/v1/draft.proto | 10 + .../nesting-inherited-enum/expected.json | 3 + .../input/temporal/api_next/fixture.proto | 4 + .../api_next/protometa/v1/draft.proto | 10 + .../nesting-inherited-message/expected.json | 3 + .../input/temporal/api_next/fixture.proto | 4 + .../api_next/protometa/v1/draft.proto | 10 + .../nesting-inherited-oneof/expected.json | 3 + .../input/temporal/api_next/fixture.proto | 4 + .../api_next/protometa/v1/draft.proto | 10 + .../nesting-message-in-message/expected.json | 3 + .../input/temporal/api_next/fixture.proto | 4 + .../api_next/protometa/v1/draft.proto | 10 + .../nesting-method-in-service/expected.json | 3 + .../input/temporal/api_next/fixture.proto | 9 + .../api_next/protometa/v1/draft.proto | 10 + .../nesting-oneof-field/expected.json | 3 + .../input/temporal/api_next/fixture.proto | 2 +- .../api_next/protometa/v1/draft.proto | 10 + .../nesting-oneof-in-message/expected.json | 3 + .../input/temporal/api_next/fixture.proto | 4 + .../api_next/protometa/v1/draft.proto | 10 + .../api_next/protometa/v1/draft.proto | 3 +- .../removed-rpc-http/expected.json | 9 + .../input/google/api/annotations.proto | 31 ++ .../input/google/api/http.proto | 379 ++++++++++++++++++ .../input/temporal/api_next/fixture.proto | 16 + .../api_next/protometa/v1/draft.proto | 10 + .../removed-rpc-request-header/expected.json | 9 + .../input/temporal/api_next/fixture.proto | 20 + .../api_next/protometa/v1/annotations.proto | 37 ++ .../api_next/protometa/v1/draft.proto | 10 + .../api_next/protometa/v1/draft.proto | 3 +- .../api_next/protometa/v1/draft.proto | 3 +- .../rpc-http-draft-oneof/expected.json | 1 + .../input/google/api/annotations.proto | 31 ++ .../input/google/api/http.proto | 379 ++++++++++++++++++ .../input/temporal/api_next/fixture.proto | 11 + .../api_next/protometa/v1/draft.proto | 10 + .../api_next/protometa/v1/draft.proto | 3 +- .../input/temporal/api_next/fixture.proto | 9 + .../api_next/protometa/v1/draft.proto | 3 +- .../api_next/protometa/v1/draft.proto | 3 +- .../api_next/protometa/v1/draft.proto | 3 +- .../rpc-inherited-input/expected.json | 3 + .../input/temporal/api_next/fixture.proto | 6 + .../api_next/protometa/v1/draft.proto | 10 + .../classification/rpc-input/expected.json | 2 +- .../api_next/protometa/v1/draft.proto | 3 +- .../classification/rpc-output/expected.json | 2 +- .../api_next/protometa/v1/draft.proto | 3 +- .../api_next/protometa/v1/draft.proto | 3 +- .../rpc-reuse-cross-file/expected.json | 3 + .../input/temporal/api_next/fixture.proto | 12 + .../api_next/protometa/v1/draft.proto | 10 + .../input/temporal/api_next/second.proto | 9 + .../rpc-reuse-draft/expected.json | 3 + .../input/temporal/api_next/fixture.proto | 11 + .../api_next/protometa/v1/draft.proto | 10 + .../rpc-same-request-response/expected.json | 3 + .../input/temporal/api_next/fixture.proto | 11 + .../api_next/protometa/v1/draft.proto | 10 + .../rpc-stable-shared-endpoints/expected.json | 3 + .../expected/temporal/api/fixture.proto | 12 + .../input/temporal/api_next/fixture.proto | 11 + .../api_next/protometa/v1/draft.proto | 10 + .../service-inherited-endpoint/expected.json | 3 + .../input/temporal/api_next/fixture.proto | 9 + .../api_next/protometa/v1/draft.proto | 10 + .../expected.json | 3 + .../input/temporal/api_next/fixture.proto | 9 + .../api_next/protometa/v1/draft.proto | 10 + .../expected.json | 3 + .../input/temporal/api_next/fixture.proto | 9 + .../api_next/protometa/v1/draft.proto | 10 + .../service-stable-request/expected.json | 3 + .../input/temporal/api_next/fixture.proto | 9 + .../api_next/protometa/v1/draft.proto | 10 + .../service-stable-response/expected.json | 3 + .../input/temporal/api_next/fixture.proto | 9 + .../api_next/protometa/v1/draft.proto | 10 + .../api_next/protometa/v1/draft.proto | 3 +- .../unsupported-enum-value/expected.json | 3 - .../input/temporal/api_next/fixture.proto | 4 - .../unsupported-enum/expected.json | 3 - .../api_next/protometa/v1/draft.proto | 3 +- .../unsupported-file/expected.json | 3 - .../unsupported-method/expected.json | 3 - .../input/temporal/api_next/fixture.proto | 4 - .../unsupported-oneof/expected.json | 3 - .../api_next/protometa/v1/draft.proto | 11 - .../unsupported-service/expected.json | 3 - .../input/temporal/api_next/fixture.proto | 4 - .../api_next/protometa/v1/draft.proto | 11 - .../classification/valid/expected.json | 2 - .../input/temporal/api_next/fixture.proto | 4 - .../api_next/protometa/v1/draft.proto | 3 +- .../api_next/protometa/v1/draft.proto | 3 +- .../api_next/protometa/v1/draft.proto | 3 +- .../api_next/protometa/v1/draft.proto | 3 +- .../api_next/protometa/v1/draft.proto | 3 +- .../api_next/protometa/v1/draft.proto | 3 +- .../api_next/protometa/v1/draft.proto | 3 +- .../api_next/protometa/v1/draft.proto | 3 +- .../api_next/protometa/v1/draft.proto | 3 +- .../api_next/protometa/v1/draft.proto | 3 +- .../api_next/protometa/v1/draft.proto | 3 +- .../schema/legacy-options/expected.json | 4 + .../input/temporal/api_next/fixture.proto | 15 + .../api_next/protometa/v1/draft.proto | 3 +- .../removed-extension-option/expected.json | 3 + .../input/temporal/api_next/fixture.proto | 5 + .../api_next/protometa/v1/draft.proto | 10 + .../api_next/protometa/v1/draft.proto | 3 +- .../schema/unsupported-file/expected.json | 3 + .../input/temporal/api_next/fixture.proto | 0 .../api_next/protometa/v1/draft.proto | 10 + .../api_next/protometa/v1/draft.proto | 3 +- .../api_next/protometa/v1/draft.proto | 3 +- temporal/api_next/protometa/v1/draft.proto | 6 +- 219 files changed, 2277 insertions(+), 222 deletions(-) create mode 100644 cmd/generate-stable-protos/rules.go create mode 100644 cmd/generate-stable-protos/testdata/classification/container-all-draft-enum/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/container-all-draft-enum/input/temporal/api_next/fixture.proto rename cmd/generate-stable-protos/testdata/classification/{unsupported-file => container-all-draft-enum}/input/temporal/api_next/protometa/v1/draft.proto (80%) create mode 100644 cmd/generate-stable-protos/testdata/classification/container-all-draft-oneof-explicit/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/container-all-draft-oneof-explicit/input/temporal/api_next/fixture.proto rename cmd/generate-stable-protos/testdata/classification/{unsupported-enum-value => container-all-draft-oneof-explicit}/input/temporal/api_next/protometa/v1/draft.proto (80%) create mode 100644 cmd/generate-stable-protos/testdata/classification/container-all-draft-oneof-implicit/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/container-all-draft-oneof-implicit/input/temporal/api_next/fixture.proto rename cmd/generate-stable-protos/testdata/classification/{unsupported-method => container-all-draft-oneof-implicit}/input/temporal/api_next/protometa/v1/draft.proto (80%) create mode 100644 cmd/generate-stable-protos/testdata/classification/container-all-draft-oneof-mixed/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/container-all-draft-oneof-mixed/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/container-all-draft-oneof-mixed/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/container-all-draft-service/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/container-all-draft-service/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/container-all-draft-service/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/draft-empty-service/expected.json rename cmd/generate-stable-protos/testdata/classification/{unsupported-enum => draft-empty-service}/input/temporal/api_next/fixture.proto (50%) create mode 100644 cmd/generate-stable-protos/testdata/classification/draft-empty-service/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/draft-enum-value/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/draft-enum-value/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/draft-enum-value/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/draft-enum/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/draft-enum/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/draft-enum/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/draft-method/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/draft-method/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/draft-method/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/draft-oneof/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/draft-oneof/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/draft-oneof/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/draft-optional-only/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/draft-optional-only/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/draft-optional-only/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/draft-service/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/draft-service/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/draft-service/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/empty-service/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/empty-service/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/empty-service/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/enum-value-alias-both-draft/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/enum-value-alias-both-draft/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/enum-value-alias-both-draft/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/enum-value-alias-draft-first/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/enum-value-alias-draft-first/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/enum-value-alias-draft-first/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/enum-value-alias-stable-first/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/enum-value-alias-stable-first/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/enum-value-alias-stable-first/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/enum-value-zero/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/enum-value-zero/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/enum-value-zero/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/extension-enum-value-type/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/extension-enum-value-type/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/extension-enum-value-type/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/external-public-import/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/external-public-import/input/bridge/pub.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/external-public-import/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/external-public-import/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/inherit-draft-message/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/inherit-draft-message/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/inherit-draft-message/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/method-inherited-endpoint/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/method-inherited-endpoint/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/method-inherited-endpoint/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/method-request-feature-mismatch/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/method-request-feature-mismatch/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/method-request-feature-mismatch/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/method-response-feature-mismatch/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/method-response-feature-mismatch/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/method-response-feature-mismatch/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/method-stable-request/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/method-stable-request/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/method-stable-request/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/method-stable-response/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/method-stable-response/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/method-stable-response/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/nesting-enum-in-message/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/nesting-enum-in-message/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/nesting-enum-in-message/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/nesting-enum-value/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/nesting-enum-value/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/nesting-enum-value/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/nesting-field-in-message/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/nesting-field-in-message/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/nesting-field-in-message/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/nesting-inherited-enum/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/nesting-inherited-enum/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/nesting-inherited-enum/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/nesting-inherited-message/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/nesting-inherited-message/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/nesting-inherited-message/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/nesting-inherited-oneof/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/nesting-inherited-oneof/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/nesting-inherited-oneof/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/nesting-message-in-message/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/nesting-message-in-message/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/nesting-message-in-message/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/nesting-method-in-service/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/nesting-method-in-service/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/nesting-method-in-service/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/nesting-oneof-field/expected.json rename cmd/generate-stable-protos/testdata/classification/{unsupported-oneof => nesting-oneof-field}/input/temporal/api_next/fixture.proto (60%) create mode 100644 cmd/generate-stable-protos/testdata/classification/nesting-oneof-field/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/nesting-oneof-in-message/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/nesting-oneof-in-message/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/nesting-oneof-in-message/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/removed-rpc-http/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/removed-rpc-http/input/google/api/annotations.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/removed-rpc-http/input/google/api/http.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/removed-rpc-http/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/removed-rpc-http/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/removed-rpc-request-header/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/removed-rpc-request-header/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/removed-rpc-request-header/input/temporal/api_next/protometa/v1/annotations.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/removed-rpc-request-header/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/rpc-http-draft-oneof/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/rpc-http-draft-oneof/input/google/api/annotations.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/rpc-http-draft-oneof/input/google/api/http.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/rpc-http-draft-oneof/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/rpc-http-draft-oneof/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/rpc-inherited-input/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/rpc-inherited-input/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/rpc-inherited-input/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/rpc-reuse-cross-file/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/rpc-reuse-cross-file/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/rpc-reuse-cross-file/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/rpc-reuse-cross-file/input/temporal/api_next/second.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/rpc-reuse-draft/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/rpc-reuse-draft/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/rpc-reuse-draft/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/rpc-same-request-response/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/rpc-same-request-response/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/rpc-same-request-response/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/rpc-stable-shared-endpoints/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/rpc-stable-shared-endpoints/expected/temporal/api/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/rpc-stable-shared-endpoints/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/rpc-stable-shared-endpoints/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/service-inherited-endpoint/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/service-inherited-endpoint/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/service-inherited-endpoint/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/service-request-feature-mismatch/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/service-request-feature-mismatch/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/service-request-feature-mismatch/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/service-response-feature-mismatch/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/service-response-feature-mismatch/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/service-response-feature-mismatch/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/service-stable-request/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/service-stable-request/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/service-stable-request/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/service-stable-response/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/service-stable-response/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/service-stable-response/input/temporal/api_next/protometa/v1/draft.proto delete mode 100644 cmd/generate-stable-protos/testdata/classification/unsupported-enum-value/expected.json delete mode 100644 cmd/generate-stable-protos/testdata/classification/unsupported-enum-value/input/temporal/api_next/fixture.proto delete mode 100644 cmd/generate-stable-protos/testdata/classification/unsupported-enum/expected.json delete mode 100644 cmd/generate-stable-protos/testdata/classification/unsupported-file/expected.json delete mode 100644 cmd/generate-stable-protos/testdata/classification/unsupported-method/expected.json delete mode 100644 cmd/generate-stable-protos/testdata/classification/unsupported-method/input/temporal/api_next/fixture.proto delete mode 100644 cmd/generate-stable-protos/testdata/classification/unsupported-oneof/expected.json delete mode 100644 cmd/generate-stable-protos/testdata/classification/unsupported-oneof/input/temporal/api_next/protometa/v1/draft.proto delete mode 100644 cmd/generate-stable-protos/testdata/classification/unsupported-service/expected.json delete mode 100644 cmd/generate-stable-protos/testdata/classification/unsupported-service/input/temporal/api_next/fixture.proto delete mode 100644 cmd/generate-stable-protos/testdata/classification/unsupported-service/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/schema/legacy-options/expected.json create mode 100644 cmd/generate-stable-protos/testdata/schema/legacy-options/input/temporal/api_next/fixture.proto rename cmd/generate-stable-protos/testdata/{classification/unsupported-enum => schema/legacy-options}/input/temporal/api_next/protometa/v1/draft.proto (81%) create mode 100644 cmd/generate-stable-protos/testdata/schema/removed-extension-option/expected.json create mode 100644 cmd/generate-stable-protos/testdata/schema/removed-extension-option/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/schema/removed-extension-option/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/schema/unsupported-file/expected.json rename cmd/generate-stable-protos/testdata/{classification => schema}/unsupported-file/input/temporal/api_next/fixture.proto (100%) create mode 100644 cmd/generate-stable-protos/testdata/schema/unsupported-file/input/temporal/api_next/protometa/v1/draft.proto diff --git a/cmd/generate-stable-protos/fixtures_test.go b/cmd/generate-stable-protos/fixtures_test.go index 10e4f25af..d654e39f6 100644 --- a/cmd/generate-stable-protos/fixtures_test.go +++ b/cmd/generate-stable-protos/fixtures_test.go @@ -33,6 +33,8 @@ type fixtureExpectation struct { Error string `json:"error"` // Annotations are the draft annotations the generator must accept. Annotations draftAnnotations `json:"annotations"` + // ValidationOnly limits the fixture to source validation until projection supports it. + ValidationOnly bool `json:"validation_only"` } // findFixtures returns the fixture directories under testdata, relative to it. @@ -73,6 +75,10 @@ func runFixture(t *testing.T, dir string) { root := filepath.Join(dir, "input") out := t.TempDir() + if expected.ValidationOnly { + checkFixtureAnnotations(t, root, expected.Annotations) + return + } if expected.Error != "" { before := readTree(t, out) err := testConfig.stableProtosGenerator(t.Context(), root, out) @@ -98,17 +104,7 @@ func runFixture(t *testing.T, dir string) { } checkIdempotent(t.Context(), t, root, out, t.TempDir()) - paths, err := testConfig.getAPINextPaths(root) - if err != nil { - t.Fatal(err) - } - _, _, annotations, err := testConfig.loadAPINext(t.Context(), root, paths) - if err != nil { - t.Fatal(err) - } - if !maps.Equal(expected.Annotations, annotations) { - t.Errorf("draft annotations differ\nexpected: %v\nactual: %v", expected.Annotations, annotations) - } + checkFixtureAnnotations(t, root, expected.Annotations) if _, err := os.Stat(filepath.Join(dir, "expected")); err == nil { bodies := map[string]string{} @@ -128,6 +124,21 @@ func runFixture(t *testing.T, dir string) { } } +func checkFixtureAnnotations(t *testing.T, root string, expected draftAnnotations) { + t.Helper() + paths, err := testConfig.getAPINextPaths(root) + if err != nil { + t.Fatal(err) + } + _, _, annotations, err := testConfig.loadAPINext(t.Context(), root, paths) + if err != nil { + t.Fatal(err) + } + if !maps.Equal(expected, annotations) { + t.Errorf("draft annotations differ\nexpected: %v\nactual: %v", expected, annotations) + } +} + var testConfig = defaultConfig() func sortedKeys(a, b map[string]string) []string { diff --git a/cmd/generate-stable-protos/main.go b/cmd/generate-stable-protos/main.go index 77432c83f..4f934a526 100644 --- a/cmd/generate-stable-protos/main.go +++ b/cmd/generate-stable-protos/main.go @@ -145,8 +145,8 @@ func (cfg config) stableProtosGenerator(ctx context.Context, root, outDir string return writeFiles(out, stableProtos) } -// loadAPINext lowers the configured source tree, discovers the draft-tag extension set and -// validates every draft annotation, returning the annotations it accepted. +// loadAPINext lowers the configured source tree, discovers the draft-tag extension set, and +// validates the draft schema rules, returning the explicit annotations it accepted. func (cfg config) loadAPINext(ctx context.Context, root string, paths []string) (map[string]*ir.File, draftTags, draftAnnotations, error) { if !slices.Contains(paths, cfg.draftSchema) { paths = slices.Concat(paths, []string{cfg.draftSchema}) @@ -176,18 +176,29 @@ func (cfg config) loadAPINext(ctx context.Context, root string, paths []string) byPath[p] = irFile } - tags, err := getDraftTags(byPath[cfg.draftSchema]) + draftSchema := byPath[cfg.draftSchema] + tags, err := getDraftTags(draftSchema) if err != nil { return nil, draftTags{}, nil, err } annotations := draftAnnotations{} for _, p := range paths { - accepted, err := validateDraftAnnotations(tags, byPath[p]) + f := byPath[p] + accepted, err := validateDraftAnnotations(tags, f) if err != nil { return nil, draftTags{}, nil, err } + if len(accepted) > 0 && !f.ImportFor(draftSchema).Direct { + return nil, draftTags{}, nil, fmt.Errorf("%s: draft annotations require a direct import of %s", p, cfg.draftSchema) + } maps.Copy(annotations, accepted) } + endpointUses := make(rpcEndpointUses) + for _, p := range paths { + if err := validateDraftRules(tags, byPath[p], endpointUses); err != nil { + return nil, draftTags{}, nil, err + } + } return byPath, tags, annotations, nil } diff --git a/cmd/generate-stable-protos/random_test.go b/cmd/generate-stable-protos/random_test.go index c4ccfb481..dcb5a8080 100644 --- a/cmd/generate-stable-protos/random_test.go +++ b/cmd/generate-stable-protos/random_test.go @@ -71,7 +71,7 @@ func (g *schemaGen) file(name string, messages int, imported []string) string { } g.types = append(append([]string{}, imported...), names...) for _, n := range names { - g.message(n, "", 0) + g.message(n, "", 0, false) } return g.b.String() } @@ -99,19 +99,21 @@ func (g *schemaGen) draft(what string) bool { return rapid.IntRange(0, 3).Draw(g.rt, "draft "+what) == 0 } -func (g *schemaGen) message(name, indent string, depth int) { +func (g *schemaGen) message(name, indent string, depth int, inheritedDraft bool) { g.leading(indent) g.b.WriteString(indent + "message " + name + " {" + g.trailing() + "\n") inner := indent + " " - if g.draft("message") { + draft := inheritedDraft + if !inheritedDraft && g.draft("message") { g.b.WriteString(inner + `option (temporal.api.protometa.v1.draft_message) = "feature";` + "\n") + draft = true } number := 0 - field := func(typ string) { + field := func(typ string, canAnnotate bool) { number++ g.leading(inner) g.b.WriteString(fmt.Sprintf("%s%s f%d = %d", inner, typ, number, number)) - if g.draft("field") { + if canAnnotate && !draft && g.draft("field") { g.b.WriteString(` [(temporal.api.protometa.v1.draft) = "feature"]`) } g.b.WriteString(";" + g.trailing() + "\n") @@ -119,29 +121,30 @@ func (g *schemaGen) message(name, indent string, depth int) { for i := range rapid.IntRange(0, 5).Draw(g.rt, "members") { switch rapid.IntRange(0, 6).Draw(g.rt, "member kind") { case 0: - field(g.fieldType()) + field(g.fieldType(), true) case 1: - field("repeated " + g.fieldType()) + field("repeated "+g.fieldType(), true) case 2: - field("optional " + g.fieldType()) + field("optional "+g.fieldType(), true) case 3: - field("map") + field("map", true) case 4: g.leading(inner) g.b.WriteString(fmt.Sprintf("%soneof o%d {%s\n", inner, i, g.trailing())) saved := inner inner += " " - for range rapid.IntRange(1, 3).Draw(g.rt, "branches") { - field(g.fieldType()) + field("string", false) + for range rapid.IntRange(0, 2).Draw(g.rt, "additional branches") { + field(g.fieldType(), true) } inner = saved g.b.WriteString(inner + "}" + g.trailing() + "\n") case 5: if depth < 2 { - g.message(fmt.Sprintf("N%d", i), inner, depth+1) + g.message(fmt.Sprintf("N%d", i), inner, depth+1, draft) } default: - field("string") + field("string", true) } } g.b.WriteString(indent + "}" + g.trailing() + "\n") diff --git a/cmd/generate-stable-protos/rules.go b/cmd/generate-stable-protos/rules.go new file mode 100644 index 000000000..569539c11 --- /dev/null +++ b/cmd/generate-stable-protos/rules.go @@ -0,0 +1,187 @@ +package main + +import ( + "fmt" + + "github.com/bufbuild/protocompile/experimental/ir" + "github.com/bufbuild/protocompile/experimental/seq" +) + +func validateDraftRules(tags draftTags, f *ir.File, endpointUses rpcEndpointUses) error { + for t := range seq.Values(f.AllTypes()) { + if t.IsMapEntry() { + continue + } + parent := t.Parent() + if tags.has(t.Options()) && isDraftType(tags, parent) { + return draftNestingError(t.FullName(), parent.FullName()) + } + draft := isDraftType(tags, t) + if t.IsEnum() { + if err := validateDraftEnum(tags, t, draft); err != nil { + return err + } + continue + } + + for o := range seq.Values(t.Oneofs()) { + if o.AST().IsZero() { + continue + } + if tags.has(o.Options()) { + if draft { + return draftNestingError(o.FullName(), t.FullName()) + } + } else if !draft && allDraft(o.Members(), func(m ir.Member) bool { return isDraftMember(tags, m) }) { + for m := range seq.Values(o.Members()) { + if tags.has(m.Options()) { + return fmt.Errorf("%s: all oneof members are draft; set draft_oneof to a common feature and remove the member draft annotations", o.FullName()) + } + } + return fmt.Errorf("%s: all oneof members are draft; add draft_oneof", o.FullName()) + } + } + for m := range seq.Values(t.Members()) { + if !tags.has(m.Options()) { + continue + } + o := m.Oneof() + if !o.AST().IsZero() && (draft || tags.has(o.Options())) { + return draftNestingError(m.FullName(), o.FullName()) + } + if draft { + return draftNestingError(m.FullName(), t.FullName()) + } + } + } + + for ext := range seq.Values(f.AllExtensions()) { + for _, ref := range []struct { + role string + typ ir.Type + }{ + {"value type", ext.Element()}, + {"extendee", ext.Container()}, + {"declaring parent", ext.Parent()}, + } { + if isDraftType(tags, ref.typ) { + return fmt.Errorf("%s: extension references draft type %s as its %s", ext.FullName(), ref.typ.FullName(), ref.role) + } + } + } + + for s := range seq.Values(f.Services()) { + if err := validateDraftService(tags, s, endpointUses); err != nil { + return err + } + } + return nil +} + +func draftNestingError(name, container ir.FullName) error { + return fmt.Errorf("%s: draft annotation is not allowed inside draft container %s", name, container) +} + +func allDraft[T any](members seq.Indexer[T], isDraft func(T) bool) bool { + for m := range seq.Values(members) { + if !isDraft(m) { + return false + } + } + return members.Len() > 0 +} + +func validateDraftEnum(tags draftTags, enum ir.Type, draft bool) error { + if !draft && allDraft(enum.Members(), func(m ir.Member) bool { return tags.has(m.Options()) }) { + return fmt.Errorf("%s: all enum values are draft; set draft_enum to a common feature and remove the draft_enum_value annotations", enum.FullName()) + } + byNumber := make(map[int32]ir.Member) + for value := range seq.Values(enum.Members()) { + valueDraft := tags.has(value.Options()) + if valueDraft && draft { + return draftNestingError(value.FullName(), enum.FullName()) + } + if valueDraft && value.Number() == 0 { + return fmt.Errorf("%s: draft enum value in stable enum %s cannot have number zero", value.FullName(), enum.FullName()) + } + if other, ok := byNumber[value.Number()]; ok && (valueDraft || tags.has(other.Options())) { + return fmt.Errorf("%s: enum value aliases %s at number %d in %s; aliases involving draft enum values are not allowed", + value.FullName(), other.FullName(), value.Number(), enum.FullName()) + } + byNumber[value.Number()] = value + } + return nil +} + +func validateDraftService(tags draftTags, service ir.Service, endpointUses rpcEndpointUses) error { + serviceFeature := tags.feature(service.Options()) + if serviceFeature == "" && allDraft(service.Methods(), func(m ir.Method) bool { return tags.has(m.Options()) }) { + return fmt.Errorf("%s: all RPCs are draft; set draft_service to a common feature, remove the draft_method annotations, and set each request and response type's explicit draft_message to the service feature", service.FullName()) + } + for method := range seq.Values(service.Methods()) { + feature, annotation := tags.feature(method.Options()), "draft_method" + if serviceFeature != "" { + if feature != "" { + return fmt.Errorf("%s: draft_method is not allowed inside draft_service %s", method.FullName(), service.FullName()) + } + feature, annotation = serviceFeature, "draft_service" + } + input, _ := method.Input() + output, _ := method.Output() + if feature != "" && input.FullName() == output.FullName() { + return fmt.Errorf("%s: RPC uses %s as both request and response", method.FullName(), input.FullName()) + } + for _, endpoint := range []struct { + role string + typ ir.Type + }{ + {"request", input}, + {"response", output}, + } { + name := endpoint.typ.FullName() + if feature == "" { + if isDraftType(tags, endpoint.typ) { + if !tags.has(endpoint.typ.Options()) { + return fmt.Errorf("%s: RPC references draft type %s as its %s; inherited draft status is insufficient, so use a type that explicitly carries draft_message and give draft_method and both endpoints the same feature", method.FullName(), name, endpoint.role) + } + return fmt.Errorf("%s: RPC references draft type %s as its %s and requires draft_method", method.FullName(), name, endpoint.role) + } + } else if actual := tags.feature(endpoint.typ.Options()); actual != feature { + if actual == "" { + return fmt.Errorf("%s: %s requires %s type %s to explicitly carry draft_message = %q", + method.FullName(), annotation, endpoint.role, name, feature) + } + return fmt.Errorf("%s: %s requires %s type %s to explicitly carry draft_message = %q; found %q", + method.FullName(), annotation, endpoint.role, name, feature, actual) + } else if err := endpointUses.add(name, rpcPosition{method.FullName(), endpoint.role}); err != nil { + // Only draft endpoint types are tracked: stable RPCs may share types + // such as google.protobuf.Empty, and stable RPCs cannot use draft types. + return err + } + } + if feature == "" { + if err := validateMethodFieldReferences(tags, method, input, output); err != nil { + return err + } + } + } + return nil +} + +type rpcPosition struct { + method ir.FullName + role string +} + +// rpcEndpointUses records the one RPC position each draft endpoint type occupies. +type rpcEndpointUses map[ir.FullName]rpcPosition + +func (uses rpcEndpointUses) add(name ir.FullName, position rpcPosition) error { + first, exists := uses[name] + if !exists { + uses[name] = position + return nil + } + return fmt.Errorf("%s: RPC endpoint type is reused at %s %s and %s %s", name, + first.method, first.role, position.method, position.role) +} diff --git a/cmd/generate-stable-protos/tags.go b/cmd/generate-stable-protos/tags.go index 9dfda6c88..0a4daad3e 100644 --- a/cmd/generate-stable-protos/tags.go +++ b/cmd/generate-stable-protos/tags.go @@ -25,9 +25,7 @@ func getDraftTags(file *ir.File) (draftTags, error) { "draft_enum_value": "EnumValueOptions", "draft_service": "ServiceOptions", "draft_method": "MethodOptions", - "draft_file": "FileOptions", "draft_oneof": "OneofOptions", - "draft_extension": "FieldOptions", } for ext := range seq.Values(file.AllExtensions()) { name, known := extendees[ext.Name()] @@ -50,94 +48,83 @@ func (tags draftTags) contains(name ir.FullName) bool { return ok } -func (tags draftTags) has(opts ir.MessageValue) bool { +func (tags draftTags) annotation(opts ir.MessageValue) ir.Value { for v := range opts.Fields() { if tags.contains(v.Field().FullName()) { - return true + return v } } - return false + return ir.Value{} +} + +func (tags draftTags) has(opts ir.MessageValue) bool { + return !tags.annotation(opts).IsZero() +} + +func (tags draftTags) feature(opts ir.MessageValue) draftFeature { + feature, _ := tags.annotation(opts).AsString() + return feature } type draftAnnotations map[ir.FullName]draftFeature type draftFeature = string -// validateDraftAnnotations rejects unsupported or malformed draft annotations in f and -// returns the accepted ones. +// validateDraftAnnotations checks annotation placement and feature names and returns the explicit annotations. func validateDraftAnnotations(tags draftTags, f *ir.File) (draftAnnotations, error) { accepted := draftAnnotations{} - draftFieldName := tags.packageName.Append("draft") - draftMessageName := tags.packageName.Append("draft_message") - check := func(name string, placement string, opts ir.MessageValue) error { - for v := range opts.Fields() { - if !tags.contains(v.Field().FullName()) { - continue - } - if !((placement == "field" && v.Field().FullName() == draftFieldName) || - (placement == "message" && v.Field().FullName() == draftMessageName)) { - return fmt.Errorf("%s: unsupported draft annotation on %s", name, placement) - } - feature, ok := v.AsString() - if !ok || feature == "" || strings.ContainsFunc(feature, unicode.IsSpace) { - return fmt.Errorf("%s: draft feature must be nonempty and contain no whitespace", name) - } - accepted[ir.FullName(name)] = feature + check := func(name ir.FullName, placement, option string, opts ir.MessageValue) error { + v := tags.annotation(opts) + if v.IsZero() { + return nil + } + if option == "" || v.Field().FullName() != tags.packageName.Append(option) { + return fmt.Errorf("%s: unsupported draft annotation on %s", name, placement) + } + feature, ok := v.AsString() + if !ok || feature == "" || strings.ContainsFunc(feature, unicode.IsSpace) { + return fmt.Errorf("%s: draft feature must be nonempty and contain no whitespace", name) } + accepted[name] = feature return nil } - if err := check(f.Path(), "file", f.Options()); err != nil { + if err := check(ir.FullName(f.Path()), "file", "", f.Options()); err != nil { return nil, err } for t := range seq.Values(f.AllTypes()) { - placement := "message" + placement, option := "message", "draft_message" if t.IsEnum() { - placement = "enum" + placement, option = "enum", "draft_enum" } - if err := check(string(t.FullName()), placement, t.Options()); err != nil { + if err := check(t.FullName(), placement, option, t.Options()); err != nil { return nil, err } for m := range seq.Values(t.Members()) { - placement := "field" + placement, option := "field", "draft" if m.IsEnumValue() { - placement = "enum value" + placement, option = "enum value", "draft_enum_value" } - if err := check(string(m.FullName()), placement, m.Options()); err != nil { + if err := check(m.FullName(), placement, option, m.Options()); err != nil { return nil, err } } for o := range seq.Values(t.Oneofs()) { - if err := check(string(o.FullName()), "oneof", o.Options()); err != nil { + if err := check(o.FullName(), "oneof", "draft_oneof", o.Options()); err != nil { return nil, err } } } for ext := range seq.Values(f.AllExtensions()) { - if err := check(string(ext.FullName()), "extension", ext.Options()); err != nil { + if err := check(ext.FullName(), "extension", "", ext.Options()); err != nil { return nil, err } - for _, t := range []ir.Type{ext.Element(), ext.Container(), ext.Parent()} { - if isDraftType(tags, t) { - return nil, fmt.Errorf("%s: extension references draft type %s unsupported by omission", ext.FullName(), t.FullName()) - } - } } for s := range seq.Values(f.Services()) { - if err := check(string(s.FullName()), "service", s.Options()); err != nil { + if err := check(s.FullName(), "service", "draft_service", s.Options()); err != nil { return nil, err } for m := range seq.Values(s.Methods()) { - if err := check(string(m.FullName()), "method", m.Options()); err != nil { - return nil, err - } - input, _ := m.Input() - output, _ := m.Output() - for _, t := range []ir.Type{input, output} { - if isDraftType(tags, t) { - return nil, fmt.Errorf("%s: RPC references draft type %s unavailable in the stable API", m.FullName(), t.FullName()) - } - } - if err := validateMethodFieldReferences(tags, m, input, output); err != nil { + if err := check(m.FullName(), "method", "draft_method", m.Options()); err != nil { return nil, err } } @@ -229,7 +216,7 @@ func referencesDraftField(tags draftTags, message ir.Type, path string) bool { if field.IsZero() { return false } - if isDraftMember(tags, field) { + if isDraftMember(tags, field) || tags.has(field.Oneof().Options()) { return true } message = field.Element() diff --git a/cmd/generate-stable-protos/testdata/classification/container-all-draft-enum/expected.json b/cmd/generate-stable-protos/testdata/classification/container-all-draft-enum/expected.json new file mode 100644 index 000000000..9181b98ef --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/container-all-draft-enum/expected.json @@ -0,0 +1,3 @@ +{ + "error": "fixture.Mode: all enum values are draft; set draft_enum to a common feature and remove the draft_enum_value annotations" +} diff --git a/cmd/generate-stable-protos/testdata/classification/container-all-draft-enum/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/container-all-draft-enum/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..62969ce0b --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/container-all-draft-enum/input/temporal/api_next/fixture.proto @@ -0,0 +1,4 @@ +syntax = "proto2"; +package fixture; +import "temporal/api_next/protometa/v1/draft.proto"; +enum Mode { PREVIEW = 1 [(temporal.api.protometa.v1.draft_enum_value) = "preview"]; } diff --git a/cmd/generate-stable-protos/testdata/classification/unsupported-file/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/container-all-draft-enum/input/temporal/api_next/protometa/v1/draft.proto similarity index 80% rename from cmd/generate-stable-protos/testdata/classification/unsupported-file/input/temporal/api_next/protometa/v1/draft.proto rename to cmd/generate-stable-protos/testdata/classification/container-all-draft-enum/input/temporal/api_next/protometa/v1/draft.proto index 79bdf536c..def18ac5d 100644 --- a/cmd/generate-stable-protos/testdata/classification/unsupported-file/input/temporal/api_next/protometa/v1/draft.proto +++ b/cmd/generate-stable-protos/testdata/classification/container-all-draft-enum/input/temporal/api_next/protometa/v1/draft.proto @@ -7,5 +7,4 @@ extend google.protobuf.EnumOptions { string draft_enum = 98008; } extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } extend google.protobuf.ServiceOptions { string draft_service = 98008; } extend google.protobuf.MethodOptions { string draft_method = 98008; } -extend google.protobuf.FileOptions { string draft_file = 98008; } -extend google.protobuf.OneofOptions { string draft_oneof = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/container-all-draft-oneof-explicit/expected.json b/cmd/generate-stable-protos/testdata/classification/container-all-draft-oneof-explicit/expected.json new file mode 100644 index 000000000..0fa92473f --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/container-all-draft-oneof-explicit/expected.json @@ -0,0 +1,3 @@ +{ + "error": "fixture.Choice.selection: all oneof members are draft; set draft_oneof to a common feature and remove the member draft annotations" +} diff --git a/cmd/generate-stable-protos/testdata/classification/container-all-draft-oneof-explicit/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/container-all-draft-oneof-explicit/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..4aeaf8c8c --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/container-all-draft-oneof-explicit/input/temporal/api_next/fixture.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; +package fixture; +import "temporal/api_next/protometa/v1/draft.proto"; +message Choice { + oneof selection { + string name = 1 [(temporal.api.protometa.v1.draft) = "preview"]; + int32 id = 2 [(temporal.api.protometa.v1.draft) = "other"]; + } +} diff --git a/cmd/generate-stable-protos/testdata/classification/unsupported-enum-value/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/container-all-draft-oneof-explicit/input/temporal/api_next/protometa/v1/draft.proto similarity index 80% rename from cmd/generate-stable-protos/testdata/classification/unsupported-enum-value/input/temporal/api_next/protometa/v1/draft.proto rename to cmd/generate-stable-protos/testdata/classification/container-all-draft-oneof-explicit/input/temporal/api_next/protometa/v1/draft.proto index 79bdf536c..def18ac5d 100644 --- a/cmd/generate-stable-protos/testdata/classification/unsupported-enum-value/input/temporal/api_next/protometa/v1/draft.proto +++ b/cmd/generate-stable-protos/testdata/classification/container-all-draft-oneof-explicit/input/temporal/api_next/protometa/v1/draft.proto @@ -7,5 +7,4 @@ extend google.protobuf.EnumOptions { string draft_enum = 98008; } extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } extend google.protobuf.ServiceOptions { string draft_service = 98008; } extend google.protobuf.MethodOptions { string draft_method = 98008; } -extend google.protobuf.FileOptions { string draft_file = 98008; } -extend google.protobuf.OneofOptions { string draft_oneof = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/container-all-draft-oneof-implicit/expected.json b/cmd/generate-stable-protos/testdata/classification/container-all-draft-oneof-implicit/expected.json new file mode 100644 index 000000000..3bcbaf0a6 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/container-all-draft-oneof-implicit/expected.json @@ -0,0 +1,3 @@ +{ + "error": "fixture.Choice.selection: all oneof members are draft; add draft_oneof" +} diff --git a/cmd/generate-stable-protos/testdata/classification/container-all-draft-oneof-implicit/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/container-all-draft-oneof-implicit/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..a2f219ab7 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/container-all-draft-oneof-implicit/input/temporal/api_next/fixture.proto @@ -0,0 +1,14 @@ +syntax = "proto3"; +package fixture; +import "temporal/api_next/protometa/v1/draft.proto"; +message Draft { + option (temporal.api.protometa.v1.draft_message) = "preview"; + message Nested {} +} +enum Mode { option (temporal.api.protometa.v1.draft_enum) = "preview"; ZERO = 0; } +message Choice { + oneof selection { + Draft.Nested target = 1; + Mode mode = 2; + } +} diff --git a/cmd/generate-stable-protos/testdata/classification/unsupported-method/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/container-all-draft-oneof-implicit/input/temporal/api_next/protometa/v1/draft.proto similarity index 80% rename from cmd/generate-stable-protos/testdata/classification/unsupported-method/input/temporal/api_next/protometa/v1/draft.proto rename to cmd/generate-stable-protos/testdata/classification/container-all-draft-oneof-implicit/input/temporal/api_next/protometa/v1/draft.proto index 79bdf536c..def18ac5d 100644 --- a/cmd/generate-stable-protos/testdata/classification/unsupported-method/input/temporal/api_next/protometa/v1/draft.proto +++ b/cmd/generate-stable-protos/testdata/classification/container-all-draft-oneof-implicit/input/temporal/api_next/protometa/v1/draft.proto @@ -7,5 +7,4 @@ extend google.protobuf.EnumOptions { string draft_enum = 98008; } extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } extend google.protobuf.ServiceOptions { string draft_service = 98008; } extend google.protobuf.MethodOptions { string draft_method = 98008; } -extend google.protobuf.FileOptions { string draft_file = 98008; } -extend google.protobuf.OneofOptions { string draft_oneof = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/container-all-draft-oneof-mixed/expected.json b/cmd/generate-stable-protos/testdata/classification/container-all-draft-oneof-mixed/expected.json new file mode 100644 index 000000000..0fa92473f --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/container-all-draft-oneof-mixed/expected.json @@ -0,0 +1,3 @@ +{ + "error": "fixture.Choice.selection: all oneof members are draft; set draft_oneof to a common feature and remove the member draft annotations" +} diff --git a/cmd/generate-stable-protos/testdata/classification/container-all-draft-oneof-mixed/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/container-all-draft-oneof-mixed/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..34b3ae73b --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/container-all-draft-oneof-mixed/input/temporal/api_next/fixture.proto @@ -0,0 +1,12 @@ +syntax = "proto3"; +package fixture; +import "temporal/api_next/protometa/v1/draft.proto"; +message Draft { + option (temporal.api.protometa.v1.draft_message) = "preview"; +} +message Choice { + oneof selection { + string name = 1 [(temporal.api.protometa.v1.draft) = "preview"]; + Draft target = 2; + } +} diff --git a/cmd/generate-stable-protos/testdata/classification/container-all-draft-oneof-mixed/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/container-all-draft-oneof-mixed/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..def18ac5d --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/container-all-draft-oneof-mixed/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98008; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/container-all-draft-service/expected.json b/cmd/generate-stable-protos/testdata/classification/container-all-draft-service/expected.json new file mode 100644 index 000000000..ce4ab1960 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/container-all-draft-service/expected.json @@ -0,0 +1,3 @@ +{ + "error": "fixture.Service: all RPCs are draft; set draft_service to a common feature, remove the draft_method annotations, and set each request and response type's explicit draft_message to the service feature" +} diff --git a/cmd/generate-stable-protos/testdata/classification/container-all-draft-service/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/container-all-draft-service/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..a69352269 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/container-all-draft-service/input/temporal/api_next/fixture.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; +package fixture; +import "temporal/api_next/protometa/v1/draft.proto"; +message Request { option (temporal.api.protometa.v1.draft_message) = "preview"; } +message Response { option (temporal.api.protometa.v1.draft_message) = "preview"; } +message OtherRequest { option (temporal.api.protometa.v1.draft_message) = "other"; } +message OtherResponse { option (temporal.api.protometa.v1.draft_message) = "other"; } +service Service { + rpc Call(Request) returns (Response) { option (temporal.api.protometa.v1.draft_method) = "preview"; } + rpc Other(OtherRequest) returns (OtherResponse) { option (temporal.api.protometa.v1.draft_method) = "other"; } +} diff --git a/cmd/generate-stable-protos/testdata/classification/container-all-draft-service/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/container-all-draft-service/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..def18ac5d --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/container-all-draft-service/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98008; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/draft-empty-service/expected.json b/cmd/generate-stable-protos/testdata/classification/draft-empty-service/expected.json new file mode 100644 index 000000000..610620ef3 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/draft-empty-service/expected.json @@ -0,0 +1,6 @@ +{ + "annotations": { + "fixture.Service": "preview" + }, + "validation_only": true +} diff --git a/cmd/generate-stable-protos/testdata/classification/unsupported-enum/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/draft-empty-service/input/temporal/api_next/fixture.proto similarity index 50% rename from cmd/generate-stable-protos/testdata/classification/unsupported-enum/input/temporal/api_next/fixture.proto rename to cmd/generate-stable-protos/testdata/classification/draft-empty-service/input/temporal/api_next/fixture.proto index f4a9afda1..64efedd5b 100644 --- a/cmd/generate-stable-protos/testdata/classification/unsupported-enum/input/temporal/api_next/fixture.proto +++ b/cmd/generate-stable-protos/testdata/classification/draft-empty-service/input/temporal/api_next/fixture.proto @@ -1,4 +1,4 @@ syntax = "proto3"; package fixture; import "temporal/api_next/protometa/v1/draft.proto"; -enum Example { option (temporal.api.protometa.v1.draft_enum) = "feature-a"; ZERO = 0; } +service Service { option (temporal.api.protometa.v1.draft_service) = "preview"; } diff --git a/cmd/generate-stable-protos/testdata/classification/draft-empty-service/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/draft-empty-service/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..def18ac5d --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/draft-empty-service/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98008; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/draft-enum-value/expected.json b/cmd/generate-stable-protos/testdata/classification/draft-enum-value/expected.json new file mode 100644 index 000000000..4d1ffb618 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/draft-enum-value/expected.json @@ -0,0 +1,6 @@ +{ + "annotations": { + "fixture.PREVIEW": "preview" + }, + "validation_only": true +} diff --git a/cmd/generate-stable-protos/testdata/classification/draft-enum-value/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/draft-enum-value/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..96b001770 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/draft-enum-value/input/temporal/api_next/fixture.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; +package fixture; +import "temporal/api_next/protometa/v1/draft.proto"; +enum Mode { + option allow_alias = true; + ZERO = 0; + STABLE = 1; + ALIAS = 1; + PREVIEW = 2 [(temporal.api.protometa.v1.draft_enum_value) = "preview"]; +} +message Config { Mode mode = 1; } diff --git a/cmd/generate-stable-protos/testdata/classification/draft-enum-value/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/draft-enum-value/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..def18ac5d --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/draft-enum-value/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98008; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/draft-enum/expected.json b/cmd/generate-stable-protos/testdata/classification/draft-enum/expected.json new file mode 100644 index 000000000..26425e1d1 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/draft-enum/expected.json @@ -0,0 +1,6 @@ +{ + "annotations": { + "fixture.Mode": "preview" + }, + "validation_only": true +} diff --git a/cmd/generate-stable-protos/testdata/classification/draft-enum/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/draft-enum/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..cd9e8e157 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/draft-enum/input/temporal/api_next/fixture.proto @@ -0,0 +1,8 @@ +syntax = "proto3"; +package fixture; +import "temporal/api_next/protometa/v1/draft.proto"; +enum Mode { + option (temporal.api.protometa.v1.draft_enum) = "preview"; + ZERO = 0; +} +message Config { map modes = 1; } diff --git a/cmd/generate-stable-protos/testdata/classification/draft-enum/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/draft-enum/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..def18ac5d --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/draft-enum/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98008; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/draft-method/expected.json b/cmd/generate-stable-protos/testdata/classification/draft-method/expected.json new file mode 100644 index 000000000..ef433d6b1 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/draft-method/expected.json @@ -0,0 +1,8 @@ +{ + "annotations": { + "fixture.Request": "preview", + "fixture.Response": "preview", + "fixture.Service.Call": "preview" + }, + "validation_only": true +} diff --git a/cmd/generate-stable-protos/testdata/classification/draft-method/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/draft-method/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..8e9bf749f --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/draft-method/input/temporal/api_next/fixture.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; +package fixture; +import "temporal/api_next/protometa/v1/draft.proto"; +message Request { option (temporal.api.protometa.v1.draft_message) = "preview"; } +message Response { option (temporal.api.protometa.v1.draft_message) = "preview"; } +message StableRequest {} +message StableResponse {} +service Service { + rpc Stable(StableRequest) returns (StableResponse); + rpc Call(Request) returns (Response) { option (temporal.api.protometa.v1.draft_method) = "preview"; } +} diff --git a/cmd/generate-stable-protos/testdata/classification/draft-method/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/draft-method/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..def18ac5d --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/draft-method/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98008; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/draft-oneof/expected.json b/cmd/generate-stable-protos/testdata/classification/draft-oneof/expected.json new file mode 100644 index 000000000..5d0fb37e9 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/draft-oneof/expected.json @@ -0,0 +1,7 @@ +{ + "annotations": { + "fixture.Draft": "type-feature", + "fixture.Choice.selection": "preview" + }, + "validation_only": true +} diff --git a/cmd/generate-stable-protos/testdata/classification/draft-oneof/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/draft-oneof/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..e04d58060 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/draft-oneof/input/temporal/api_next/fixture.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package fixture; +import "temporal/api_next/protometa/v1/draft.proto"; +message Draft { option (temporal.api.protometa.v1.draft_message) = "type-feature"; } +message Choice { + oneof selection { + option (temporal.api.protometa.v1.draft_oneof) = "preview"; + Draft target = 1; + } +} diff --git a/cmd/generate-stable-protos/testdata/classification/draft-oneof/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/draft-oneof/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..def18ac5d --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/draft-oneof/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98008; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/draft-optional-only/expected.json b/cmd/generate-stable-protos/testdata/classification/draft-optional-only/expected.json new file mode 100644 index 000000000..abafe0197 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/draft-optional-only/expected.json @@ -0,0 +1,5 @@ +{ + "annotations": { + "fixture.Example.value": "preview" + } +} diff --git a/cmd/generate-stable-protos/testdata/classification/draft-optional-only/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/draft-optional-only/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..f56759763 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/draft-optional-only/input/temporal/api_next/fixture.proto @@ -0,0 +1,4 @@ +syntax = "proto3"; +package fixture; +import "temporal/api_next/protometa/v1/draft.proto"; +message Example { optional string value = 1 [(temporal.api.protometa.v1.draft) = "preview"]; } diff --git a/cmd/generate-stable-protos/testdata/classification/draft-optional-only/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/draft-optional-only/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..def18ac5d --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/draft-optional-only/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98008; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/draft-service/expected.json b/cmd/generate-stable-protos/testdata/classification/draft-service/expected.json new file mode 100644 index 000000000..e974d6af5 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/draft-service/expected.json @@ -0,0 +1,8 @@ +{ + "annotations": { + "fixture.Request": "preview", + "fixture.Response": "preview", + "fixture.Service": "preview" + }, + "validation_only": true +} diff --git a/cmd/generate-stable-protos/testdata/classification/draft-service/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/draft-service/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..d51418c67 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/draft-service/input/temporal/api_next/fixture.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; +package fixture; +import "temporal/api_next/protometa/v1/draft.proto"; +message Request { option (temporal.api.protometa.v1.draft_message) = "preview"; } +message Response { option (temporal.api.protometa.v1.draft_message) = "preview"; } +service Service { + option (temporal.api.protometa.v1.draft_service) = "preview"; + rpc Call(Request) returns (Response); +} diff --git a/cmd/generate-stable-protos/testdata/classification/draft-service/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/draft-service/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..def18ac5d --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/draft-service/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98008; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/empty-service/expected.json b/cmd/generate-stable-protos/testdata/classification/empty-service/expected.json new file mode 100644 index 000000000..b7363b0cd --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/empty-service/expected.json @@ -0,0 +1,3 @@ +{ + "annotations": {} +} diff --git a/cmd/generate-stable-protos/testdata/classification/empty-service/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/empty-service/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..a6a8bc3b8 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/empty-service/input/temporal/api_next/fixture.proto @@ -0,0 +1,3 @@ +syntax = "proto3"; +package fixture; +service Service {} diff --git a/cmd/generate-stable-protos/testdata/classification/empty-service/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/empty-service/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..def18ac5d --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/empty-service/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98008; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/empty/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/empty/input/temporal/api_next/protometa/v1/draft.proto index 79bdf536c..def18ac5d 100644 --- a/cmd/generate-stable-protos/testdata/classification/empty/input/temporal/api_next/protometa/v1/draft.proto +++ b/cmd/generate-stable-protos/testdata/classification/empty/input/temporal/api_next/protometa/v1/draft.proto @@ -7,5 +7,4 @@ extend google.protobuf.EnumOptions { string draft_enum = 98008; } extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } extend google.protobuf.ServiceOptions { string draft_service = 98008; } extend google.protobuf.MethodOptions { string draft_method = 98008; } -extend google.protobuf.FileOptions { string draft_file = 98008; } -extend google.protobuf.OneofOptions { string draft_oneof = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/enum-value-alias-both-draft/expected.json b/cmd/generate-stable-protos/testdata/classification/enum-value-alias-both-draft/expected.json new file mode 100644 index 000000000..010fbb32e --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/enum-value-alias-both-draft/expected.json @@ -0,0 +1,3 @@ +{ + "error": "fixture.SECOND: enum value aliases fixture.FIRST at number 1 in fixture.Mode; aliases involving draft enum values are not allowed" +} diff --git a/cmd/generate-stable-protos/testdata/classification/enum-value-alias-both-draft/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/enum-value-alias-both-draft/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..3932c1e54 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/enum-value-alias-both-draft/input/temporal/api_next/fixture.proto @@ -0,0 +1,4 @@ +syntax = "proto3"; +package fixture; +import "temporal/api_next/protometa/v1/draft.proto"; +enum Mode { option allow_alias = true; ZERO = 0; FIRST = 1 [(temporal.api.protometa.v1.draft_enum_value) = "preview"]; SECOND = 1 [(temporal.api.protometa.v1.draft_enum_value) = "preview"]; } diff --git a/cmd/generate-stable-protos/testdata/classification/enum-value-alias-both-draft/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/enum-value-alias-both-draft/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..def18ac5d --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/enum-value-alias-both-draft/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98008; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/enum-value-alias-draft-first/expected.json b/cmd/generate-stable-protos/testdata/classification/enum-value-alias-draft-first/expected.json new file mode 100644 index 000000000..010fbb32e --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/enum-value-alias-draft-first/expected.json @@ -0,0 +1,3 @@ +{ + "error": "fixture.SECOND: enum value aliases fixture.FIRST at number 1 in fixture.Mode; aliases involving draft enum values are not allowed" +} diff --git a/cmd/generate-stable-protos/testdata/classification/enum-value-alias-draft-first/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/enum-value-alias-draft-first/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..0a848a58c --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/enum-value-alias-draft-first/input/temporal/api_next/fixture.proto @@ -0,0 +1,4 @@ +syntax = "proto3"; +package fixture; +import "temporal/api_next/protometa/v1/draft.proto"; +enum Mode { option allow_alias = true; ZERO = 0; FIRST = 1 [(temporal.api.protometa.v1.draft_enum_value) = "preview"]; SECOND = 1; } diff --git a/cmd/generate-stable-protos/testdata/classification/enum-value-alias-draft-first/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/enum-value-alias-draft-first/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..def18ac5d --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/enum-value-alias-draft-first/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98008; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/enum-value-alias-stable-first/expected.json b/cmd/generate-stable-protos/testdata/classification/enum-value-alias-stable-first/expected.json new file mode 100644 index 000000000..010fbb32e --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/enum-value-alias-stable-first/expected.json @@ -0,0 +1,3 @@ +{ + "error": "fixture.SECOND: enum value aliases fixture.FIRST at number 1 in fixture.Mode; aliases involving draft enum values are not allowed" +} diff --git a/cmd/generate-stable-protos/testdata/classification/enum-value-alias-stable-first/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/enum-value-alias-stable-first/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..b5e235896 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/enum-value-alias-stable-first/input/temporal/api_next/fixture.proto @@ -0,0 +1,4 @@ +syntax = "proto3"; +package fixture; +import "temporal/api_next/protometa/v1/draft.proto"; +enum Mode { option allow_alias = true; ZERO = 0; FIRST = 1; SECOND = 1 [(temporal.api.protometa.v1.draft_enum_value) = "preview"]; } diff --git a/cmd/generate-stable-protos/testdata/classification/enum-value-alias-stable-first/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/enum-value-alias-stable-first/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..def18ac5d --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/enum-value-alias-stable-first/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98008; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/enum-value-zero/expected.json b/cmd/generate-stable-protos/testdata/classification/enum-value-zero/expected.json new file mode 100644 index 000000000..1d0e17820 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/enum-value-zero/expected.json @@ -0,0 +1,3 @@ +{ + "error": "fixture.ZERO: draft enum value in stable enum fixture.Mode cannot have number zero" +} diff --git a/cmd/generate-stable-protos/testdata/classification/enum-value-zero/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/enum-value-zero/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..791f11e50 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/enum-value-zero/input/temporal/api_next/fixture.proto @@ -0,0 +1,4 @@ +syntax = "proto3"; +package fixture; +import "temporal/api_next/protometa/v1/draft.proto"; +enum Mode { ZERO = 0 [(temporal.api.protometa.v1.draft_enum_value) = "preview"]; STABLE = 1; } diff --git a/cmd/generate-stable-protos/testdata/classification/enum-value-zero/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/enum-value-zero/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..def18ac5d --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/enum-value-zero/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98008; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/extension-enum-value-type/expected.json b/cmd/generate-stable-protos/testdata/classification/extension-enum-value-type/expected.json new file mode 100644 index 000000000..b936bff08 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/extension-enum-value-type/expected.json @@ -0,0 +1,3 @@ +{ + "error": "extension references draft type" +} diff --git a/cmd/generate-stable-protos/testdata/classification/extension-enum-value-type/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/extension-enum-value-type/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..7aaeb9fb5 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/extension-enum-value-type/input/temporal/api_next/fixture.proto @@ -0,0 +1,6 @@ +syntax = "proto2"; +package fixture; +import "temporal/api_next/protometa/v1/draft.proto"; +enum Draft { option (temporal.api.protometa.v1.draft_enum) = "feature-a"; ZERO = 0; } +message Stable { extensions 100 to max; } +extend Stable { optional Draft value = 100; } diff --git a/cmd/generate-stable-protos/testdata/classification/extension-enum-value-type/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/extension-enum-value-type/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..44dde8528 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/extension-enum-value-type/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98111; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/extension-extendee/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/extension-extendee/input/temporal/api_next/protometa/v1/draft.proto index 03c5c5701..44dde8528 100644 --- a/cmd/generate-stable-protos/testdata/classification/extension-extendee/input/temporal/api_next/protometa/v1/draft.proto +++ b/cmd/generate-stable-protos/testdata/classification/extension-extendee/input/temporal/api_next/protometa/v1/draft.proto @@ -7,5 +7,4 @@ extend google.protobuf.EnumOptions { string draft_enum = 98008; } extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } extend google.protobuf.ServiceOptions { string draft_service = 98008; } extend google.protobuf.MethodOptions { string draft_method = 98008; } -extend google.protobuf.FileOptions { string draft_file = 98008; } -extend google.protobuf.OneofOptions { string draft_oneof = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/extension-reference/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/extension-reference/input/temporal/api_next/protometa/v1/draft.proto index 03c5c5701..44dde8528 100644 --- a/cmd/generate-stable-protos/testdata/classification/extension-reference/input/temporal/api_next/protometa/v1/draft.proto +++ b/cmd/generate-stable-protos/testdata/classification/extension-reference/input/temporal/api_next/protometa/v1/draft.proto @@ -7,5 +7,4 @@ extend google.protobuf.EnumOptions { string draft_enum = 98008; } extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } extend google.protobuf.ServiceOptions { string draft_service = 98008; } extend google.protobuf.MethodOptions { string draft_method = 98008; } -extend google.protobuf.FileOptions { string draft_file = 98008; } -extend google.protobuf.OneofOptions { string draft_oneof = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/external-public-import/expected.json b/cmd/generate-stable-protos/testdata/classification/external-public-import/expected.json new file mode 100644 index 000000000..93c3f8e1d --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/external-public-import/expected.json @@ -0,0 +1,3 @@ +{ + "error": "temporal/api_next/fixture.proto: draft annotations require a direct import of temporal/api_next/protometa/v1/draft.proto" +} diff --git a/cmd/generate-stable-protos/testdata/classification/external-public-import/input/bridge/pub.proto b/cmd/generate-stable-protos/testdata/classification/external-public-import/input/bridge/pub.proto new file mode 100644 index 000000000..d6867106e --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/external-public-import/input/bridge/pub.proto @@ -0,0 +1,3 @@ +syntax = "proto3"; +package fixture; +import public "temporal/api_next/protometa/v1/draft.proto"; diff --git a/cmd/generate-stable-protos/testdata/classification/external-public-import/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/external-public-import/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..f116ab88c --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/external-public-import/input/temporal/api_next/fixture.proto @@ -0,0 +1,4 @@ +syntax = "proto3"; +package fixture; +import "bridge/pub.proto"; +message Stable { string gated = 1 [(temporal.api.protometa.v1.draft) = "feature-a"]; } diff --git a/cmd/generate-stable-protos/testdata/classification/external-public-import/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/external-public-import/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..def18ac5d --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/external-public-import/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98008; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/inherit-draft-message/expected.json b/cmd/generate-stable-protos/testdata/classification/inherit-draft-message/expected.json new file mode 100644 index 000000000..13ed1e7c7 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/inherit-draft-message/expected.json @@ -0,0 +1,5 @@ +{ + "annotations": { + "fixture.Draft": "preview" + } +} diff --git a/cmd/generate-stable-protos/testdata/classification/inherit-draft-message/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/inherit-draft-message/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..df215a0eb --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/inherit-draft-message/input/temporal/api_next/fixture.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; +package fixture; +import "temporal/api_next/protometa/v1/draft.proto"; +message Draft { + option (temporal.api.protometa.v1.draft_message) = "preview"; + message Nested {} + enum Mode { ZERO = 0; } + oneof choice { string value = 1; } +} diff --git a/cmd/generate-stable-protos/testdata/classification/inherit-draft-message/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/inherit-draft-message/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..def18ac5d --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/inherit-draft-message/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98008; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/internal-whitespace/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/internal-whitespace/input/temporal/api_next/protometa/v1/draft.proto index 03c5c5701..44dde8528 100644 --- a/cmd/generate-stable-protos/testdata/classification/internal-whitespace/input/temporal/api_next/protometa/v1/draft.proto +++ b/cmd/generate-stable-protos/testdata/classification/internal-whitespace/input/temporal/api_next/protometa/v1/draft.proto @@ -7,5 +7,4 @@ extend google.protobuf.EnumOptions { string draft_enum = 98008; } extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } extend google.protobuf.ServiceOptions { string draft_service = 98008; } extend google.protobuf.MethodOptions { string draft_method = 98008; } -extend google.protobuf.FileOptions { string draft_file = 98008; } -extend google.protobuf.OneofOptions { string draft_oneof = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/message-types/expected.json b/cmd/generate-stable-protos/testdata/classification/message-types/expected.json index 719578c09..d13c9c31a 100644 --- a/cmd/generate-stable-protos/testdata/classification/message-types/expected.json +++ b/cmd/generate-stable-protos/testdata/classification/message-types/expected.json @@ -1,7 +1,6 @@ { "annotations": { - "fixture.Draft": "feature-a", - "fixture.Draft.Extra": "feature-b", - "fixture.Parent.extra": "feature-c" + "fixture.Parent.extra": "feature-c", + "fixture.Draft": "feature-a" } } diff --git a/cmd/generate-stable-protos/testdata/classification/message-types/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/message-types/input/temporal/api_next/fixture.proto index 4ea6e7414..24a8a024c 100644 --- a/cmd/generate-stable-protos/testdata/classification/message-types/input/temporal/api_next/fixture.proto +++ b/cmd/generate-stable-protos/testdata/classification/message-types/input/temporal/api_next/fixture.proto @@ -11,10 +11,6 @@ message Parent { Draft draft = 5; string stable_choice = 6; } - oneof all_draft { - Draft first = 7; - Draft.Nested second = 8; - } Draft.Nested nested = 9; Draft.State state = 10; Draft.Extra extra = 11 [(temporal.api.protometa.v1.draft) = "feature-c"]; diff --git a/cmd/generate-stable-protos/testdata/classification/message-types/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/message-types/input/temporal/api_next/protometa/v1/draft.proto index 03c5c5701..44dde8528 100644 --- a/cmd/generate-stable-protos/testdata/classification/message-types/input/temporal/api_next/protometa/v1/draft.proto +++ b/cmd/generate-stable-protos/testdata/classification/message-types/input/temporal/api_next/protometa/v1/draft.proto @@ -7,5 +7,4 @@ extend google.protobuf.EnumOptions { string draft_enum = 98008; } extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } extend google.protobuf.ServiceOptions { string draft_service = 98008; } extend google.protobuf.MethodOptions { string draft_method = 98008; } -extend google.protobuf.FileOptions { string draft_file = 98008; } -extend google.protobuf.OneofOptions { string draft_oneof = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/message-types/input/temporal/api_next/types.proto b/cmd/generate-stable-protos/testdata/classification/message-types/input/temporal/api_next/types.proto index 80070c37f..0cb5890c9 100644 --- a/cmd/generate-stable-protos/testdata/classification/message-types/input/temporal/api_next/types.proto +++ b/cmd/generate-stable-protos/testdata/classification/message-types/input/temporal/api_next/types.proto @@ -7,7 +7,6 @@ message Draft { message Nested { string value = 1; } enum State { STATE_UNSPECIFIED = 0; STATE_READY = 1; } message Extra { - option (temporal.api.protometa.v1.draft_message) = "feature-b"; string value = 1; } } diff --git a/cmd/generate-stable-protos/testdata/classification/message/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/message/input/temporal/api_next/protometa/v1/draft.proto index 79bdf536c..def18ac5d 100644 --- a/cmd/generate-stable-protos/testdata/classification/message/input/temporal/api_next/protometa/v1/draft.proto +++ b/cmd/generate-stable-protos/testdata/classification/message/input/temporal/api_next/protometa/v1/draft.proto @@ -7,5 +7,4 @@ extend google.protobuf.EnumOptions { string draft_enum = 98008; } extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } extend google.protobuf.ServiceOptions { string draft_service = 98008; } extend google.protobuf.MethodOptions { string draft_method = 98008; } -extend google.protobuf.FileOptions { string draft_file = 98008; } -extend google.protobuf.OneofOptions { string draft_oneof = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/method-inherited-endpoint/expected.json b/cmd/generate-stable-protos/testdata/classification/method-inherited-endpoint/expected.json new file mode 100644 index 000000000..a9a0ca5e5 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/method-inherited-endpoint/expected.json @@ -0,0 +1,3 @@ +{ + "error": "fixture.Service.Call: draft_method requires request type fixture.Outer.Nested to explicitly carry draft_message = \"preview\"" +} diff --git a/cmd/generate-stable-protos/testdata/classification/method-inherited-endpoint/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/method-inherited-endpoint/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..8e8a467c9 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/method-inherited-endpoint/input/temporal/api_next/fixture.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; +package fixture; +import "temporal/api_next/protometa/v1/draft.proto"; +message Outer { option (temporal.api.protometa.v1.draft_message) = "preview"; message Nested {} } +message Response { option (temporal.api.protometa.v1.draft_message) = "preview"; } +message StableRequest {} +message StableResponse {} +service Service { + rpc Stable(StableRequest) returns (StableResponse); + rpc Call(Outer.Nested) returns (Response) { option (temporal.api.protometa.v1.draft_method) = "preview"; } +} diff --git a/cmd/generate-stable-protos/testdata/classification/method-inherited-endpoint/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/method-inherited-endpoint/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..def18ac5d --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/method-inherited-endpoint/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98008; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/method-request-feature-mismatch/expected.json b/cmd/generate-stable-protos/testdata/classification/method-request-feature-mismatch/expected.json new file mode 100644 index 000000000..70f2f32ed --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/method-request-feature-mismatch/expected.json @@ -0,0 +1,3 @@ +{ + "error": "fixture.Service.Call: draft_method requires request type fixture.Request to explicitly carry draft_message = \"preview\"; found \"Preview\"" +} diff --git a/cmd/generate-stable-protos/testdata/classification/method-request-feature-mismatch/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/method-request-feature-mismatch/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..c8c34678b --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/method-request-feature-mismatch/input/temporal/api_next/fixture.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; +package fixture; +import "temporal/api_next/protometa/v1/draft.proto"; +message Request { option (temporal.api.protometa.v1.draft_message) = "Preview"; } +message Response { option (temporal.api.protometa.v1.draft_message) = "preview"; } +message StableRequest {} +message StableResponse {} +service Service { + rpc Stable(StableRequest) returns (StableResponse); + rpc Call(Request) returns (Response) { option (temporal.api.protometa.v1.draft_method) = "preview"; } +} diff --git a/cmd/generate-stable-protos/testdata/classification/method-request-feature-mismatch/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/method-request-feature-mismatch/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..def18ac5d --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/method-request-feature-mismatch/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98008; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/method-response-feature-mismatch/expected.json b/cmd/generate-stable-protos/testdata/classification/method-response-feature-mismatch/expected.json new file mode 100644 index 000000000..a4a43846a --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/method-response-feature-mismatch/expected.json @@ -0,0 +1,3 @@ +{ + "error": "fixture.Service.Call: draft_method requires response type fixture.Response to explicitly carry draft_message = \"preview\"; found \"other\"" +} diff --git a/cmd/generate-stable-protos/testdata/classification/method-response-feature-mismatch/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/method-response-feature-mismatch/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..5f529a146 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/method-response-feature-mismatch/input/temporal/api_next/fixture.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; +package fixture; +import "temporal/api_next/protometa/v1/draft.proto"; +message Request { option (temporal.api.protometa.v1.draft_message) = "preview"; } +message Response { option (temporal.api.protometa.v1.draft_message) = "other"; } +message StableRequest {} +message StableResponse {} +service Service { + rpc Stable(StableRequest) returns (StableResponse); + rpc Call(Request) returns (Response) { option (temporal.api.protometa.v1.draft_method) = "preview"; } +} diff --git a/cmd/generate-stable-protos/testdata/classification/method-response-feature-mismatch/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/method-response-feature-mismatch/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..def18ac5d --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/method-response-feature-mismatch/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98008; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/method-stable-request/expected.json b/cmd/generate-stable-protos/testdata/classification/method-stable-request/expected.json new file mode 100644 index 000000000..d8b00fa5e --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/method-stable-request/expected.json @@ -0,0 +1,3 @@ +{ + "error": "fixture.Service.Call: draft_method requires request type fixture.Request to explicitly carry draft_message = \"preview\"" +} diff --git a/cmd/generate-stable-protos/testdata/classification/method-stable-request/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/method-stable-request/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..3b44febf0 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/method-stable-request/input/temporal/api_next/fixture.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; +package fixture; +import "temporal/api_next/protometa/v1/draft.proto"; +message Request {} +message Response { option (temporal.api.protometa.v1.draft_message) = "preview"; } +message StableRequest {} +message StableResponse {} +service Service { + rpc Stable(StableRequest) returns (StableResponse); + rpc Call(Request) returns (Response) { option (temporal.api.protometa.v1.draft_method) = "preview"; } +} diff --git a/cmd/generate-stable-protos/testdata/classification/method-stable-request/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/method-stable-request/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..def18ac5d --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/method-stable-request/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98008; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/method-stable-response/expected.json b/cmd/generate-stable-protos/testdata/classification/method-stable-response/expected.json new file mode 100644 index 000000000..74dec45f0 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/method-stable-response/expected.json @@ -0,0 +1,3 @@ +{ + "error": "fixture.Service.Call: draft_method requires response type fixture.Response to explicitly carry draft_message = \"preview\"" +} diff --git a/cmd/generate-stable-protos/testdata/classification/method-stable-response/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/method-stable-response/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..8faa5de0a --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/method-stable-response/input/temporal/api_next/fixture.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; +package fixture; +import "temporal/api_next/protometa/v1/draft.proto"; +message Request { option (temporal.api.protometa.v1.draft_message) = "preview"; } +message Response {} +message StableRequest {} +message StableResponse {} +service Service { + rpc Stable(StableRequest) returns (StableResponse); + rpc Call(Request) returns (Response) { option (temporal.api.protometa.v1.draft_method) = "preview"; } +} diff --git a/cmd/generate-stable-protos/testdata/classification/method-stable-response/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/method-stable-response/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..def18ac5d --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/method-stable-response/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98008; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/nested-extension/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/nested-extension/input/temporal/api_next/protometa/v1/draft.proto index 03c5c5701..44dde8528 100644 --- a/cmd/generate-stable-protos/testdata/classification/nested-extension/input/temporal/api_next/protometa/v1/draft.proto +++ b/cmd/generate-stable-protos/testdata/classification/nested-extension/input/temporal/api_next/protometa/v1/draft.proto @@ -7,5 +7,4 @@ extend google.protobuf.EnumOptions { string draft_enum = 98008; } extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } extend google.protobuf.ServiceOptions { string draft_service = 98008; } extend google.protobuf.MethodOptions { string draft_method = 98008; } -extend google.protobuf.FileOptions { string draft_file = 98008; } -extend google.protobuf.OneofOptions { string draft_oneof = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/nesting-enum-in-message/expected.json b/cmd/generate-stable-protos/testdata/classification/nesting-enum-in-message/expected.json new file mode 100644 index 000000000..a038cdbf1 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/nesting-enum-in-message/expected.json @@ -0,0 +1,3 @@ +{ + "error": "fixture.Draft.Mode: draft annotation is not allowed inside draft container fixture.Draft" +} diff --git a/cmd/generate-stable-protos/testdata/classification/nesting-enum-in-message/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/nesting-enum-in-message/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..8c54c2b5f --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/nesting-enum-in-message/input/temporal/api_next/fixture.proto @@ -0,0 +1,4 @@ +syntax = "proto3"; +package fixture; +import "temporal/api_next/protometa/v1/draft.proto"; +message Draft { option (temporal.api.protometa.v1.draft_message) = "preview"; enum Mode { option (temporal.api.protometa.v1.draft_enum) = "preview"; ZERO = 0; } } diff --git a/cmd/generate-stable-protos/testdata/classification/nesting-enum-in-message/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/nesting-enum-in-message/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..def18ac5d --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/nesting-enum-in-message/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98008; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/nesting-enum-value/expected.json b/cmd/generate-stable-protos/testdata/classification/nesting-enum-value/expected.json new file mode 100644 index 000000000..ec7a23102 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/nesting-enum-value/expected.json @@ -0,0 +1,3 @@ +{ + "error": "fixture.ZERO: draft annotation is not allowed inside draft container fixture.Mode" +} diff --git a/cmd/generate-stable-protos/testdata/classification/nesting-enum-value/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/nesting-enum-value/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..3f8166d64 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/nesting-enum-value/input/temporal/api_next/fixture.proto @@ -0,0 +1,4 @@ +syntax = "proto3"; +package fixture; +import "temporal/api_next/protometa/v1/draft.proto"; +enum Mode { option (temporal.api.protometa.v1.draft_enum) = "preview"; ZERO = 0 [(temporal.api.protometa.v1.draft_enum_value) = "preview"]; } diff --git a/cmd/generate-stable-protos/testdata/classification/nesting-enum-value/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/nesting-enum-value/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..def18ac5d --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/nesting-enum-value/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98008; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/nesting-field-in-message/expected.json b/cmd/generate-stable-protos/testdata/classification/nesting-field-in-message/expected.json new file mode 100644 index 000000000..aca4c5582 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/nesting-field-in-message/expected.json @@ -0,0 +1,3 @@ +{ + "error": "fixture.Draft.value: draft annotation is not allowed inside draft container fixture.Draft" +} diff --git a/cmd/generate-stable-protos/testdata/classification/nesting-field-in-message/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/nesting-field-in-message/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..f74e8507e --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/nesting-field-in-message/input/temporal/api_next/fixture.proto @@ -0,0 +1,4 @@ +syntax = "proto3"; +package fixture; +import "temporal/api_next/protometa/v1/draft.proto"; +message Draft { option (temporal.api.protometa.v1.draft_message) = "preview"; string value = 1 [(temporal.api.protometa.v1.draft) = "preview"]; } diff --git a/cmd/generate-stable-protos/testdata/classification/nesting-field-in-message/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/nesting-field-in-message/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..def18ac5d --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/nesting-field-in-message/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98008; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/nesting-inherited-enum/expected.json b/cmd/generate-stable-protos/testdata/classification/nesting-inherited-enum/expected.json new file mode 100644 index 000000000..7952b0ac8 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/nesting-inherited-enum/expected.json @@ -0,0 +1,3 @@ +{ + "error": "fixture.Draft.ZERO: draft annotation is not allowed inside draft container fixture.Draft.Mode" +} diff --git a/cmd/generate-stable-protos/testdata/classification/nesting-inherited-enum/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/nesting-inherited-enum/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..cef084c98 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/nesting-inherited-enum/input/temporal/api_next/fixture.proto @@ -0,0 +1,4 @@ +syntax = "proto3"; +package fixture; +import "temporal/api_next/protometa/v1/draft.proto"; +message Draft { option (temporal.api.protometa.v1.draft_message) = "preview"; enum Mode { ZERO = 0 [(temporal.api.protometa.v1.draft_enum_value) = "preview"]; } } diff --git a/cmd/generate-stable-protos/testdata/classification/nesting-inherited-enum/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/nesting-inherited-enum/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..def18ac5d --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/nesting-inherited-enum/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98008; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/nesting-inherited-message/expected.json b/cmd/generate-stable-protos/testdata/classification/nesting-inherited-message/expected.json new file mode 100644 index 000000000..fbe725295 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/nesting-inherited-message/expected.json @@ -0,0 +1,3 @@ +{ + "error": "fixture.Draft.Nested.value: draft annotation is not allowed inside draft container fixture.Draft.Nested" +} diff --git a/cmd/generate-stable-protos/testdata/classification/nesting-inherited-message/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/nesting-inherited-message/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..f017afe4c --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/nesting-inherited-message/input/temporal/api_next/fixture.proto @@ -0,0 +1,4 @@ +syntax = "proto3"; +package fixture; +import "temporal/api_next/protometa/v1/draft.proto"; +message Draft { option (temporal.api.protometa.v1.draft_message) = "preview"; message Nested { string value = 1 [(temporal.api.protometa.v1.draft) = "preview"]; } } diff --git a/cmd/generate-stable-protos/testdata/classification/nesting-inherited-message/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/nesting-inherited-message/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..def18ac5d --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/nesting-inherited-message/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98008; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/nesting-inherited-oneof/expected.json b/cmd/generate-stable-protos/testdata/classification/nesting-inherited-oneof/expected.json new file mode 100644 index 000000000..86e2a92c6 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/nesting-inherited-oneof/expected.json @@ -0,0 +1,3 @@ +{ + "error": "fixture.Draft.value: draft annotation is not allowed inside draft container fixture.Draft.choice" +} diff --git a/cmd/generate-stable-protos/testdata/classification/nesting-inherited-oneof/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/nesting-inherited-oneof/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..2085efd8a --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/nesting-inherited-oneof/input/temporal/api_next/fixture.proto @@ -0,0 +1,4 @@ +syntax = "proto3"; +package fixture; +import "temporal/api_next/protometa/v1/draft.proto"; +message Draft { option (temporal.api.protometa.v1.draft_message) = "preview"; oneof choice { string value = 1 [(temporal.api.protometa.v1.draft) = "preview"]; } } diff --git a/cmd/generate-stable-protos/testdata/classification/nesting-inherited-oneof/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/nesting-inherited-oneof/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..def18ac5d --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/nesting-inherited-oneof/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98008; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/nesting-message-in-message/expected.json b/cmd/generate-stable-protos/testdata/classification/nesting-message-in-message/expected.json new file mode 100644 index 000000000..0deb85de1 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/nesting-message-in-message/expected.json @@ -0,0 +1,3 @@ +{ + "error": "fixture.Draft.Nested: draft annotation is not allowed inside draft container fixture.Draft" +} diff --git a/cmd/generate-stable-protos/testdata/classification/nesting-message-in-message/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/nesting-message-in-message/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..5b05be9f0 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/nesting-message-in-message/input/temporal/api_next/fixture.proto @@ -0,0 +1,4 @@ +syntax = "proto3"; +package fixture; +import "temporal/api_next/protometa/v1/draft.proto"; +message Draft { option (temporal.api.protometa.v1.draft_message) = "preview"; message Nested { option (temporal.api.protometa.v1.draft_message) = "another"; } } diff --git a/cmd/generate-stable-protos/testdata/classification/nesting-message-in-message/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/nesting-message-in-message/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..def18ac5d --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/nesting-message-in-message/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98008; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/nesting-method-in-service/expected.json b/cmd/generate-stable-protos/testdata/classification/nesting-method-in-service/expected.json new file mode 100644 index 000000000..572f2bd69 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/nesting-method-in-service/expected.json @@ -0,0 +1,3 @@ +{ + "error": "fixture.Service.Call: draft_method is not allowed inside draft_service fixture.Service" +} diff --git a/cmd/generate-stable-protos/testdata/classification/nesting-method-in-service/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/nesting-method-in-service/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..18f8652fc --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/nesting-method-in-service/input/temporal/api_next/fixture.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; +package fixture; +import "temporal/api_next/protometa/v1/draft.proto"; +message Request { option (temporal.api.protometa.v1.draft_message) = "preview"; } +message Response { option (temporal.api.protometa.v1.draft_message) = "preview"; } +service Service { + option (temporal.api.protometa.v1.draft_service) = "preview"; + rpc Call(Request) returns (Response) { option (temporal.api.protometa.v1.draft_method) = "preview"; } +} diff --git a/cmd/generate-stable-protos/testdata/classification/nesting-method-in-service/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/nesting-method-in-service/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..def18ac5d --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/nesting-method-in-service/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98008; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/nesting-oneof-field/expected.json b/cmd/generate-stable-protos/testdata/classification/nesting-oneof-field/expected.json new file mode 100644 index 000000000..62916cdd8 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/nesting-oneof-field/expected.json @@ -0,0 +1,3 @@ +{ + "error": "fixture.Example.value: draft annotation is not allowed inside draft container fixture.Example.choice" +} diff --git a/cmd/generate-stable-protos/testdata/classification/unsupported-oneof/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/nesting-oneof-field/input/temporal/api_next/fixture.proto similarity index 60% rename from cmd/generate-stable-protos/testdata/classification/unsupported-oneof/input/temporal/api_next/fixture.proto rename to cmd/generate-stable-protos/testdata/classification/nesting-oneof-field/input/temporal/api_next/fixture.proto index 9f2dcddff..00669556e 100644 --- a/cmd/generate-stable-protos/testdata/classification/unsupported-oneof/input/temporal/api_next/fixture.proto +++ b/cmd/generate-stable-protos/testdata/classification/nesting-oneof-field/input/temporal/api_next/fixture.proto @@ -1,4 +1,4 @@ syntax = "proto3"; package fixture; import "temporal/api_next/protometa/v1/draft.proto"; -message Example { oneof choice { option (temporal.api.protometa.v1.draft_oneof) = "feature-a"; string a = 1; } } +message Example { oneof choice { option (temporal.api.protometa.v1.draft_oneof) = "preview"; string value = 1 [(temporal.api.protometa.v1.draft) = "preview"]; } } diff --git a/cmd/generate-stable-protos/testdata/classification/nesting-oneof-field/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/nesting-oneof-field/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..def18ac5d --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/nesting-oneof-field/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98008; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/nesting-oneof-in-message/expected.json b/cmd/generate-stable-protos/testdata/classification/nesting-oneof-in-message/expected.json new file mode 100644 index 000000000..195e90c19 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/nesting-oneof-in-message/expected.json @@ -0,0 +1,3 @@ +{ + "error": "fixture.Draft.choice: draft annotation is not allowed inside draft container fixture.Draft" +} diff --git a/cmd/generate-stable-protos/testdata/classification/nesting-oneof-in-message/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/nesting-oneof-in-message/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..a8bf56709 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/nesting-oneof-in-message/input/temporal/api_next/fixture.proto @@ -0,0 +1,4 @@ +syntax = "proto3"; +package fixture; +import "temporal/api_next/protometa/v1/draft.proto"; +message Draft { option (temporal.api.protometa.v1.draft_message) = "preview"; oneof choice { option (temporal.api.protometa.v1.draft_oneof) = "preview"; string value = 1; } } diff --git a/cmd/generate-stable-protos/testdata/classification/nesting-oneof-in-message/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/nesting-oneof-in-message/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..def18ac5d --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/nesting-oneof-in-message/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98008; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/public-import/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/public-import/input/temporal/api_next/protometa/v1/draft.proto index 03c5c5701..44dde8528 100644 --- a/cmd/generate-stable-protos/testdata/classification/public-import/input/temporal/api_next/protometa/v1/draft.proto +++ b/cmd/generate-stable-protos/testdata/classification/public-import/input/temporal/api_next/protometa/v1/draft.proto @@ -7,5 +7,4 @@ extend google.protobuf.EnumOptions { string draft_enum = 98008; } extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } extend google.protobuf.ServiceOptions { string draft_service = 98008; } extend google.protobuf.MethodOptions { string draft_method = 98008; } -extend google.protobuf.FileOptions { string draft_file = 98008; } -extend google.protobuf.OneofOptions { string draft_oneof = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/removed-rpc-http/expected.json b/cmd/generate-stable-protos/testdata/classification/removed-rpc-http/expected.json new file mode 100644 index 000000000..d2bf1f20b --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/removed-rpc-http/expected.json @@ -0,0 +1,9 @@ +{ + "annotations": { + "fixture.Request": "preview", + "fixture.Response": "preview", + "fixture.Service.Call": "preview", + "fixture.Item.draft_id": "preview" + }, + "validation_only": true +} diff --git a/cmd/generate-stable-protos/testdata/classification/removed-rpc-http/input/google/api/annotations.proto b/cmd/generate-stable-protos/testdata/classification/removed-rpc-http/input/google/api/annotations.proto new file mode 100644 index 000000000..efdab3db6 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/removed-rpc-http/input/google/api/annotations.proto @@ -0,0 +1,31 @@ +// Copyright 2015 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package google.api; + +import "google/api/http.proto"; +import "google/protobuf/descriptor.proto"; + +option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations"; +option java_multiple_files = true; +option java_outer_classname = "AnnotationsProto"; +option java_package = "com.google.api"; +option objc_class_prefix = "GAPI"; + +extend google.protobuf.MethodOptions { + // See `HttpRule`. + HttpRule http = 72295728; +} diff --git a/cmd/generate-stable-protos/testdata/classification/removed-rpc-http/input/google/api/http.proto b/cmd/generate-stable-protos/testdata/classification/removed-rpc-http/input/google/api/http.proto new file mode 100644 index 000000000..31d867a27 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/removed-rpc-http/input/google/api/http.proto @@ -0,0 +1,379 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package google.api; + +option cc_enable_arenas = true; +option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations"; +option java_multiple_files = true; +option java_outer_classname = "HttpProto"; +option java_package = "com.google.api"; +option objc_class_prefix = "GAPI"; + +// Defines the HTTP configuration for an API service. It contains a list of +// [HttpRule][google.api.HttpRule], each specifying the mapping of an RPC method +// to one or more HTTP REST API methods. +message Http { + // A list of HTTP configuration rules that apply to individual API methods. + // + // **NOTE:** All service configuration rules follow "last one wins" order. + repeated HttpRule rules = 1; + + // When set to true, URL path parameters will be fully URI-decoded except in + // cases of single segment matches in reserved expansion, where "%2F" will be + // left encoded. + // + // The default behavior is to not decode RFC 6570 reserved characters in multi + // segment matches. + bool fully_decode_reserved_expansion = 2; +} + +// # gRPC Transcoding +// +// gRPC Transcoding is a feature for mapping between a gRPC method and one or +// more HTTP REST endpoints. It allows developers to build a single API service +// that supports both gRPC APIs and REST APIs. Many systems, including [Google +// APIs](https://github.com/googleapis/googleapis), +// [Cloud Endpoints](https://cloud.google.com/endpoints), [gRPC +// Gateway](https://github.com/grpc-ecosystem/grpc-gateway), +// and [Envoy](https://github.com/envoyproxy/envoy) proxy support this feature +// and use it for large scale production services. +// +// `HttpRule` defines the schema of the gRPC/REST mapping. The mapping specifies +// how different portions of the gRPC request message are mapped to the URL +// path, URL query parameters, and HTTP request body. It also controls how the +// gRPC response message is mapped to the HTTP response body. `HttpRule` is +// typically specified as an `google.api.http` annotation on the gRPC method. +// +// Each mapping specifies a URL path template and an HTTP method. The path +// template may refer to one or more fields in the gRPC request message, as long +// as each field is a non-repeated field with a primitive (non-message) type. +// The path template controls how fields of the request message are mapped to +// the URL path. +// +// Example: +// +// service Messaging { +// rpc GetMessage(GetMessageRequest) returns (Message) { +// option (google.api.http) = { +// get: "/v1/{name=messages/*}" +// }; +// } +// } +// message GetMessageRequest { +// string name = 1; // Mapped to URL path. +// } +// message Message { +// string text = 1; // The resource content. +// } +// +// This enables an HTTP REST to gRPC mapping as below: +// +// HTTP | gRPC +// -----|----- +// `GET /v1/messages/123456` | `GetMessage(name: "messages/123456")` +// +// Any fields in the request message which are not bound by the path template +// automatically become HTTP query parameters if there is no HTTP request body. +// For example: +// +// service Messaging { +// rpc GetMessage(GetMessageRequest) returns (Message) { +// option (google.api.http) = { +// get:"/v1/messages/{message_id}" +// }; +// } +// } +// message GetMessageRequest { +// message SubMessage { +// string subfield = 1; +// } +// string message_id = 1; // Mapped to URL path. +// int64 revision = 2; // Mapped to URL query parameter `revision`. +// SubMessage sub = 3; // Mapped to URL query parameter `sub.subfield`. +// } +// +// This enables a HTTP JSON to RPC mapping as below: +// +// HTTP | gRPC +// -----|----- +// `GET /v1/messages/123456?revision=2&sub.subfield=foo` | +// `GetMessage(message_id: "123456" revision: 2 sub: SubMessage(subfield: +// "foo"))` +// +// Note that fields which are mapped to URL query parameters must have a +// primitive type or a repeated primitive type or a non-repeated message type. +// In the case of a repeated type, the parameter can be repeated in the URL +// as `...?param=A¶m=B`. In the case of a message type, each field of the +// message is mapped to a separate parameter, such as +// `...?foo.a=A&foo.b=B&foo.c=C`. +// +// For HTTP methods that allow a request body, the `body` field +// specifies the mapping. Consider a REST update method on the +// message resource collection: +// +// service Messaging { +// rpc UpdateMessage(UpdateMessageRequest) returns (Message) { +// option (google.api.http) = { +// patch: "/v1/messages/{message_id}" +// body: "message" +// }; +// } +// } +// message UpdateMessageRequest { +// string message_id = 1; // mapped to the URL +// Message message = 2; // mapped to the body +// } +// +// The following HTTP JSON to RPC mapping is enabled, where the +// representation of the JSON in the request body is determined by +// protos JSON encoding: +// +// HTTP | gRPC +// -----|----- +// `PATCH /v1/messages/123456 { "text": "Hi!" }` | `UpdateMessage(message_id: +// "123456" message { text: "Hi!" })` +// +// The special name `*` can be used in the body mapping to define that +// every field not bound by the path template should be mapped to the +// request body. This enables the following alternative definition of +// the update method: +// +// service Messaging { +// rpc UpdateMessage(Message) returns (Message) { +// option (google.api.http) = { +// patch: "/v1/messages/{message_id}" +// body: "*" +// }; +// } +// } +// message Message { +// string message_id = 1; +// string text = 2; +// } +// +// +// The following HTTP JSON to RPC mapping is enabled: +// +// HTTP | gRPC +// -----|----- +// `PATCH /v1/messages/123456 { "text": "Hi!" }` | `UpdateMessage(message_id: +// "123456" text: "Hi!")` +// +// Note that when using `*` in the body mapping, it is not possible to +// have HTTP parameters, as all fields not bound by the path end in +// the body. This makes this option more rarely used in practice when +// defining REST APIs. The common usage of `*` is in custom methods +// which don't use the URL at all for transferring data. +// +// It is possible to define multiple HTTP methods for one RPC by using +// the `additional_bindings` option. Example: +// +// service Messaging { +// rpc GetMessage(GetMessageRequest) returns (Message) { +// option (google.api.http) = { +// get: "/v1/messages/{message_id}" +// additional_bindings { +// get: "/v1/users/{user_id}/messages/{message_id}" +// } +// }; +// } +// } +// message GetMessageRequest { +// string message_id = 1; +// string user_id = 2; +// } +// +// This enables the following two alternative HTTP JSON to RPC mappings: +// +// HTTP | gRPC +// -----|----- +// `GET /v1/messages/123456` | `GetMessage(message_id: "123456")` +// `GET /v1/users/me/messages/123456` | `GetMessage(user_id: "me" message_id: +// "123456")` +// +// ## Rules for HTTP mapping +// +// 1. Leaf request fields (recursive expansion nested messages in the request +// message) are classified into three categories: +// - Fields referred by the path template. They are passed via the URL path. +// - Fields referred by the [HttpRule.body][google.api.HttpRule.body]. They +// are passed via the HTTP +// request body. +// - All other fields are passed via the URL query parameters, and the +// parameter name is the field path in the request message. A repeated +// field can be represented as multiple query parameters under the same +// name. +// 2. If [HttpRule.body][google.api.HttpRule.body] is "*", there is no URL +// query parameter, all fields +// are passed via URL path and HTTP request body. +// 3. If [HttpRule.body][google.api.HttpRule.body] is omitted, there is no HTTP +// request body, all +// fields are passed via URL path and URL query parameters. +// +// ### Path template syntax +// +// Template = "/" Segments [ Verb ] ; +// Segments = Segment { "/" Segment } ; +// Segment = "*" | "**" | LITERAL | Variable ; +// Variable = "{" FieldPath [ "=" Segments ] "}" ; +// FieldPath = IDENT { "." IDENT } ; +// Verb = ":" LITERAL ; +// +// The syntax `*` matches a single URL path segment. The syntax `**` matches +// zero or more URL path segments, which must be the last part of the URL path +// except the `Verb`. +// +// The syntax `Variable` matches part of the URL path as specified by its +// template. A variable template must not contain other variables. If a variable +// matches a single path segment, its template may be omitted, e.g. `{var}` +// is equivalent to `{var=*}`. +// +// The syntax `LITERAL` matches literal text in the URL path. If the `LITERAL` +// contains any reserved character, such characters should be percent-encoded +// before the matching. +// +// If a variable contains exactly one path segment, such as `"{var}"` or +// `"{var=*}"`, when such a variable is expanded into a URL path on the client +// side, all characters except `[-_.~0-9a-zA-Z]` are percent-encoded. The +// server side does the reverse decoding. Such variables show up in the +// [Discovery +// Document](https://developers.google.com/discovery/v1/reference/apis) as +// `{var}`. +// +// If a variable contains multiple path segments, such as `"{var=foo/*}"` +// or `"{var=**}"`, when such a variable is expanded into a URL path on the +// client side, all characters except `[-_.~/0-9a-zA-Z]` are percent-encoded. +// The server side does the reverse decoding, except "%2F" and "%2f" are left +// unchanged. Such variables show up in the +// [Discovery +// Document](https://developers.google.com/discovery/v1/reference/apis) as +// `{+var}`. +// +// ## Using gRPC API Service Configuration +// +// gRPC API Service Configuration (service config) is a configuration language +// for configuring a gRPC service to become a user-facing product. The +// service config is simply the YAML representation of the `google.api.Service` +// proto message. +// +// As an alternative to annotating your proto file, you can configure gRPC +// transcoding in your service config YAML files. You do this by specifying a +// `HttpRule` that maps the gRPC method to a REST endpoint, achieving the same +// effect as the proto annotation. This can be particularly useful if you +// have a proto that is reused in multiple services. Note that any transcoding +// specified in the service config will override any matching transcoding +// configuration in the proto. +// +// Example: +// +// http: +// rules: +// # Selects a gRPC method and applies HttpRule to it. +// - selector: example.v1.Messaging.GetMessage +// get: /v1/messages/{message_id}/{sub.subfield} +// +// ## Special notes +// +// When gRPC Transcoding is used to map a gRPC to JSON REST endpoints, the +// proto to JSON conversion must follow the [proto3 +// specification](https://developers.google.com/protocol-buffers/docs/proto3#json). +// +// While the single segment variable follows the semantics of +// [RFC 6570](https://tools.ietf.org/html/rfc6570) Section 3.2.2 Simple String +// Expansion, the multi segment variable **does not** follow RFC 6570 Section +// 3.2.3 Reserved Expansion. The reason is that the Reserved Expansion +// does not expand special characters like `?` and `#`, which would lead +// to invalid URLs. As the result, gRPC Transcoding uses a custom encoding +// for multi segment variables. +// +// The path variables **must not** refer to any repeated or mapped field, +// because client libraries are not capable of handling such variable expansion. +// +// The path variables **must not** capture the leading "/" character. The reason +// is that the most common use case "{var}" does not capture the leading "/" +// character. For consistency, all path variables must share the same behavior. +// +// Repeated message fields must not be mapped to URL query parameters, because +// no client library can support such complicated mapping. +// +// If an API needs to use a JSON array for request or response body, it can map +// the request or response body to a repeated field. However, some gRPC +// Transcoding implementations may not support this feature. +message HttpRule { + // Selects a method to which this rule applies. + // + // Refer to [selector][google.api.DocumentationRule.selector] for syntax + // details. + string selector = 1; + + // Determines the URL pattern is matched by this rules. This pattern can be + // used with any of the {get|put|post|delete|patch} methods. A custom method + // can be defined using the 'custom' field. + oneof pattern { + // Maps to HTTP GET. Used for listing and getting information about + // resources. + string get = 2; + + // Maps to HTTP PUT. Used for replacing a resource. + string put = 3; + + // Maps to HTTP POST. Used for creating a resource or performing an action. + string post = 4; + + // Maps to HTTP DELETE. Used for deleting a resource. + string delete = 5; + + // Maps to HTTP PATCH. Used for updating a resource. + string patch = 6; + + // The custom pattern is used for specifying an HTTP method that is not + // included in the `pattern` field, such as HEAD, or "*" to leave the + // HTTP method unspecified for this rule. The wild-card rule is useful + // for services that provide content to Web (HTML) clients. + CustomHttpPattern custom = 8; + } + + // The name of the request field whose value is mapped to the HTTP request + // body, or `*` for mapping all request fields not captured by the path + // pattern to the HTTP body, or omitted for not having any HTTP request body. + // + // NOTE: the referred field must be present at the top-level of the request + // message type. + string body = 7; + + // Optional. The name of the response field whose value is mapped to the HTTP + // response body. When omitted, the entire response message will be used + // as the HTTP response body. + // + // NOTE: The referred field must be present at the top-level of the response + // message type. + string response_body = 12; + + // Additional HTTP bindings for the selector. Nested bindings must + // not contain an `additional_bindings` field themselves (that is, + // the nesting may only be one level deep). + repeated HttpRule additional_bindings = 11; +} + +// A custom pattern is used for defining custom HTTP verb. +message CustomHttpPattern { + // The name of this custom HTTP verb. + string kind = 1; + + // The path matched by this custom verb. + string path = 2; +} diff --git a/cmd/generate-stable-protos/testdata/classification/removed-rpc-http/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/removed-rpc-http/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..acda8a01c --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/removed-rpc-http/input/temporal/api_next/fixture.proto @@ -0,0 +1,16 @@ +syntax = "proto3"; +package fixture; +import "google/api/annotations.proto"; +import "temporal/api_next/protometa/v1/draft.proto"; +message Request { option (temporal.api.protometa.v1.draft_message) = "preview"; Item item = 1; } +message Item { string draft_id = 1 [(temporal.api.protometa.v1.draft) = "preview"]; } +message Response { option (temporal.api.protometa.v1.draft_message) = "preview"; } +message OtherRequest {} +message OtherResponse {} +service Service { + rpc Stable(OtherRequest) returns (OtherResponse); + rpc Call (Request) returns (Response) { + option (temporal.api.protometa.v1.draft_method) = "preview"; + option (google.api.http) = { get: "/items/{item.draft_id=items/*}" }; + } +} diff --git a/cmd/generate-stable-protos/testdata/classification/removed-rpc-http/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/removed-rpc-http/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..def18ac5d --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/removed-rpc-http/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98008; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/removed-rpc-request-header/expected.json b/cmd/generate-stable-protos/testdata/classification/removed-rpc-request-header/expected.json new file mode 100644 index 000000000..d7c3237a7 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/removed-rpc-request-header/expected.json @@ -0,0 +1,9 @@ +{ + "annotations": { + "fixture.Request": "preview", + "fixture.Response": "preview", + "fixture.Service": "preview", + "fixture.Item.draft_id": "feature-a" + }, + "validation_only": true +} diff --git a/cmd/generate-stable-protos/testdata/classification/removed-rpc-request-header/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/removed-rpc-request-header/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..79a4ed701 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/removed-rpc-request-header/input/temporal/api_next/fixture.proto @@ -0,0 +1,20 @@ +syntax = "proto3"; +package fixture; +import "temporal/api_next/protometa/v1/annotations.proto"; +import "temporal/api_next/protometa/v1/draft.proto"; +message Request { option (temporal.api.protometa.v1.draft_message) = "preview"; Item item = 1; } +message Item { + string id = 1; + string draft_id = 2 [(temporal.api.protometa.v1.draft) = "feature-a"]; +} +message Response { option (temporal.api.protometa.v1.draft_message) = "preview"; } +service Service { + option (temporal.api.protometa.v1.draft_service) = "preview"; + rpc Call (Request) returns (Response) { + option (temporal.api.protometa.v1.request_header) = { header: "item-kind" value: "item" }; + option (temporal.api.protometa.v1.request_header) = { + header: "item-id" + value: "{item.id}/{item.draft_id}" + }; + } +} diff --git a/cmd/generate-stable-protos/testdata/classification/removed-rpc-request-header/input/temporal/api_next/protometa/v1/annotations.proto b/cmd/generate-stable-protos/testdata/classification/removed-rpc-request-header/input/temporal/api_next/protometa/v1/annotations.proto new file mode 100644 index 000000000..483ffd676 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/removed-rpc-request-header/input/temporal/api_next/protometa/v1/annotations.proto @@ -0,0 +1,37 @@ +syntax = "proto3"; + +package temporal.api.protometa.v1; + +option go_package = "go.temporal.io/api/protometa/v1;protometa"; +option java_package = "io.temporal.api.protometa.v1"; +option java_multiple_files = true; +option java_outer_classname = "AnnotationsProto"; +option ruby_package = "Temporalio::Api::Protometa::V1"; +option csharp_namespace = "Temporalio.Api.Protometa.V1"; + +import "google/protobuf/descriptor.proto"; + +// RequestHeaderAnnotation allows specifying that field values from a request +// should be propagated as outbound headers. +// +// The value field supports template interpolation where field paths enclosed +// in braces will be replaced with the actual field values from the request. +// For example: +// value: "{workflow_execution.workflow_id}" +// value: "workflow-{workflow_execution.workflow_id}" +// value: "{namespace}/{workflow_execution.workflow_id}" +message RequestHeaderAnnotation { + // The name of the header to set (e.g., "temporal-resource-id") + string header = 1; + + // A template string that may contain field paths in braces. + // Field paths use dot notation to traverse nested messages. + // Example: "{workflow_execution.workflow_id}" + string value = 2; +} + +// Extension to add request-header annotations to RPC methods. +// Multiple headers can be set by repeating this option. +extend google.protobuf.MethodOptions { + repeated RequestHeaderAnnotation request_header = 7234001; +} \ No newline at end of file diff --git a/cmd/generate-stable-protos/testdata/classification/removed-rpc-request-header/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/removed-rpc-request-header/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..def18ac5d --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/removed-rpc-request-header/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98008; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-http-additional-binding/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/rpc-http-additional-binding/input/temporal/api_next/protometa/v1/draft.proto index 03c5c5701..44dde8528 100644 --- a/cmd/generate-stable-protos/testdata/classification/rpc-http-additional-binding/input/temporal/api_next/protometa/v1/draft.proto +++ b/cmd/generate-stable-protos/testdata/classification/rpc-http-additional-binding/input/temporal/api_next/protometa/v1/draft.proto @@ -7,5 +7,4 @@ extend google.protobuf.EnumOptions { string draft_enum = 98008; } extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } extend google.protobuf.ServiceOptions { string draft_service = 98008; } extend google.protobuf.MethodOptions { string draft_method = 98008; } -extend google.protobuf.FileOptions { string draft_file = 98008; } -extend google.protobuf.OneofOptions { string draft_oneof = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-http-body/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/rpc-http-body/input/temporal/api_next/protometa/v1/draft.proto index 03c5c5701..44dde8528 100644 --- a/cmd/generate-stable-protos/testdata/classification/rpc-http-body/input/temporal/api_next/protometa/v1/draft.proto +++ b/cmd/generate-stable-protos/testdata/classification/rpc-http-body/input/temporal/api_next/protometa/v1/draft.proto @@ -7,5 +7,4 @@ extend google.protobuf.EnumOptions { string draft_enum = 98008; } extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } extend google.protobuf.ServiceOptions { string draft_service = 98008; } extend google.protobuf.MethodOptions { string draft_method = 98008; } -extend google.protobuf.FileOptions { string draft_file = 98008; } -extend google.protobuf.OneofOptions { string draft_oneof = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-http-draft-oneof/expected.json b/cmd/generate-stable-protos/testdata/classification/rpc-http-draft-oneof/expected.json new file mode 100644 index 000000000..1424194f2 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/rpc-http-draft-oneof/expected.json @@ -0,0 +1 @@ +{"error": "fixture.Service.Call: http rule references draft field draft_id"} diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-http-draft-oneof/input/google/api/annotations.proto b/cmd/generate-stable-protos/testdata/classification/rpc-http-draft-oneof/input/google/api/annotations.proto new file mode 100644 index 000000000..efdab3db6 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/rpc-http-draft-oneof/input/google/api/annotations.proto @@ -0,0 +1,31 @@ +// Copyright 2015 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package google.api; + +import "google/api/http.proto"; +import "google/protobuf/descriptor.proto"; + +option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations"; +option java_multiple_files = true; +option java_outer_classname = "AnnotationsProto"; +option java_package = "com.google.api"; +option objc_class_prefix = "GAPI"; + +extend google.protobuf.MethodOptions { + // See `HttpRule`. + HttpRule http = 72295728; +} diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-http-draft-oneof/input/google/api/http.proto b/cmd/generate-stable-protos/testdata/classification/rpc-http-draft-oneof/input/google/api/http.proto new file mode 100644 index 000000000..31d867a27 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/rpc-http-draft-oneof/input/google/api/http.proto @@ -0,0 +1,379 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package google.api; + +option cc_enable_arenas = true; +option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations"; +option java_multiple_files = true; +option java_outer_classname = "HttpProto"; +option java_package = "com.google.api"; +option objc_class_prefix = "GAPI"; + +// Defines the HTTP configuration for an API service. It contains a list of +// [HttpRule][google.api.HttpRule], each specifying the mapping of an RPC method +// to one or more HTTP REST API methods. +message Http { + // A list of HTTP configuration rules that apply to individual API methods. + // + // **NOTE:** All service configuration rules follow "last one wins" order. + repeated HttpRule rules = 1; + + // When set to true, URL path parameters will be fully URI-decoded except in + // cases of single segment matches in reserved expansion, where "%2F" will be + // left encoded. + // + // The default behavior is to not decode RFC 6570 reserved characters in multi + // segment matches. + bool fully_decode_reserved_expansion = 2; +} + +// # gRPC Transcoding +// +// gRPC Transcoding is a feature for mapping between a gRPC method and one or +// more HTTP REST endpoints. It allows developers to build a single API service +// that supports both gRPC APIs and REST APIs. Many systems, including [Google +// APIs](https://github.com/googleapis/googleapis), +// [Cloud Endpoints](https://cloud.google.com/endpoints), [gRPC +// Gateway](https://github.com/grpc-ecosystem/grpc-gateway), +// and [Envoy](https://github.com/envoyproxy/envoy) proxy support this feature +// and use it for large scale production services. +// +// `HttpRule` defines the schema of the gRPC/REST mapping. The mapping specifies +// how different portions of the gRPC request message are mapped to the URL +// path, URL query parameters, and HTTP request body. It also controls how the +// gRPC response message is mapped to the HTTP response body. `HttpRule` is +// typically specified as an `google.api.http` annotation on the gRPC method. +// +// Each mapping specifies a URL path template and an HTTP method. The path +// template may refer to one or more fields in the gRPC request message, as long +// as each field is a non-repeated field with a primitive (non-message) type. +// The path template controls how fields of the request message are mapped to +// the URL path. +// +// Example: +// +// service Messaging { +// rpc GetMessage(GetMessageRequest) returns (Message) { +// option (google.api.http) = { +// get: "/v1/{name=messages/*}" +// }; +// } +// } +// message GetMessageRequest { +// string name = 1; // Mapped to URL path. +// } +// message Message { +// string text = 1; // The resource content. +// } +// +// This enables an HTTP REST to gRPC mapping as below: +// +// HTTP | gRPC +// -----|----- +// `GET /v1/messages/123456` | `GetMessage(name: "messages/123456")` +// +// Any fields in the request message which are not bound by the path template +// automatically become HTTP query parameters if there is no HTTP request body. +// For example: +// +// service Messaging { +// rpc GetMessage(GetMessageRequest) returns (Message) { +// option (google.api.http) = { +// get:"/v1/messages/{message_id}" +// }; +// } +// } +// message GetMessageRequest { +// message SubMessage { +// string subfield = 1; +// } +// string message_id = 1; // Mapped to URL path. +// int64 revision = 2; // Mapped to URL query parameter `revision`. +// SubMessage sub = 3; // Mapped to URL query parameter `sub.subfield`. +// } +// +// This enables a HTTP JSON to RPC mapping as below: +// +// HTTP | gRPC +// -----|----- +// `GET /v1/messages/123456?revision=2&sub.subfield=foo` | +// `GetMessage(message_id: "123456" revision: 2 sub: SubMessage(subfield: +// "foo"))` +// +// Note that fields which are mapped to URL query parameters must have a +// primitive type or a repeated primitive type or a non-repeated message type. +// In the case of a repeated type, the parameter can be repeated in the URL +// as `...?param=A¶m=B`. In the case of a message type, each field of the +// message is mapped to a separate parameter, such as +// `...?foo.a=A&foo.b=B&foo.c=C`. +// +// For HTTP methods that allow a request body, the `body` field +// specifies the mapping. Consider a REST update method on the +// message resource collection: +// +// service Messaging { +// rpc UpdateMessage(UpdateMessageRequest) returns (Message) { +// option (google.api.http) = { +// patch: "/v1/messages/{message_id}" +// body: "message" +// }; +// } +// } +// message UpdateMessageRequest { +// string message_id = 1; // mapped to the URL +// Message message = 2; // mapped to the body +// } +// +// The following HTTP JSON to RPC mapping is enabled, where the +// representation of the JSON in the request body is determined by +// protos JSON encoding: +// +// HTTP | gRPC +// -----|----- +// `PATCH /v1/messages/123456 { "text": "Hi!" }` | `UpdateMessage(message_id: +// "123456" message { text: "Hi!" })` +// +// The special name `*` can be used in the body mapping to define that +// every field not bound by the path template should be mapped to the +// request body. This enables the following alternative definition of +// the update method: +// +// service Messaging { +// rpc UpdateMessage(Message) returns (Message) { +// option (google.api.http) = { +// patch: "/v1/messages/{message_id}" +// body: "*" +// }; +// } +// } +// message Message { +// string message_id = 1; +// string text = 2; +// } +// +// +// The following HTTP JSON to RPC mapping is enabled: +// +// HTTP | gRPC +// -----|----- +// `PATCH /v1/messages/123456 { "text": "Hi!" }` | `UpdateMessage(message_id: +// "123456" text: "Hi!")` +// +// Note that when using `*` in the body mapping, it is not possible to +// have HTTP parameters, as all fields not bound by the path end in +// the body. This makes this option more rarely used in practice when +// defining REST APIs. The common usage of `*` is in custom methods +// which don't use the URL at all for transferring data. +// +// It is possible to define multiple HTTP methods for one RPC by using +// the `additional_bindings` option. Example: +// +// service Messaging { +// rpc GetMessage(GetMessageRequest) returns (Message) { +// option (google.api.http) = { +// get: "/v1/messages/{message_id}" +// additional_bindings { +// get: "/v1/users/{user_id}/messages/{message_id}" +// } +// }; +// } +// } +// message GetMessageRequest { +// string message_id = 1; +// string user_id = 2; +// } +// +// This enables the following two alternative HTTP JSON to RPC mappings: +// +// HTTP | gRPC +// -----|----- +// `GET /v1/messages/123456` | `GetMessage(message_id: "123456")` +// `GET /v1/users/me/messages/123456` | `GetMessage(user_id: "me" message_id: +// "123456")` +// +// ## Rules for HTTP mapping +// +// 1. Leaf request fields (recursive expansion nested messages in the request +// message) are classified into three categories: +// - Fields referred by the path template. They are passed via the URL path. +// - Fields referred by the [HttpRule.body][google.api.HttpRule.body]. They +// are passed via the HTTP +// request body. +// - All other fields are passed via the URL query parameters, and the +// parameter name is the field path in the request message. A repeated +// field can be represented as multiple query parameters under the same +// name. +// 2. If [HttpRule.body][google.api.HttpRule.body] is "*", there is no URL +// query parameter, all fields +// are passed via URL path and HTTP request body. +// 3. If [HttpRule.body][google.api.HttpRule.body] is omitted, there is no HTTP +// request body, all +// fields are passed via URL path and URL query parameters. +// +// ### Path template syntax +// +// Template = "/" Segments [ Verb ] ; +// Segments = Segment { "/" Segment } ; +// Segment = "*" | "**" | LITERAL | Variable ; +// Variable = "{" FieldPath [ "=" Segments ] "}" ; +// FieldPath = IDENT { "." IDENT } ; +// Verb = ":" LITERAL ; +// +// The syntax `*` matches a single URL path segment. The syntax `**` matches +// zero or more URL path segments, which must be the last part of the URL path +// except the `Verb`. +// +// The syntax `Variable` matches part of the URL path as specified by its +// template. A variable template must not contain other variables. If a variable +// matches a single path segment, its template may be omitted, e.g. `{var}` +// is equivalent to `{var=*}`. +// +// The syntax `LITERAL` matches literal text in the URL path. If the `LITERAL` +// contains any reserved character, such characters should be percent-encoded +// before the matching. +// +// If a variable contains exactly one path segment, such as `"{var}"` or +// `"{var=*}"`, when such a variable is expanded into a URL path on the client +// side, all characters except `[-_.~0-9a-zA-Z]` are percent-encoded. The +// server side does the reverse decoding. Such variables show up in the +// [Discovery +// Document](https://developers.google.com/discovery/v1/reference/apis) as +// `{var}`. +// +// If a variable contains multiple path segments, such as `"{var=foo/*}"` +// or `"{var=**}"`, when such a variable is expanded into a URL path on the +// client side, all characters except `[-_.~/0-9a-zA-Z]` are percent-encoded. +// The server side does the reverse decoding, except "%2F" and "%2f" are left +// unchanged. Such variables show up in the +// [Discovery +// Document](https://developers.google.com/discovery/v1/reference/apis) as +// `{+var}`. +// +// ## Using gRPC API Service Configuration +// +// gRPC API Service Configuration (service config) is a configuration language +// for configuring a gRPC service to become a user-facing product. The +// service config is simply the YAML representation of the `google.api.Service` +// proto message. +// +// As an alternative to annotating your proto file, you can configure gRPC +// transcoding in your service config YAML files. You do this by specifying a +// `HttpRule` that maps the gRPC method to a REST endpoint, achieving the same +// effect as the proto annotation. This can be particularly useful if you +// have a proto that is reused in multiple services. Note that any transcoding +// specified in the service config will override any matching transcoding +// configuration in the proto. +// +// Example: +// +// http: +// rules: +// # Selects a gRPC method and applies HttpRule to it. +// - selector: example.v1.Messaging.GetMessage +// get: /v1/messages/{message_id}/{sub.subfield} +// +// ## Special notes +// +// When gRPC Transcoding is used to map a gRPC to JSON REST endpoints, the +// proto to JSON conversion must follow the [proto3 +// specification](https://developers.google.com/protocol-buffers/docs/proto3#json). +// +// While the single segment variable follows the semantics of +// [RFC 6570](https://tools.ietf.org/html/rfc6570) Section 3.2.2 Simple String +// Expansion, the multi segment variable **does not** follow RFC 6570 Section +// 3.2.3 Reserved Expansion. The reason is that the Reserved Expansion +// does not expand special characters like `?` and `#`, which would lead +// to invalid URLs. As the result, gRPC Transcoding uses a custom encoding +// for multi segment variables. +// +// The path variables **must not** refer to any repeated or mapped field, +// because client libraries are not capable of handling such variable expansion. +// +// The path variables **must not** capture the leading "/" character. The reason +// is that the most common use case "{var}" does not capture the leading "/" +// character. For consistency, all path variables must share the same behavior. +// +// Repeated message fields must not be mapped to URL query parameters, because +// no client library can support such complicated mapping. +// +// If an API needs to use a JSON array for request or response body, it can map +// the request or response body to a repeated field. However, some gRPC +// Transcoding implementations may not support this feature. +message HttpRule { + // Selects a method to which this rule applies. + // + // Refer to [selector][google.api.DocumentationRule.selector] for syntax + // details. + string selector = 1; + + // Determines the URL pattern is matched by this rules. This pattern can be + // used with any of the {get|put|post|delete|patch} methods. A custom method + // can be defined using the 'custom' field. + oneof pattern { + // Maps to HTTP GET. Used for listing and getting information about + // resources. + string get = 2; + + // Maps to HTTP PUT. Used for replacing a resource. + string put = 3; + + // Maps to HTTP POST. Used for creating a resource or performing an action. + string post = 4; + + // Maps to HTTP DELETE. Used for deleting a resource. + string delete = 5; + + // Maps to HTTP PATCH. Used for updating a resource. + string patch = 6; + + // The custom pattern is used for specifying an HTTP method that is not + // included in the `pattern` field, such as HEAD, or "*" to leave the + // HTTP method unspecified for this rule. The wild-card rule is useful + // for services that provide content to Web (HTML) clients. + CustomHttpPattern custom = 8; + } + + // The name of the request field whose value is mapped to the HTTP request + // body, or `*` for mapping all request fields not captured by the path + // pattern to the HTTP body, or omitted for not having any HTTP request body. + // + // NOTE: the referred field must be present at the top-level of the request + // message type. + string body = 7; + + // Optional. The name of the response field whose value is mapped to the HTTP + // response body. When omitted, the entire response message will be used + // as the HTTP response body. + // + // NOTE: The referred field must be present at the top-level of the response + // message type. + string response_body = 12; + + // Additional HTTP bindings for the selector. Nested bindings must + // not contain an `additional_bindings` field themselves (that is, + // the nesting may only be one level deep). + repeated HttpRule additional_bindings = 11; +} + +// A custom pattern is used for defining custom HTTP verb. +message CustomHttpPattern { + // The name of this custom HTTP verb. + string kind = 1; + + // The path matched by this custom verb. + string path = 2; +} diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-http-draft-oneof/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/rpc-http-draft-oneof/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..c08777245 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/rpc-http-draft-oneof/input/temporal/api_next/fixture.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; +package fixture; +import "google/api/annotations.proto"; +import "temporal/api_next/protometa/v1/draft.proto"; +message Request { oneof selection { option (temporal.api.protometa.v1.draft_oneof) = "preview"; string draft_id = 1; } } +message Response {} +service Service { + rpc Call (Request) returns (Response) { + option (google.api.http) = { get: "/items/{draft_id=items/*}" }; + } +} diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-http-draft-oneof/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/rpc-http-draft-oneof/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..44dde8528 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/rpc-http-draft-oneof/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98111; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-http-nested/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/rpc-http-nested/input/temporal/api_next/protometa/v1/draft.proto index 03c5c5701..44dde8528 100644 --- a/cmd/generate-stable-protos/testdata/classification/rpc-http-nested/input/temporal/api_next/protometa/v1/draft.proto +++ b/cmd/generate-stable-protos/testdata/classification/rpc-http-nested/input/temporal/api_next/protometa/v1/draft.proto @@ -7,5 +7,4 @@ extend google.protobuf.EnumOptions { string draft_enum = 98008; } extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } extend google.protobuf.ServiceOptions { string draft_service = 98008; } extend google.protobuf.MethodOptions { string draft_method = 98008; } -extend google.protobuf.FileOptions { string draft_file = 98008; } -extend google.protobuf.OneofOptions { string draft_oneof = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-http-path/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/rpc-http-path/input/temporal/api_next/fixture.proto index 70c32437b..6da9c9bc6 100644 --- a/cmd/generate-stable-protos/testdata/classification/rpc-http-path/input/temporal/api_next/fixture.proto +++ b/cmd/generate-stable-protos/testdata/classification/rpc-http-path/input/temporal/api_next/fixture.proto @@ -4,7 +4,16 @@ import "google/api/annotations.proto"; import "temporal/api_next/protometa/v1/draft.proto"; message Request { string draft_id = 1 [(temporal.api.protometa.v1.draft) = "feature-a"]; } message Response {} +message PreviewRequest { + option (temporal.api.protometa.v1.draft_message) = "preview"; +} +message PreviewResponse { + option (temporal.api.protometa.v1.draft_message) = "preview"; +} service Service { + rpc Preview (PreviewRequest) returns (PreviewResponse) { + option (temporal.api.protometa.v1.draft_method) = "preview"; + } rpc Call (Request) returns (Response) { option (google.api.http) = { get: "/items/{draft_id=items/*}" }; } diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-http-path/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/rpc-http-path/input/temporal/api_next/protometa/v1/draft.proto index 03c5c5701..44dde8528 100644 --- a/cmd/generate-stable-protos/testdata/classification/rpc-http-path/input/temporal/api_next/protometa/v1/draft.proto +++ b/cmd/generate-stable-protos/testdata/classification/rpc-http-path/input/temporal/api_next/protometa/v1/draft.proto @@ -7,5 +7,4 @@ extend google.protobuf.EnumOptions { string draft_enum = 98008; } extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } extend google.protobuf.ServiceOptions { string draft_service = 98008; } extend google.protobuf.MethodOptions { string draft_method = 98008; } -extend google.protobuf.FileOptions { string draft_file = 98008; } -extend google.protobuf.OneofOptions { string draft_oneof = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-http-response-body/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/rpc-http-response-body/input/temporal/api_next/protometa/v1/draft.proto index 03c5c5701..44dde8528 100644 --- a/cmd/generate-stable-protos/testdata/classification/rpc-http-response-body/input/temporal/api_next/protometa/v1/draft.proto +++ b/cmd/generate-stable-protos/testdata/classification/rpc-http-response-body/input/temporal/api_next/protometa/v1/draft.proto @@ -7,5 +7,4 @@ extend google.protobuf.EnumOptions { string draft_enum = 98008; } extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } extend google.protobuf.ServiceOptions { string draft_service = 98008; } extend google.protobuf.MethodOptions { string draft_method = 98008; } -extend google.protobuf.FileOptions { string draft_file = 98008; } -extend google.protobuf.OneofOptions { string draft_oneof = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-http-stable/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/rpc-http-stable/input/temporal/api_next/protometa/v1/draft.proto index 03c5c5701..44dde8528 100644 --- a/cmd/generate-stable-protos/testdata/classification/rpc-http-stable/input/temporal/api_next/protometa/v1/draft.proto +++ b/cmd/generate-stable-protos/testdata/classification/rpc-http-stable/input/temporal/api_next/protometa/v1/draft.proto @@ -7,5 +7,4 @@ extend google.protobuf.EnumOptions { string draft_enum = 98008; } extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } extend google.protobuf.ServiceOptions { string draft_service = 98008; } extend google.protobuf.MethodOptions { string draft_method = 98008; } -extend google.protobuf.FileOptions { string draft_file = 98008; } -extend google.protobuf.OneofOptions { string draft_oneof = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-inherited-input/expected.json b/cmd/generate-stable-protos/testdata/classification/rpc-inherited-input/expected.json new file mode 100644 index 000000000..8c6402d70 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/rpc-inherited-input/expected.json @@ -0,0 +1,3 @@ +{ + "error": "fixture.Service.Call: RPC references draft type fixture.Draft.Nested as its request; inherited draft status is insufficient, so use a type that explicitly carries draft_message and give draft_method and both endpoints the same feature" +} diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-inherited-input/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/rpc-inherited-input/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..bb6c64627 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/rpc-inherited-input/input/temporal/api_next/fixture.proto @@ -0,0 +1,6 @@ +syntax = "proto3"; +package fixture; +import "temporal/api_next/protometa/v1/draft.proto"; +message Draft { option (temporal.api.protometa.v1.draft_message) = "feature-a"; message Nested {} } +message Stable {} +service Service { rpc Call (Draft.Nested) returns (Stable); } diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-inherited-input/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/rpc-inherited-input/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..44dde8528 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/rpc-inherited-input/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98111; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-input/expected.json b/cmd/generate-stable-protos/testdata/classification/rpc-input/expected.json index 7ca4feb3b..2766e1533 100644 --- a/cmd/generate-stable-protos/testdata/classification/rpc-input/expected.json +++ b/cmd/generate-stable-protos/testdata/classification/rpc-input/expected.json @@ -1,3 +1,3 @@ { - "error": "RPC references draft type" + "error": "fixture.Service.Call: RPC references draft type fixture.Draft as its request and requires draft_method" } diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-input/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/rpc-input/input/temporal/api_next/protometa/v1/draft.proto index 03c5c5701..44dde8528 100644 --- a/cmd/generate-stable-protos/testdata/classification/rpc-input/input/temporal/api_next/protometa/v1/draft.proto +++ b/cmd/generate-stable-protos/testdata/classification/rpc-input/input/temporal/api_next/protometa/v1/draft.proto @@ -7,5 +7,4 @@ extend google.protobuf.EnumOptions { string draft_enum = 98008; } extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } extend google.protobuf.ServiceOptions { string draft_service = 98008; } extend google.protobuf.MethodOptions { string draft_method = 98008; } -extend google.protobuf.FileOptions { string draft_file = 98008; } -extend google.protobuf.OneofOptions { string draft_oneof = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-output/expected.json b/cmd/generate-stable-protos/testdata/classification/rpc-output/expected.json index 7ca4feb3b..31e711440 100644 --- a/cmd/generate-stable-protos/testdata/classification/rpc-output/expected.json +++ b/cmd/generate-stable-protos/testdata/classification/rpc-output/expected.json @@ -1,3 +1,3 @@ { - "error": "RPC references draft type" + "error": "fixture.Service.Call: RPC references draft type fixture.Draft as its response and requires draft_method" } diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-output/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/rpc-output/input/temporal/api_next/protometa/v1/draft.proto index 03c5c5701..44dde8528 100644 --- a/cmd/generate-stable-protos/testdata/classification/rpc-output/input/temporal/api_next/protometa/v1/draft.proto +++ b/cmd/generate-stable-protos/testdata/classification/rpc-output/input/temporal/api_next/protometa/v1/draft.proto @@ -7,5 +7,4 @@ extend google.protobuf.EnumOptions { string draft_enum = 98008; } extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } extend google.protobuf.ServiceOptions { string draft_service = 98008; } extend google.protobuf.MethodOptions { string draft_method = 98008; } -extend google.protobuf.FileOptions { string draft_file = 98008; } -extend google.protobuf.OneofOptions { string draft_oneof = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-request-header/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/rpc-request-header/input/temporal/api_next/protometa/v1/draft.proto index 03c5c5701..44dde8528 100644 --- a/cmd/generate-stable-protos/testdata/classification/rpc-request-header/input/temporal/api_next/protometa/v1/draft.proto +++ b/cmd/generate-stable-protos/testdata/classification/rpc-request-header/input/temporal/api_next/protometa/v1/draft.proto @@ -7,5 +7,4 @@ extend google.protobuf.EnumOptions { string draft_enum = 98008; } extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } extend google.protobuf.ServiceOptions { string draft_service = 98008; } extend google.protobuf.MethodOptions { string draft_method = 98008; } -extend google.protobuf.FileOptions { string draft_file = 98008; } -extend google.protobuf.OneofOptions { string draft_oneof = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-reuse-cross-file/expected.json b/cmd/generate-stable-protos/testdata/classification/rpc-reuse-cross-file/expected.json new file mode 100644 index 000000000..100e84ca8 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/rpc-reuse-cross-file/expected.json @@ -0,0 +1,3 @@ +{ + "error": "fixture.Request: RPC endpoint type is reused at fixture.First.Call request and fixture.Second.Call response" +} diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-reuse-cross-file/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/rpc-reuse-cross-file/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..749b17fb6 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/rpc-reuse-cross-file/input/temporal/api_next/fixture.proto @@ -0,0 +1,12 @@ +syntax = "proto3"; +package fixture; +import "temporal/api_next/protometa/v1/draft.proto"; +message Request { option (temporal.api.protometa.v1.draft_message) = "preview"; } +message Response { option (temporal.api.protometa.v1.draft_message) = "preview"; } +service First { + rpc Ping(Stable) returns (Stable); + rpc Call(Request) returns (Response) { + option (temporal.api.protometa.v1.draft_method) = "preview"; + } +} +message Stable {} diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-reuse-cross-file/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/rpc-reuse-cross-file/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..def18ac5d --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/rpc-reuse-cross-file/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98008; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-reuse-cross-file/input/temporal/api_next/second.proto b/cmd/generate-stable-protos/testdata/classification/rpc-reuse-cross-file/input/temporal/api_next/second.proto new file mode 100644 index 000000000..f243a8cf8 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/rpc-reuse-cross-file/input/temporal/api_next/second.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; +package fixture; +import "temporal/api_next/fixture.proto"; +import "temporal/api_next/protometa/v1/draft.proto"; +message OtherRequest { option (temporal.api.protometa.v1.draft_message) = "preview"; } +service Second { + option (temporal.api.protometa.v1.draft_service) = "preview"; + rpc Call(OtherRequest) returns (Request); +} diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-reuse-draft/expected.json b/cmd/generate-stable-protos/testdata/classification/rpc-reuse-draft/expected.json new file mode 100644 index 000000000..99b2bcb87 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/rpc-reuse-draft/expected.json @@ -0,0 +1,3 @@ +{ + "error": "fixture.Request: RPC endpoint type is reused at fixture.Service.Call request and fixture.Service.Other request" +} diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-reuse-draft/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/rpc-reuse-draft/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..e85579b01 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/rpc-reuse-draft/input/temporal/api_next/fixture.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; +package fixture; +import "temporal/api_next/protometa/v1/draft.proto"; +message Request { option (temporal.api.protometa.v1.draft_message) = "preview"; } +message Response { option (temporal.api.protometa.v1.draft_message) = "preview"; } +message OtherResponse { option (temporal.api.protometa.v1.draft_message) = "preview"; } +service Service { + option (temporal.api.protometa.v1.draft_service) = "preview"; + rpc Call(Request) returns (Response); + rpc Other(Request) returns (OtherResponse); +} diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-reuse-draft/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/rpc-reuse-draft/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..def18ac5d --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/rpc-reuse-draft/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98008; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-same-request-response/expected.json b/cmd/generate-stable-protos/testdata/classification/rpc-same-request-response/expected.json new file mode 100644 index 000000000..fa65d7c36 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/rpc-same-request-response/expected.json @@ -0,0 +1,3 @@ +{ + "error": "fixture.Service.Call: RPC uses fixture.Request as both request and response" +} diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-same-request-response/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/rpc-same-request-response/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..d0ab4b282 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/rpc-same-request-response/input/temporal/api_next/fixture.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; +package fixture; +import "temporal/api_next/protometa/v1/draft.proto"; +message Request { option (temporal.api.protometa.v1.draft_message) = "preview"; } +service Service { + rpc Ping(Stable) returns (Stable); + rpc Call(Request) returns (Request) { + option (temporal.api.protometa.v1.draft_method) = "preview"; + } +} +message Stable {} diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-same-request-response/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/rpc-same-request-response/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..def18ac5d --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/rpc-same-request-response/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98008; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-stable-shared-endpoints/expected.json b/cmd/generate-stable-protos/testdata/classification/rpc-stable-shared-endpoints/expected.json new file mode 100644 index 000000000..b7363b0cd --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/rpc-stable-shared-endpoints/expected.json @@ -0,0 +1,3 @@ +{ + "annotations": {} +} diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-stable-shared-endpoints/expected/temporal/api/fixture.proto b/cmd/generate-stable-protos/testdata/classification/rpc-stable-shared-endpoints/expected/temporal/api/fixture.proto new file mode 100644 index 000000000..22abf329d --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/rpc-stable-shared-endpoints/expected/temporal/api/fixture.proto @@ -0,0 +1,12 @@ +syntax = "proto3"; +package fixture; + +import "google/protobuf/empty.proto"; +message Request {} +service First { + rpc Ping(google.protobuf.Empty) returns (google.protobuf.Empty); + rpc Call(Request) returns (google.protobuf.Empty); +} +service Second { + rpc Call(Request) returns (google.protobuf.Empty); +} diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-stable-shared-endpoints/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/rpc-stable-shared-endpoints/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..51db54221 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/rpc-stable-shared-endpoints/input/temporal/api_next/fixture.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; +package fixture; +import "google/protobuf/empty.proto"; +message Request {} +service First { + rpc Ping(google.protobuf.Empty) returns (google.protobuf.Empty); + rpc Call(Request) returns (google.protobuf.Empty); +} +service Second { + rpc Call(Request) returns (google.protobuf.Empty); +} diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-stable-shared-endpoints/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/rpc-stable-shared-endpoints/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..def18ac5d --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/rpc-stable-shared-endpoints/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98008; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/service-inherited-endpoint/expected.json b/cmd/generate-stable-protos/testdata/classification/service-inherited-endpoint/expected.json new file mode 100644 index 000000000..032d252ba --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/service-inherited-endpoint/expected.json @@ -0,0 +1,3 @@ +{ + "error": "fixture.Service.Call: draft_service requires request type fixture.Outer.Nested to explicitly carry draft_message = \"preview\"" +} diff --git a/cmd/generate-stable-protos/testdata/classification/service-inherited-endpoint/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/service-inherited-endpoint/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..c7d022748 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/service-inherited-endpoint/input/temporal/api_next/fixture.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; +package fixture; +import "temporal/api_next/protometa/v1/draft.proto"; +message Outer { option (temporal.api.protometa.v1.draft_message) = "preview"; message Nested {} } +message Response { option (temporal.api.protometa.v1.draft_message) = "preview"; } +service Service { + option (temporal.api.protometa.v1.draft_service) = "preview"; + rpc Call(Outer.Nested) returns (Response); +} diff --git a/cmd/generate-stable-protos/testdata/classification/service-inherited-endpoint/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/service-inherited-endpoint/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..def18ac5d --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/service-inherited-endpoint/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98008; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/service-request-feature-mismatch/expected.json b/cmd/generate-stable-protos/testdata/classification/service-request-feature-mismatch/expected.json new file mode 100644 index 000000000..b7d120515 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/service-request-feature-mismatch/expected.json @@ -0,0 +1,3 @@ +{ + "error": "fixture.Service.Call: draft_service requires request type fixture.Request to explicitly carry draft_message = \"preview\"; found \"Preview\"" +} diff --git a/cmd/generate-stable-protos/testdata/classification/service-request-feature-mismatch/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/service-request-feature-mismatch/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..589bbe3e3 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/service-request-feature-mismatch/input/temporal/api_next/fixture.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; +package fixture; +import "temporal/api_next/protometa/v1/draft.proto"; +message Request { option (temporal.api.protometa.v1.draft_message) = "Preview"; } +message Response { option (temporal.api.protometa.v1.draft_message) = "preview"; } +service Service { + option (temporal.api.protometa.v1.draft_service) = "preview"; + rpc Call(Request) returns (Response); +} diff --git a/cmd/generate-stable-protos/testdata/classification/service-request-feature-mismatch/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/service-request-feature-mismatch/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..def18ac5d --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/service-request-feature-mismatch/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98008; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/service-response-feature-mismatch/expected.json b/cmd/generate-stable-protos/testdata/classification/service-response-feature-mismatch/expected.json new file mode 100644 index 000000000..20b2419bc --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/service-response-feature-mismatch/expected.json @@ -0,0 +1,3 @@ +{ + "error": "fixture.Service.Call: draft_service requires response type fixture.Response to explicitly carry draft_message = \"preview\"; found \"other\"" +} diff --git a/cmd/generate-stable-protos/testdata/classification/service-response-feature-mismatch/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/service-response-feature-mismatch/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..f6ccfef59 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/service-response-feature-mismatch/input/temporal/api_next/fixture.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; +package fixture; +import "temporal/api_next/protometa/v1/draft.proto"; +message Request { option (temporal.api.protometa.v1.draft_message) = "preview"; } +message Response { option (temporal.api.protometa.v1.draft_message) = "other"; } +service Service { + option (temporal.api.protometa.v1.draft_service) = "preview"; + rpc Call(Request) returns (Response); +} diff --git a/cmd/generate-stable-protos/testdata/classification/service-response-feature-mismatch/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/service-response-feature-mismatch/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..def18ac5d --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/service-response-feature-mismatch/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98008; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/service-stable-request/expected.json b/cmd/generate-stable-protos/testdata/classification/service-stable-request/expected.json new file mode 100644 index 000000000..ed40d1f26 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/service-stable-request/expected.json @@ -0,0 +1,3 @@ +{ + "error": "fixture.Service.Call: draft_service requires request type fixture.Request to explicitly carry draft_message = \"preview\"" +} diff --git a/cmd/generate-stable-protos/testdata/classification/service-stable-request/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/service-stable-request/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..7660442b6 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/service-stable-request/input/temporal/api_next/fixture.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; +package fixture; +import "temporal/api_next/protometa/v1/draft.proto"; +message Request {} +message Response { option (temporal.api.protometa.v1.draft_message) = "preview"; } +service Service { + option (temporal.api.protometa.v1.draft_service) = "preview"; + rpc Call(Request) returns (Response); +} diff --git a/cmd/generate-stable-protos/testdata/classification/service-stable-request/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/service-stable-request/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..def18ac5d --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/service-stable-request/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98008; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/service-stable-response/expected.json b/cmd/generate-stable-protos/testdata/classification/service-stable-response/expected.json new file mode 100644 index 000000000..6f2daa9ba --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/service-stable-response/expected.json @@ -0,0 +1,3 @@ +{ + "error": "fixture.Service.Call: draft_service requires response type fixture.Response to explicitly carry draft_message = \"preview\"" +} diff --git a/cmd/generate-stable-protos/testdata/classification/service-stable-response/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/service-stable-response/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..358a17983 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/service-stable-response/input/temporal/api_next/fixture.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; +package fixture; +import "temporal/api_next/protometa/v1/draft.proto"; +message Request { option (temporal.api.protometa.v1.draft_message) = "preview"; } +message Response {} +service Service { + option (temporal.api.protometa.v1.draft_service) = "preview"; + rpc Call(Request) returns (Response); +} diff --git a/cmd/generate-stable-protos/testdata/classification/service-stable-response/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/service-stable-response/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..def18ac5d --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/service-stable-response/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98008; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/trailing-whitespace/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/trailing-whitespace/input/temporal/api_next/protometa/v1/draft.proto index 79bdf536c..def18ac5d 100644 --- a/cmd/generate-stable-protos/testdata/classification/trailing-whitespace/input/temporal/api_next/protometa/v1/draft.proto +++ b/cmd/generate-stable-protos/testdata/classification/trailing-whitespace/input/temporal/api_next/protometa/v1/draft.proto @@ -7,5 +7,4 @@ extend google.protobuf.EnumOptions { string draft_enum = 98008; } extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } extend google.protobuf.ServiceOptions { string draft_service = 98008; } extend google.protobuf.MethodOptions { string draft_method = 98008; } -extend google.protobuf.FileOptions { string draft_file = 98008; } -extend google.protobuf.OneofOptions { string draft_oneof = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/unsupported-enum-value/expected.json b/cmd/generate-stable-protos/testdata/classification/unsupported-enum-value/expected.json deleted file mode 100644 index 9c77d358b..000000000 --- a/cmd/generate-stable-protos/testdata/classification/unsupported-enum-value/expected.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "error": "unsupported draft annotation on enum value" -} diff --git a/cmd/generate-stable-protos/testdata/classification/unsupported-enum-value/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/unsupported-enum-value/input/temporal/api_next/fixture.proto deleted file mode 100644 index 577e62658..000000000 --- a/cmd/generate-stable-protos/testdata/classification/unsupported-enum-value/input/temporal/api_next/fixture.proto +++ /dev/null @@ -1,4 +0,0 @@ -syntax = "proto3"; -package fixture; -import "temporal/api_next/protometa/v1/draft.proto"; -enum Example { ZERO = 0 [(temporal.api.protometa.v1.draft_enum_value) = "feature-a"]; } diff --git a/cmd/generate-stable-protos/testdata/classification/unsupported-enum/expected.json b/cmd/generate-stable-protos/testdata/classification/unsupported-enum/expected.json deleted file mode 100644 index 788900dea..000000000 --- a/cmd/generate-stable-protos/testdata/classification/unsupported-enum/expected.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "error": "unsupported draft annotation on enum" -} diff --git a/cmd/generate-stable-protos/testdata/classification/unsupported-extension/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/unsupported-extension/input/temporal/api_next/protometa/v1/draft.proto index 79bdf536c..def18ac5d 100644 --- a/cmd/generate-stable-protos/testdata/classification/unsupported-extension/input/temporal/api_next/protometa/v1/draft.proto +++ b/cmd/generate-stable-protos/testdata/classification/unsupported-extension/input/temporal/api_next/protometa/v1/draft.proto @@ -7,5 +7,4 @@ extend google.protobuf.EnumOptions { string draft_enum = 98008; } extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } extend google.protobuf.ServiceOptions { string draft_service = 98008; } extend google.protobuf.MethodOptions { string draft_method = 98008; } -extend google.protobuf.FileOptions { string draft_file = 98008; } -extend google.protobuf.OneofOptions { string draft_oneof = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/unsupported-file/expected.json b/cmd/generate-stable-protos/testdata/classification/unsupported-file/expected.json deleted file mode 100644 index cd8235ba9..000000000 --- a/cmd/generate-stable-protos/testdata/classification/unsupported-file/expected.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "error": "unsupported draft annotation on file" -} diff --git a/cmd/generate-stable-protos/testdata/classification/unsupported-method/expected.json b/cmd/generate-stable-protos/testdata/classification/unsupported-method/expected.json deleted file mode 100644 index 9fb988286..000000000 --- a/cmd/generate-stable-protos/testdata/classification/unsupported-method/expected.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "error": "unsupported draft annotation on method" -} diff --git a/cmd/generate-stable-protos/testdata/classification/unsupported-method/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/unsupported-method/input/temporal/api_next/fixture.proto deleted file mode 100644 index 666cce725..000000000 --- a/cmd/generate-stable-protos/testdata/classification/unsupported-method/input/temporal/api_next/fixture.proto +++ /dev/null @@ -1,4 +0,0 @@ -syntax = "proto3"; -package fixture; -import "temporal/api_next/protometa/v1/draft.proto"; -message Example {} service Service { rpc Call(Example) returns (Example) { option (temporal.api.protometa.v1.draft_method) = "feature-a"; } } diff --git a/cmd/generate-stable-protos/testdata/classification/unsupported-oneof/expected.json b/cmd/generate-stable-protos/testdata/classification/unsupported-oneof/expected.json deleted file mode 100644 index 0ff7dc143..000000000 --- a/cmd/generate-stable-protos/testdata/classification/unsupported-oneof/expected.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "error": "unsupported draft annotation on oneof" -} diff --git a/cmd/generate-stable-protos/testdata/classification/unsupported-oneof/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/unsupported-oneof/input/temporal/api_next/protometa/v1/draft.proto deleted file mode 100644 index 79bdf536c..000000000 --- a/cmd/generate-stable-protos/testdata/classification/unsupported-oneof/input/temporal/api_next/protometa/v1/draft.proto +++ /dev/null @@ -1,11 +0,0 @@ -syntax = "proto3"; -package temporal.api.protometa.v1; -import "google/protobuf/descriptor.proto"; -extend google.protobuf.FieldOptions { string draft = 98008; } -extend google.protobuf.MessageOptions { string draft_message = 98008; } -extend google.protobuf.EnumOptions { string draft_enum = 98008; } -extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } -extend google.protobuf.ServiceOptions { string draft_service = 98008; } -extend google.protobuf.MethodOptions { string draft_method = 98008; } -extend google.protobuf.FileOptions { string draft_file = 98008; } -extend google.protobuf.OneofOptions { string draft_oneof = 98008; } diff --git a/cmd/generate-stable-protos/testdata/classification/unsupported-service/expected.json b/cmd/generate-stable-protos/testdata/classification/unsupported-service/expected.json deleted file mode 100644 index f51cbd3ff..000000000 --- a/cmd/generate-stable-protos/testdata/classification/unsupported-service/expected.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "error": "unsupported draft annotation on service" -} diff --git a/cmd/generate-stable-protos/testdata/classification/unsupported-service/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/unsupported-service/input/temporal/api_next/fixture.proto deleted file mode 100644 index 5df5882c6..000000000 --- a/cmd/generate-stable-protos/testdata/classification/unsupported-service/input/temporal/api_next/fixture.proto +++ /dev/null @@ -1,4 +0,0 @@ -syntax = "proto3"; -package fixture; -import "temporal/api_next/protometa/v1/draft.proto"; -message Example {} service Service { option (temporal.api.protometa.v1.draft_service) = "feature-a"; rpc Call(Example) returns (Example); } diff --git a/cmd/generate-stable-protos/testdata/classification/unsupported-service/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/unsupported-service/input/temporal/api_next/protometa/v1/draft.proto deleted file mode 100644 index 79bdf536c..000000000 --- a/cmd/generate-stable-protos/testdata/classification/unsupported-service/input/temporal/api_next/protometa/v1/draft.proto +++ /dev/null @@ -1,11 +0,0 @@ -syntax = "proto3"; -package temporal.api.protometa.v1; -import "google/protobuf/descriptor.proto"; -extend google.protobuf.FieldOptions { string draft = 98008; } -extend google.protobuf.MessageOptions { string draft_message = 98008; } -extend google.protobuf.EnumOptions { string draft_enum = 98008; } -extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } -extend google.protobuf.ServiceOptions { string draft_service = 98008; } -extend google.protobuf.MethodOptions { string draft_method = 98008; } -extend google.protobuf.FileOptions { string draft_file = 98008; } -extend google.protobuf.OneofOptions { string draft_oneof = 98008; } diff --git a/cmd/generate-stable-protos/testdata/classification/valid/expected.json b/cmd/generate-stable-protos/testdata/classification/valid/expected.json index 0c140cb07..8562b0e7a 100644 --- a/cmd/generate-stable-protos/testdata/classification/valid/expected.json +++ b/cmd/generate-stable-protos/testdata/classification/valid/expected.json @@ -3,8 +3,6 @@ "fixture.Example.a": "feature-a", "fixture.Example.optional_b": "feature-b", "fixture.Example.draft_choice": "feature-a", - "fixture.Example.draft_one": "feature-a", - "fixture.Example.draft_two": "feature-b", "fixture.Example.Child.draft": "feature-b", "fixture.Example.draft_list": "feature-a", "fixture.Example.draft_map": "feature-b" diff --git a/cmd/generate-stable-protos/testdata/classification/valid/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/valid/input/temporal/api_next/fixture.proto index 47c43c766..b7b65707d 100644 --- a/cmd/generate-stable-protos/testdata/classification/valid/input/temporal/api_next/fixture.proto +++ b/cmd/generate-stable-protos/testdata/classification/valid/input/temporal/api_next/fixture.proto @@ -12,10 +12,6 @@ message Example { string stable_choice = 6; int32 draft_choice = 7 [(temporal.api.protometa.v1.draft) = "feature-a"]; } - oneof all_draft { - string draft_one = 8 [(temporal.api.protometa.v1.draft) = "feature-a"]; - bool draft_two = 9 [(temporal.api.protometa.v1.draft) = "feature-b"]; - } message Child { // Stable child comment. string stable = 1; diff --git a/cmd/generate-stable-protos/testdata/classification/valid/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/valid/input/temporal/api_next/protometa/v1/draft.proto index 03c5c5701..44dde8528 100644 --- a/cmd/generate-stable-protos/testdata/classification/valid/input/temporal/api_next/protometa/v1/draft.proto +++ b/cmd/generate-stable-protos/testdata/classification/valid/input/temporal/api_next/protometa/v1/draft.proto @@ -7,5 +7,4 @@ extend google.protobuf.EnumOptions { string draft_enum = 98008; } extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } extend google.protobuf.ServiceOptions { string draft_service = 98008; } extend google.protobuf.MethodOptions { string draft_method = 98008; } -extend google.protobuf.FileOptions { string draft_file = 98008; } -extend google.protobuf.OneofOptions { string draft_oneof = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/whitespace/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/whitespace/input/temporal/api_next/protometa/v1/draft.proto index 79bdf536c..def18ac5d 100644 --- a/cmd/generate-stable-protos/testdata/classification/whitespace/input/temporal/api_next/protometa/v1/draft.proto +++ b/cmd/generate-stable-protos/testdata/classification/whitespace/input/temporal/api_next/protometa/v1/draft.proto @@ -7,5 +7,4 @@ extend google.protobuf.EnumOptions { string draft_enum = 98008; } extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } extend google.protobuf.ServiceOptions { string draft_service = 98008; } extend google.protobuf.MethodOptions { string draft_method = 98008; } -extend google.protobuf.FileOptions { string draft_file = 98008; } -extend google.protobuf.OneofOptions { string draft_oneof = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/comments/after-nested-draft-message/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/comments/after-nested-draft-message/input/temporal/api_next/protometa/v1/draft.proto index 03c5c5701..44dde8528 100644 --- a/cmd/generate-stable-protos/testdata/comments/after-nested-draft-message/input/temporal/api_next/protometa/v1/draft.proto +++ b/cmd/generate-stable-protos/testdata/comments/after-nested-draft-message/input/temporal/api_next/protometa/v1/draft.proto @@ -7,5 +7,4 @@ extend google.protobuf.EnumOptions { string draft_enum = 98008; } extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } extend google.protobuf.ServiceOptions { string draft_service = 98008; } extend google.protobuf.MethodOptions { string draft_method = 98008; } -extend google.protobuf.FileOptions { string draft_file = 98008; } -extend google.protobuf.OneofOptions { string draft_oneof = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/comments/attached/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/comments/attached/input/temporal/api_next/protometa/v1/draft.proto index 03c5c5701..44dde8528 100644 --- a/cmd/generate-stable-protos/testdata/comments/attached/input/temporal/api_next/protometa/v1/draft.proto +++ b/cmd/generate-stable-protos/testdata/comments/attached/input/temporal/api_next/protometa/v1/draft.proto @@ -7,5 +7,4 @@ extend google.protobuf.EnumOptions { string draft_enum = 98008; } extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } extend google.protobuf.ServiceOptions { string draft_service = 98008; } extend google.protobuf.MethodOptions { string draft_method = 98008; } -extend google.protobuf.FileOptions { string draft_file = 98008; } -extend google.protobuf.OneofOptions { string draft_oneof = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/comments/dangling-after-last-draft-field/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/comments/dangling-after-last-draft-field/input/temporal/api_next/protometa/v1/draft.proto index 03c5c5701..44dde8528 100644 --- a/cmd/generate-stable-protos/testdata/comments/dangling-after-last-draft-field/input/temporal/api_next/protometa/v1/draft.proto +++ b/cmd/generate-stable-protos/testdata/comments/dangling-after-last-draft-field/input/temporal/api_next/protometa/v1/draft.proto @@ -7,5 +7,4 @@ extend google.protobuf.EnumOptions { string draft_enum = 98008; } extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } extend google.protobuf.ServiceOptions { string draft_service = 98008; } extend google.protobuf.MethodOptions { string draft_method = 98008; } -extend google.protobuf.FileOptions { string draft_file = 98008; } -extend google.protobuf.OneofOptions { string draft_oneof = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/comments/detached-before-stable-field/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/comments/detached-before-stable-field/input/temporal/api_next/protometa/v1/draft.proto index 03c5c5701..44dde8528 100644 --- a/cmd/generate-stable-protos/testdata/comments/detached-before-stable-field/input/temporal/api_next/protometa/v1/draft.proto +++ b/cmd/generate-stable-protos/testdata/comments/detached-before-stable-field/input/temporal/api_next/protometa/v1/draft.proto @@ -7,5 +7,4 @@ extend google.protobuf.EnumOptions { string draft_enum = 98008; } extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } extend google.protobuf.ServiceOptions { string draft_service = 98008; } extend google.protobuf.MethodOptions { string draft_method = 98008; } -extend google.protobuf.FileOptions { string draft_file = 98008; } -extend google.protobuf.OneofOptions { string draft_oneof = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/comments/detached-section-header/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/comments/detached-section-header/input/temporal/api_next/protometa/v1/draft.proto index 03c5c5701..44dde8528 100644 --- a/cmd/generate-stable-protos/testdata/comments/detached-section-header/input/temporal/api_next/protometa/v1/draft.proto +++ b/cmd/generate-stable-protos/testdata/comments/detached-section-header/input/temporal/api_next/protometa/v1/draft.proto @@ -7,5 +7,4 @@ extend google.protobuf.EnumOptions { string draft_enum = 98008; } extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } extend google.protobuf.ServiceOptions { string draft_service = 98008; } extend google.protobuf.MethodOptions { string draft_method = 98008; } -extend google.protobuf.FileOptions { string draft_file = 98008; } -extend google.protobuf.OneofOptions { string draft_oneof = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/comments/end-of-file-after-draft-message/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/comments/end-of-file-after-draft-message/input/temporal/api_next/protometa/v1/draft.proto index 03c5c5701..44dde8528 100644 --- a/cmd/generate-stable-protos/testdata/comments/end-of-file-after-draft-message/input/temporal/api_next/protometa/v1/draft.proto +++ b/cmd/generate-stable-protos/testdata/comments/end-of-file-after-draft-message/input/temporal/api_next/protometa/v1/draft.proto @@ -7,5 +7,4 @@ extend google.protobuf.EnumOptions { string draft_enum = 98008; } extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } extend google.protobuf.ServiceOptions { string draft_service = 98008; } extend google.protobuf.MethodOptions { string draft_method = 98008; } -extend google.protobuf.FileOptions { string draft_file = 98008; } -extend google.protobuf.OneofOptions { string draft_oneof = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/comments/next-line-trailing/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/comments/next-line-trailing/input/temporal/api_next/protometa/v1/draft.proto index 03c5c5701..44dde8528 100644 --- a/cmd/generate-stable-protos/testdata/comments/next-line-trailing/input/temporal/api_next/protometa/v1/draft.proto +++ b/cmd/generate-stable-protos/testdata/comments/next-line-trailing/input/temporal/api_next/protometa/v1/draft.proto @@ -7,5 +7,4 @@ extend google.protobuf.EnumOptions { string draft_enum = 98008; } extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } extend google.protobuf.ServiceOptions { string draft_service = 98008; } extend google.protobuf.MethodOptions { string draft_method = 98008; } -extend google.protobuf.FileOptions { string draft_file = 98008; } -extend google.protobuf.OneofOptions { string draft_oneof = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/dangling/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/dangling/input/temporal/api_next/protometa/v1/draft.proto index 79bdf536c..def18ac5d 100644 --- a/cmd/generate-stable-protos/testdata/dangling/input/temporal/api_next/protometa/v1/draft.proto +++ b/cmd/generate-stable-protos/testdata/dangling/input/temporal/api_next/protometa/v1/draft.proto @@ -7,5 +7,4 @@ extend google.protobuf.EnumOptions { string draft_enum = 98008; } extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } extend google.protobuf.ServiceOptions { string draft_service = 98008; } extend google.protobuf.MethodOptions { string draft_method = 98008; } -extend google.protobuf.FileOptions { string draft_file = 98008; } -extend google.protobuf.OneofOptions { string draft_oneof = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/imports/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/imports/input/temporal/api_next/protometa/v1/draft.proto index 79bdf536c..def18ac5d 100644 --- a/cmd/generate-stable-protos/testdata/imports/input/temporal/api_next/protometa/v1/draft.proto +++ b/cmd/generate-stable-protos/testdata/imports/input/temporal/api_next/protometa/v1/draft.proto @@ -7,5 +7,4 @@ extend google.protobuf.EnumOptions { string draft_enum = 98008; } extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } extend google.protobuf.ServiceOptions { string draft_service = 98008; } extend google.protobuf.MethodOptions { string draft_method = 98008; } -extend google.protobuf.FileOptions { string draft_file = 98008; } -extend google.protobuf.OneofOptions { string draft_oneof = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/schema/legacy-options/expected.json b/cmd/generate-stable-protos/testdata/schema/legacy-options/expected.json new file mode 100644 index 000000000..446ed66ca --- /dev/null +++ b/cmd/generate-stable-protos/testdata/schema/legacy-options/expected.json @@ -0,0 +1,4 @@ +{ + "annotations": {}, + "validation_only": true +} diff --git a/cmd/generate-stable-protos/testdata/schema/legacy-options/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/schema/legacy-options/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..39eacdcdb --- /dev/null +++ b/cmd/generate-stable-protos/testdata/schema/legacy-options/input/temporal/api_next/fixture.proto @@ -0,0 +1,15 @@ +syntax = "proto2"; + +package fixture; + +import "temporal/api_next/protometa/v1/draft.proto"; + +option (temporal.api.protometa.v1.draft_file) = "legacy"; + +message Example { + extensions 100 to max; +} + +extend Example { + optional string value = 100 [(temporal.api.protometa.v1.draft_extension) = "legacy"]; +} diff --git a/cmd/generate-stable-protos/testdata/classification/unsupported-enum/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/schema/legacy-options/input/temporal/api_next/protometa/v1/draft.proto similarity index 81% rename from cmd/generate-stable-protos/testdata/classification/unsupported-enum/input/temporal/api_next/protometa/v1/draft.proto rename to cmd/generate-stable-protos/testdata/schema/legacy-options/input/temporal/api_next/protometa/v1/draft.proto index 79bdf536c..43b7e0e95 100644 --- a/cmd/generate-stable-protos/testdata/classification/unsupported-enum/input/temporal/api_next/protometa/v1/draft.proto +++ b/cmd/generate-stable-protos/testdata/schema/legacy-options/input/temporal/api_next/protometa/v1/draft.proto @@ -7,5 +7,6 @@ extend google.protobuf.EnumOptions { string draft_enum = 98008; } extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } extend google.protobuf.ServiceOptions { string draft_service = 98008; } extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } extend google.protobuf.FileOptions { string draft_file = 98008; } -extend google.protobuf.OneofOptions { string draft_oneof = 98008; } +extend google.protobuf.FieldOptions { string draft_extension = 98009; } diff --git a/cmd/generate-stable-protos/testdata/schema/removed-extension-option/expected.json b/cmd/generate-stable-protos/testdata/schema/removed-extension-option/expected.json new file mode 100644 index 000000000..261b495d7 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/schema/removed-extension-option/expected.json @@ -0,0 +1,3 @@ +{ + "error": "temporal.api.protometa.v1.draft_extension" +} diff --git a/cmd/generate-stable-protos/testdata/schema/removed-extension-option/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/schema/removed-extension-option/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..cb790e911 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/schema/removed-extension-option/input/temporal/api_next/fixture.proto @@ -0,0 +1,5 @@ +syntax = "proto2"; +package fixture; +import "temporal/api_next/protometa/v1/draft.proto"; +message Example { extensions 100 to max; } +extend Example { optional string value = 100 [(temporal.api.protometa.v1.draft_extension) = "preview"]; } diff --git a/cmd/generate-stable-protos/testdata/schema/removed-extension-option/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/schema/removed-extension-option/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..def18ac5d --- /dev/null +++ b/cmd/generate-stable-protos/testdata/schema/removed-extension-option/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98008; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/schema/unrelated-extension/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/schema/unrelated-extension/input/temporal/api_next/protometa/v1/draft.proto index 9be4b3dea..4a6996cbe 100644 --- a/cmd/generate-stable-protos/testdata/schema/unrelated-extension/input/temporal/api_next/protometa/v1/draft.proto +++ b/cmd/generate-stable-protos/testdata/schema/unrelated-extension/input/temporal/api_next/protometa/v1/draft.proto @@ -7,7 +7,6 @@ extend google.protobuf.EnumOptions { string draft_enum = 98008; } extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } extend google.protobuf.ServiceOptions { string draft_service = 98008; } extend google.protobuf.MethodOptions { string draft_method = 98008; } -extend google.protobuf.FileOptions { string draft_file = 98008; } -extend google.protobuf.OneofOptions { string draft_oneof = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } // An extension outside the draft name table is not a draft option and needs no schema check. extend google.protobuf.FileOptions { bool draft_notes = 98112; } diff --git a/cmd/generate-stable-protos/testdata/schema/unsupported-file/expected.json b/cmd/generate-stable-protos/testdata/schema/unsupported-file/expected.json new file mode 100644 index 000000000..3724b7716 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/schema/unsupported-file/expected.json @@ -0,0 +1,3 @@ +{ + "error": "temporal.api.protometa.v1.draft_file" +} diff --git a/cmd/generate-stable-protos/testdata/classification/unsupported-file/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/schema/unsupported-file/input/temporal/api_next/fixture.proto similarity index 100% rename from cmd/generate-stable-protos/testdata/classification/unsupported-file/input/temporal/api_next/fixture.proto rename to cmd/generate-stable-protos/testdata/schema/unsupported-file/input/temporal/api_next/fixture.proto diff --git a/cmd/generate-stable-protos/testdata/schema/unsupported-file/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/schema/unsupported-file/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..def18ac5d --- /dev/null +++ b/cmd/generate-stable-protos/testdata/schema/unsupported-file/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98008; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/schema/wrong-extendee/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/schema/wrong-extendee/input/temporal/api_next/protometa/v1/draft.proto index 6ddd4255e..791571ef5 100644 --- a/cmd/generate-stable-protos/testdata/schema/wrong-extendee/input/temporal/api_next/protometa/v1/draft.proto +++ b/cmd/generate-stable-protos/testdata/schema/wrong-extendee/input/temporal/api_next/protometa/v1/draft.proto @@ -7,5 +7,4 @@ extend google.protobuf.EnumOptions { string draft_enum = 98008; } extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } extend google.protobuf.ServiceOptions { string draft_service = 98008; } extend google.protobuf.MethodOptions { string draft_method = 98008; } -extend google.protobuf.FileOptions { string draft_file = 98008; } -extend google.protobuf.OneofOptions { string draft_oneof = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/schema/wrong-type/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/schema/wrong-type/input/temporal/api_next/protometa/v1/draft.proto index 83f5b25e3..f35af0265 100644 --- a/cmd/generate-stable-protos/testdata/schema/wrong-type/input/temporal/api_next/protometa/v1/draft.proto +++ b/cmd/generate-stable-protos/testdata/schema/wrong-type/input/temporal/api_next/protometa/v1/draft.proto @@ -7,5 +7,4 @@ extend google.protobuf.EnumOptions { string draft_enum = 98008; } extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } extend google.protobuf.ServiceOptions { string draft_service = 98008; } extend google.protobuf.MethodOptions { string draft_method = 98008; } -extend google.protobuf.FileOptions { string draft_file = 98008; } -extend google.protobuf.OneofOptions { string draft_oneof = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/temporal/api_next/protometa/v1/draft.proto b/temporal/api_next/protometa/v1/draft.proto index 4aa4268a8..4ca06461c 100644 --- a/temporal/api_next/protometa/v1/draft.proto +++ b/temporal/api_next/protometa/v1/draft.proto @@ -29,10 +29,14 @@ extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.OneofOptions { + string draft_oneof = 98009; +} + extend google.protobuf.ServiceOptions { string draft_service = 98008; } extend google.protobuf.MethodOptions { string draft_method = 98008; -} \ No newline at end of file +} From 37a931b5be36ee4b36cb967db27db876b8c10fa7 Mon Sep 17 00:00:00 2001 From: Stephan Behnke Date: Sat, 21 Nov 2026 10:09:33 -0700 Subject: [PATCH 12/20] generate-stable-protos: require proto3 in api_next What Requires every proto in the draft source tree to declare `proto3` explicitly. Why The draft rules can focus on proto3 semantics while still allowing external dependencies with other syntax. Co-Authored-By: Claude Opus 5.5 --- cmd/generate-stable-protos/main.go | 4 ++ .../input/temporal/api_next/fixture.proto | 4 +- .../input/temporal/api_next/fixture.proto | 6 +-- .../extension-extendee/expected.json | 3 -- .../input/temporal/api_next/fixture.proto | 5 --- .../api_next/protometa/v1/draft.proto | 10 ----- .../input/temporal/api_next/fixture.proto | 8 ++-- .../input/temporal/api_next/fixture.proto | 6 +-- .../input/temporal/api_next/fixture.proto | 5 ++- .../generator/edition-source/expected.json | 3 ++ .../input/temporal/api_next/fixture.proto | 3 ++ .../api_next/protometa/v1/draft.proto | 42 +++++++++++++++++++ .../implicit-proto2-source/expected.json | 3 ++ .../input/temporal/api_next/fixture.proto | 2 + .../api_next/protometa/v1/draft.proto | 42 +++++++++++++++++++ .../generator/proto2-source/expected.json | 3 ++ .../input/temporal/api_next/fixture.proto | 16 +++++++ .../api_next/protometa/v1/draft.proto | 42 +++++++++++++++++++ .../input/temporal/api_next/fixture.proto | 11 ++--- 19 files changed, 179 insertions(+), 39 deletions(-) delete mode 100644 cmd/generate-stable-protos/testdata/classification/extension-extendee/expected.json delete mode 100644 cmd/generate-stable-protos/testdata/classification/extension-extendee/input/temporal/api_next/fixture.proto delete mode 100644 cmd/generate-stable-protos/testdata/classification/extension-extendee/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/generator/edition-source/expected.json create mode 100644 cmd/generate-stable-protos/testdata/generator/edition-source/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/generator/edition-source/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/generator/implicit-proto2-source/expected.json create mode 100644 cmd/generate-stable-protos/testdata/generator/implicit-proto2-source/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/generator/implicit-proto2-source/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/generator/proto2-source/expected.json create mode 100644 cmd/generate-stable-protos/testdata/generator/proto2-source/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/generator/proto2-source/input/temporal/api_next/protometa/v1/draft.proto diff --git a/cmd/generate-stable-protos/main.go b/cmd/generate-stable-protos/main.go index 4f934a526..8b5eeaa79 100644 --- a/cmd/generate-stable-protos/main.go +++ b/cmd/generate-stable-protos/main.go @@ -16,6 +16,7 @@ import ( "github.com/bufbuild/protocompile/experimental/ast/edit" "github.com/bufbuild/protocompile/experimental/ast/printer" + "github.com/bufbuild/protocompile/experimental/ast/syntax" "github.com/bufbuild/protocompile/experimental/incremental" "github.com/bufbuild/protocompile/experimental/incremental/queries" "github.com/bufbuild/protocompile/experimental/ir" @@ -167,6 +168,9 @@ func (cfg config) loadAPINext(ctx context.Context, root string, paths []string) if got := irFile.Path(); got != p { return nil, draftTags{}, nil, fmt.Errorf("internal error: incremental.Run result %d has path %q, expected %q", i, got, p) } + if strings.HasPrefix(p, cfg.nextDir+"/") && irFile.Syntax() != syntax.Proto3 { + return nil, draftTags{}, nil, fmt.Errorf("%s: api_next requires syntax = %q", p, "proto3") + } for imp := range seq.Values(irFile.Imports()) { // A public re-export of the draft options proto would leak it into the stable tree. if imp.Direct && imp.Public && imp.Path() == cfg.draftSchema { diff --git a/cmd/generate-stable-protos/testdata/classification/container-all-draft-enum/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/container-all-draft-enum/input/temporal/api_next/fixture.proto index 62969ce0b..783087b2c 100644 --- a/cmd/generate-stable-protos/testdata/classification/container-all-draft-enum/input/temporal/api_next/fixture.proto +++ b/cmd/generate-stable-protos/testdata/classification/container-all-draft-enum/input/temporal/api_next/fixture.proto @@ -1,4 +1,4 @@ -syntax = "proto2"; +syntax = "proto3"; package fixture; import "temporal/api_next/protometa/v1/draft.proto"; -enum Mode { PREVIEW = 1 [(temporal.api.protometa.v1.draft_enum_value) = "preview"]; } +enum Mode { PREVIEW = 0 [(temporal.api.protometa.v1.draft_enum_value) = "preview"]; } diff --git a/cmd/generate-stable-protos/testdata/classification/extension-enum-value-type/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/extension-enum-value-type/input/temporal/api_next/fixture.proto index 7aaeb9fb5..a2167393c 100644 --- a/cmd/generate-stable-protos/testdata/classification/extension-enum-value-type/input/temporal/api_next/fixture.proto +++ b/cmd/generate-stable-protos/testdata/classification/extension-enum-value-type/input/temporal/api_next/fixture.proto @@ -1,6 +1,6 @@ -syntax = "proto2"; +syntax = "proto3"; package fixture; +import "google/protobuf/descriptor.proto"; import "temporal/api_next/protometa/v1/draft.proto"; enum Draft { option (temporal.api.protometa.v1.draft_enum) = "feature-a"; ZERO = 0; } -message Stable { extensions 100 to max; } -extend Stable { optional Draft value = 100; } +extend google.protobuf.MessageOptions { Draft value = 50000; } diff --git a/cmd/generate-stable-protos/testdata/classification/extension-extendee/expected.json b/cmd/generate-stable-protos/testdata/classification/extension-extendee/expected.json deleted file mode 100644 index b936bff08..000000000 --- a/cmd/generate-stable-protos/testdata/classification/extension-extendee/expected.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "error": "extension references draft type" -} diff --git a/cmd/generate-stable-protos/testdata/classification/extension-extendee/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/extension-extendee/input/temporal/api_next/fixture.proto deleted file mode 100644 index 37f7bb5fe..000000000 --- a/cmd/generate-stable-protos/testdata/classification/extension-extendee/input/temporal/api_next/fixture.proto +++ /dev/null @@ -1,5 +0,0 @@ -syntax = "proto2"; -package fixture; -import "temporal/api_next/protometa/v1/draft.proto"; -message Draft { option (temporal.api.protometa.v1.draft_message) = "feature-a"; extensions 100 to max; } -extend Draft { optional string value = 100; } diff --git a/cmd/generate-stable-protos/testdata/classification/extension-extendee/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/extension-extendee/input/temporal/api_next/protometa/v1/draft.proto deleted file mode 100644 index 44dde8528..000000000 --- a/cmd/generate-stable-protos/testdata/classification/extension-extendee/input/temporal/api_next/protometa/v1/draft.proto +++ /dev/null @@ -1,10 +0,0 @@ -syntax = "proto3"; -package temporal.api.protometa.v1; -import "google/protobuf/descriptor.proto"; -extend google.protobuf.FieldOptions { string draft = 98111; } -extend google.protobuf.MessageOptions { string draft_message = 98008; } -extend google.protobuf.EnumOptions { string draft_enum = 98008; } -extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } -extend google.protobuf.ServiceOptions { string draft_service = 98008; } -extend google.protobuf.MethodOptions { string draft_method = 98008; } -extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/classification/extension-reference/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/extension-reference/input/temporal/api_next/fixture.proto index c86243123..6a9a65af1 100644 --- a/cmd/generate-stable-protos/testdata/classification/extension-reference/input/temporal/api_next/fixture.proto +++ b/cmd/generate-stable-protos/testdata/classification/extension-reference/input/temporal/api_next/fixture.proto @@ -1,6 +1,6 @@ -syntax = "proto2"; +syntax = "proto3"; package fixture; +import "google/protobuf/descriptor.proto"; import "temporal/api_next/protometa/v1/draft.proto"; -message Draft { option (temporal.api.protometa.v1.draft_message) = "feature-a"; optional string value = 1; } -message Stable { extensions 100 to max; } -extend Stable { optional Draft value = 100; } +message Draft { option (temporal.api.protometa.v1.draft_message) = "feature-a"; string value = 1; } +extend google.protobuf.MessageOptions { Draft value = 50000; } diff --git a/cmd/generate-stable-protos/testdata/classification/nested-extension/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/nested-extension/input/temporal/api_next/fixture.proto index c27d41972..3c7c46811 100644 --- a/cmd/generate-stable-protos/testdata/classification/nested-extension/input/temporal/api_next/fixture.proto +++ b/cmd/generate-stable-protos/testdata/classification/nested-extension/input/temporal/api_next/fixture.proto @@ -1,8 +1,8 @@ -syntax = "proto2"; +syntax = "proto3"; package fixture; +import "google/protobuf/descriptor.proto"; import "temporal/api_next/protometa/v1/draft.proto"; -message Stable { extensions 100 to max; } message Draft { option (temporal.api.protometa.v1.draft_message) = "feature-a"; - extend Stable { optional string value = 100; } + extend google.protobuf.MessageOptions { string value = 50000; } } diff --git a/cmd/generate-stable-protos/testdata/classification/unsupported-extension/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/unsupported-extension/input/temporal/api_next/fixture.proto index 13e183b85..af2846b44 100644 --- a/cmd/generate-stable-protos/testdata/classification/unsupported-extension/input/temporal/api_next/fixture.proto +++ b/cmd/generate-stable-protos/testdata/classification/unsupported-extension/input/temporal/api_next/fixture.proto @@ -1,4 +1,5 @@ -syntax = "proto2"; +syntax = "proto3"; package fixture; +import "google/protobuf/descriptor.proto"; import "temporal/api_next/protometa/v1/draft.proto"; -message Example { extensions 100 to 199; } extend Example { optional string a = 100 [(temporal.api.protometa.v1.draft) = "feature-a"]; } +extend google.protobuf.MessageOptions { string a = 50000 [(temporal.api.protometa.v1.draft) = "feature-a"]; } diff --git a/cmd/generate-stable-protos/testdata/generator/edition-source/expected.json b/cmd/generate-stable-protos/testdata/generator/edition-source/expected.json new file mode 100644 index 000000000..c1c96ea24 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/generator/edition-source/expected.json @@ -0,0 +1,3 @@ +{ + "error": "temporal/api_next/fixture.proto: api_next requires syntax = \"proto3\"" +} diff --git a/cmd/generate-stable-protos/testdata/generator/edition-source/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/generator/edition-source/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..cb32d6284 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/generator/edition-source/input/temporal/api_next/fixture.proto @@ -0,0 +1,3 @@ +edition = "2023"; +package fixture; +message Example {} diff --git a/cmd/generate-stable-protos/testdata/generator/edition-source/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/generator/edition-source/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..4ca06461c --- /dev/null +++ b/cmd/generate-stable-protos/testdata/generator/edition-source/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,42 @@ +syntax = "proto3"; + +package temporal.api.protometa.v1; + +option go_package = "go.temporal.io/api/protometa/v1;protometa"; +option java_package = "io.temporal.api.protometa.v1"; +option java_multiple_files = true; +option java_outer_classname = "DraftProto"; +option ruby_package = "Temporalio::Api::Protometa::V1"; +option csharp_namespace = "Temporalio.Api.Protometa.V1"; + +import "google/protobuf/descriptor.proto"; + +// Tags for draft declarations. + +extend google.protobuf.FieldOptions { + string draft = 98008; +} + +extend google.protobuf.MessageOptions { + string draft_message = 98008; +} + +extend google.protobuf.EnumOptions { + string draft_enum = 98008; +} + +extend google.protobuf.EnumValueOptions { + string draft_enum_value = 98008; +} + +extend google.protobuf.OneofOptions { + string draft_oneof = 98009; +} + +extend google.protobuf.ServiceOptions { + string draft_service = 98008; +} + +extend google.protobuf.MethodOptions { + string draft_method = 98008; +} diff --git a/cmd/generate-stable-protos/testdata/generator/implicit-proto2-source/expected.json b/cmd/generate-stable-protos/testdata/generator/implicit-proto2-source/expected.json new file mode 100644 index 000000000..c1c96ea24 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/generator/implicit-proto2-source/expected.json @@ -0,0 +1,3 @@ +{ + "error": "temporal/api_next/fixture.proto: api_next requires syntax = \"proto3\"" +} diff --git a/cmd/generate-stable-protos/testdata/generator/implicit-proto2-source/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/generator/implicit-proto2-source/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..a8347485f --- /dev/null +++ b/cmd/generate-stable-protos/testdata/generator/implicit-proto2-source/input/temporal/api_next/fixture.proto @@ -0,0 +1,2 @@ +package fixture; +message Example {} diff --git a/cmd/generate-stable-protos/testdata/generator/implicit-proto2-source/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/generator/implicit-proto2-source/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..4ca06461c --- /dev/null +++ b/cmd/generate-stable-protos/testdata/generator/implicit-proto2-source/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,42 @@ +syntax = "proto3"; + +package temporal.api.protometa.v1; + +option go_package = "go.temporal.io/api/protometa/v1;protometa"; +option java_package = "io.temporal.api.protometa.v1"; +option java_multiple_files = true; +option java_outer_classname = "DraftProto"; +option ruby_package = "Temporalio::Api::Protometa::V1"; +option csharp_namespace = "Temporalio.Api.Protometa.V1"; + +import "google/protobuf/descriptor.proto"; + +// Tags for draft declarations. + +extend google.protobuf.FieldOptions { + string draft = 98008; +} + +extend google.protobuf.MessageOptions { + string draft_message = 98008; +} + +extend google.protobuf.EnumOptions { + string draft_enum = 98008; +} + +extend google.protobuf.EnumValueOptions { + string draft_enum_value = 98008; +} + +extend google.protobuf.OneofOptions { + string draft_oneof = 98009; +} + +extend google.protobuf.ServiceOptions { + string draft_service = 98008; +} + +extend google.protobuf.MethodOptions { + string draft_method = 98008; +} diff --git a/cmd/generate-stable-protos/testdata/generator/proto2-source/expected.json b/cmd/generate-stable-protos/testdata/generator/proto2-source/expected.json new file mode 100644 index 000000000..c1c96ea24 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/generator/proto2-source/expected.json @@ -0,0 +1,3 @@ +{ + "error": "temporal/api_next/fixture.proto: api_next requires syntax = \"proto3\"" +} diff --git a/cmd/generate-stable-protos/testdata/generator/proto2-source/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/generator/proto2-source/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..5decd76c6 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/generator/proto2-source/input/temporal/api_next/fixture.proto @@ -0,0 +1,16 @@ +syntax = "proto2"; +package fixture; +import "temporal/api_next/protometa/v1/draft.proto"; + +enum Mode { + PREVIEW = 1 [(temporal.api.protometa.v1.draft_enum_value) = "preview"]; + STABLE = 0; +} + +message Example { + optional Mode mode = 1; + optional group Preview = 2 [(temporal.api.protometa.v1.draft) = "preview"] { + optional string name = 3; + } + optional Preview alias = 4; +} diff --git a/cmd/generate-stable-protos/testdata/generator/proto2-source/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/generator/proto2-source/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..4ca06461c --- /dev/null +++ b/cmd/generate-stable-protos/testdata/generator/proto2-source/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,42 @@ +syntax = "proto3"; + +package temporal.api.protometa.v1; + +option go_package = "go.temporal.io/api/protometa/v1;protometa"; +option java_package = "io.temporal.api.protometa.v1"; +option java_multiple_files = true; +option java_outer_classname = "DraftProto"; +option ruby_package = "Temporalio::Api::Protometa::V1"; +option csharp_namespace = "Temporalio.Api.Protometa.V1"; + +import "google/protobuf/descriptor.proto"; + +// Tags for draft declarations. + +extend google.protobuf.FieldOptions { + string draft = 98008; +} + +extend google.protobuf.MessageOptions { + string draft_message = 98008; +} + +extend google.protobuf.EnumOptions { + string draft_enum = 98008; +} + +extend google.protobuf.EnumValueOptions { + string draft_enum_value = 98008; +} + +extend google.protobuf.OneofOptions { + string draft_oneof = 98009; +} + +extend google.protobuf.ServiceOptions { + string draft_service = 98008; +} + +extend google.protobuf.MethodOptions { + string draft_method = 98008; +} diff --git a/cmd/generate-stable-protos/testdata/schema/legacy-options/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/schema/legacy-options/input/temporal/api_next/fixture.proto index 39eacdcdb..e1fe03212 100644 --- a/cmd/generate-stable-protos/testdata/schema/legacy-options/input/temporal/api_next/fixture.proto +++ b/cmd/generate-stable-protos/testdata/schema/legacy-options/input/temporal/api_next/fixture.proto @@ -1,15 +1,12 @@ -syntax = "proto2"; +syntax = "proto3"; package fixture; +import "google/protobuf/descriptor.proto"; import "temporal/api_next/protometa/v1/draft.proto"; option (temporal.api.protometa.v1.draft_file) = "legacy"; -message Example { - extensions 100 to max; -} - -extend Example { - optional string value = 100 [(temporal.api.protometa.v1.draft_extension) = "legacy"]; +extend google.protobuf.MessageOptions { + string value = 50000 [(temporal.api.protometa.v1.draft_extension) = "legacy"]; } From 2f3ed6cdb08b34da8a218188597336018d228a66 Mon Sep 17 00:00:00 2001 From: Stephan Behnke Date: Sat, 21 Nov 2026 10:12:59 -0700 Subject: [PATCH 13/20] generate-stable-protos: drop the comments of pruned imports What Removes comments owned by pruned imports and preserves source order until import ownership is resolved. Why Deleting an unused import should also remove its comments without disturbing the comments on retained imports. Co-Authored-By: Claude Opus 5.5 --- cmd/generate-stable-protos/comments.go | 117 ++++++++++++++++++ cmd/generate-stable-protos/main.go | 22 ++-- .../import-comment-ownership/expected.json | 5 + .../expected/temporal/api/fixture.proto | 8 ++ .../input/temporal/api_next/fixture.proto | 13 ++ .../api_next/protometa/v1/draft.proto | 42 +++++++ 6 files changed, 195 insertions(+), 12 deletions(-) create mode 100644 cmd/generate-stable-protos/testdata/classification/import-comment-ownership/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/import-comment-ownership/expected/temporal/api/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/import-comment-ownership/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/import-comment-ownership/input/temporal/api_next/protometa/v1/draft.proto diff --git a/cmd/generate-stable-protos/comments.go b/cmd/generate-stable-protos/comments.go index c472c55d8..b5cfc0b5c 100644 --- a/cmd/generate-stable-protos/comments.go +++ b/cmd/generate-stable-protos/comments.go @@ -6,11 +6,128 @@ import ( "strings" "github.com/bufbuild/protocompile/experimental/ast" + "github.com/bufbuild/protocompile/experimental/ast/edit" "github.com/bufbuild/protocompile/experimental/fdp" "github.com/bufbuild/protocompile/experimental/ir" + "github.com/bufbuild/protocompile/experimental/parser" + "github.com/bufbuild/protocompile/experimental/report" + "github.com/bufbuild/protocompile/experimental/seq" + "github.com/bufbuild/protocompile/experimental/source" "github.com/bufbuild/protocompile/experimental/token" ) +// pruneImports removes unused imports and the external trivia attributed to them. +func pruneImports(f *ir.File) (*ast.File, error) { + unused := map[string]ast.DeclImport{} + for imp := range seq.Values(f.Imports()) { + if !imp.Used && !imp.Decl.IsZero() { + unused[imp.Path()] = imp.Decl + } + } + if len(unused) == 0 { + return f.AST(), nil + } + fd, err := fdp.DescriptorProto(f, fdp.IncludeSourceCodeInfo(true)) + if err != nil { + return nil, fmt.Errorf("reading import source info: %w", err) + } + stream := f.AST().Stream() + var text []byte + // Replace comment bytes with whitespace so the import offsets remain valid after parsing. + mask := func(span source.Span) { + if text == nil { + text = []byte(stream.File.Text()) + } + for i := span.Start; i < span.End; i++ { + if text[i] != '\n' && text[i] != '\r' { + text[i] = ' ' + } + } + } + starts := map[int]bool{} + const dependencyTag = 3 + for _, loc := range fd.GetSourceCodeInfo().GetLocation() { + path := loc.GetPath() + if len(path) != 2 || path[0] != dependencyTag { + continue + } + dependency := fd.GetDependency()[path[1]] + decl, drop := unused[dependency] + if !drop { + continue + } + delete(unused, dependency) + span := decl.Span() + starts[span.Start] = true + leading := strings.Fields(strings.Join(loc.GetLeadingDetachedComments(), " ") + " " + loc.GetLeadingComments()) + trailing := strings.Fields(loc.GetTrailingComments()) + before, _ := stream.Around(span.Start) + _, after := stream.Around(span.End) + if !maskImportComments(before, leading, true, mask) || !maskImportComments(after, trailing, false, mask) { + return nil, fmt.Errorf("locating comments of import %q", dependency) + } + } + if len(unused) != 0 { + return nil, fmt.Errorf("missing source locations for %d unused imports", len(unused)) + } + + file := f.AST() + if text != nil { + var diagnostics report.Report + file, _ = parser.Parse(f.Path(), source.NewFile(f.Path(), string(text)), &diagnostics) + if message, failed := errorDiagnostics(&diagnostics); failed { + return nil, fmt.Errorf("parsing source with pruned import comments: %s", message) + } + } + var dels []edit.Edit + for decl := range seq.Values(file.Decls()) { + if !decl.AsImport().IsZero() && starts[decl.Span().Start] { + dels = append(dels, edit.Edit{Kind: edit.KindDelete, Target: decl}) + } + } + if err := edit.ApplyEdits(file, dels); err != nil { + return nil, err + } + return file, nil +} + +// maskImportComments locates attributed comments in the trivia adjacent to an import. +func maskImportComments(start token.Token, words []string, backwards bool, mask func(source.Span)) bool { + if len(words) == 0 { + return true + } + if start.IsZero() { + return false + } + cursor := token.NewCursorAt(start) + next := cursor.NextSkippable + if backwards { + cursor.NextSkippable() + next = cursor.PrevSkippable + } + for tok := next(); !tok.IsZero() && tok.Kind().IsSkippable(); tok = next() { + if tok.Kind() != token.Comment { + continue + } + got := commentTokenWords(tok.Text()) + if len(got) > len(words) { + return false + } + if backwards && slices.Equal(words[len(words)-len(got):], got) { + words = words[:len(words)-len(got)] + } else if !backwards && slices.Equal(words[:len(got)], got) { + words = words[len(got):] + } else { + return false + } + mask(tok.LeafSpan()) + if len(words) == 0 { + return true + } + } + return false +} + // draftComments holds the comments protoc attributes to a file's removed draft // declarations, and how often each comment word may still occur in the stable file. type draftComments struct { diff --git a/cmd/generate-stable-protos/main.go b/cmd/generate-stable-protos/main.go index 8b5eeaa79..0c1a693fb 100644 --- a/cmd/generate-stable-protos/main.go +++ b/cmd/generate-stable-protos/main.go @@ -14,6 +14,7 @@ import ( "strconv" "strings" + "github.com/bufbuild/protocompile/experimental/ast" "github.com/bufbuild/protocompile/experimental/ast/edit" "github.com/bufbuild/protocompile/experimental/ast/printer" "github.com/bufbuild/protocompile/experimental/ast/syntax" @@ -232,7 +233,10 @@ func (cfg config) stripDrafts(ctx context.Context, root string, paths []string) if err := edit.ApplyEdits(irFile.AST(), edits); err != nil { return nil, nil, nil, fmt.Errorf("delete draft declarations: %s: %w", p, err) } - protoText, err := printFile(irFile) + formatting := printer.Legacy() + // Keep detached comments beside their original imports until pruning determines ownership. + formatting.CanonicalizeFileOrder = false + protoText, err := printer.PrintFile(printer.Options{Format: true, Formatting: formatting}, irFile.AST()) if err != nil { return nil, nil, nil, fmt.Errorf("print %s: %w", p, err) } @@ -256,17 +260,11 @@ func (cfg config) organizeImports(ctx context.Context, root string, order []stri } irFile := results[i].Value - var importDels []edit.Edit - for j := 0; j < irFile.Imports().Len(); j++ { - imp := irFile.Imports().At(j) - if !imp.Used && !imp.Decl.IsZero() { - importDels = append(importDels, edit.Edit{Kind: edit.KindDelete, Target: imp.Decl.AsAny()}) - } - } - if err := edit.ApplyEdits(irFile.AST(), importDels); err != nil { + file, err := pruneImports(irFile) + if err != nil { return nil, fmt.Errorf("prune imports: %s: %w", p, err) } - protoText, err := printFile(irFile) + protoText, err := printFile(file) if err != nil { return nil, fmt.Errorf("print %s: %w", p, err) } @@ -314,8 +312,8 @@ func lowerFiles(ctx context.Context, opener source.Opener, paths []string) ([]in // printFile formats the file with the legacy formatter. // // TODO: Check whether a custom formatter can reuse Buf's formatting rules. -func printFile(file *ir.File) (string, error) { - return printer.PrintFile(printer.Options{Format: true, Formatting: printer.Legacy()}, file.AST()) +func printFile(file *ast.File) (string, error) { + return printer.PrintFile(printer.Options{Format: true, Formatting: printer.Legacy()}, file) } func errorDiagnostics(r *report.Report) (renderText string, hasErrors bool) { diff --git a/cmd/generate-stable-protos/testdata/classification/import-comment-ownership/expected.json b/cmd/generate-stable-protos/testdata/classification/import-comment-ownership/expected.json new file mode 100644 index 000000000..3082f3207 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/import-comment-ownership/expected.json @@ -0,0 +1,5 @@ +{ + "annotations": { + "fixture.Marker.draft": "preview" + } +} diff --git a/cmd/generate-stable-protos/testdata/classification/import-comment-ownership/expected/temporal/api/fixture.proto b/cmd/generate-stable-protos/testdata/classification/import-comment-ownership/expected/temporal/api/fixture.proto new file mode 100644 index 000000000..55ac9ad39 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/import-comment-ownership/expected/temporal/api/fixture.proto @@ -0,0 +1,8 @@ +syntax = "proto3"; +package fixture; + +// The marker uses the empty message. +import "google/protobuf/empty.proto"; +message Marker { + google.protobuf.Empty value = 1; +} diff --git a/cmd/generate-stable-protos/testdata/classification/import-comment-ownership/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/import-comment-ownership/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..d9b2ff5e6 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/import-comment-ownership/input/temporal/api_next/fixture.proto @@ -0,0 +1,13 @@ +syntax = "proto3"; +package fixture; + +// This paragraph belongs to the draft annotation import. + +import "temporal/api_next/protometa/v1/draft.proto"; +// The marker uses the empty message. +import "google/protobuf/empty.proto"; + +message Marker { + google.protobuf.Empty value = 1; + string draft = 2 [(temporal.api.protometa.v1.draft) = "preview"]; +} diff --git a/cmd/generate-stable-protos/testdata/classification/import-comment-ownership/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/import-comment-ownership/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..4ca06461c --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/import-comment-ownership/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,42 @@ +syntax = "proto3"; + +package temporal.api.protometa.v1; + +option go_package = "go.temporal.io/api/protometa/v1;protometa"; +option java_package = "io.temporal.api.protometa.v1"; +option java_multiple_files = true; +option java_outer_classname = "DraftProto"; +option ruby_package = "Temporalio::Api::Protometa::V1"; +option csharp_namespace = "Temporalio.Api.Protometa.V1"; + +import "google/protobuf/descriptor.proto"; + +// Tags for draft declarations. + +extend google.protobuf.FieldOptions { + string draft = 98008; +} + +extend google.protobuf.MessageOptions { + string draft_message = 98008; +} + +extend google.protobuf.EnumOptions { + string draft_enum = 98008; +} + +extend google.protobuf.EnumValueOptions { + string draft_enum_value = 98008; +} + +extend google.protobuf.OneofOptions { + string draft_oneof = 98009; +} + +extend google.protobuf.ServiceOptions { + string draft_service = 98008; +} + +extend google.protobuf.MethodOptions { + string draft_method = 98008; +} From 738e12c1ccc59844ec63615a73d255ee62b88ee2 Mon Sep 17 00:00:00 2001 From: Stephan Behnke Date: Sat, 21 Nov 2026 10:16:04 -0700 Subject: [PATCH 14/20] generate-stable-protos: project every draft placement What Projects all supported draft placements out of the stable schema. Why Draft enums, oneofs, RPCs, and services need the same stable-output guarantees as draft fields and messages. Co-Authored-By: Claude Opus 5.5 --- cmd/generate-stable-protos/random_test.go | 60 +++++++++------- cmd/generate-stable-protos/rules.go | 69 ++++++++++++------- cmd/generate-stable-protos/tags.go | 24 ++----- .../expected.json | 2 +- .../input/temporal/api_next/fixture.proto | 2 +- .../expected.json | 3 + .../input/temporal/api_next/fixture.proto | 15 ++++ .../api_next/protometa/v1/draft.proto | 42 +++++++++++ .../draft-empty-service/expected.json | 3 +- .../expected/temporal/api/fixture.proto | 2 + .../draft-enum-value/expected.json | 6 +- .../expected/temporal/api/fixture.proto | 19 +++++ .../input/temporal/api_next/fixture.proto | 17 ++++- .../classification/draft-enum/expected.json | 11 ++- .../expected/temporal/api/fixture.proto | 7 ++ .../input/temporal/api_next/fixture.proto | 21 +++++- .../classification/draft-method/expected.json | 3 +- .../expected/temporal/api/fixture.proto | 11 +++ .../input/temporal/api_next/fixture.proto | 11 ++- .../expected.json | 3 + .../input/temporal/api_next/fixture.proto | 14 ++++ .../api_next/protometa/v1/draft.proto | 42 +++++++++++ .../classification/draft-oneof/expected.json | 8 +-- .../expected/temporal/api/fixture.proto | 10 +++ .../input/temporal/api_next/fixture.proto | 14 +++- .../draft-service/expected.json | 3 +- .../expected/temporal/api/fixture.proto | 5 ++ .../input/temporal/api_next/fixture.proto | 11 ++- .../expected/temporal/api/fixture.proto | 3 + .../field-feature-mismatch/expected.json | 3 + .../input/temporal/api_next/fixture.proto | 12 ++++ .../api_next/protometa/v1/draft.proto | 42 +++++++++++ .../input/temporal/api_next/fixture.proto | 2 + .../message-types/expected.json | 15 +++- .../input/temporal/api_next/fixture.proto | 22 +++--- .../input/temporal/api_next/types.proto | 2 +- .../missing-field-draft/expected.json | 3 + .../input/temporal/api_next/fixture.proto | 12 ++++ .../api_next/protometa/v1/draft.proto | 42 +++++++++++ .../removed-rpc-http/expected.json | 3 +- .../expected/temporal/api/fixture.proto | 16 +++++ .../input/temporal/api_next/fixture.proto | 12 +++- .../removed-rpc-request-header/expected.json | 3 +- .../expected/temporal/api/fixture.proto | 6 ++ .../api/protometa/v1/annotations.proto | 37 ++++++++++ .../input/temporal/api_next/fixture.proto | 2 +- .../expected.json | 5 ++ .../expected/temporal/api/fixture.proto | 6 ++ .../input/temporal/api_next/fixture.proto | 11 +++ .../api_next/protometa/v1/draft.proto | 42 +++++++++++ .../input/temporal/api_next/fixture.proto | 2 +- .../testdata/comments/attached/expected.json | 3 +- .../input/temporal/api_next/fixture.proto | 2 +- .../input/temporal/api_next/fixture.proto | 2 +- .../input/temporal/api_next/fixture.proto | 2 +- .../input/temporal/api_next/fixture.proto | 2 +- .../input/temporal/api_next/fixture.proto | 2 +- .../input/temporal/api_next/fixture.proto | 2 +- .../input/temporal/api_next/fixture.proto | 6 +- cmd/generate-stable-protos/walk.go | 35 +++++----- 60 files changed, 654 insertions(+), 143 deletions(-) create mode 100644 cmd/generate-stable-protos/testdata/classification/draft-container-feature-mismatch/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/draft-container-feature-mismatch/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/draft-container-feature-mismatch/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/draft-empty-service/expected/temporal/api/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/draft-enum-value/expected/temporal/api/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/draft-enum/expected/temporal/api/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/draft-method/expected/temporal/api/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/draft-oneof-feature-mismatch/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/draft-oneof-feature-mismatch/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/draft-oneof-feature-mismatch/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/draft-oneof/expected/temporal/api/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/draft-service/expected/temporal/api/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/empty-service/expected/temporal/api/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/field-feature-mismatch/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/field-feature-mismatch/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/field-feature-mismatch/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/missing-field-draft/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/missing-field-draft/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/missing-field-draft/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/removed-rpc-http/expected/temporal/api/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/removed-rpc-request-header/expected/temporal/api/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/removed-rpc-request-header/expected/temporal/api/protometa/v1/annotations.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/synthetic-oneof-name-collision/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/synthetic-oneof-name-collision/expected/temporal/api/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/synthetic-oneof-name-collision/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/synthetic-oneof-name-collision/input/temporal/api_next/protometa/v1/draft.proto diff --git a/cmd/generate-stable-protos/random_test.go b/cmd/generate-stable-protos/random_test.go index dcb5a8080..4c54d3780 100644 --- a/cmd/generate-stable-protos/random_test.go +++ b/cmd/generate-stable-protos/random_test.go @@ -43,8 +43,13 @@ type schemaGen struct { rt *rapid.T b *strings.Builder comments int - // types are the message names fields in the current file may reference. - types []string + // types are the messages fields in the current file may reference and their draft status. + types []schemaType +} + +type schemaType struct { + name string + draft bool } func newSchemaGen(rt *rapid.T) *schemaGen { return &schemaGen{rt: rt} } @@ -58,20 +63,20 @@ func (g *schemaGen) files() map[string]string { } } -func (g *schemaGen) file(name string, messages int, imported []string) string { +func (g *schemaGen) file(name string, messages int, imported []schemaType) string { g.b = &strings.Builder{} g.b.WriteString("syntax = \"proto3\";\npackage fixture;\n") g.b.WriteString("import \"" + testConfig.draftSchema + "\";\n") if name == "dependent" { g.b.WriteString("import \"" + testConfig.nextDir + "/base.proto\";\n") } - names := make([]string, messages) - for i := range names { - names[i] = fmt.Sprintf("%s%d", strings.ToUpper(name[:1]), i) + types := make([]schemaType, messages) + for i := range types { + types[i] = schemaType{fmt.Sprintf("%s%d", strings.ToUpper(name[:1]), i), g.draft("message")} } - g.types = append(append([]string{}, imported...), names...) - for _, n := range names { - g.message(n, "", 0, false) + g.types = append(append([]schemaType{}, imported...), types...) + for _, typ := range types { + g.message(typ, "", 0, false) } return g.b.String() } @@ -99,35 +104,37 @@ func (g *schemaGen) draft(what string) bool { return rapid.IntRange(0, 3).Draw(g.rt, "draft "+what) == 0 } -func (g *schemaGen) message(name, indent string, depth int, inheritedDraft bool) { +func (g *schemaGen) message(typ schemaType, indent string, depth int, inheritedDraft bool) { g.leading(indent) - g.b.WriteString(indent + "message " + name + " {" + g.trailing() + "\n") + g.b.WriteString(indent + "message " + typ.name + " {" + g.trailing() + "\n") inner := indent + " " - draft := inheritedDraft - if !inheritedDraft && g.draft("message") { + if !inheritedDraft && typ.draft { g.b.WriteString(inner + `option (temporal.api.protometa.v1.draft_message) = "feature";` + "\n") - draft = true } number := 0 - field := func(typ string, canAnnotate bool) { + field := func(decl string, annotate bool) { number++ g.leading(inner) - g.b.WriteString(fmt.Sprintf("%s%s f%d = %d", inner, typ, number, number)) - if canAnnotate && !draft && g.draft("field") { + g.b.WriteString(fmt.Sprintf("%s%s f%d = %d", inner, decl, number, number)) + if annotate { g.b.WriteString(` [(temporal.api.protometa.v1.draft) = "feature"]`) } g.b.WriteString(";" + g.trailing() + "\n") } + randomField := func(prefix, suffix string) { + ref := g.fieldType() + field(prefix+ref.name+suffix, !typ.draft && (ref.draft || g.draft("field"))) + } for i := range rapid.IntRange(0, 5).Draw(g.rt, "members") { switch rapid.IntRange(0, 6).Draw(g.rt, "member kind") { case 0: - field(g.fieldType(), true) + randomField("", "") case 1: - field("repeated "+g.fieldType(), true) + randomField("repeated ", "") case 2: - field("optional "+g.fieldType(), true) + randomField("optional ", "") case 3: - field("map", true) + randomField("map") case 4: g.leading(inner) g.b.WriteString(fmt.Sprintf("%soneof o%d {%s\n", inner, i, g.trailing())) @@ -135,24 +142,25 @@ func (g *schemaGen) message(name, indent string, depth int, inheritedDraft bool) inner += " " field("string", false) for range rapid.IntRange(0, 2).Draw(g.rt, "additional branches") { - field(g.fieldType(), true) + randomField("", "") } inner = saved g.b.WriteString(inner + "}" + g.trailing() + "\n") case 5: if depth < 2 { - g.message(fmt.Sprintf("N%d", i), inner, depth+1, draft) + nested := schemaType{fmt.Sprintf("N%d", i), typ.draft || g.draft("message")} + g.message(nested, inner, depth+1, typ.draft) } default: - field("string", true) + field("string", !typ.draft && g.draft("field")) } } g.b.WriteString(indent + "}" + g.trailing() + "\n") } -func (g *schemaGen) fieldType() string { +func (g *schemaGen) fieldType() schemaType { if len(g.types) > 0 && rapid.Bool().Draw(g.rt, "message type") { return rapid.SampledFrom(g.types).Draw(g.rt, "type") } - return rapid.SampledFrom([]string{"string", "int32", "bool", "bytes"}).Draw(g.rt, "scalar") + return schemaType{name: rapid.SampledFrom([]string{"string", "int32", "bool", "bytes"}).Draw(g.rt, "scalar")} } diff --git a/cmd/generate-stable-protos/rules.go b/cmd/generate-stable-protos/rules.go index 569539c11..815b5e96f 100644 --- a/cmd/generate-stable-protos/rules.go +++ b/cmd/generate-stable-protos/rules.go @@ -13,44 +13,32 @@ func validateDraftRules(tags draftTags, f *ir.File, endpointUses rpcEndpointUses continue } parent := t.Parent() - if tags.has(t.Options()) && isDraftType(tags, parent) { + if tags.has(t.Options()) && tags.typeFeature(parent) != "" { return draftNestingError(t.FullName(), parent.FullName()) } - draft := isDraftType(tags, t) + feature := tags.typeFeature(t) if t.IsEnum() { - if err := validateDraftEnum(tags, t, draft); err != nil { + if err := validateDraftEnum(tags, t, feature != ""); err != nil { return err } continue } + for m := range seq.Values(t.Members()) { + if err := validateDraftField(tags, m, feature); err != nil { + return err + } + } for o := range seq.Values(t.Oneofs()) { if o.AST().IsZero() { continue } if tags.has(o.Options()) { - if draft { + if feature != "" { return draftNestingError(o.FullName(), t.FullName()) } - } else if !draft && allDraft(o.Members(), func(m ir.Member) bool { return isDraftMember(tags, m) }) { - for m := range seq.Values(o.Members()) { - if tags.has(m.Options()) { - return fmt.Errorf("%s: all oneof members are draft; set draft_oneof to a common feature and remove the member draft annotations", o.FullName()) - } - } - return fmt.Errorf("%s: all oneof members are draft; add draft_oneof", o.FullName()) - } - } - for m := range seq.Values(t.Members()) { - if !tags.has(m.Options()) { - continue - } - o := m.Oneof() - if !o.AST().IsZero() && (draft || tags.has(o.Options())) { - return draftNestingError(m.FullName(), o.FullName()) - } - if draft { - return draftNestingError(m.FullName(), t.FullName()) + } else if feature == "" && allDraft(o.Members(), func(m ir.Member) bool { return tags.has(m.Options()) }) { + return fmt.Errorf("%s: all oneof members are draft; set draft_oneof to a common feature and remove the member draft annotations", o.FullName()) } } } @@ -64,7 +52,7 @@ func validateDraftRules(tags draftTags, f *ir.File, endpointUses rpcEndpointUses {"extendee", ext.Container()}, {"declaring parent", ext.Parent()}, } { - if isDraftType(tags, ref.typ) { + if tags.typeFeature(ref.typ) != "" { return fmt.Errorf("%s: extension references draft type %s as its %s", ext.FullName(), ref.typ.FullName(), ref.role) } } @@ -78,6 +66,37 @@ func validateDraftRules(tags draftTags, f *ir.File, endpointUses rpcEndpointUses return nil } +func validateDraftField(tags draftTags, field ir.Member, messageFeature draftFeature) error { + oneof := field.Oneof() + containerFeature := tags.feature(oneof.Options()) + if containerFeature == "" { + containerFeature = messageFeature + } + feature := tags.feature(field.Options()) + if containerFeature != "" { + if feature != "" { + if !oneof.AST().IsZero() { + return draftNestingError(field.FullName(), oneof.FullName()) + } + return draftNestingError(field.FullName(), field.Parent().FullName()) + } + feature = containerFeature + } + + typ := field.Element() + if field.IsMap() { + _, value := typ.EntryFields() + typ = value.Element() + } + if typeFeature := tags.typeFeature(typ); typeFeature != "" && typeFeature != feature { + if feature == "" { + return fmt.Errorf("%s: field references draft type %s and requires draft = %q", field.FullName(), typ.FullName(), typeFeature) + } + return fmt.Errorf("%s: draft feature %q does not match draft type %s feature %q", field.FullName(), feature, typ.FullName(), typeFeature) + } + return nil +} + func draftNestingError(name, container ir.FullName) error { return fmt.Errorf("%s: draft annotation is not allowed inside draft container %s", name, container) } @@ -140,7 +159,7 @@ func validateDraftService(tags draftTags, service ir.Service, endpointUses rpcEn } { name := endpoint.typ.FullName() if feature == "" { - if isDraftType(tags, endpoint.typ) { + if tags.typeFeature(endpoint.typ) != "" { if !tags.has(endpoint.typ.Options()) { return fmt.Errorf("%s: RPC references draft type %s as its %s; inherited draft status is insufficient, so use a type that explicitly carries draft_message and give draft_method and both endpoints the same feature", method.FullName(), name, endpoint.role) } diff --git a/cmd/generate-stable-protos/tags.go b/cmd/generate-stable-protos/tags.go index 0a4daad3e..6eaa8486b 100644 --- a/cmd/generate-stable-protos/tags.go +++ b/cmd/generate-stable-protos/tags.go @@ -216,7 +216,7 @@ func referencesDraftField(tags draftTags, message ir.Type, path string) bool { if field.IsZero() { return false } - if isDraftMember(tags, field) || tags.has(field.Oneof().Options()) { + if tags.has(field.Options()) || tags.has(field.Oneof().Options()) { return true } message = field.Element() @@ -224,21 +224,11 @@ func referencesDraftField(tags draftTags, message ir.Type, path string) bool { return false } -func isDraftType(tags draftTags, t ir.Type) bool { - if t.IsZero() || t.IsPredeclared() { - return false - } - return tags.has(t.Options()) || isDraftType(tags, t.Parent()) -} - -func isDraftMember(tags draftTags, m ir.Member) bool { - if tags.has(m.Options()) { - return true - } - t := m.Element() - if m.IsMap() { - _, value := t.EntryFields() - t = value.Element() +func (tags draftTags) typeFeature(t ir.Type) draftFeature { + for ; !t.IsZero() && !t.IsPredeclared(); t = t.Parent() { + if feature := tags.feature(t.Options()); feature != "" { + return feature + } } - return isDraftType(tags, t) + return "" } diff --git a/cmd/generate-stable-protos/testdata/classification/container-all-draft-oneof-implicit/expected.json b/cmd/generate-stable-protos/testdata/classification/container-all-draft-oneof-implicit/expected.json index 3bcbaf0a6..08d78cf92 100644 --- a/cmd/generate-stable-protos/testdata/classification/container-all-draft-oneof-implicit/expected.json +++ b/cmd/generate-stable-protos/testdata/classification/container-all-draft-oneof-implicit/expected.json @@ -1,3 +1,3 @@ { - "error": "fixture.Choice.selection: all oneof members are draft; add draft_oneof" + "error": "fixture.Choice.target: field references draft type fixture.Draft.Nested and requires draft = \"preview\"" } diff --git a/cmd/generate-stable-protos/testdata/classification/container-all-draft-oneof-mixed/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/container-all-draft-oneof-mixed/input/temporal/api_next/fixture.proto index 34b3ae73b..cab809ee6 100644 --- a/cmd/generate-stable-protos/testdata/classification/container-all-draft-oneof-mixed/input/temporal/api_next/fixture.proto +++ b/cmd/generate-stable-protos/testdata/classification/container-all-draft-oneof-mixed/input/temporal/api_next/fixture.proto @@ -7,6 +7,6 @@ message Draft { message Choice { oneof selection { string name = 1 [(temporal.api.protometa.v1.draft) = "preview"]; - Draft target = 2; + Draft target = 2 [(temporal.api.protometa.v1.draft) = "preview"]; } } diff --git a/cmd/generate-stable-protos/testdata/classification/draft-container-feature-mismatch/expected.json b/cmd/generate-stable-protos/testdata/classification/draft-container-feature-mismatch/expected.json new file mode 100644 index 000000000..31c72e7d8 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/draft-container-feature-mismatch/expected.json @@ -0,0 +1,3 @@ +{ + "error": "fixture.Draft.Nested.modes: draft feature \"other\" does not match draft type fixture.Mode feature \"preview\"" +} diff --git a/cmd/generate-stable-protos/testdata/classification/draft-container-feature-mismatch/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/draft-container-feature-mismatch/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..f0d308e50 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/draft-container-feature-mismatch/input/temporal/api_next/fixture.proto @@ -0,0 +1,15 @@ +syntax = "proto3"; +package fixture; +import "temporal/api_next/protometa/v1/draft.proto"; + +enum Mode { + option (temporal.api.protometa.v1.draft_enum) = "preview"; + ZERO = 0; +} + +message Draft { + option (temporal.api.protometa.v1.draft_message) = "other"; + message Nested { + map modes = 1; + } +} diff --git a/cmd/generate-stable-protos/testdata/classification/draft-container-feature-mismatch/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/draft-container-feature-mismatch/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..4ca06461c --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/draft-container-feature-mismatch/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,42 @@ +syntax = "proto3"; + +package temporal.api.protometa.v1; + +option go_package = "go.temporal.io/api/protometa/v1;protometa"; +option java_package = "io.temporal.api.protometa.v1"; +option java_multiple_files = true; +option java_outer_classname = "DraftProto"; +option ruby_package = "Temporalio::Api::Protometa::V1"; +option csharp_namespace = "Temporalio.Api.Protometa.V1"; + +import "google/protobuf/descriptor.proto"; + +// Tags for draft declarations. + +extend google.protobuf.FieldOptions { + string draft = 98008; +} + +extend google.protobuf.MessageOptions { + string draft_message = 98008; +} + +extend google.protobuf.EnumOptions { + string draft_enum = 98008; +} + +extend google.protobuf.EnumValueOptions { + string draft_enum_value = 98008; +} + +extend google.protobuf.OneofOptions { + string draft_oneof = 98009; +} + +extend google.protobuf.ServiceOptions { + string draft_service = 98008; +} + +extend google.protobuf.MethodOptions { + string draft_method = 98008; +} diff --git a/cmd/generate-stable-protos/testdata/classification/draft-empty-service/expected.json b/cmd/generate-stable-protos/testdata/classification/draft-empty-service/expected.json index 610620ef3..b73a65391 100644 --- a/cmd/generate-stable-protos/testdata/classification/draft-empty-service/expected.json +++ b/cmd/generate-stable-protos/testdata/classification/draft-empty-service/expected.json @@ -1,6 +1,5 @@ { "annotations": { "fixture.Service": "preview" - }, - "validation_only": true + } } diff --git a/cmd/generate-stable-protos/testdata/classification/draft-empty-service/expected/temporal/api/fixture.proto b/cmd/generate-stable-protos/testdata/classification/draft-empty-service/expected/temporal/api/fixture.proto new file mode 100644 index 000000000..49ab17440 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/draft-empty-service/expected/temporal/api/fixture.proto @@ -0,0 +1,2 @@ +syntax = "proto3"; +package fixture; diff --git a/cmd/generate-stable-protos/testdata/classification/draft-enum-value/expected.json b/cmd/generate-stable-protos/testdata/classification/draft-enum-value/expected.json index 4d1ffb618..bbee07d60 100644 --- a/cmd/generate-stable-protos/testdata/classification/draft-enum-value/expected.json +++ b/cmd/generate-stable-protos/testdata/classification/draft-enum-value/expected.json @@ -1,6 +1,6 @@ { "annotations": { - "fixture.PREVIEW": "preview" - }, - "validation_only": true + "fixture.PREVIEW": "preview", + "fixture.Config.NESTED_MODE_PREVIEW": "preview" + } } diff --git a/cmd/generate-stable-protos/testdata/classification/draft-enum-value/expected/temporal/api/fixture.proto b/cmd/generate-stable-protos/testdata/classification/draft-enum-value/expected/temporal/api/fixture.proto new file mode 100644 index 000000000..7d4b4d040 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/draft-enum-value/expected/temporal/api/fixture.proto @@ -0,0 +1,19 @@ +syntax = "proto3"; +package fixture; + +// Mode controls behavior. +enum Mode { + option allow_alias = true; + ZERO = 0; + STABLE = 1; // This stable value remains. + ALIAS = 1; +} + +message Config { + Mode mode = 1; + + enum NestedMode { + NESTED_MODE_UNSPECIFIED = 0; + } + NestedMode nested_mode = 2; +} diff --git a/cmd/generate-stable-protos/testdata/classification/draft-enum-value/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/draft-enum-value/input/temporal/api_next/fixture.proto index 96b001770..80d070eb1 100644 --- a/cmd/generate-stable-protos/testdata/classification/draft-enum-value/input/temporal/api_next/fixture.proto +++ b/cmd/generate-stable-protos/testdata/classification/draft-enum-value/input/temporal/api_next/fixture.proto @@ -1,11 +1,22 @@ syntax = "proto3"; package fixture; import "temporal/api_next/protometa/v1/draft.proto"; + +// Mode controls behavior. enum Mode { option allow_alias = true; ZERO = 0; - STABLE = 1; + // PREVIEW opts in to the new behavior. + PREVIEW = 2 [(temporal.api.protometa.v1.draft_enum_value) = "preview"]; STABLE = 1; // This stable value remains. ALIAS = 1; - PREVIEW = 2 [(temporal.api.protometa.v1.draft_enum_value) = "preview"]; } -message Config { Mode mode = 1; } +message Config { + Mode mode = 1; + + enum NestedMode { + NESTED_MODE_UNSPECIFIED = 0; + // NESTED_MODE_PREVIEW is a draft option. + NESTED_MODE_PREVIEW = 1 [(temporal.api.protometa.v1.draft_enum_value) = "preview"]; // This nested value is draft. + } + NestedMode nested_mode = 2; +} diff --git a/cmd/generate-stable-protos/testdata/classification/draft-enum/expected.json b/cmd/generate-stable-protos/testdata/classification/draft-enum/expected.json index 26425e1d1..68abefd63 100644 --- a/cmd/generate-stable-protos/testdata/classification/draft-enum/expected.json +++ b/cmd/generate-stable-protos/testdata/classification/draft-enum/expected.json @@ -1,6 +1,11 @@ { "annotations": { - "fixture.Mode": "preview" - }, - "validation_only": true + "fixture.Mode": "preview", + "fixture.Config.NestedMode": "nested-preview", + "fixture.Config.mode": "preview", + "fixture.Config.ordered_modes": "preview", + "fixture.Config.modes": "preview", + "fixture.Config.nested_mode": "nested-preview", + "fixture.Config.nested_modes": "nested-preview" + } } diff --git a/cmd/generate-stable-protos/testdata/classification/draft-enum/expected/temporal/api/fixture.proto b/cmd/generate-stable-protos/testdata/classification/draft-enum/expected/temporal/api/fixture.proto new file mode 100644 index 000000000..def088ada --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/draft-enum/expected/temporal/api/fixture.proto @@ -0,0 +1,7 @@ +syntax = "proto3"; +package fixture; + +message Config { + // name identifies the config. + string name = 6; +} diff --git a/cmd/generate-stable-protos/testdata/classification/draft-enum/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/draft-enum/input/temporal/api_next/fixture.proto index cd9e8e157..9092f1f3d 100644 --- a/cmd/generate-stable-protos/testdata/classification/draft-enum/input/temporal/api_next/fixture.proto +++ b/cmd/generate-stable-protos/testdata/classification/draft-enum/input/temporal/api_next/fixture.proto @@ -1,8 +1,27 @@ syntax = "proto3"; package fixture; import "temporal/api_next/protometa/v1/draft.proto"; + +// Mode is available in preview. enum Mode { option (temporal.api.protometa.v1.draft_enum) = "preview"; + // ZERO is the default preview mode. ZERO = 0; +} // This enum is preview-only. + +message Config { + // mode selects a preview mode. + Mode mode = 1 [(temporal.api.protometa.v1.draft) = "preview"]; + repeated Mode ordered_modes = 2 [(temporal.api.protometa.v1.draft) = "preview"]; + map modes = 3 [(temporal.api.protometa.v1.draft) = "preview"]; // This lookup is preview-only. + optional NestedMode nested_mode = 4 [(temporal.api.protometa.v1.draft) = "nested-preview"]; + map nested_modes = 5 [(temporal.api.protometa.v1.draft) = "nested-preview"]; + // name identifies the config. + string name = 6; + + // NestedMode is scoped to Config. + enum NestedMode { + option (temporal.api.protometa.v1.draft_enum) = "nested-preview"; + NESTED_MODE_UNSPECIFIED = 0; + } } -message Config { map modes = 1; } diff --git a/cmd/generate-stable-protos/testdata/classification/draft-method/expected.json b/cmd/generate-stable-protos/testdata/classification/draft-method/expected.json index ef433d6b1..fd194a4b2 100644 --- a/cmd/generate-stable-protos/testdata/classification/draft-method/expected.json +++ b/cmd/generate-stable-protos/testdata/classification/draft-method/expected.json @@ -3,6 +3,5 @@ "fixture.Request": "preview", "fixture.Response": "preview", "fixture.Service.Call": "preview" - }, - "validation_only": true + } } diff --git a/cmd/generate-stable-protos/testdata/classification/draft-method/expected/temporal/api/fixture.proto b/cmd/generate-stable-protos/testdata/classification/draft-method/expected/temporal/api/fixture.proto new file mode 100644 index 000000000..e784bcac3 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/draft-method/expected/temporal/api/fixture.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; +package fixture; + +message StableRequest {} + +message StableResponse {} +// Service provides both stable and preview calls. +service Service { + // Stable invokes the stable behavior. + rpc Stable(StableRequest) returns (StableResponse); +} diff --git a/cmd/generate-stable-protos/testdata/classification/draft-method/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/draft-method/input/temporal/api_next/fixture.proto index 8e9bf749f..85aafcd88 100644 --- a/cmd/generate-stable-protos/testdata/classification/draft-method/input/temporal/api_next/fixture.proto +++ b/cmd/generate-stable-protos/testdata/classification/draft-method/input/temporal/api_next/fixture.proto @@ -1,11 +1,20 @@ syntax = "proto3"; package fixture; import "temporal/api_next/protometa/v1/draft.proto"; + +// Request starts the preview call. message Request { option (temporal.api.protometa.v1.draft_message) = "preview"; } +// Response reports the preview result. message Response { option (temporal.api.protometa.v1.draft_message) = "preview"; } message StableRequest {} message StableResponse {} +// Service provides both stable and preview calls. service Service { + // Call invokes the preview behavior. + rpc Call(Request) returns (Response) { + // This option applies only to Call. + option (temporal.api.protometa.v1.draft_method) = "preview"; + } // This RPC is preview-only. + // Stable invokes the stable behavior. rpc Stable(StableRequest) returns (StableResponse); - rpc Call(Request) returns (Response) { option (temporal.api.protometa.v1.draft_method) = "preview"; } } diff --git a/cmd/generate-stable-protos/testdata/classification/draft-oneof-feature-mismatch/expected.json b/cmd/generate-stable-protos/testdata/classification/draft-oneof-feature-mismatch/expected.json new file mode 100644 index 000000000..d417bb88a --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/draft-oneof-feature-mismatch/expected.json @@ -0,0 +1,3 @@ +{ + "error": "fixture.Config.target: draft feature \"other\" does not match draft type fixture.Draft feature \"preview\"" +} diff --git a/cmd/generate-stable-protos/testdata/classification/draft-oneof-feature-mismatch/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/draft-oneof-feature-mismatch/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..1e5ab3204 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/draft-oneof-feature-mismatch/input/temporal/api_next/fixture.proto @@ -0,0 +1,14 @@ +syntax = "proto3"; +package fixture; +import "temporal/api_next/protometa/v1/draft.proto"; + +message Draft { + option (temporal.api.protometa.v1.draft_message) = "preview"; +} + +message Config { + oneof selection { + option (temporal.api.protometa.v1.draft_oneof) = "other"; + Draft target = 1; + } +} diff --git a/cmd/generate-stable-protos/testdata/classification/draft-oneof-feature-mismatch/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/draft-oneof-feature-mismatch/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..4ca06461c --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/draft-oneof-feature-mismatch/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,42 @@ +syntax = "proto3"; + +package temporal.api.protometa.v1; + +option go_package = "go.temporal.io/api/protometa/v1;protometa"; +option java_package = "io.temporal.api.protometa.v1"; +option java_multiple_files = true; +option java_outer_classname = "DraftProto"; +option ruby_package = "Temporalio::Api::Protometa::V1"; +option csharp_namespace = "Temporalio.Api.Protometa.V1"; + +import "google/protobuf/descriptor.proto"; + +// Tags for draft declarations. + +extend google.protobuf.FieldOptions { + string draft = 98008; +} + +extend google.protobuf.MessageOptions { + string draft_message = 98008; +} + +extend google.protobuf.EnumOptions { + string draft_enum = 98008; +} + +extend google.protobuf.EnumValueOptions { + string draft_enum_value = 98008; +} + +extend google.protobuf.OneofOptions { + string draft_oneof = 98009; +} + +extend google.protobuf.ServiceOptions { + string draft_service = 98008; +} + +extend google.protobuf.MethodOptions { + string draft_method = 98008; +} diff --git a/cmd/generate-stable-protos/testdata/classification/draft-oneof/expected.json b/cmd/generate-stable-protos/testdata/classification/draft-oneof/expected.json index 5d0fb37e9..66da09c30 100644 --- a/cmd/generate-stable-protos/testdata/classification/draft-oneof/expected.json +++ b/cmd/generate-stable-protos/testdata/classification/draft-oneof/expected.json @@ -1,7 +1,7 @@ { "annotations": { - "fixture.Draft": "type-feature", - "fixture.Choice.selection": "preview" - }, - "validation_only": true + "fixture.Draft": "preview", + "fixture.Choice.selection": "preview", + "fixture.Choice.draft_key": "preview" + } } diff --git a/cmd/generate-stable-protos/testdata/classification/draft-oneof/expected/temporal/api/fixture.proto b/cmd/generate-stable-protos/testdata/classification/draft-oneof/expected/temporal/api/fixture.proto new file mode 100644 index 000000000..a3645dbbc --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/draft-oneof/expected/temporal/api/fixture.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package fixture; + +message Choice { + // key selects a stable target. + oneof key { + string id = 3; + } + optional bool enabled = 5; +} diff --git a/cmd/generate-stable-protos/testdata/classification/draft-oneof/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/draft-oneof/input/temporal/api_next/fixture.proto index e04d58060..2e29bcb7d 100644 --- a/cmd/generate-stable-protos/testdata/classification/draft-oneof/input/temporal/api_next/fixture.proto +++ b/cmd/generate-stable-protos/testdata/classification/draft-oneof/input/temporal/api_next/fixture.proto @@ -1,10 +1,22 @@ syntax = "proto3"; package fixture; import "temporal/api_next/protometa/v1/draft.proto"; -message Draft { option (temporal.api.protometa.v1.draft_message) = "type-feature"; } + +// Draft carries preview data. +message Draft { option (temporal.api.protometa.v1.draft_message) = "preview"; } message Choice { + // selection selects a preview target. oneof selection { option (temporal.api.protometa.v1.draft_oneof) = "preview"; + // target selects a structured target. Draft target = 1; + string alias = 2; + } // This oneof is preview-only. + // key selects a stable target. + oneof key { + string id = 3; + // draft_key selects a preview key. + string draft_key = 4 [(temporal.api.protometa.v1.draft) = "preview"]; } + optional bool enabled = 5; } diff --git a/cmd/generate-stable-protos/testdata/classification/draft-service/expected.json b/cmd/generate-stable-protos/testdata/classification/draft-service/expected.json index e974d6af5..ac9620521 100644 --- a/cmd/generate-stable-protos/testdata/classification/draft-service/expected.json +++ b/cmd/generate-stable-protos/testdata/classification/draft-service/expected.json @@ -3,6 +3,5 @@ "fixture.Request": "preview", "fixture.Response": "preview", "fixture.Service": "preview" - }, - "validation_only": true + } } diff --git a/cmd/generate-stable-protos/testdata/classification/draft-service/expected/temporal/api/fixture.proto b/cmd/generate-stable-protos/testdata/classification/draft-service/expected/temporal/api/fixture.proto new file mode 100644 index 000000000..c7544bf16 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/draft-service/expected/temporal/api/fixture.proto @@ -0,0 +1,5 @@ +syntax = "proto3"; +package fixture; + +// StableService is declared without RPCs. +service StableService {} diff --git a/cmd/generate-stable-protos/testdata/classification/draft-service/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/draft-service/input/temporal/api_next/fixture.proto index d51418c67..c9e2487f1 100644 --- a/cmd/generate-stable-protos/testdata/classification/draft-service/input/temporal/api_next/fixture.proto +++ b/cmd/generate-stable-protos/testdata/classification/draft-service/input/temporal/api_next/fixture.proto @@ -1,9 +1,16 @@ syntax = "proto3"; package fixture; import "temporal/api_next/protometa/v1/draft.proto"; + +// Request starts the preview call. message Request { option (temporal.api.protometa.v1.draft_message) = "preview"; } +// Response reports the preview result. message Response { option (temporal.api.protometa.v1.draft_message) = "preview"; } +// Service exposes preview calls. service Service { option (temporal.api.protometa.v1.draft_service) = "preview"; - rpc Call(Request) returns (Response); -} + // Call invokes the preview behavior. + rpc Call(Request) returns (Response); // This RPC is preview-only. +} // This service is preview-only. +// StableService is declared without RPCs. +service StableService {} diff --git a/cmd/generate-stable-protos/testdata/classification/empty-service/expected/temporal/api/fixture.proto b/cmd/generate-stable-protos/testdata/classification/empty-service/expected/temporal/api/fixture.proto new file mode 100644 index 000000000..a6a8bc3b8 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/empty-service/expected/temporal/api/fixture.proto @@ -0,0 +1,3 @@ +syntax = "proto3"; +package fixture; +service Service {} diff --git a/cmd/generate-stable-protos/testdata/classification/field-feature-mismatch/expected.json b/cmd/generate-stable-protos/testdata/classification/field-feature-mismatch/expected.json new file mode 100644 index 000000000..d1d42f625 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/field-feature-mismatch/expected.json @@ -0,0 +1,3 @@ +{ + "error": "fixture.Config.children: draft feature \"Preview\" does not match draft type fixture.Draft.Nested feature \"preview\"" +} diff --git a/cmd/generate-stable-protos/testdata/classification/field-feature-mismatch/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/field-feature-mismatch/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..aa85dc55e --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/field-feature-mismatch/input/temporal/api_next/fixture.proto @@ -0,0 +1,12 @@ +syntax = "proto3"; +package fixture; +import "temporal/api_next/protometa/v1/draft.proto"; + +message Draft { + option (temporal.api.protometa.v1.draft_message) = "preview"; + message Nested {} +} + +message Config { + repeated Draft.Nested children = 1 [(temporal.api.protometa.v1.draft) = "Preview"]; +} diff --git a/cmd/generate-stable-protos/testdata/classification/field-feature-mismatch/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/field-feature-mismatch/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..4ca06461c --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/field-feature-mismatch/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,42 @@ +syntax = "proto3"; + +package temporal.api.protometa.v1; + +option go_package = "go.temporal.io/api/protometa/v1;protometa"; +option java_package = "io.temporal.api.protometa.v1"; +option java_multiple_files = true; +option java_outer_classname = "DraftProto"; +option ruby_package = "Temporalio::Api::Protometa::V1"; +option csharp_namespace = "Temporalio.Api.Protometa.V1"; + +import "google/protobuf/descriptor.proto"; + +// Tags for draft declarations. + +extend google.protobuf.FieldOptions { + string draft = 98008; +} + +extend google.protobuf.MessageOptions { + string draft_message = 98008; +} + +extend google.protobuf.EnumOptions { + string draft_enum = 98008; +} + +extend google.protobuf.EnumValueOptions { + string draft_enum_value = 98008; +} + +extend google.protobuf.OneofOptions { + string draft_oneof = 98009; +} + +extend google.protobuf.ServiceOptions { + string draft_service = 98008; +} + +extend google.protobuf.MethodOptions { + string draft_method = 98008; +} diff --git a/cmd/generate-stable-protos/testdata/classification/inherit-draft-message/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/inherit-draft-message/input/temporal/api_next/fixture.proto index df215a0eb..7266f7210 100644 --- a/cmd/generate-stable-protos/testdata/classification/inherit-draft-message/input/temporal/api_next/fixture.proto +++ b/cmd/generate-stable-protos/testdata/classification/inherit-draft-message/input/temporal/api_next/fixture.proto @@ -6,4 +6,6 @@ message Draft { message Nested {} enum Mode { ZERO = 0; } oneof choice { string value = 1; } + repeated Nested children = 2; + map modes = 3; } diff --git a/cmd/generate-stable-protos/testdata/classification/message-types/expected.json b/cmd/generate-stable-protos/testdata/classification/message-types/expected.json index d13c9c31a..3e3ff3dc2 100644 --- a/cmd/generate-stable-protos/testdata/classification/message-types/expected.json +++ b/cmd/generate-stable-protos/testdata/classification/message-types/expected.json @@ -1,6 +1,17 @@ { "annotations": { - "fixture.Parent.extra": "feature-c", - "fixture.Draft": "feature-a" + "fixture.Parent.extra": "feature-a", + "fixture.Draft": "feature-a", + "fixture.Parent.single": "feature-a", + "fixture.Parent.list": "feature-a", + "fixture.Parent.by_name": "feature-a", + "fixture.Parent.draft": "feature-a", + "fixture.Parent.nested": "feature-a", + "fixture.Parent.state": "feature-a", + "fixture.Parent.states": "feature-a", + "fixture.Parent.state_by_name": "feature-a", + "fixture.Empty.draft": "feature-a", + "fixture.CycleB.draft": "feature-a", + "fixture.StableChild.draft": "feature-a" } } diff --git a/cmd/generate-stable-protos/testdata/classification/message-types/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/message-types/input/temporal/api_next/fixture.proto index 24a8a024c..18e299cd7 100644 --- a/cmd/generate-stable-protos/testdata/classification/message-types/input/temporal/api_next/fixture.proto +++ b/cmd/generate-stable-protos/testdata/classification/message-types/input/temporal/api_next/fixture.proto @@ -4,20 +4,20 @@ import "temporal/api_next/protometa/v1/draft.proto"; import "temporal/api_next/types.proto"; message Parent { string stable = 1; - Draft single = 2; - repeated Draft list = 3; - map by_name = 4; + Draft single = 2 [(temporal.api.protometa.v1.draft) = "feature-a"]; + repeated Draft list = 3 [(temporal.api.protometa.v1.draft) = "feature-a"]; + map by_name = 4 [(temporal.api.protometa.v1.draft) = "feature-a"]; oneof choice { - Draft draft = 5; + Draft draft = 5 [(temporal.api.protometa.v1.draft) = "feature-a"]; string stable_choice = 6; } - Draft.Nested nested = 9; - Draft.State state = 10; - Draft.Extra extra = 11 [(temporal.api.protometa.v1.draft) = "feature-c"]; + Draft.Nested nested = 9 [(temporal.api.protometa.v1.draft) = "feature-a"]; + Draft.State state = 10 [(temporal.api.protometa.v1.draft) = "feature-a"]; + Draft.Extra extra = 11 [(temporal.api.protometa.v1.draft) = "feature-a"]; StableChild stable_child = 12; - repeated Draft.State states = 13; - map state_by_name = 14; + repeated Draft.State states = 13 [(temporal.api.protometa.v1.draft) = "feature-a"]; + map state_by_name = 14 [(temporal.api.protometa.v1.draft) = "feature-a"]; } -message Empty { Draft draft = 1; } +message Empty { Draft draft = 1 [(temporal.api.protometa.v1.draft) = "feature-a"]; } message CycleA { CycleB child = 1; } -message CycleB { CycleA next = 1; Draft draft = 2; } +message CycleB { CycleA next = 1; Draft draft = 2 [(temporal.api.protometa.v1.draft) = "feature-a"]; } diff --git a/cmd/generate-stable-protos/testdata/classification/message-types/input/temporal/api_next/types.proto b/cmd/generate-stable-protos/testdata/classification/message-types/input/temporal/api_next/types.proto index 0cb5890c9..56697b1a2 100644 --- a/cmd/generate-stable-protos/testdata/classification/message-types/input/temporal/api_next/types.proto +++ b/cmd/generate-stable-protos/testdata/classification/message-types/input/temporal/api_next/types.proto @@ -12,5 +12,5 @@ message Draft { } message StableChild { string stable = 1; - Draft draft = 2; + Draft draft = 2 [(temporal.api.protometa.v1.draft) = "feature-a"]; } diff --git a/cmd/generate-stable-protos/testdata/classification/missing-field-draft/expected.json b/cmd/generate-stable-protos/testdata/classification/missing-field-draft/expected.json new file mode 100644 index 000000000..2d6fd4425 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/missing-field-draft/expected.json @@ -0,0 +1,3 @@ +{ + "error": "fixture.Config.modes: field references draft type fixture.Mode and requires draft = \"preview\"" +} diff --git a/cmd/generate-stable-protos/testdata/classification/missing-field-draft/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/missing-field-draft/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..389eba92d --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/missing-field-draft/input/temporal/api_next/fixture.proto @@ -0,0 +1,12 @@ +syntax = "proto3"; +package fixture; +import "temporal/api_next/protometa/v1/draft.proto"; + +enum Mode { + option (temporal.api.protometa.v1.draft_enum) = "preview"; + ZERO = 0; +} + +message Config { + map modes = 1; +} diff --git a/cmd/generate-stable-protos/testdata/classification/missing-field-draft/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/missing-field-draft/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..4ca06461c --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/missing-field-draft/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,42 @@ +syntax = "proto3"; + +package temporal.api.protometa.v1; + +option go_package = "go.temporal.io/api/protometa/v1;protometa"; +option java_package = "io.temporal.api.protometa.v1"; +option java_multiple_files = true; +option java_outer_classname = "DraftProto"; +option ruby_package = "Temporalio::Api::Protometa::V1"; +option csharp_namespace = "Temporalio.Api.Protometa.V1"; + +import "google/protobuf/descriptor.proto"; + +// Tags for draft declarations. + +extend google.protobuf.FieldOptions { + string draft = 98008; +} + +extend google.protobuf.MessageOptions { + string draft_message = 98008; +} + +extend google.protobuf.EnumOptions { + string draft_enum = 98008; +} + +extend google.protobuf.EnumValueOptions { + string draft_enum_value = 98008; +} + +extend google.protobuf.OneofOptions { + string draft_oneof = 98009; +} + +extend google.protobuf.ServiceOptions { + string draft_service = 98008; +} + +extend google.protobuf.MethodOptions { + string draft_method = 98008; +} diff --git a/cmd/generate-stable-protos/testdata/classification/removed-rpc-http/expected.json b/cmd/generate-stable-protos/testdata/classification/removed-rpc-http/expected.json index d2bf1f20b..28b9bfbbd 100644 --- a/cmd/generate-stable-protos/testdata/classification/removed-rpc-http/expected.json +++ b/cmd/generate-stable-protos/testdata/classification/removed-rpc-http/expected.json @@ -4,6 +4,5 @@ "fixture.Response": "preview", "fixture.Service.Call": "preview", "fixture.Item.draft_id": "preview" - }, - "validation_only": true + } } diff --git a/cmd/generate-stable-protos/testdata/classification/removed-rpc-http/expected/temporal/api/fixture.proto b/cmd/generate-stable-protos/testdata/classification/removed-rpc-http/expected/temporal/api/fixture.proto new file mode 100644 index 000000000..28e46e5ad --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/removed-rpc-http/expected/temporal/api/fixture.proto @@ -0,0 +1,16 @@ +syntax = "proto3"; +package fixture; + +// The marker uses the empty message. +import "google/protobuf/empty.proto"; + +// Item holds the request data. +message Item { + google.protobuf.Empty marker = 2; +} + +message OtherRequest {} +message OtherResponse {} +service Service { + rpc Stable(OtherRequest) returns (OtherResponse); +} diff --git a/cmd/generate-stable-protos/testdata/classification/removed-rpc-http/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/removed-rpc-http/input/temporal/api_next/fixture.proto index acda8a01c..0549b2e3d 100644 --- a/cmd/generate-stable-protos/testdata/classification/removed-rpc-http/input/temporal/api_next/fixture.proto +++ b/cmd/generate-stable-protos/testdata/classification/removed-rpc-http/input/temporal/api_next/fixture.proto @@ -1,9 +1,17 @@ syntax = "proto3"; package fixture; -import "google/api/annotations.proto"; import "temporal/api_next/protometa/v1/draft.proto"; + +// The HTTP annotations are used only by the preview call. + +import "google/api/annotations.proto"; +// This import can be pruned. + +// The marker uses the empty message. +import "google/protobuf/empty.proto"; message Request { option (temporal.api.protometa.v1.draft_message) = "preview"; Item item = 1; } -message Item { string draft_id = 1 [(temporal.api.protometa.v1.draft) = "preview"]; } +// Item holds the request data. +message Item { string draft_id = 1 [(temporal.api.protometa.v1.draft) = "preview"]; google.protobuf.Empty marker = 2; } message Response { option (temporal.api.protometa.v1.draft_message) = "preview"; } message OtherRequest {} message OtherResponse {} diff --git a/cmd/generate-stable-protos/testdata/classification/removed-rpc-request-header/expected.json b/cmd/generate-stable-protos/testdata/classification/removed-rpc-request-header/expected.json index d7c3237a7..6aa2b6f7b 100644 --- a/cmd/generate-stable-protos/testdata/classification/removed-rpc-request-header/expected.json +++ b/cmd/generate-stable-protos/testdata/classification/removed-rpc-request-header/expected.json @@ -4,6 +4,5 @@ "fixture.Response": "preview", "fixture.Service": "preview", "fixture.Item.draft_id": "feature-a" - }, - "validation_only": true + } } diff --git a/cmd/generate-stable-protos/testdata/classification/removed-rpc-request-header/expected/temporal/api/fixture.proto b/cmd/generate-stable-protos/testdata/classification/removed-rpc-request-header/expected/temporal/api/fixture.proto new file mode 100644 index 000000000..2f2132962 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/removed-rpc-request-header/expected/temporal/api/fixture.proto @@ -0,0 +1,6 @@ +syntax = "proto3"; +package fixture; + +message Item { + string id = 1; +} diff --git a/cmd/generate-stable-protos/testdata/classification/removed-rpc-request-header/expected/temporal/api/protometa/v1/annotations.proto b/cmd/generate-stable-protos/testdata/classification/removed-rpc-request-header/expected/temporal/api/protometa/v1/annotations.proto new file mode 100644 index 000000000..b14bec22a --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/removed-rpc-request-header/expected/temporal/api/protometa/v1/annotations.proto @@ -0,0 +1,37 @@ +syntax = "proto3"; + +package temporal.api.protometa.v1; + +import "google/protobuf/descriptor.proto"; + +option csharp_namespace = "Temporalio.Api.Protometa.V1"; +option go_package = "go.temporal.io/api/protometa/v1;protometa"; +option java_multiple_files = true; +option java_outer_classname = "AnnotationsProto"; +option java_package = "io.temporal.api.protometa.v1"; +option ruby_package = "Temporalio::Api::Protometa::V1"; + +// RequestHeaderAnnotation allows specifying that field values from a request +// should be propagated as outbound headers. +// +// The value field supports template interpolation where field paths enclosed +// in braces will be replaced with the actual field values from the request. +// For example: +// value: "{workflow_execution.workflow_id}" +// value: "workflow-{workflow_execution.workflow_id}" +// value: "{namespace}/{workflow_execution.workflow_id}" +message RequestHeaderAnnotation { + // The name of the header to set (e.g., "temporal-resource-id") + string header = 1; + + // A template string that may contain field paths in braces. + // Field paths use dot notation to traverse nested messages. + // Example: "{workflow_execution.workflow_id}" + string value = 2; +} + +// Extension to add request-header annotations to RPC methods. +// Multiple headers can be set by repeating this option. +extend google.protobuf.MethodOptions { + repeated RequestHeaderAnnotation request_header = 7234001; +} diff --git a/cmd/generate-stable-protos/testdata/classification/rpc-http-nested/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/rpc-http-nested/input/temporal/api_next/fixture.proto index a3a669069..246c8bbbb 100644 --- a/cmd/generate-stable-protos/testdata/classification/rpc-http-nested/input/temporal/api_next/fixture.proto +++ b/cmd/generate-stable-protos/testdata/classification/rpc-http-nested/input/temporal/api_next/fixture.proto @@ -2,7 +2,7 @@ syntax = "proto3"; package fixture; import "google/api/annotations.proto"; import "temporal/api_next/protometa/v1/draft.proto"; -message Request { Draft item = 1; } +message Request { Draft item = 1 [(temporal.api.protometa.v1.draft) = "feature-a"]; } message Draft { option (temporal.api.protometa.v1.draft_message) = "feature-a"; string id = 1; diff --git a/cmd/generate-stable-protos/testdata/classification/synthetic-oneof-name-collision/expected.json b/cmd/generate-stable-protos/testdata/classification/synthetic-oneof-name-collision/expected.json new file mode 100644 index 000000000..faf5f36c3 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/synthetic-oneof-name-collision/expected.json @@ -0,0 +1,5 @@ +{ + "annotations": { + "fixture.Example._foo": "preview" + } +} diff --git a/cmd/generate-stable-protos/testdata/classification/synthetic-oneof-name-collision/expected/temporal/api/fixture.proto b/cmd/generate-stable-protos/testdata/classification/synthetic-oneof-name-collision/expected/temporal/api/fixture.proto new file mode 100644 index 000000000..1ae65d2e1 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/synthetic-oneof-name-collision/expected/temporal/api/fixture.proto @@ -0,0 +1,6 @@ +syntax = "proto3"; +package fixture; + +message Example { + optional string foo = 2; +} diff --git a/cmd/generate-stable-protos/testdata/classification/synthetic-oneof-name-collision/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/synthetic-oneof-name-collision/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..4330d51bd --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/synthetic-oneof-name-collision/input/temporal/api_next/fixture.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; +package fixture; +import "temporal/api_next/protometa/v1/draft.proto"; + +message Example { + oneof _foo { + option (temporal.api.protometa.v1.draft_oneof) = "preview"; + string value = 1; + } + optional string foo = 2; +} diff --git a/cmd/generate-stable-protos/testdata/classification/synthetic-oneof-name-collision/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/synthetic-oneof-name-collision/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..4ca06461c --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/synthetic-oneof-name-collision/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,42 @@ +syntax = "proto3"; + +package temporal.api.protometa.v1; + +option go_package = "go.temporal.io/api/protometa/v1;protometa"; +option java_package = "io.temporal.api.protometa.v1"; +option java_multiple_files = true; +option java_outer_classname = "DraftProto"; +option ruby_package = "Temporalio::Api::Protometa::V1"; +option csharp_namespace = "Temporalio.Api.Protometa.V1"; + +import "google/protobuf/descriptor.proto"; + +// Tags for draft declarations. + +extend google.protobuf.FieldOptions { + string draft = 98008; +} + +extend google.protobuf.MessageOptions { + string draft_message = 98008; +} + +extend google.protobuf.EnumOptions { + string draft_enum = 98008; +} + +extend google.protobuf.EnumValueOptions { + string draft_enum_value = 98008; +} + +extend google.protobuf.OneofOptions { + string draft_oneof = 98009; +} + +extend google.protobuf.ServiceOptions { + string draft_service = 98008; +} + +extend google.protobuf.MethodOptions { + string draft_method = 98008; +} diff --git a/cmd/generate-stable-protos/testdata/comments/after-nested-draft-message/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/comments/after-nested-draft-message/input/temporal/api_next/fixture.proto index 8675696cf..f6b5db726 100644 --- a/cmd/generate-stable-protos/testdata/comments/after-nested-draft-message/input/temporal/api_next/fixture.proto +++ b/cmd/generate-stable-protos/testdata/comments/after-nested-draft-message/input/temporal/api_next/fixture.proto @@ -16,7 +16,7 @@ message Keeper { // leading d string d=5 ; - Thing t = 6; /* DRAFT block trailing t */ + Thing t = 6 [(temporal.api.protometa.v1.draft) = "thing"]; /* DRAFT block trailing t */ string e = 7 [ // DRAFT inside options (temporal.api.protometa.v1.draft) = "e" /* DRAFT inside options block */ diff --git a/cmd/generate-stable-protos/testdata/comments/attached/expected.json b/cmd/generate-stable-protos/testdata/comments/attached/expected.json index 5f0ed611d..1b63ad45f 100644 --- a/cmd/generate-stable-protos/testdata/comments/attached/expected.json +++ b/cmd/generate-stable-protos/testdata/comments/attached/expected.json @@ -5,6 +5,7 @@ "fixture.Keeper.e": "e", "fixture.Keeper.f": "f", "fixture.Keeper.g": "g", - "fixture.Thing": "thing" + "fixture.Thing": "thing", + "fixture.Keeper.t": "thing" } } diff --git a/cmd/generate-stable-protos/testdata/comments/attached/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/comments/attached/input/temporal/api_next/fixture.proto index 56b77a97c..22c9ac616 100644 --- a/cmd/generate-stable-protos/testdata/comments/attached/input/temporal/api_next/fixture.proto +++ b/cmd/generate-stable-protos/testdata/comments/attached/input/temporal/api_next/fixture.proto @@ -16,7 +16,7 @@ message Keeper { // leading d string d=5 ; - Thing t = 6; /* DRAFT block trailing t */ + Thing t = 6 [(temporal.api.protometa.v1.draft) = "thing"]; /* DRAFT block trailing t */ string e = 7 [ // DRAFT inside options (temporal.api.protometa.v1.draft) = "e" /* DRAFT inside options block */ diff --git a/cmd/generate-stable-protos/testdata/comments/dangling-after-last-draft-field/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/comments/dangling-after-last-draft-field/input/temporal/api_next/fixture.proto index 3930a3ee7..18c833043 100644 --- a/cmd/generate-stable-protos/testdata/comments/dangling-after-last-draft-field/input/temporal/api_next/fixture.proto +++ b/cmd/generate-stable-protos/testdata/comments/dangling-after-last-draft-field/input/temporal/api_next/fixture.proto @@ -16,7 +16,7 @@ message Keeper { // leading d string d=5 ; - Thing t = 6; /* DRAFT block trailing t */ + Thing t = 6 [(temporal.api.protometa.v1.draft) = "thing"]; /* DRAFT block trailing t */ string e = 7 [ // DRAFT inside options (temporal.api.protometa.v1.draft) = "e" /* DRAFT inside options block */ diff --git a/cmd/generate-stable-protos/testdata/comments/detached-before-stable-field/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/comments/detached-before-stable-field/input/temporal/api_next/fixture.proto index e0176368d..c876bbd7d 100644 --- a/cmd/generate-stable-protos/testdata/comments/detached-before-stable-field/input/temporal/api_next/fixture.proto +++ b/cmd/generate-stable-protos/testdata/comments/detached-before-stable-field/input/temporal/api_next/fixture.proto @@ -18,7 +18,7 @@ message Keeper { // leading d string d=5 ; - Thing t = 6; /* DRAFT block trailing t */ + Thing t = 6 [(temporal.api.protometa.v1.draft) = "thing"]; /* DRAFT block trailing t */ string e = 7 [ // DRAFT inside options (temporal.api.protometa.v1.draft) = "e" /* DRAFT inside options block */ diff --git a/cmd/generate-stable-protos/testdata/comments/detached-section-header/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/comments/detached-section-header/input/temporal/api_next/fixture.proto index 6ecd6d257..37dba9351 100644 --- a/cmd/generate-stable-protos/testdata/comments/detached-section-header/input/temporal/api_next/fixture.proto +++ b/cmd/generate-stable-protos/testdata/comments/detached-section-header/input/temporal/api_next/fixture.proto @@ -16,7 +16,7 @@ message Keeper { // leading d string d=5 ; - Thing t = 6; /* DRAFT block trailing t */ + Thing t = 6 [(temporal.api.protometa.v1.draft) = "thing"]; /* DRAFT block trailing t */ string e = 7 [ // DRAFT inside options (temporal.api.protometa.v1.draft) = "e" /* DRAFT inside options block */ diff --git a/cmd/generate-stable-protos/testdata/comments/end-of-file-after-draft-message/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/comments/end-of-file-after-draft-message/input/temporal/api_next/fixture.proto index 7fba453b7..0b0c2fa5a 100644 --- a/cmd/generate-stable-protos/testdata/comments/end-of-file-after-draft-message/input/temporal/api_next/fixture.proto +++ b/cmd/generate-stable-protos/testdata/comments/end-of-file-after-draft-message/input/temporal/api_next/fixture.proto @@ -16,7 +16,7 @@ message Keeper { // leading d string d=5 ; - Thing t = 6; /* DRAFT block trailing t */ + Thing t = 6 [(temporal.api.protometa.v1.draft) = "thing"]; /* DRAFT block trailing t */ string e = 7 [ // DRAFT inside options (temporal.api.protometa.v1.draft) = "e" /* DRAFT inside options block */ diff --git a/cmd/generate-stable-protos/testdata/comments/next-line-trailing/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/comments/next-line-trailing/input/temporal/api_next/fixture.proto index a8f50958e..5ffbd73ee 100644 --- a/cmd/generate-stable-protos/testdata/comments/next-line-trailing/input/temporal/api_next/fixture.proto +++ b/cmd/generate-stable-protos/testdata/comments/next-line-trailing/input/temporal/api_next/fixture.proto @@ -17,7 +17,7 @@ message Keeper { // leading d string d=5 ; - Thing t = 6; /* DRAFT block trailing t */ + Thing t = 6 [(temporal.api.protometa.v1.draft) = "thing"]; /* DRAFT block trailing t */ string e = 7 [ // DRAFT inside options (temporal.api.protometa.v1.draft) = "e" /* DRAFT inside options block */ diff --git a/cmd/generate-stable-protos/testdata/schema/removed-extension-option/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/schema/removed-extension-option/input/temporal/api_next/fixture.proto index cb790e911..d5c83afd5 100644 --- a/cmd/generate-stable-protos/testdata/schema/removed-extension-option/input/temporal/api_next/fixture.proto +++ b/cmd/generate-stable-protos/testdata/schema/removed-extension-option/input/temporal/api_next/fixture.proto @@ -1,5 +1,5 @@ -syntax = "proto2"; +syntax = "proto3"; package fixture; +import "google/protobuf/descriptor.proto"; import "temporal/api_next/protometa/v1/draft.proto"; -message Example { extensions 100 to max; } -extend Example { optional string value = 100 [(temporal.api.protometa.v1.draft_extension) = "preview"]; } +extend google.protobuf.MessageOptions { string value = 50000 [(temporal.api.protometa.v1.draft_extension) = "preview"]; } diff --git a/cmd/generate-stable-protos/walk.go b/cmd/generate-stable-protos/walk.go index 8dbc82aff..c8ccf48a8 100644 --- a/cmd/generate-stable-protos/walk.go +++ b/cmd/generate-stable-protos/walk.go @@ -11,35 +11,36 @@ func findDraftNodes(tags draftTags, f *ir.File) []ast.DeclAny { for t := range seq.Values(f.Types()) { walkType(tags, t, &dels) } + for service := range seq.Values(f.Services()) { + if tags.has(service.Options()) { + dels = append(dels, service.AST().AsAny()) + continue + } + for method := range seq.Values(service.Methods()) { + if tags.has(method.Options()) { + dels = append(dels, method.AST().AsAny()) + } + } + } return dels } func walkType(tags draftTags, t ir.Type, dels *[]ast.DeclAny) { - if isDraftType(tags, t) { + if tags.has(t.Options()) { *dels = append(*dels, t.AST().AsAny()) return } - draftByOneof := map[ir.Oneof][]ir.Member{} - for m := range seq.Values(t.Members()) { - if m.IsSynthetic() || !isDraftMember(tags, m) { - continue - } - if o := m.Oneof(); !o.IsZero() { - draftByOneof[o] = append(draftByOneof[o], m) - continue - } - *dels = append(*dels, m.AST().AsAny()) - } for o := range seq.Values(t.Oneofs()) { - draft := draftByOneof[o] - if total := o.Members().Len(); total > 0 && len(draft) == total { + if tags.has(o.Options()) { // An empty oneof is invalid, so remove the declaration with its branches. *dels = append(*dels, o.AST().AsAny()) - continue } - for _, m := range draft { - *dels = append(*dels, m.AST().AsAny()) + } + for m := range seq.Values(t.Members()) { + if m.IsSynthetic() || !tags.has(m.Options()) { + continue } + *dels = append(*dels, m.AST().AsAny()) } for nested := range seq.Values(t.Nested()) { // Synthetic map entries share the AST of the field handled above. From eeb6922321ac3fd9bcdb2bab7c0a4560df10da29 Mon Sep 17 00:00:00 2001 From: Stephan Behnke Date: Sat, 21 Nov 2026 10:18:28 -0700 Subject: [PATCH 15/20] generate-stable-protos: reject draft references in retained option literals What Rejects draft references in option literals on retained declarations, using validation and recompilation of the stable tree. Why A retained option needs to reference declarations that still exist after projection. Co-Authored-By: Claude Opus 5.5 --- cmd/generate-stable-protos/fixtures_test.go | 5 +++ cmd/generate-stable-protos/main.go | 17 +++++--- cmd/generate-stable-protos/tags.go | 42 ++++++++++++++----- .../removed-enum-option/expected.json | 7 ++++ .../expected/temporal/api/fixture.proto | 23 ++++++++++ .../input/temporal/api_next/fixture.proto | 31 ++++++++++++++ .../api_next/protometa/v1/draft.proto | 42 +++++++++++++++++++ .../expected.json | 3 ++ .../input/temporal/api_next/fixture.proto | 23 ++++++++++ .../api_next/protometa/v1/draft.proto | 42 +++++++++++++++++++ .../retained-any-option/expected.json | 4 ++ .../input/temporal/api_next/fixture.proto | 19 +++++++++ .../api_next/protometa/v1/draft.proto | 42 +++++++++++++++++++ .../retained-draft-enum-option/expected.json | 3 ++ .../input/temporal/api_next/fixture.proto | 22 ++++++++++ .../api_next/protometa/v1/draft.proto | 42 +++++++++++++++++++ .../retained-draft-option-field/expected.json | 4 ++ .../input/temporal/api_next/fixture.proto | 14 +++++++ .../api_next/protometa/v1/draft.proto | 42 +++++++++++++++++++ .../retained-enum-option/expected.json | 3 ++ .../input/temporal/api_next/fixture.proto | 23 ++++++++++ .../api_next/protometa/v1/draft.proto | 42 +++++++++++++++++++ docs/draft-apis.md | 2 +- 23 files changed, 481 insertions(+), 16 deletions(-) create mode 100644 cmd/generate-stable-protos/testdata/classification/removed-enum-option/expected.json create mode 100644 cmd/generate-stable-protos/testdata/classification/removed-enum-option/expected/temporal/api/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/removed-enum-option/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/classification/removed-enum-option/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/generator/retained-aggregate-enum-option/expected.json create mode 100644 cmd/generate-stable-protos/testdata/generator/retained-aggregate-enum-option/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/generator/retained-aggregate-enum-option/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/generator/retained-any-option/expected.json create mode 100644 cmd/generate-stable-protos/testdata/generator/retained-any-option/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/generator/retained-any-option/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/generator/retained-draft-enum-option/expected.json create mode 100644 cmd/generate-stable-protos/testdata/generator/retained-draft-enum-option/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/generator/retained-draft-enum-option/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/generator/retained-draft-option-field/expected.json create mode 100644 cmd/generate-stable-protos/testdata/generator/retained-draft-option-field/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/generator/retained-draft-option-field/input/temporal/api_next/protometa/v1/draft.proto create mode 100644 cmd/generate-stable-protos/testdata/generator/retained-enum-option/expected.json create mode 100644 cmd/generate-stable-protos/testdata/generator/retained-enum-option/input/temporal/api_next/fixture.proto create mode 100644 cmd/generate-stable-protos/testdata/generator/retained-enum-option/input/temporal/api_next/protometa/v1/draft.proto diff --git a/cmd/generate-stable-protos/fixtures_test.go b/cmd/generate-stable-protos/fixtures_test.go index d654e39f6..785de0025 100644 --- a/cmd/generate-stable-protos/fixtures_test.go +++ b/cmd/generate-stable-protos/fixtures_test.go @@ -31,6 +31,8 @@ func TestFixtures(t *testing.T) { type fixtureExpectation struct { // Error is a substring of the expected generator error; empty means success. Error string `json:"error"` + // Diagnostic is an optional compiler diagnostic required alongside Error. + Diagnostic string `json:"diagnostic"` // Annotations are the draft annotations the generator must accept. Annotations draftAnnotations `json:"annotations"` // ValidationOnly limits the fixture to source validation until projection supports it. @@ -85,6 +87,9 @@ func runFixture(t *testing.T, dir string) { if err == nil || !strings.Contains(err.Error(), expected.Error) { t.Fatalf("want error %q, got %v", expected.Error, err) } + if expected.Diagnostic != "" && !strings.Contains(err.Error(), expected.Diagnostic) { + t.Errorf("want diagnostic %q, got %v", expected.Diagnostic, err) + } if !maps.Equal(before, readTree(t, out)) { t.Fatal("generation failure modified output") } diff --git a/cmd/generate-stable-protos/main.go b/cmd/generate-stable-protos/main.go index 0c1a693fb..dd47785f6 100644 --- a/cmd/generate-stable-protos/main.go +++ b/cmd/generate-stable-protos/main.go @@ -189,7 +189,7 @@ func (cfg config) loadAPINext(ctx context.Context, root string, paths []string) annotations := draftAnnotations{} for _, p := range paths { f := byPath[p] - accepted, err := validateDraftAnnotations(tags, f) + accepted, err := validateDraftAnnotations(tags, f, p != cfg.draftSchema) if err != nil { return nil, draftTags{}, nil, err } @@ -250,13 +250,13 @@ func (cfg config) stripDrafts(ctx context.Context, root string, paths []string) func (cfg config) organizeImports(ctx context.Context, root string, order []string, texts map[string]string) (map[string]string, error) { results, err := lowerFiles(ctx, memOpener(root, texts), order) if err != nil { - return nil, fmt.Errorf("re-lower draft-stripped corpus: %w", err) + return nil, stableCompileError(err) } stableTexts := make(map[string]string, len(order)) for i, p := range order { if results[i].Fatal != nil { - return nil, fmt.Errorf("%s: %w", p, results[i].Fatal) + return nil, stableCompileError(fmt.Errorf("%s: %w", p, results[i].Fatal)) } irFile := results[i].Value @@ -281,7 +281,7 @@ func verifyGeneratedProtos(ctx context.Context, root string, stableTexts map[str paths := slices.Sorted(maps.Keys(stableTexts)) results, err := lowerFiles(ctx, memOpener(root, stableTexts), paths) if err != nil { - return fmt.Errorf("verify stable tree failed: %w", err) + return stableCompileError(err) } var errs error for i, r := range results { @@ -289,7 +289,14 @@ func verifyGeneratedProtos(ctx context.Context, root string, stableTexts map[str errs = errors.Join(errs, fmt.Errorf("verification failed at file %q: %w", paths[i], r.Fatal)) } } - return errs + if errs != nil { + return stableCompileError(errs) + } + return nil +} + +func stableCompileError(err error) error { + return fmt.Errorf("stable projection does not compile: a retained declaration likely references a draft declaration: %w", err) } // lowerFiles lowers paths in one session. Each pass must construct its opener once. diff --git a/cmd/generate-stable-protos/tags.go b/cmd/generate-stable-protos/tags.go index 6eaa8486b..525c61b44 100644 --- a/cmd/generate-stable-protos/tags.go +++ b/cmd/generate-stable-protos/tags.go @@ -70,12 +70,19 @@ type draftAnnotations map[ir.FullName]draftFeature type draftFeature = string -// validateDraftAnnotations checks annotation placement and feature names and returns the explicit annotations. -func validateDraftAnnotations(tags draftTags, f *ir.File) (draftAnnotations, error) { +// validateDraftAnnotations checks annotation placement, feature names, and enum values in retained options. +func validateDraftAnnotations(tags draftTags, f *ir.File, projected bool) (draftAnnotations, error) { accepted := draftAnnotations{} - check := func(name ir.FullName, placement, option string, opts ir.MessageValue) error { + check := func(name ir.FullName, placement, option string, opts ir.MessageValue, draftParent bool) error { v := tags.annotation(opts) if v.IsZero() { + if projected && !draftParent { + for opt := range opts.Fields() { + if value := draftOptionEnumValue(tags, opt); value != "" { + return fmt.Errorf("%s: option %s references draft enum value %s", name, opt.Field().FullName(), value) + } + } + } return nil } if option == "" || v.Field().FullName() != tags.packageName.Append(option) { @@ -88,7 +95,7 @@ func validateDraftAnnotations(tags draftTags, f *ir.File) (draftAnnotations, err accepted[name] = feature return nil } - if err := check(ir.FullName(f.Path()), "file", "", f.Options()); err != nil { + if err := check(ir.FullName(f.Path()), "file", "", f.Options(), false); err != nil { return nil, err } for t := range seq.Values(f.AllTypes()) { @@ -96,35 +103,36 @@ func validateDraftAnnotations(tags draftTags, f *ir.File) (draftAnnotations, err if t.IsEnum() { placement, option = "enum", "draft_enum" } - if err := check(t.FullName(), placement, option, t.Options()); err != nil { + if err := check(t.FullName(), placement, option, t.Options(), tags.typeFeature(t.Parent()) != ""); err != nil { return nil, err } + draft := tags.typeFeature(t) != "" for m := range seq.Values(t.Members()) { placement, option := "field", "draft" if m.IsEnumValue() { placement, option = "enum value", "draft_enum_value" } - if err := check(m.FullName(), placement, option, m.Options()); err != nil { + if err := check(m.FullName(), placement, option, m.Options(), draft || tags.has(m.Oneof().Options())); err != nil { return nil, err } } for o := range seq.Values(t.Oneofs()) { - if err := check(o.FullName(), "oneof", "draft_oneof", o.Options()); err != nil { + if err := check(o.FullName(), "oneof", "draft_oneof", o.Options(), draft); err != nil { return nil, err } } } for ext := range seq.Values(f.AllExtensions()) { - if err := check(ext.FullName(), "extension", "", ext.Options()); err != nil { + if err := check(ext.FullName(), "extension", "", ext.Options(), tags.typeFeature(ext.Parent()) != ""); err != nil { return nil, err } } for s := range seq.Values(f.Services()) { - if err := check(s.FullName(), "service", "draft_service", s.Options()); err != nil { + if err := check(s.FullName(), "service", "draft_service", s.Options(), false); err != nil { return nil, err } for m := range seq.Values(s.Methods()) { - if err := check(m.FullName(), "method", "draft_method", m.Options()); err != nil { + if err := check(m.FullName(), "method", "draft_method", m.Options(), tags.has(s.Options())); err != nil { return nil, err } } @@ -132,6 +140,20 @@ func validateDraftAnnotations(tags draftTags, f *ir.File) (draftAnnotations, err return accepted, nil } +func draftOptionEnumValue(tags draftTags, option ir.Value) ir.FullName { + for element := range seq.Values(option.Elements()) { + if value := element.AsEnum(); !value.IsZero() && (tags.has(value.Options()) || tags.typeFeature(value.Parent()) != "") { + return value.FullName() + } + for field := range element.AsMessage().Fields() { + if value := draftOptionEnumValue(tags, field); value != "" { + return value + } + } + } + return "" +} + const fieldPathPattern = `([a-zA-Z_][a-zA-Z_0-9]*(?:\.[a-zA-Z_][a-zA-Z_0-9]*)*)` var ( diff --git a/cmd/generate-stable-protos/testdata/classification/removed-enum-option/expected.json b/cmd/generate-stable-protos/testdata/classification/removed-enum-option/expected.json new file mode 100644 index 000000000..cb4f39f89 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/removed-enum-option/expected.json @@ -0,0 +1,7 @@ +{ + "annotations": { + "fixture.PREVIEW": "preview", + "fixture.Preview": "preview", + "fixture.Labels.preview": "preview" + } +} diff --git a/cmd/generate-stable-protos/testdata/classification/removed-enum-option/expected/temporal/api/fixture.proto b/cmd/generate-stable-protos/testdata/classification/removed-enum-option/expected/temporal/api/fixture.proto new file mode 100644 index 000000000..ac0feadce --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/removed-enum-option/expected/temporal/api/fixture.proto @@ -0,0 +1,23 @@ +syntax = "proto3"; +package fixture; + +import "google/protobuf/descriptor.proto"; +enum Mode { + STABLE = 0; +} + +message Labels { + repeated Mode modes = 1; +} + +extend google.protobuf.MessageOptions { + Mode mode = 50000; + Labels labels = 50001; +} + +message Stored { + option (mode) = STABLE; + option (labels) = { + modes: [STABLE] + }; +} diff --git a/cmd/generate-stable-protos/testdata/classification/removed-enum-option/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/removed-enum-option/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..b460fadee --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/removed-enum-option/input/temporal/api_next/fixture.proto @@ -0,0 +1,31 @@ +syntax = "proto3"; +package fixture; + +import "google/protobuf/descriptor.proto"; +import "temporal/api_next/protometa/v1/draft.proto"; + +enum Mode { + STABLE = 0; + PREVIEW = 1 [(temporal.api.protometa.v1.draft_enum_value) = "preview"]; +} + +message Labels { + repeated Mode modes = 1; + string preview = 2 [(temporal.api.protometa.v1.draft) = "preview"]; +} + +extend google.protobuf.MessageOptions { + Mode mode = 50000; + Labels labels = 50001; +} + +message Stored { + option (mode) = STABLE; + option (labels) = { modes: [STABLE] }; +} + +message Preview { + option (temporal.api.protometa.v1.draft_message) = "preview"; + option (mode) = PREVIEW; + option (labels) = { modes: [STABLE, PREVIEW], preview: "on" }; +} diff --git a/cmd/generate-stable-protos/testdata/classification/removed-enum-option/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/classification/removed-enum-option/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..4ca06461c --- /dev/null +++ b/cmd/generate-stable-protos/testdata/classification/removed-enum-option/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,42 @@ +syntax = "proto3"; + +package temporal.api.protometa.v1; + +option go_package = "go.temporal.io/api/protometa/v1;protometa"; +option java_package = "io.temporal.api.protometa.v1"; +option java_multiple_files = true; +option java_outer_classname = "DraftProto"; +option ruby_package = "Temporalio::Api::Protometa::V1"; +option csharp_namespace = "Temporalio.Api.Protometa.V1"; + +import "google/protobuf/descriptor.proto"; + +// Tags for draft declarations. + +extend google.protobuf.FieldOptions { + string draft = 98008; +} + +extend google.protobuf.MessageOptions { + string draft_message = 98008; +} + +extend google.protobuf.EnumOptions { + string draft_enum = 98008; +} + +extend google.protobuf.EnumValueOptions { + string draft_enum_value = 98008; +} + +extend google.protobuf.OneofOptions { + string draft_oneof = 98009; +} + +extend google.protobuf.ServiceOptions { + string draft_service = 98008; +} + +extend google.protobuf.MethodOptions { + string draft_method = 98008; +} diff --git a/cmd/generate-stable-protos/testdata/generator/retained-aggregate-enum-option/expected.json b/cmd/generate-stable-protos/testdata/generator/retained-aggregate-enum-option/expected.json new file mode 100644 index 000000000..8353dfcb9 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/generator/retained-aggregate-enum-option/expected.json @@ -0,0 +1,3 @@ +{ + "error": "fixture.Stored: option fixture.labels references draft enum value fixture.PREVIEW" +} diff --git a/cmd/generate-stable-protos/testdata/generator/retained-aggregate-enum-option/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/generator/retained-aggregate-enum-option/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..50427e658 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/generator/retained-aggregate-enum-option/input/temporal/api_next/fixture.proto @@ -0,0 +1,23 @@ +syntax = "proto3"; +package fixture; + +import "google/protobuf/descriptor.proto"; +import "temporal/api_next/protometa/v1/draft.proto"; + +enum Mode { + STABLE = 0; + PREVIEW = 1 [(temporal.api.protometa.v1.draft_enum_value) = "preview"]; +} + +message Labels { + repeated Mode modes = 1; +} + +extend google.protobuf.MessageOptions { + Mode mode = 50000; + Labels labels = 50001; +} + +message Stored { + option (labels) = { modes: [STABLE, PREVIEW] }; +} diff --git a/cmd/generate-stable-protos/testdata/generator/retained-aggregate-enum-option/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/generator/retained-aggregate-enum-option/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..4ca06461c --- /dev/null +++ b/cmd/generate-stable-protos/testdata/generator/retained-aggregate-enum-option/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,42 @@ +syntax = "proto3"; + +package temporal.api.protometa.v1; + +option go_package = "go.temporal.io/api/protometa/v1;protometa"; +option java_package = "io.temporal.api.protometa.v1"; +option java_multiple_files = true; +option java_outer_classname = "DraftProto"; +option ruby_package = "Temporalio::Api::Protometa::V1"; +option csharp_namespace = "Temporalio.Api.Protometa.V1"; + +import "google/protobuf/descriptor.proto"; + +// Tags for draft declarations. + +extend google.protobuf.FieldOptions { + string draft = 98008; +} + +extend google.protobuf.MessageOptions { + string draft_message = 98008; +} + +extend google.protobuf.EnumOptions { + string draft_enum = 98008; +} + +extend google.protobuf.EnumValueOptions { + string draft_enum_value = 98008; +} + +extend google.protobuf.OneofOptions { + string draft_oneof = 98009; +} + +extend google.protobuf.ServiceOptions { + string draft_service = 98008; +} + +extend google.protobuf.MethodOptions { + string draft_method = 98008; +} diff --git a/cmd/generate-stable-protos/testdata/generator/retained-any-option/expected.json b/cmd/generate-stable-protos/testdata/generator/retained-any-option/expected.json new file mode 100644 index 000000000..5bae95f2b --- /dev/null +++ b/cmd/generate-stable-protos/testdata/generator/retained-any-option/expected.json @@ -0,0 +1,4 @@ +{ + "error": "stable projection does not compile: a retained declaration likely references a draft declaration", + "diagnostic": "cannot find `PREVIEW`" +} diff --git a/cmd/generate-stable-protos/testdata/generator/retained-any-option/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/generator/retained-any-option/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..744ffadad --- /dev/null +++ b/cmd/generate-stable-protos/testdata/generator/retained-any-option/input/temporal/api_next/fixture.proto @@ -0,0 +1,19 @@ +syntax = "proto3"; +package fixture; +import "temporal/api_next/protometa/v1/draft.proto"; +import "google/protobuf/descriptor.proto"; +import "google/protobuf/any.proto"; + +enum Mode { + STABLE = 0; + PREVIEW = 1 [(temporal.api.protometa.v1.draft_enum_value) = "preview"]; +} +message Labels { + Mode mode = 1; +} +extend google.protobuf.MessageOptions { + google.protobuf.Any label = 50000; +} +message Stored { + option (label) = { [type.googleapis.com/fixture.Labels]: { mode: PREVIEW } }; +} diff --git a/cmd/generate-stable-protos/testdata/generator/retained-any-option/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/generator/retained-any-option/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..4ca06461c --- /dev/null +++ b/cmd/generate-stable-protos/testdata/generator/retained-any-option/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,42 @@ +syntax = "proto3"; + +package temporal.api.protometa.v1; + +option go_package = "go.temporal.io/api/protometa/v1;protometa"; +option java_package = "io.temporal.api.protometa.v1"; +option java_multiple_files = true; +option java_outer_classname = "DraftProto"; +option ruby_package = "Temporalio::Api::Protometa::V1"; +option csharp_namespace = "Temporalio.Api.Protometa.V1"; + +import "google/protobuf/descriptor.proto"; + +// Tags for draft declarations. + +extend google.protobuf.FieldOptions { + string draft = 98008; +} + +extend google.protobuf.MessageOptions { + string draft_message = 98008; +} + +extend google.protobuf.EnumOptions { + string draft_enum = 98008; +} + +extend google.protobuf.EnumValueOptions { + string draft_enum_value = 98008; +} + +extend google.protobuf.OneofOptions { + string draft_oneof = 98009; +} + +extend google.protobuf.ServiceOptions { + string draft_service = 98008; +} + +extend google.protobuf.MethodOptions { + string draft_method = 98008; +} diff --git a/cmd/generate-stable-protos/testdata/generator/retained-draft-enum-option/expected.json b/cmd/generate-stable-protos/testdata/generator/retained-draft-enum-option/expected.json new file mode 100644 index 000000000..8353dfcb9 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/generator/retained-draft-enum-option/expected.json @@ -0,0 +1,3 @@ +{ + "error": "fixture.Stored: option fixture.labels references draft enum value fixture.PREVIEW" +} diff --git a/cmd/generate-stable-protos/testdata/generator/retained-draft-enum-option/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/generator/retained-draft-enum-option/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..23f93454d --- /dev/null +++ b/cmd/generate-stable-protos/testdata/generator/retained-draft-enum-option/input/temporal/api_next/fixture.proto @@ -0,0 +1,22 @@ +syntax = "proto3"; +package fixture; + +import "google/protobuf/descriptor.proto"; +import "temporal/api_next/protometa/v1/draft.proto"; + +enum Mode { + option (temporal.api.protometa.v1.draft_enum) = "preview"; + PREVIEW = 0; +} + +message Labels { + Mode mode = 1 [(temporal.api.protometa.v1.draft) = "preview"]; +} + +extend google.protobuf.MessageOptions { + Labels labels = 50001; +} + +message Stored { + option (labels) = { mode: PREVIEW }; +} diff --git a/cmd/generate-stable-protos/testdata/generator/retained-draft-enum-option/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/generator/retained-draft-enum-option/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..4ca06461c --- /dev/null +++ b/cmd/generate-stable-protos/testdata/generator/retained-draft-enum-option/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,42 @@ +syntax = "proto3"; + +package temporal.api.protometa.v1; + +option go_package = "go.temporal.io/api/protometa/v1;protometa"; +option java_package = "io.temporal.api.protometa.v1"; +option java_multiple_files = true; +option java_outer_classname = "DraftProto"; +option ruby_package = "Temporalio::Api::Protometa::V1"; +option csharp_namespace = "Temporalio.Api.Protometa.V1"; + +import "google/protobuf/descriptor.proto"; + +// Tags for draft declarations. + +extend google.protobuf.FieldOptions { + string draft = 98008; +} + +extend google.protobuf.MessageOptions { + string draft_message = 98008; +} + +extend google.protobuf.EnumOptions { + string draft_enum = 98008; +} + +extend google.protobuf.EnumValueOptions { + string draft_enum_value = 98008; +} + +extend google.protobuf.OneofOptions { + string draft_oneof = 98009; +} + +extend google.protobuf.ServiceOptions { + string draft_service = 98008; +} + +extend google.protobuf.MethodOptions { + string draft_method = 98008; +} diff --git a/cmd/generate-stable-protos/testdata/generator/retained-draft-option-field/expected.json b/cmd/generate-stable-protos/testdata/generator/retained-draft-option-field/expected.json new file mode 100644 index 000000000..da304c3b2 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/generator/retained-draft-option-field/expected.json @@ -0,0 +1,4 @@ +{ + "error": "stable projection does not compile: a retained declaration likely references a draft declaration", + "diagnostic": "field referenced here" +} diff --git a/cmd/generate-stable-protos/testdata/generator/retained-draft-option-field/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/generator/retained-draft-option-field/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..2ac566f9e --- /dev/null +++ b/cmd/generate-stable-protos/testdata/generator/retained-draft-option-field/input/temporal/api_next/fixture.proto @@ -0,0 +1,14 @@ +syntax = "proto3"; +package fixture; +import "temporal/api_next/protometa/v1/draft.proto"; +import "google/protobuf/descriptor.proto"; + +message Labels { + string preview = 1 [(temporal.api.protometa.v1.draft) = "preview"]; +} +extend google.protobuf.MessageOptions { + Labels labels = 50000; +} +message Stored { + option (labels) = { preview: "on" }; +} diff --git a/cmd/generate-stable-protos/testdata/generator/retained-draft-option-field/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/generator/retained-draft-option-field/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..4ca06461c --- /dev/null +++ b/cmd/generate-stable-protos/testdata/generator/retained-draft-option-field/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,42 @@ +syntax = "proto3"; + +package temporal.api.protometa.v1; + +option go_package = "go.temporal.io/api/protometa/v1;protometa"; +option java_package = "io.temporal.api.protometa.v1"; +option java_multiple_files = true; +option java_outer_classname = "DraftProto"; +option ruby_package = "Temporalio::Api::Protometa::V1"; +option csharp_namespace = "Temporalio.Api.Protometa.V1"; + +import "google/protobuf/descriptor.proto"; + +// Tags for draft declarations. + +extend google.protobuf.FieldOptions { + string draft = 98008; +} + +extend google.protobuf.MessageOptions { + string draft_message = 98008; +} + +extend google.protobuf.EnumOptions { + string draft_enum = 98008; +} + +extend google.protobuf.EnumValueOptions { + string draft_enum_value = 98008; +} + +extend google.protobuf.OneofOptions { + string draft_oneof = 98009; +} + +extend google.protobuf.ServiceOptions { + string draft_service = 98008; +} + +extend google.protobuf.MethodOptions { + string draft_method = 98008; +} diff --git a/cmd/generate-stable-protos/testdata/generator/retained-enum-option/expected.json b/cmd/generate-stable-protos/testdata/generator/retained-enum-option/expected.json new file mode 100644 index 000000000..79df3f745 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/generator/retained-enum-option/expected.json @@ -0,0 +1,3 @@ +{ + "error": "fixture.Stored: option fixture.mode references draft enum value fixture.PREVIEW" +} diff --git a/cmd/generate-stable-protos/testdata/generator/retained-enum-option/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/generator/retained-enum-option/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..8223b6e2a --- /dev/null +++ b/cmd/generate-stable-protos/testdata/generator/retained-enum-option/input/temporal/api_next/fixture.proto @@ -0,0 +1,23 @@ +syntax = "proto3"; +package fixture; + +import "google/protobuf/descriptor.proto"; +import "temporal/api_next/protometa/v1/draft.proto"; + +enum Mode { + STABLE = 0; + PREVIEW = 1 [(temporal.api.protometa.v1.draft_enum_value) = "preview"]; +} + +message Labels { + repeated Mode modes = 1; +} + +extend google.protobuf.MessageOptions { + Mode mode = 50000; + Labels labels = 50001; +} + +message Stored { + option (mode) = PREVIEW; +} diff --git a/cmd/generate-stable-protos/testdata/generator/retained-enum-option/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/generator/retained-enum-option/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..4ca06461c --- /dev/null +++ b/cmd/generate-stable-protos/testdata/generator/retained-enum-option/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,42 @@ +syntax = "proto3"; + +package temporal.api.protometa.v1; + +option go_package = "go.temporal.io/api/protometa/v1;protometa"; +option java_package = "io.temporal.api.protometa.v1"; +option java_multiple_files = true; +option java_outer_classname = "DraftProto"; +option ruby_package = "Temporalio::Api::Protometa::V1"; +option csharp_namespace = "Temporalio.Api.Protometa.V1"; + +import "google/protobuf/descriptor.proto"; + +// Tags for draft declarations. + +extend google.protobuf.FieldOptions { + string draft = 98008; +} + +extend google.protobuf.MessageOptions { + string draft_message = 98008; +} + +extend google.protobuf.EnumOptions { + string draft_enum = 98008; +} + +extend google.protobuf.EnumValueOptions { + string draft_enum_value = 98008; +} + +extend google.protobuf.OneofOptions { + string draft_oneof = 98009; +} + +extend google.protobuf.ServiceOptions { + string draft_service = 98008; +} + +extend google.protobuf.MethodOptions { + string draft_method = 98008; +} diff --git a/docs/draft-apis.md b/docs/draft-apis.md index 0bf2db109..bde750503 100644 --- a/docs/draft-apis.md +++ b/docs/draft-apis.md @@ -173,7 +173,7 @@ _ = cfg.GetOverride() // temporal:allow-draft-api preview | Repository | Implemented today | Required by this specification | | --- | --- | --- | -| `api` | `draft.proto` declares `draft`, `draft_message`, `draft_enum`, `draft_enum_value`, `draft_service`, and `draft_method`. The generator accepts field and message annotations only, strips their comments, removes references to draft messages and to types that inherit draft status from enclosing messages, including nested enums and map value types, and drops emptied oneofs. It rejects RPCs and extensions using draft types and HTTP or request-header options naming removed fields. Buf checks preview reservations. | Add `draft_oneof` and remove recognition of `draft_file` and `draft_extension`. Validate before projection and support all seven placements, including explicit `draft_enum`. Limit RPC option reference checks to retained RPCs and continue rejecting extensions that reference draft types. Infer draft status only through containment, with one feature per declaration. | +| `api` | `draft.proto` declares all seven options. Before projection, the generator validates proto3 syntax, direct imports, annotation placement, feature names, containers and nesting, matching features on field type references, enum numbers and aliases, enum values in retained options, RPC signatures and draft endpoint uniqueness, and extension references to draft types. It checks HTTP and request-header field references on retained RPCs. Stable projection removes all seven draft placements, their contained declarations, unused imports, and comments owned by removed declarations and imports. The independent descriptor oracle checks the projected schema, surviving comments, and attachment by descriptor path. Buf checks preview reservations. | Implemented. | | `api-go` | `protoc-gen-go-helpers` accepts field and message annotations and generates recursive omission through affected messages, including message-valued maps. It infers draft status through type references and clears draft members of stable oneofs. It resets a disabled draft root with `proto.Reset`, clearing unknown fields. It rejects RPC signatures and extensions using draft types and checks HTTP and request-header references to removed fields. | Accept all seven placements, enforce one feature per declaration with implicit draft status only through containment, and accept valid draft RPC signatures. Remove recognition of `draft_file` and `draft_extension`. Limit RPC option reference checks to retained RPCs and keep the extension checks. Extend `OmitDraftFields` to cover whole draft oneofs and reachable draft enum values, and return whether it removed a disabled enum value from a retained field. | | Temporal server | `draftapi` accepts field and message placements and tracks their generated Go references, including affected oneof wrappers and enums and values inherited from draft messages. The runtime omits fields in covered unary requests, responses, error details, and Nexus paths. The unary-only guard test exists. | Remove recognition of `draft_file` and `draft_extension`. Extend the analyzer to the new placements and generated RPC and service symbols, using a single feature per declaration. Add descriptor-based RPC gating in covered public Temporal services and the frontend registration guard. Invoke the unified `OmitDraftFields` on affected roots and use its result to reject requests with a generic `codes.InvalidArgument` error. | From 096e0316403de450684908958ec5289e536ad84a Mon Sep 17 00:00:00 2001 From: Stephan Behnke Date: Fri, 20 Nov 2026 19:51:53 -0700 Subject: [PATCH 16/20] generate-stable-protos: generate random schemas with every draft placement What Expands the generated schema tests to cover every draft placement and a deliberately missing field annotation. Why The tests exercise combinations of draft declarations and verify rejection when a required annotation is missing. Co-Authored-By: Claude Opus 5.5 --- cmd/generate-stable-protos/random_test.go | 256 +++++++++++++++++----- 1 file changed, 202 insertions(+), 54 deletions(-) diff --git a/cmd/generate-stable-protos/random_test.go b/cmd/generate-stable-protos/random_test.go index 4c54d3780..05918f791 100644 --- a/cmd/generate-stable-protos/random_test.go +++ b/cmd/generate-stable-protos/random_test.go @@ -9,19 +9,15 @@ import ( "pgregory.net/rapid" ) -// TestRandomSchemas generates random api_next trees with draft fields and messages and +// TestRandomSchemas generates random api_next trees with all draft placements and // requires the generator to accept each one and a // second pass to reproduce it. Comments only sit where the generator accepts them: -// directly above a declaration or after it on the same line. +// directly above a declaration or on the same line as its opening or closing token. func TestRandomSchemas(t *testing.T) { t.Parallel() rapid.Check(t, func(rt *rapid.T) { root := t.TempDir() - writeFile(rt, filepath.Join(root, testConfig.draftSchema), randomDraftSchema) - for path, text := range newSchemaGen(rt).files() { - rt.Logf("%s:\n%s", path, text) - writeFile(rt, filepath.Join(root, path), text) - } + writeRandomSchema(rt, root, newSchemaGen(rt).files()) out := t.TempDir() if err := testConfig.stableProtosGenerator(t.Context(), root, out); err != nil { rt.Fatalf("generator rejected the schema: %v", err) @@ -30,11 +26,48 @@ func TestRandomSchemas(t *testing.T) { }) } +func TestRandomSchemasRejectMissingFieldDraft(t *testing.T) { + t.Parallel() + rapid.Check(t, func(rt *rapid.T) { + g := newSchemaGen(rt) + g.startFile("base") + typ := schemaType{name: "Preview", feature: g.feature()} + if rapid.Bool().Draw(rt, "enum target") { + g.enum(typ, "", "") + } else { + g.message(typ, "", 0, "") + } + format := rapid.SampledFrom(fieldFormats[:]).Draw(rt, "field format") + fmt.Fprintf(g.b, "message Stable { %s preview = 1; }\n", fmt.Sprintf(format, typ.name)) + + root := t.TempDir() + writeRandomSchema(rt, root, map[string]string{testConfig.nextDir + "/base.proto": g.b.String()}) + err := testConfig.stableProtosGenerator(t.Context(), root, t.TempDir()) + want := fmt.Sprintf("fixture.Stable.preview: field references draft type fixture.Preview and requires draft = %q", typ.feature) + if err == nil || !strings.Contains(err.Error(), want) { + rt.Fatalf("expected generator error containing %q, got %v", want, err) + } + }) +} + +func writeRandomSchema(rt *rapid.T, root string, files map[string]string) { + files[testConfig.draftSchema] = randomDraftSchema + for _, path := range sortedKeys(files, nil) { + rt.Logf("%s:\n%s", path, files[path]) + writeFile(rt, filepath.Join(root, path), files[path]) + } +} + const randomDraftSchema = `syntax = "proto3"; package temporal.api.protometa.v1; import "google/protobuf/descriptor.proto"; extend google.protobuf.FieldOptions { string draft = 98111; } extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } ` // schemaGen writes a base file and a dependent file, so that references, and the @@ -43,13 +76,13 @@ type schemaGen struct { rt *rapid.T b *strings.Builder comments int - // types are the messages fields in the current file may reference and their draft status. + // types are the messages and enums fields in the current file may reference and their draft status. types []schemaType } type schemaType struct { - name string - draft bool + name string + feature string } func newSchemaGen(rt *rapid.T) *schemaGen { return &schemaGen{rt: rt} } @@ -63,20 +96,35 @@ func (g *schemaGen) files() map[string]string { } } -func (g *schemaGen) file(name string, messages int, imported []schemaType) string { +func (g *schemaGen) startFile(name string) { g.b = &strings.Builder{} g.b.WriteString("syntax = \"proto3\";\npackage fixture;\n") g.b.WriteString("import \"" + testConfig.draftSchema + "\";\n") if name == "dependent" { g.b.WriteString("import \"" + testConfig.nextDir + "/base.proto\";\n") } +} + +func (g *schemaGen) file(name string, messages int, imported []schemaType) string { + g.startFile(name) + prefix := strings.ToUpper(name[:1]) + enums := make([]schemaType, rapid.IntRange(0, 2).Draw(g.rt, "enums")) + for i := range enums { + enums[i] = schemaType{fmt.Sprintf("%sEnum%d", prefix, i), g.maybeFeature("enum")} + } types := make([]schemaType, messages) for i := range types { - types[i] = schemaType{fmt.Sprintf("%s%d", strings.ToUpper(name[:1]), i), g.draft("message")} + types[i] = schemaType{fmt.Sprintf("%s%d", prefix, i), g.maybeFeature("message")} + } + g.types = append(append(append([]schemaType{}, imported...), types...), enums...) + for _, typ := range enums { + g.enum(typ, "", "") } - g.types = append(append([]schemaType{}, imported...), types...) for _, typ := range types { - g.message(typ, "", 0, false) + g.message(typ, "", 0, "") + } + for i := range rapid.IntRange(0, 2).Draw(g.rt, "services") { + g.service(fmt.Sprintf("%sService%d", prefix, i), g.maybeFeature("service")) } return g.b.String() } @@ -100,67 +148,167 @@ func (g *schemaGen) trailing() string { return "" } -func (g *schemaGen) draft(what string) bool { - return rapid.IntRange(0, 3).Draw(g.rt, "draft "+what) == 0 +func (g *schemaGen) declaration(indent, text string) { + g.leading(indent) + g.line(indent, text) } -func (g *schemaGen) message(typ schemaType, indent string, depth int, inheritedDraft bool) { - g.leading(indent) - g.b.WriteString(indent + "message " + typ.name + " {" + g.trailing() + "\n") +func (g *schemaGen) line(indent, text string) { + g.b.WriteString(indent + text + g.trailing() + "\n") +} + +func (g *schemaGen) feature() string { + return rapid.SampledFrom([]string{"preview", "feature"}).Draw(g.rt, "feature") +} + +func (g *schemaGen) maybeFeature(what string) string { + if rapid.IntRange(0, 3).Draw(g.rt, "draft "+what) == 0 { + return g.feature() + } + return "" +} + +func draftOption(annotation, feature string) string { + return fmt.Sprintf("(temporal.api.protometa.v1.%s) = %q", annotation, feature) +} + +func (g *schemaGen) option(indent, annotation, feature string) { + g.declaration(indent, "option "+draftOption(annotation, feature)+";") +} + +func (g *schemaGen) enum(typ schemaType, indent, inheritedFeature string) { + g.declaration(indent, "enum "+typ.name+" {") inner := indent + " " - if !inheritedDraft && typ.draft { - g.b.WriteString(inner + `option (temporal.api.protometa.v1.draft_message) = "feature";` + "\n") + if inheritedFeature == "" && typ.feature != "" { + g.option(inner, "draft_enum", typ.feature) + } + for i := range rapid.IntRange(1, 4).Draw(g.rt, "enum values") { + value := fmt.Sprintf("%s_%d = %d", strings.ToUpper(typ.name), i, i) + if i > 0 && typ.feature == "" { + if feature := g.maybeFeature("enum value"); feature != "" { + value += " [" + draftOption("draft_enum_value", feature) + "]" + } + } + g.declaration(inner, value+";") + } + g.line(indent, "}") +} + +var fieldFormats = [...]string{"%s", "repeated %s", "optional %s", "map"} + +func (g *schemaGen) message(typ schemaType, indent string, depth int, inheritedFeature string) { + g.declaration(indent, "message "+typ.name+" {") + inner := indent + " " + if inheritedFeature == "" && typ.feature != "" { + g.option(inner, "draft_message", typ.feature) } number := 0 - field := func(decl string, annotate bool) { + field := func(indent, decl, feature string) { number++ - g.leading(inner) - g.b.WriteString(fmt.Sprintf("%s%s f%d = %d", inner, decl, number, number)) - if annotate { - g.b.WriteString(` [(temporal.api.protometa.v1.draft) = "feature"]`) + text := fmt.Sprintf("%s f%d = %d", decl, number, number) + if feature != "" { + text += " [" + draftOption("draft", feature) + "]" } - g.b.WriteString(";" + g.trailing() + "\n") + g.declaration(indent, text+";") } - randomField := func(prefix, suffix string) { - ref := g.fieldType() - field(prefix+ref.name+suffix, !typ.draft && (ref.draft || g.draft("field"))) + randomField := func(indent, format, containerFeature string) { + ref := g.fieldType(containerFeature) + feature := "" + if containerFeature == "" { + feature = ref.feature + if feature == "" { + feature = g.maybeFeature("field") + } + } + field(indent, fmt.Sprintf(format, ref.name), feature) } for i := range rapid.IntRange(0, 5).Draw(g.rt, "members") { - switch rapid.IntRange(0, 6).Draw(g.rt, "member kind") { - case 0: - randomField("", "") - case 1: - randomField("repeated ", "") - case 2: - randomField("optional ", "") - case 3: - randomField("map") + switch kind := rapid.IntRange(0, 7).Draw(g.rt, "member kind"); kind { + case 0, 1, 2, 3: + randomField(inner, fieldFormats[kind], typ.feature) case 4: - g.leading(inner) - g.b.WriteString(fmt.Sprintf("%soneof o%d {%s\n", inner, i, g.trailing())) - saved := inner - inner += " " - field("string", false) + feature := typ.feature + if feature == "" { + feature = g.maybeFeature("oneof") + } + g.declaration(inner, fmt.Sprintf("oneof o%d {", i)) + branchIndent := inner + " " + if typ.feature == "" && feature != "" { + g.option(branchIndent, "draft_oneof", feature) + } + field(branchIndent, "string", "") for range rapid.IntRange(0, 2).Draw(g.rt, "additional branches") { - randomField("", "") + randomField(branchIndent, "%s", feature) } - inner = saved - g.b.WriteString(inner + "}" + g.trailing() + "\n") + g.line(inner, "}") case 5: if depth < 2 { - nested := schemaType{fmt.Sprintf("N%d", i), typ.draft || g.draft("message")} - g.message(nested, inner, depth+1, typ.draft) + feature := typ.feature + if feature == "" { + feature = g.maybeFeature("message") + } + nested := schemaType{fmt.Sprintf("N%d", i), feature} + g.message(nested, inner, depth+1, typ.feature) } + case 6: + feature := typ.feature + if feature == "" { + feature = g.maybeFeature("enum") + } + g.enum(schemaType{fmt.Sprintf("Enum%d", i), feature}, inner, typ.feature) default: - field("string", !typ.draft && g.draft("field")) + feature := "" + if typ.feature == "" { + feature = g.maybeFeature("field") + } + field(inner, "string", feature) } } - g.b.WriteString(indent + "}" + g.trailing() + "\n") + g.line(indent, "}") } -func (g *schemaGen) fieldType() schemaType { - if len(g.types) > 0 && rapid.Bool().Draw(g.rt, "message type") { - return rapid.SampledFrom(g.types).Draw(g.rt, "type") +func (g *schemaGen) fieldType(containerFeature string) schemaType { + if len(g.types) > 0 && rapid.Bool().Draw(g.rt, "named type") { + var candidates []schemaType + for _, typ := range g.types { + if containerFeature == "" || typ.feature == "" || typ.feature == containerFeature { + candidates = append(candidates, typ) + } + } + if len(candidates) > 0 { + return rapid.SampledFrom(candidates).Draw(g.rt, "type") + } } return schemaType{name: rapid.SampledFrom([]string{"string", "int32", "bool", "bytes"}).Draw(g.rt, "scalar")} } + +func (g *schemaGen) service(name, feature string) { + methods := make([]string, rapid.IntRange(1, 3).Draw(g.rt, "RPCs")) + for i := range methods { + methodFeature := feature + if feature == "" && i > 0 { + methodFeature = g.maybeFeature("method") + } + methods[i] = methodFeature + prefix := fmt.Sprintf("%sCall%d", name, i) + g.message(schemaType{prefix + "Request", methodFeature}, "", 0, "") + g.message(schemaType{prefix + "Response", methodFeature}, "", 0, "") + } + g.declaration("", "service "+name+" {") + if feature != "" { + g.option(" ", "draft_service", feature) + } + for i, methodFeature := range methods { + method := fmt.Sprintf("Call%d", i) + prefix := name + method + rpc := fmt.Sprintf("rpc %s(%sRequest) returns (%sResponse)", method, prefix, prefix) + if feature == "" && methodFeature != "" { + g.declaration(" ", rpc+" {") + g.option(" ", "draft_method", methodFeature) + g.line(" ", "}") + } else { + g.declaration(" ", rpc+";") + } + } + g.line("", "}") +} From 8fefb3b6c07f1f7b31d37171113b232346e8dde4 Mon Sep 17 00:00:00 2001 From: Stephan Behnke Date: Mon, 23 Nov 2026 13:33:20 -0700 Subject: [PATCH 17/20] generate-stable-protos: emit resolved draft feature gates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit What Emits a manifest with the effective draft feature gate for each classified declaration. Why Downstream generators can reuse the stable generator’s gate decisions and inheritance rules. --- README.md | 4 +- cmd/generate-stable-protos/main.go | 42 +++++++++++---- cmd/generate-stable-protos/main_test.go | 70 ++++++++++++++++++++++++- cmd/generate-stable-protos/rules.go | 5 +- cmd/generate-stable-protos/tags.go | 35 +++++++++++++ scripts/stable-api.sh | 2 +- temporal/api/draft-manifest.json | 7 +++ 7 files changed, 147 insertions(+), 18 deletions(-) create mode 100644 temporal/api/draft-manifest.json diff --git a/README.md b/README.md index 2d940f829..da17817d8 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,9 @@ Use `buf.next.yaml` to compile the preview tree. Edit proto files under `temporal/api_next/`. Run `make stable-api` to regenerate `temporal/api/`, or run `make` to also update the OpenAPI definitions. Do not edit `temporal/api/` by hand. Commit the regenerated -tree with your changes because CI fails if it is stale. +tree with your changes because CI fails if it is stale. This also regenerates +`temporal/api/draft-manifest.json`, which records the resolved feature gate for each draft +declaration for Go code generation. Use the `draft` field option or the `draft_message` message option from [`temporal/api_next/protometa/v1/draft.proto`](temporal/api_next/protometa/v1/draft.proto) to mark draft diff --git a/cmd/generate-stable-protos/main.go b/cmd/generate-stable-protos/main.go index dd47785f6..b052f06c7 100644 --- a/cmd/generate-stable-protos/main.go +++ b/cmd/generate-stable-protos/main.go @@ -2,6 +2,7 @@ package main import ( "context" + "encoding/json" "errors" "flag" "fmt" @@ -33,9 +34,10 @@ import ( const generatedHeader = "// Code generated by generate-stable-protos. DO NOT EDIT. \n // @generated \n\n" type config struct { - nextDir string - stableDir string - draftSchema string + nextDir string + stableDir string + draftSchema string + draftManifest bool } func defaultConfig() config { @@ -71,6 +73,7 @@ func main() { flag.StringVar(&cfg.nextDir, "next", cfg.nextDir, "source proto subdirectory relative to -root") flag.StringVar(&cfg.stableDir, "stable", cfg.stableDir, "stable proto subdirectory relative to -out") flag.StringVar(&cfg.draftSchema, "draft-schema", cfg.draftSchema, "draft option schema path relative to -root") + flag.BoolVar(&cfg.draftManifest, "draft-manifest", false, "write the resolved draft gates alongside the stable proto tree") flag.Parse() if err := cfg.stableProtosGenerator(context.Background(), *root, *outDir); err != nil { fmt.Fprintln(os.Stderr, err) @@ -116,7 +119,25 @@ func (cfg config) stableProtosGenerator(ctx context.Context, root, outDir string return fmt.Errorf("no protos found under %q", filepath.Join(root, cfg.nextDir)) } - strippedOrder, strippedProtos, comments, err := cfg.stripDrafts(ctx, root, paths) + byPath, tags, _, err := cfg.loadAPINext(ctx, root, paths) + if err != nil { + return err + } + var manifest []byte + if cfg.draftManifest { + gates := draftAnnotations{} + for _, p := range paths { + tags.collectGates(byPath[p], gates) + } + manifest, err = json.MarshalIndent(struct { + Version int `json:"version"` + Gates draftAnnotations `json:"gates"` + }{Version: 1, Gates: gates}, "", " ") + if err != nil { + return fmt.Errorf("encode draft manifest: %w", err) + } + } + strippedOrder, strippedProtos, comments, err := cfg.stripDrafts(byPath, tags, paths) if err != nil { return err } @@ -144,6 +165,9 @@ func (cfg config) stableProtosGenerator(ctx context.Context, root, outDir string return err } + if manifest != nil { + stableProtos[cfg.stableDir+"/draft-manifest.json"] = string(manifest) + "\n" + } return writeFiles(out, stableProtos) } @@ -207,11 +231,7 @@ func (cfg config) loadAPINext(ctx context.Context, root string, paths []string) return byPath, tags, annotations, nil } -func (cfg config) stripDrafts(ctx context.Context, root string, paths []string) ([]string, map[string]string, map[string]draftComments, error) { - byPath, tags, _, err := cfg.loadAPINext(ctx, root, paths) - if err != nil { - return nil, nil, nil, err - } +func (cfg config) stripDrafts(byPath map[string]*ir.File, tags draftTags, paths []string) ([]string, map[string]string, map[string]draftComments, error) { protoTexts := make(map[string]string, len(paths)) comments := make(map[string]draftComments, len(paths)) @@ -223,9 +243,11 @@ func (cfg config) stripDrafts(ctx context.Context, root string, paths []string) } dels := findDraftNodes(tags, irFile) - if comments[p], err = findDraftComments(irFile, dels); err != nil { + draftComments, err := findDraftComments(irFile, dels) + if err != nil { return nil, nil, nil, err } + comments[p] = draftComments edits := make([]edit.Edit, len(dels)) for j, d := range dels { edits[j] = edit.Edit{Kind: edit.KindDelete, Target: d} diff --git a/cmd/generate-stable-protos/main_test.go b/cmd/generate-stable-protos/main_test.go index 57a8c41f7..a201de890 100644 --- a/cmd/generate-stable-protos/main_test.go +++ b/cmd/generate-stable-protos/main_test.go @@ -1,6 +1,7 @@ package main import ( + "encoding/json" "errors" "io/fs" "maps" @@ -24,6 +25,11 @@ package example.meta; import "google/protobuf/descriptor.proto"; extend google.protobuf.FieldOptions { string draft = 50000; } extend google.protobuf.MessageOptions { string draft_message = 50000; } +extend google.protobuf.OneofOptions { string draft_oneof = 50000; } +extend google.protobuf.EnumOptions { string draft_enum = 50000; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 50000; } +extend google.protobuf.ServiceOptions { string draft_service = 50000; } +extend google.protobuf.MethodOptions { string draft_method = 50000; } `) writeFile(t, filepath.Join(root, "next/shared.proto"), `syntax = "proto3"; package example.api; @@ -36,19 +42,79 @@ import "next/meta/options.proto"; message Request { Shared shared = 1; string draft_field = 2 [(example.meta.draft) = "feature"]; + oneof choice { + option (example.meta.draft_oneof) = "choice-feature"; + string left = 3; + string right = 4; + } } message DraftMessage { option (example.meta.draft_message) = "feature"; + string child = 1; +} +message DraftResponse { + option (example.meta.draft_message) = "feature"; +} +message MixedRequest { + option (example.meta.draft_message) = "feature"; +} +message MixedResponse { + option (example.meta.draft_message) = "feature"; +} +enum Level { + LEVEL_UNSPECIFIED = 0; + LEVEL_PREVIEW = 1 [(example.meta.draft_enum_value) = "enum-value-feature"]; +} +enum Mode { + option (example.meta.draft_enum) = "enum-feature"; + MODE_UNSPECIFIED = 0; +} +service Preview { + option (example.meta.draft_service) = "feature"; + rpc Call(DraftMessage) returns (DraftResponse); +} +service Mixed { + rpc Call(Request) returns (Shared); + rpc PreviewCall(MixedRequest) returns (MixedResponse) { + option (example.meta.draft_method) = "feature"; + } } `) cmd := exec.Command("go", "run", ".", "-root", root, "-out", out, - "-next", "next", "-stable", "stable", "-draft-schema", "next/meta/options.proto") + "-next", "next", "-stable", "stable", "-draft-schema", "next/meta/options.proto", "-draft-manifest") if output, err := cmd.CombinedOutput(); err != nil { t.Fatalf("generate with custom paths: %v\n%s", err, output) } files := readTree(t, out) - if paths := slices.Sorted(maps.Keys(files)); !slices.Equal(paths, []string{"stable/service.proto", "stable/shared.proto"}) { + var manifest struct { + Version int `json:"version"` + Gates map[string]string `json:"gates"` + } + if err := json.Unmarshal([]byte(files["stable/draft-manifest.json"]), &manifest); err != nil { + t.Fatal(err) + } + wantGates := map[string]string{ + "example.api.DraftMessage": "feature", + "example.api.DraftMessage.child": "feature", + "example.api.DraftResponse": "feature", + "example.api.LEVEL_PREVIEW": "enum-value-feature", + "example.api.Mode": "enum-feature", + "example.api.MODE_UNSPECIFIED": "enum-feature", + "example.api.Preview": "feature", + "example.api.Preview.Call": "feature", + "example.api.Mixed.PreviewCall": "feature", + "example.api.MixedRequest": "feature", + "example.api.MixedResponse": "feature", + "example.api.Request.draft_field": "feature", + "example.api.Request.choice": "choice-feature", + "example.api.Request.left": "choice-feature", + "example.api.Request.right": "choice-feature", + } + if manifest.Version != 1 || !maps.Equal(manifest.Gates, wantGates) { + t.Fatalf("unexpected draft manifest: %+v", manifest) + } + if paths := slices.Sorted(maps.Keys(files)); !slices.Equal(paths, []string{"stable/draft-manifest.json", "stable/service.proto", "stable/shared.proto"}) { t.Fatalf("unexpected generated files: %v", paths) } service := files["stable/service.proto"] diff --git a/cmd/generate-stable-protos/rules.go b/cmd/generate-stable-protos/rules.go index 815b5e96f..6b2251ff7 100644 --- a/cmd/generate-stable-protos/rules.go +++ b/cmd/generate-stable-protos/rules.go @@ -68,10 +68,7 @@ func validateDraftRules(tags draftTags, f *ir.File, endpointUses rpcEndpointUses func validateDraftField(tags draftTags, field ir.Member, messageFeature draftFeature) error { oneof := field.Oneof() - containerFeature := tags.feature(oneof.Options()) - if containerFeature == "" { - containerFeature = messageFeature - } + containerFeature := tags.memberContainerFeature(field, messageFeature) feature := tags.feature(field.Options()) if containerFeature != "" { if feature != "" { diff --git a/cmd/generate-stable-protos/tags.go b/cmd/generate-stable-protos/tags.go index 525c61b44..7fa21cf1c 100644 --- a/cmd/generate-stable-protos/tags.go +++ b/cmd/generate-stable-protos/tags.go @@ -1,6 +1,7 @@ package main import ( + "cmp" "fmt" "regexp" "strings" @@ -254,3 +255,37 @@ func (tags draftTags) typeFeature(t ir.Type) draftFeature { } return "" } + +func (tags draftTags) memberContainerFeature(field ir.Member, parent draftFeature) draftFeature { + return cmp.Or(tags.feature(field.Oneof().Options()), parent) +} + +func (tags draftTags) collectGates(file *ir.File, gates draftAnnotations) { + add := func(name ir.FullName, gate draftFeature) { + if gate != "" { + gates[name] = gate + } + } + for typ := range seq.Values(file.AllTypes()) { + if typ.IsMapEntry() { + continue + } + parent := tags.typeFeature(typ) + add(typ.FullName(), parent) + for member := range seq.Values(typ.Members()) { + add(member.FullName(), cmp.Or(tags.feature(member.Options()), tags.memberContainerFeature(member, parent))) + } + for oneof := range seq.Values(typ.Oneofs()) { + if !oneof.AST().IsZero() { + add(oneof.FullName(), cmp.Or(tags.feature(oneof.Options()), parent)) + } + } + } + for service := range seq.Values(file.Services()) { + parent := tags.feature(service.Options()) + add(service.FullName(), parent) + for method := range seq.Values(service.Methods()) { + add(method.FullName(), cmp.Or(tags.feature(method.Options()), parent)) + } + } +} diff --git a/scripts/stable-api.sh b/scripts/stable-api.sh index 9fa19b2aa..46a9cc90c 100755 --- a/scripts/stable-api.sh +++ b/scripts/stable-api.sh @@ -13,7 +13,7 @@ cleanup() { exit "$status" } trap cleanup EXIT -"${GO:-go}" -C "$root/cmd/generate-stable-protos" run . -root "$root" -out "$stage" +"${GO:-go}" -C "$root/cmd/generate-stable-protos" run . -root "$root" -out "$stage" -draft-manifest (cd "$stage" && "${BUF:-buf}" format -w --config '{"version":"v2","modules":[{"path":"."}]}' .) if [[ -e "$destination" ]]; then mv "$destination" "$backup"; fi mv "$stage/temporal/api" "$destination" diff --git a/temporal/api/draft-manifest.json b/temporal/api/draft-manifest.json new file mode 100644 index 000000000..687a6e3cd --- /dev/null +++ b/temporal/api/draft-manifest.json @@ -0,0 +1,7 @@ +{ + "version": 1, + "gates": { + "temporal.api.update.v1.Request.user": "update-user-tagging", + "temporal.api.update.v1.Response.user": "update-user-tagging" + } +} From d91ac8e74482eda9933c86cfaef057dc4d334096 Mon Sep 17 00:00:00 2001 From: Stephan Behnke Date: Mon, 23 Nov 2026 14:39:51 -0700 Subject: [PATCH 18/20] api_next: move the draft example off workflow updates What Moves the draft example from workflow update user fields to `preview_note` on `DescribeNamespaceRequest`. Why A singular request field exercises draft filtering without reaching history or multi-operation collections. --- README.md | 2 +- temporal/api/draft-manifest.json | 3 +-- temporal/api/workflowservice/v1/request_response.proto | 2 -- temporal/api_next/update/v1/message.proto | 5 ----- temporal/api_next/workflowservice/v1/request_response.proto | 3 +++ 5 files changed, 5 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index da17817d8..aff2d381f 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ declaration for Go code generation. Use the `draft` field option or the `draft_message` message option from [`temporal/api_next/protometa/v1/draft.proto`](temporal/api_next/protometa/v1/draft.proto) to mark draft -declarations. For example, `string user = 7 [(temporal.api.protometa.v1.draft) = "update-user-tagging"];` +declarations. For example, `string preview_note = 4 [(temporal.api.protometa.v1.draft) = "draft-api-example"];` is a draft field. The generator removes annotated declarations from the stable tree. See the [draft API specification](docs/draft-apis.md) for annotation rules, runtime behavior, and implementation gaps. diff --git a/temporal/api/draft-manifest.json b/temporal/api/draft-manifest.json index 687a6e3cd..309bc5a0a 100644 --- a/temporal/api/draft-manifest.json +++ b/temporal/api/draft-manifest.json @@ -1,7 +1,6 @@ { "version": 1, "gates": { - "temporal.api.update.v1.Request.user": "update-user-tagging", - "temporal.api.update.v1.Response.user": "update-user-tagging" + "temporal.api.workflowservice.v1.DescribeNamespaceRequest.preview_note": "draft-api-example" } } diff --git a/temporal/api/workflowservice/v1/request_response.proto b/temporal/api/workflowservice/v1/request_response.proto index 8f2eec15a..14b269139 100644 --- a/temporal/api/workflowservice/v1/request_response.proto +++ b/temporal/api/workflowservice/v1/request_response.proto @@ -53,7 +53,6 @@ option java_multiple_files = true; option java_outer_classname = "RequestResponseProto"; option java_package = "io.temporal.api.workflowservice.v1"; option ruby_package = "Temporalio::Api::WorkflowService::V1"; - message RegisterNamespaceRequest { string namespace = 1; string description = 2; @@ -2506,7 +2505,6 @@ message DescribeDeploymentRequest { message DescribeDeploymentResponse { deployment.v1.DeploymentInfo deployment_info = 1; } - message DescribeWorkerDeploymentVersionRequest { string namespace = 1; // Deprecated. Use `deployment_version`. diff --git a/temporal/api_next/update/v1/message.proto b/temporal/api_next/update/v1/message.proto index 7a8da4f74..2c680312c 100644 --- a/temporal/api_next/update/v1/message.proto +++ b/temporal/api_next/update/v1/message.proto @@ -13,7 +13,6 @@ import "temporal/api_next/common/v1/message.proto"; import "temporal/api_next/enums/v1/update.proto"; import "temporal/api_next/failure/v1/message.proto"; import "temporal/api_next/nexus/v1/message.proto"; -import "temporal/api_next/protometa/v1/draft.proto"; // Specifies client's intent to wait for Update results. message WaitPolicy { @@ -72,8 +71,6 @@ message Request { repeated temporal.api.common.v1.Link links = 5; // Serialization context propagated from the Nexus caller that started this update. temporal.api.nexus.v1.PropagatedSerializationContext propagated_nexus_serialization_context = 6; - // User that triggered the update. - string user = 7 [(temporal.api.protometa.v1.draft) = "update-user-tagging"]; } // An Update protocol message indicating that a Workflow Update has been rejected. @@ -97,6 +94,4 @@ message Acceptance { message Response { Meta meta = 1; Outcome outcome = 2; - // User that triggered the update. - string user = 3 [(temporal.api.protometa.v1.draft) = "update-user-tagging"]; } diff --git a/temporal/api_next/workflowservice/v1/request_response.proto b/temporal/api_next/workflowservice/v1/request_response.proto index 82d23979e..47df6e841 100644 --- a/temporal/api_next/workflowservice/v1/request_response.proto +++ b/temporal/api_next/workflowservice/v1/request_response.proto @@ -34,6 +34,7 @@ import "temporal/api_next/filter/v1/message.proto"; import "temporal/api_next/protocol/v1/message.proto"; import "temporal/api_next/namespace/v1/message.proto"; import "temporal/api_next/query/v1/message.proto"; +import "temporal/api_next/protometa/v1/draft.proto"; import "temporal/api_next/replication/v1/message.proto"; import "temporal/api_next/rules/v1/message.proto"; import "temporal/api_next/sdk/v1/worker_config.proto"; @@ -93,6 +94,8 @@ message DescribeNamespaceRequest { // which preserves read-after-write consistency. SDKs should set this when // fetching namespace capabilities on worker/client startup. bool weak_consistency = 3; + // Example field for exercising draft API filtering. + string preview_note = 4 [(temporal.api.protometa.v1.draft) = "draft-api-example"]; } message DescribeNamespaceResponse { From af52922763ad361ab2566cd08ed04d0164f166f5 Mon Sep 17 00:00:00 2001 From: Stephan Behnke Date: Mon, 23 Nov 2026 14:39:51 -0700 Subject: [PATCH 19/20] generate-stable-protos: reject draft filtering inside retained collections What Rejects retained lists and maps whose entries could need draft filtering and records the guarantee in manifest version 2. Why Go bindings can clear a draft collection under its own gate and keep retained collections without visiting their entries. --- .../collections_test.go | 90 +++++++++++++++++++ cmd/generate-stable-protos/main.go | 2 +- cmd/generate-stable-protos/main_test.go | 2 +- cmd/generate-stable-protos/random_test.go | 12 ++- cmd/generate-stable-protos/rules.go | 43 +++++++-- cmd/generate-stable-protos/tags.go | 6 +- .../expected/temporal/api/fixture.proto | 6 +- .../input/temporal/api_next/fixture.proto | 6 +- .../classification/valid/expected.json | 2 + .../valid/expected/temporal/api/fixture.proto | 2 - .../input/temporal/api_next/fixture.proto | 4 +- docs/draft-apis.md | 10 ++- temporal/api/draft-manifest.json | 2 +- 13 files changed, 162 insertions(+), 25 deletions(-) create mode 100644 cmd/generate-stable-protos/collections_test.go diff --git a/cmd/generate-stable-protos/collections_test.go b/cmd/generate-stable-protos/collections_test.go new file mode 100644 index 000000000..2412c10da --- /dev/null +++ b/cmd/generate-stable-protos/collections_test.go @@ -0,0 +1,90 @@ +package main + +import ( + "os" + "path/filepath" + "strings" + "testing" +) + +func TestDraftCollections(t *testing.T) { + schema, err := os.ReadFile("../../temporal/api_next/protometa/v1/draft.proto") + if err != nil { + t.Fatal(err) + } + for _, tc := range []struct { + name string + proto string + want string + }{ + { + name: "stable repeated message reaches draft through a cycle", + proto: ` +message Root { repeated Item entries = 1; } +message Item { Nested nested = 1; } +message Nested { + Item cycle = 1; + string secret = 2 [(temporal.api.protometa.v1.draft) = "preview"]; +}`, + want: "fixture.Root.entries: retained collection reaches draft declaration fixture.Nested.secret", + }, + { + name: "stable map reaches an individually gated enum value", + proto: ` +message Root { map entries = 1; } +enum Mode { + MODE_UNSPECIFIED = 0; + MODE_PREVIEW = 1 [(temporal.api.protometa.v1.draft_enum_value) = "preview"]; +}`, + want: "fixture.Root.entries: retained collection reaches draft declaration fixture.MODE_PREVIEW", + }, + { + name: "gated list reaches a different gate", + proto: ` +message Root { repeated Item entries = 1 [(temporal.api.protometa.v1.draft) = "preview"]; } +message Item { + string secret = 1 [(temporal.api.protometa.v1.draft) = "details"]; +}`, + want: "fixture.Root.entries: retained collection reaches draft declaration fixture.Item.secret", + }, + { + name: "list and map clear under one gate", + proto: ` +message Root { + repeated Item entries = 1 [(temporal.api.protometa.v1.draft) = "preview"]; + map by_name = 2 [(temporal.api.protometa.v1.draft) = "preview"]; +} +message Item { + option (temporal.api.protometa.v1.draft_message) = "preview"; + repeated string names = 1; + Item cycle = 2; +}`, + }, + { + name: "gated collection can share a stable message with the same gate", + proto: ` +message Root { repeated Item entries = 1 [(temporal.api.protometa.v1.draft) = "preview"]; } +message Item { + string secret = 1 [(temporal.api.protometa.v1.draft) = "preview"]; +}`, + }, + } { + t.Run(tc.name, func(t *testing.T) { + cfg := defaultConfig() + root := t.TempDir() + writeFile(t, filepath.Join(root, cfg.draftSchema), string(schema)) + writeFile(t, filepath.Join(root, cfg.nextDir, "fixture.proto"), `syntax = "proto3"; +package fixture; +import "temporal/api_next/protometa/v1/draft.proto"; +`+tc.proto) + err := cfg.stableProtosGenerator(t.Context(), root, t.TempDir()) + if tc.want == "" { + if err != nil { + t.Fatal(err) + } + } else if err == nil || !strings.Contains(err.Error(), tc.want) { + t.Fatalf("want error containing %q, got %v", tc.want, err) + } + }) + } +} diff --git a/cmd/generate-stable-protos/main.go b/cmd/generate-stable-protos/main.go index b052f06c7..e2bd8630e 100644 --- a/cmd/generate-stable-protos/main.go +++ b/cmd/generate-stable-protos/main.go @@ -132,7 +132,7 @@ func (cfg config) stableProtosGenerator(ctx context.Context, root, outDir string manifest, err = json.MarshalIndent(struct { Version int `json:"version"` Gates draftAnnotations `json:"gates"` - }{Version: 1, Gates: gates}, "", " ") + }{Version: 2, Gates: gates}, "", " ") if err != nil { return fmt.Errorf("encode draft manifest: %w", err) } diff --git a/cmd/generate-stable-protos/main_test.go b/cmd/generate-stable-protos/main_test.go index a201de890..c13c55be8 100644 --- a/cmd/generate-stable-protos/main_test.go +++ b/cmd/generate-stable-protos/main_test.go @@ -111,7 +111,7 @@ service Mixed { "example.api.Request.left": "choice-feature", "example.api.Request.right": "choice-feature", } - if manifest.Version != 1 || !maps.Equal(manifest.Gates, wantGates) { + if manifest.Version != 2 || !maps.Equal(manifest.Gates, wantGates) { t.Fatalf("unexpected draft manifest: %+v", manifest) } if paths := slices.Sorted(maps.Keys(files)); !slices.Equal(paths, []string{"stable/draft-manifest.json", "stable/service.proto", "stable/shared.proto"}) { diff --git a/cmd/generate-stable-protos/random_test.go b/cmd/generate-stable-protos/random_test.go index 05918f791..49aa081d3 100644 --- a/cmd/generate-stable-protos/random_test.go +++ b/cmd/generate-stable-protos/random_test.go @@ -212,7 +212,13 @@ func (g *schemaGen) message(typ schemaType, indent string, depth int, inheritedF g.declaration(indent, text+";") } randomField := func(indent, format, containerFeature string) { - ref := g.fieldType(containerFeature) + var ref schemaType + switch format { + case "repeated %s", "map": + ref = g.scalarType() + default: + ref = g.fieldType(containerFeature) + } feature := "" if containerFeature == "" { feature = ref.feature @@ -279,6 +285,10 @@ func (g *schemaGen) fieldType(containerFeature string) schemaType { return rapid.SampledFrom(candidates).Draw(g.rt, "type") } } + return g.scalarType() +} + +func (g *schemaGen) scalarType() schemaType { return schemaType{name: rapid.SampledFrom([]string{"string", "int32", "bool", "bytes"}).Draw(g.rt, "scalar")} } diff --git a/cmd/generate-stable-protos/rules.go b/cmd/generate-stable-protos/rules.go index 6b2251ff7..dc2375774 100644 --- a/cmd/generate-stable-protos/rules.go +++ b/cmd/generate-stable-protos/rules.go @@ -80,20 +80,53 @@ func validateDraftField(tags draftTags, field ir.Member, messageFeature draftFea feature = containerFeature } - typ := field.Element() - if field.IsMap() { - _, value := typ.EntryFields() - typ = value.Element() - } + typ := fieldValueType(field) if typeFeature := tags.typeFeature(typ); typeFeature != "" && typeFeature != feature { if feature == "" { return fmt.Errorf("%s: field references draft type %s and requires draft = %q", field.FullName(), typ.FullName(), typeFeature) } return fmt.Errorf("%s: draft feature %q does not match draft type %s feature %q", field.FullName(), feature, typ.FullName(), typeFeature) } + if field.IsRepeated() || field.IsMap() { + if declaration, gate := tags.findCollectionDraft(typ, feature, make(map[ir.FullName]bool)); gate != "" { + return fmt.Errorf("%s: retained collection reaches draft declaration %s gated by %q", field.FullName(), declaration, gate) + } + } return nil } +func fieldValueType(field ir.Member) ir.Type { + typ := field.Element() + if field.IsMap() { + _, value := typ.EntryFields() + return value.Element() + } + return typ +} + +func (tags draftTags) findCollectionDraft(typ ir.Type, enabled draftFeature, seen map[ir.FullName]bool) (ir.FullName, draftFeature) { + if typ.IsZero() || typ.IsPredeclared() || seen[typ.FullName()] { + return "", "" + } + seen[typ.FullName()] = true + + typeFeature := tags.typeFeature(typ) + if typeFeature != "" && typeFeature != enabled { + return typ.FullName(), typeFeature + } + for member := range seq.Values(typ.Members()) { + if gate := tags.memberFeature(member, typeFeature); gate != "" && gate != enabled { + return member.FullName(), gate + } + if !typ.IsEnum() { + if name, gate := tags.findCollectionDraft(fieldValueType(member), enabled, seen); gate != "" { + return name, gate + } + } + } + return "", "" +} + func draftNestingError(name, container ir.FullName) error { return fmt.Errorf("%s: draft annotation is not allowed inside draft container %s", name, container) } diff --git a/cmd/generate-stable-protos/tags.go b/cmd/generate-stable-protos/tags.go index 7fa21cf1c..1a0b16480 100644 --- a/cmd/generate-stable-protos/tags.go +++ b/cmd/generate-stable-protos/tags.go @@ -260,6 +260,10 @@ func (tags draftTags) memberContainerFeature(field ir.Member, parent draftFeatur return cmp.Or(tags.feature(field.Oneof().Options()), parent) } +func (tags draftTags) memberFeature(member ir.Member, parent draftFeature) draftFeature { + return cmp.Or(tags.feature(member.Options()), tags.memberContainerFeature(member, parent)) +} + func (tags draftTags) collectGates(file *ir.File, gates draftAnnotations) { add := func(name ir.FullName, gate draftFeature) { if gate != "" { @@ -273,7 +277,7 @@ func (tags draftTags) collectGates(file *ir.File, gates draftAnnotations) { parent := tags.typeFeature(typ) add(typ.FullName(), parent) for member := range seq.Values(typ.Members()) { - add(member.FullName(), cmp.Or(tags.feature(member.Options()), tags.memberContainerFeature(member, parent))) + add(member.FullName(), tags.memberFeature(member, parent)) } for oneof := range seq.Values(typ.Oneofs()) { if !oneof.AST().IsZero() { diff --git a/cmd/generate-stable-protos/testdata/classification/removed-enum-option/expected/temporal/api/fixture.proto b/cmd/generate-stable-protos/testdata/classification/removed-enum-option/expected/temporal/api/fixture.proto index ac0feadce..2f5f2db25 100644 --- a/cmd/generate-stable-protos/testdata/classification/removed-enum-option/expected/temporal/api/fixture.proto +++ b/cmd/generate-stable-protos/testdata/classification/removed-enum-option/expected/temporal/api/fixture.proto @@ -7,7 +7,7 @@ enum Mode { } message Labels { - repeated Mode modes = 1; + Mode mode = 1; } extend google.protobuf.MessageOptions { @@ -17,7 +17,5 @@ extend google.protobuf.MessageOptions { message Stored { option (mode) = STABLE; - option (labels) = { - modes: [STABLE] - }; + option (labels) = {mode: STABLE}; } diff --git a/cmd/generate-stable-protos/testdata/classification/removed-enum-option/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/removed-enum-option/input/temporal/api_next/fixture.proto index b460fadee..71d96158b 100644 --- a/cmd/generate-stable-protos/testdata/classification/removed-enum-option/input/temporal/api_next/fixture.proto +++ b/cmd/generate-stable-protos/testdata/classification/removed-enum-option/input/temporal/api_next/fixture.proto @@ -10,7 +10,7 @@ enum Mode { } message Labels { - repeated Mode modes = 1; + Mode mode = 1; string preview = 2 [(temporal.api.protometa.v1.draft) = "preview"]; } @@ -21,11 +21,11 @@ extend google.protobuf.MessageOptions { message Stored { option (mode) = STABLE; - option (labels) = { modes: [STABLE] }; + option (labels) = { mode: STABLE }; } message Preview { option (temporal.api.protometa.v1.draft_message) = "preview"; option (mode) = PREVIEW; - option (labels) = { modes: [STABLE, PREVIEW], preview: "on" }; + option (labels) = { mode: PREVIEW, preview: "on" }; } diff --git a/cmd/generate-stable-protos/testdata/classification/valid/expected.json b/cmd/generate-stable-protos/testdata/classification/valid/expected.json index 8562b0e7a..72801f55a 100644 --- a/cmd/generate-stable-protos/testdata/classification/valid/expected.json +++ b/cmd/generate-stable-protos/testdata/classification/valid/expected.json @@ -1,5 +1,7 @@ { "annotations": { + "fixture.Example.by_name": "feature-b", + "fixture.Example.children": "feature-b", "fixture.Example.a": "feature-a", "fixture.Example.optional_b": "feature-b", "fixture.Example.draft_choice": "feature-a", diff --git a/cmd/generate-stable-protos/testdata/classification/valid/expected/temporal/api/fixture.proto b/cmd/generate-stable-protos/testdata/classification/valid/expected/temporal/api/fixture.proto index 2c0adb7f4..15c805954 100644 --- a/cmd/generate-stable-protos/testdata/classification/valid/expected/temporal/api/fixture.proto +++ b/cmd/generate-stable-protos/testdata/classification/valid/expected/temporal/api/fixture.proto @@ -4,8 +4,6 @@ package fixture; // Stable root comment. message Example { string stable = 1; - repeated Child children = 4; - map by_name = 5; oneof choice { string stable_choice = 6; } diff --git a/cmd/generate-stable-protos/testdata/classification/valid/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/classification/valid/input/temporal/api_next/fixture.proto index b7b65707d..a3a842342 100644 --- a/cmd/generate-stable-protos/testdata/classification/valid/input/temporal/api_next/fixture.proto +++ b/cmd/generate-stable-protos/testdata/classification/valid/input/temporal/api_next/fixture.proto @@ -6,8 +6,8 @@ message Example { string stable = 1; string a = 2 [(temporal.api.protometa.v1.draft) = "feature-a"]; optional int32 optional_b = 3 [(temporal.api.protometa.v1.draft) = "feature-b"]; - repeated Child children = 4; - map by_name = 5; + repeated Child children = 4 [(temporal.api.protometa.v1.draft) = "feature-b"]; + map by_name = 5 [(temporal.api.protometa.v1.draft) = "feature-b"]; oneof choice { string stable_choice = 6; int32 draft_choice = 7 [(temporal.api.protometa.v1.draft) = "feature-a"]; diff --git a/docs/draft-apis.md b/docs/draft-apis.md index bde750503..1dcdbf37a 100644 --- a/docs/draft-apis.md +++ b/docs/draft-apis.md @@ -102,6 +102,8 @@ Every draft declaration has exactly one feature. Containment is the only source A message with draft fields and an enum with draft values can each remain stable. Fields that use those stable types can remain stable, and runtime filtering visits the draft contents recursively. +A retained list or map must be safe to send without filtering individual entries. A stable collection cannot reach any draft fields, types, or enum values through its element or value type. A draft collection can reach declarations with the same feature as the collection, because retaining it means that feature is enabled. A field inside a draft message also inherits that message's feature for this check. + ```proto message PreviewConfig { option (temporal.api.protometa.v1.draft_message) = "preview"; @@ -143,11 +145,11 @@ Reject any protobuf extension declaration whose value type, extendee, or declari ## Runtime filtering -`api-go` generates a single method, `OmitDraftFields(enabled func(string) bool) (removedEnumValue bool)`, for affected `api_next` Go types. Determine reachability statically through singular fields, oneof members, repeated elements, and map values. Generate the method for roots that reach draft fields or containers and for roots that reach only individually annotated draft enum values. +`api-go` generates a single method, `OmitDraftFields(enabled func(string) bool) (removedEnumValue bool)`, for affected `api_next` Go types. Determine reachability statically through singular fields and oneof members. A repeated or map field contributes its own feature gate. Generate the method for roots that reach draft fields or containers and for roots that reach only individually annotated draft enum values. -In one traversal, the method clears fields and oneofs whose features are disabled and skips their contents. In retained fields, it clears singular occurrences of disabled draft enum values, drops matching repeated elements, and deletes map entries containing a matching value. Clearing a singular field also removes explicit presence or unsets its active oneof member where applicable. The return value is true if the traversal removed at least one disabled draft enum value from a retained field, including in a nested message. Removing an entire disabled field or container leaves the return value false unless the traversal finds a disabled enum value elsewhere. +In one traversal, the method clears fields and oneofs whose features are disabled and skips their contents. The helper clears draft lists and maps as whole fields and leaves the entries of retained collections in place. It clears disabled draft enum values from retained singular fields. Clearing a singular field also removes explicit presence or unsets its active oneof member where applicable. The return value is true if the traversal removed at least one disabled draft enum value from a retained field, including in a nested message. Removing an entire disabled field or container leaves the return value false unless the traversal finds a disabled enum value elsewhere. -On requests, the server rejects a true result with `codes.InvalidArgument` and a generic message such as “Request contains a disabled draft enum value.” The message never names the enum, value, or field. On responses and outbound protobuf error details, the server applies the same method and ignores its result. For example, with `priority` disabled, a request that includes `PRIORITY_HIGH` in a retained `repeated Priority priorities` field is rejected. The same element is dropped from a response, preserving the other elements. +On requests, the server rejects a true result with `codes.InvalidArgument` and a generic message such as “Request contains a disabled draft enum value.” The message never names the enum, value, or field. On responses and outbound protobuf error details, the server applies the same method and ignores its result. For example, with `priority` disabled, a request with `PRIORITY_HIGH` in a retained `Priority priority` field is rejected. The filter clears that field on a response. The server reads draft RPC features from method and service descriptors. On public Temporal API services registered by the frontend, a draft RPC returns `codes.Unimplemented` before dispatch if its feature is disabled. This scope includes `WorkflowService`, `OperatorService`, and future public Temporal API services registered by the frontend. @@ -180,5 +182,5 @@ _ = cfg.GetOverride() // temporal:allow-draft-api preview ### PR order and verification 1. **`api`** supplies the annotation schema, stable projection, and shared classification fixtures for valid and invalid declarations, including field type references, all-draft containers, endpoint reuse, enum aliases, and retained versus removed RPC option references. The independent descriptor oracle compares the projected schema and surviving comments for all placements. -2. **`api-go`** takes the updated `api` revision, consumes the shared classification fixtures, and regenerates the Go trees and helper fixtures. Extend `draftwire` to check that field and enum omission with features disabled matches the stable projection and that enabling all features preserves the input. Build the expected result independently of the generated helper. Walk a copy of the original payload using the `api_next` descriptors. Clear disabled fields and containers and skip their contents. From retained fields, remove enum occurrences whose numbers have a `draft_enum_value` annotation with a disabled feature. Clear singular fields, drop matching repeated elements and map entries, and preserve all other values, including unrecognized enum numbers. Check that the helper's result reports whether the walk removed an enum value from a retained field. Marshal the copy, decode it against stable descriptors with `DiscardUnknown`, and compare it with the filtered output decoded against the same descriptors. `DiscardUnknown` alone preserves unrecognized proto3 enum numbers in known fields, including numbers of projected-out enum values. +2. **`api-go`** takes the updated `api` revision, consumes the shared classification fixtures, and regenerates the Go trees and helper fixtures. Extend `draftwire` to check that field and enum omission with features disabled matches the stable projection and that enabling all features preserves the input. Build the expected result independently of the generated helper. Walk a copy of the original payload using the `api_next` descriptors. Clear disabled fields and containers and skip their contents. From retained singular fields, remove enum occurrences whose numbers have a `draft_enum_value` annotation with a disabled feature. Preserve all other values, including unrecognized enum numbers, and leave retained collection entries in place. Check that the helper's result reports whether the walk removed an enum value from a retained field. Marshal the copy, decode it against stable descriptors with `DiscardUnknown`, and compare it with the filtered output decoded against the same descriptors. `DiscardUnknown` alone preserves unrecognized proto3 enum numbers in known fields, including numbers of projected-out enum values. 3. **Temporal server** takes the regenerated `api-go/api_next` revision. Extend the `draftapi` contract test to cover the new generated symbols and their features. Extend the descriptor-based filter properties to cover RPC gating and enum-only roots, including generic request rejection and omission from responses and error details. Check that enum values inside disabled fields do not trigger rejection and that the frontend registration guard accounts for every registered service. diff --git a/temporal/api/draft-manifest.json b/temporal/api/draft-manifest.json index 309bc5a0a..379f2a4ff 100644 --- a/temporal/api/draft-manifest.json +++ b/temporal/api/draft-manifest.json @@ -1,5 +1,5 @@ { - "version": 1, + "version": 2, "gates": { "temporal.api.workflowservice.v1.DescribeNamespaceRequest.preview_note": "draft-api-example" } From 48b07668a9dd11e1b2d2760d4029da143114fc2a Mon Sep 17 00:00:00 2001 From: Stephan Behnke Date: Tue, 24 Nov 2026 09:35:50 -0700 Subject: [PATCH 20/20] Document how to develop and release draft protos What Explains where to edit draft and stable declarations, when to remove a draft annotation, and how to regenerate both outputs. Why Contributors need a clear path from editing the source schema to committing the generated stable files. --- README.md | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index aff2d381f..76601bb3c 100644 --- a/README.md +++ b/README.md @@ -15,17 +15,14 @@ Use `buf.next.yaml` to compile the preview tree. ## Contribution -Edit proto files under `temporal/api_next/`. Run `make stable-api` to regenerate `temporal/api/`, or run -`make` to also update the OpenAPI definitions. Do not edit `temporal/api/` by hand. Commit the regenerated -tree with your changes because CI fails if it is stale. This also regenerates -`temporal/api/draft-manifest.json`, which records the resolved feature gate for each draft -declaration for Go code generation. - -Use the `draft` field option or the `draft_message` message option from -[`temporal/api_next/protometa/v1/draft.proto`](temporal/api_next/protometa/v1/draft.proto) to mark draft -declarations. For example, `string preview_note = 4 [(temporal.api.protometa.v1.draft) = "draft-api-example"];` -is a draft field. The generator removes annotated declarations from the stable tree. -See the [draft API specification](docs/draft-apis.md) for annotation rules, runtime behavior, and implementation gaps. +Edit `temporal/api_next/` for all schema changes. The generator writes the stable schema to +`temporal/api/`. Do not edit that folder by hand. + +Use a [draft annotation](docs/draft-apis.md) to keep a declaration out of the stable schema while +you develop it. Remove the annotation when the declaration is ready to ship. + +Run `make` to regenerate the stable protos, draft manifest, and OpenAPI definitions. To update +just `temporal/api/`, run `make stable-api`. Commit the source changes and generated files together. Rust is also required because `make` installs and runs `nex-gen` when regenerating system Nexus WIT files.