Skip to content

Commit efd9273

Browse files
authored
Fix default behavior of swift_prefix to remain unset in managed mode (#4245)
1 parent c7c37dc commit efd9273

File tree

4 files changed

+6
-23
lines changed

4 files changed

+6
-23
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
## [Unreleased]
44

5-
- No changes yet.
5+
- Fix default behavior for `swift_prefix` to remain unset when no override is provided in
6+
managed mode.
67

78
## [v1.62.0] - 2025-12-29
89

private/bufpkg/bufimage/bufimagemodify/bufimagemodify_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ func TestModifyImage(t *testing.T) {
9999
PhpMetadataNamespace: proto.String(`Foo\Empty_\GPBMetadata`),
100100
PhpNamespace: proto.String(`Foo\Empty_`),
101101
RubyPackage: proto.String("Foo::Empty"),
102-
SwiftPrefix: proto.String("Foo_Empty_"),
103102
},
104103
"foo_empty/without_package.proto": {
105104
// CcEnableArena's default value is true
@@ -126,7 +125,7 @@ func TestModifyImage(t *testing.T) {
126125
PhpNamespace: proto.String(`Bar\All`),
127126
PyGenericServices: proto.Bool(false),
128127
RubyPackage: proto.String("Bar::All"),
129-
SwiftPrefix: proto.String("Bar_All_"),
128+
SwiftPrefix: proto.String("bar"),
130129
},
131130
"bar_all/without_package.proto": {
132131
CcEnableArenas: proto.Bool(true),

private/bufpkg/bufimage/bufimagemodify/file_option.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,10 +380,10 @@ func modifySwiftPrefix(
380380
bufconfig.FileOptionUnspecified,
381381
bufconfig.FileOptionUnspecified,
382382
func(bufimage.ImageFile) stringOverrideOptions {
383-
return stringOverrideOptions{value: swiftPrefixValue(imageFile)}
383+
return stringOverrideOptions{}
384384
},
385-
func(imageFile bufimage.ImageFile, _ stringOverrideOptions) string {
386-
return swiftPrefixValue(imageFile)
385+
func(imageFile bufimage.ImageFile, stringOverrideOptions stringOverrideOptions) string {
386+
return stringOverrideOptions.value
387387
},
388388
func(options *descriptorpb.FileOptions) string {
389389
return options.GetSwiftPrefix()

private/bufpkg/bufimage/bufimagemodify/override.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -422,20 +422,3 @@ func rubyPackageValue(imageFile bufimage.ImageFile) string {
422422
}
423423
return strings.Join(packageParts, "::")
424424
}
425-
426-
// swiftPrefixValue returns the swift_prefix for the given ImageFile based on its
427-
// package declaration. If the image file doesn't have a package declaration, an
428-
// empty string is returned.
429-
func swiftPrefixValue(imageFile bufimage.ImageFile) string {
430-
pkg := imageFile.FileDescriptorProto().GetPackage()
431-
if pkg == "" {
432-
return ""
433-
}
434-
packageParts := strings.Split(pkg, ".")
435-
for i, part := range packageParts {
436-
packageParts[i] = xstrings.ToPascalCase(part)
437-
}
438-
// We add a "_" as the suffix since this emulates the default behavior if swift_prefix
439-
// is not set.
440-
return strings.Join(packageParts, "_") + "_"
441-
}

0 commit comments

Comments
 (0)