square / square/wire

Swift generation ignores proto packages, leading to name collisions.

Open
#1,880 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Kotlin
Stars
4.4k
Forks
627
Avg merge
3d 15m
Merged PRs (30d)
20

Description

When generating Swift code, the proto package is ignored, and all files are output in the same directory. This can easily lead to name collisions where there are two types with the same name, but in different packages.

The protobuf spec says:

  // By default Swift generators will take the proto package and CamelCase it
  // replacing '.' with underscore and use that to prefix the types/symbols
  // defined. When this options is provided, they will use this value instead
  // to prefix the types/symbols defined.
  optional string swift_prefix = 39;

The Swift generator is not creating this CamelCase with underscores type prefix. I didn't check, but it seems likely that the Swift generator is also ignoring the swift_prefix file option.

I understand that Wire is taking a different approach with Swift but this should be opt-in. The default behaviour should be to create the type prefixes based on the proto package.

As an aside, there is absolutely zero documentation about the --experimental-module-manifest option other than the above linked blog post, which took me a long time to find.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the Swift generation behavior against the protobuf descriptor.proto documentation for the proto package and swift_prefix option. Reproduce generation with two types sharing a name across packages, then verify that generated symbols receive the expected package-based or configured prefixes and that module-manifest behavior is documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin, swift
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.