Skip to content

Fix Swift generator naming collisions#5

Merged
tolgahan-arikan merged 3 commits into
masterfrom
fix-swift-generator-collisions
Jun 4, 2026
Merged

Fix Swift generator naming collisions#5
tolgahan-arikan merged 3 commits into
masterfrom
fix-swift-generator-collisions

Conversation

@tolgahan-arikan

@tolgahan-arikan tolgahan-arikan commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • make generated Swift enum fallback cases collision-aware, preserving schema cases such as .unknown and using a separate associated-value fallback for unrecognized wire values
  • add bounded numeric fallback names for exhausted enum and method namespace collisions, with explicit template failures instead of emitting blank or invalid Swift
  • emit raw-value-free empty CodingKeys enums so structs and method wrappers with no exported fields compile
  • make generated method namespaces collision-aware when a method name shadows a top-level type, while preserving the public client method name and RPC path
  • add Swift compile-backed regression tests for enum fallback collisions, empty coding keys, and method/type naming collisions

Trails API verification

Verified against ../trails-api/proto/trails-api.ridl with -service=Trails -methodTreeShake -ignore=@onramp. Fresh Swift output:

  • keeps public func runtimeStatus() as the client method
  • preserves /rpc/Trails/RuntimeStatus as the wire path
  • uses TrailsApiTrailsAPI.RuntimeStatusMethod for the nested method namespace, avoiding the top-level RuntimeStatus DTO collision
  • uses .unknownValue(String) for enums in that schema that already define UNKNOWN
  • emits enum CodingKeys: CodingKey for empty generated request/response structs

Test Plan

  • go test ./...
  • ./Tests/test.sh
  • go -C tools tool webrpc-gen -schema=../../trails-api/proto/trails-api.ridl -target=.. -client -service=Trails -methodTreeShake -ignore=@onramp -out=/tmp/trails-relative.gen.swift
  • swiftc -parse-as-library -target arm64-apple-macosx12.0 -c /tmp/trails-relative.gen.swift -o /tmp/trails-relative.gen.o
  • rg -n '(/Users/|manual|FIXME|TODO|RuntimeStatusMethod|enum CodingKeys: CodingKey|unknownValue)' /tmp/trails-relative.gen.swift

@VojtechVitek VojtechVitek left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM.

Can you regenerate the examples and potentially add some unit tests (with Claude)?

@tolgahan-arikan tolgahan-arikan force-pushed the fix-swift-generator-collisions branch from 39d7ffd to a724923 Compare June 4, 2026 13:13
@tolgahan-arikan tolgahan-arikan merged commit 5b10349 into master Jun 4, 2026
2 checks passed
@tolgahan-arikan tolgahan-arikan deleted the fix-swift-generator-collisions branch June 4, 2026 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants