Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ exception ExWithoutAnnotation {

struct Struct {
1: optional string baz
2: optional string UserIdentifier (auth.actor_uuid = "true")
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

@bananacocodrilo bananacocodrilo Apr 20, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

empty line on each new .thrift

// We cannot have 2 fields annotated with actor uuid in the same struct.
struct BadStruct {
1: optional string baz (auth.actor_uuid = "true")
2: optional string UserIdentifier (auth.actor_uuid = "true")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

struct Struct {
1: optional string baz
2: optional string UserIdentifier (auth.actor_uuid = "true")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

struct RedStruct {
1: optional string baz
2: optional string UserIdentifier (auth.actor_uuid = "true")
}

struct GreenStruct {
1: optional string baz
2: optional string CatIdentifier (auth.actor_uuid = "true")
}
2 changes: 1 addition & 1 deletion encoding/thrift/thriftrw-plugin-yarpc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ type g struct {
func (g g) Generate(req *api.GenerateServiceRequest) (*api.GenerateServiceResponse, error) {
// moduleGenerators apply to all Thrift IDL files, even when no service
// definition exists
moduleGenerators := []moduleGenFunc{yarpcErrorGenerator}
moduleGenerators := []moduleGenFunc{yarpcErrorGenerator, yarpcUUIDGenerator}

// serviceGenerators apply only when one or more services are defined in the
// Thrift IDL file.
Expand Down
100 changes: 100 additions & 0 deletions encoding/thrift/thriftrw-plugin-yarpc/uuid.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

84 changes: 84 additions & 0 deletions encoding/thrift/thriftrw-plugin-yarpc/uuid_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Copyright (c) 2026 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package main

import (
"testing"

"github.com/stretchr/testify/assert"
"go.uber.org/thriftrw/compile"
"go.uber.org/thriftrw/ptr"
noservices "go.uber.org/yarpc/encoding/thrift/thriftrw-plugin-yarpc/internal/tests/NOSERVICES"
)

func TestGetUUID(t *testing.T) {
t.Run("happyCase", func(t *testing.T) {
assert.NotPanics(t, func() {
spec, err := compile.Compile("internal/uuid_test_thrift/happy.thrift")
assert.NoError(t, err)
annotatedTypes, err := anyAnnotatedTypes(spec.Types)
assert.NoError(t, err)
assert.Equal(t, 1, len(annotatedTypes))
for k, v := range annotatedTypes {
assert.Equal(t, "Struct", k.Name)
assert.Equal(t, v, "UserIdentifier")
}

})
})
t.Run("multipleAnnotatedStructs", func(t *testing.T) {
assert.NotPanics(t, func() {
spec, err := compile.Compile("internal/uuid_test_thrift/multipleAnnotatedStructs.thrift")
assert.NoError(t, err)
annotatedTypes, err := anyAnnotatedTypes(spec.Types)
assert.NoError(t, err)
assert.Equal(t, 2, len(annotatedTypes))
uuidFields := map[string]string{
"RedStruct": "UserIdentifier",
"GreenStruct": "CatIdentifier",
}
for k, v := range annotatedTypes {
assert.Equal(t, uuidFields[k.Name], v)
}

})
})

t.Run("errorCase", func(t *testing.T) {
assert.NotPanics(t, func() {
spec, err := compile.Compile("internal/uuid_test_thrift/broken.thrift")
assert.NoError(t, err)
_, err = anyAnnotatedTypes(spec.Types)
assert.Error(t, err)

})
})
}

func TestGetGeneratedUUID(t *testing.T) {
t.Run("Found the UUID", func(t *testing.T) {
st := noservices.Struct{
Baz: ptr.String("asdf"),
UserIdentifier: ptr.String("my-uuid"),
}
assert.Equal(t, "my-uuid", st.ActorUUID())
})
}