Skip to content

feat(swift): generate Version.swift with sdkVersion constant#14724

Merged
kafkas merged 3 commits intomainfrom
devin/1775594200-swift-version-constant
Apr 8, 2026
Merged

feat(swift): generate Version.swift with sdkVersion constant#14724
kafkas merged 3 commits intomainfrom
devin/1775594200-swift-version-constant

Conversation

@Swimburger
Copy link
Copy Markdown
Member

@Swimburger Swimburger commented Apr 7, 2026

Description

Adds Version.swift generation to the Swift SDK generator, embedding the SDK version as a public source-level constant. This brings the Swift generator in line with other SDK generators and fixes auto-versioning for Swift SDKs (the magic placeholder version will now appear in git diffs, allowing the auto-versioning system to detect and bump versions).

Split from #14719 (git tag fallback for auto-versioning) so each concern can be reviewed independently.

Changes Made

  • Added generateVersionFile() method to SdkGeneratorCli.ts that emits Version.swift with a top-level public let sdkVersion constant
  • The file is only generated when minVersion is available (i.e., GitHub output mode with a version configured — not for local/download modes)
  • Added versions.yml entry for Swift SDK generator 0.31.0

Updates since last revision

  • Made sdkVersion constant public so SDK consumers can access it (Swift defaults to internal access)
  • Ran seed tests (swift-sdk): 122/123 passed (1 expected failure in literal)
  • Committed seed test snapshot updates — all fixtures now include Version.swift with public let sdkVersion = "0.0.1" (the seed default version)

Testing

  • Seed tests run and passing (122/123, 1 expected failure)
  • Seed snapshots committed (122 Version.swift files added across all swift-sdk fixtures)
  • Manual testing not performed locally

Review Checklist

  • Verify that addSourceAsIsFile with name "Version" won't collide with any IR-generated type names
  • Confirm top-level public let sdkVersion = "..." is acceptable Swift style (vs. namespacing inside a struct or enum)
  • Confirm the generated constant is intentionally not yet wired into User-Agent or other headers (this PR is purely for consistency and auto-versioning support)

Link to Devin session: https://app.devin.ai/sessions/eeaa831f68d14737a731b1c8cb4968b4
Requested by: @Swimburger


Open with Devin

Swimburger and others added 2 commits April 7, 2026 20:36
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration
Copy link
Copy Markdown
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

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

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.

Tip: disable this comment in your organization's Code Review settings.

hex-security-app[bot]

This comment was marked as resolved.

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 2 additional findings.

Open in Devin Review

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 7, 2026

SDK Generation Benchmark Results

Comparing PR branch against latest nightly baseline on main (2026-04-07T04:47:12Z).

Full benchmark table (click to expand)
Generator Spec main (generator) main (E2E) PR (generator) Delta
swift-sdk square 142s 506s 140s -2s (-1.4%)

main (generator): generator-only time via --skip-scripts (includes Docker image build, container startup, IR parsing, and code generation — this is the same Docker-based flow customers use via fern generate). main (E2E): full customer-observable time including build/test scripts (nightly baseline, informational). Delta is computed against generator-only baseline.
⚠️ = generation exited with a non-zero exit code (timing may not reflect a successful run).
Baseline from nightly runs on main (latest: 2026-04-07T04:47:12Z). Trigger benchmark-baseline to refresh.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
context.project.addSourceAsIsFile({
nameCandidateWithoutExtension: "Version",
directory: RelativeFilePath.of(""),
contents: `public let sdkVersion = "${version}"\n`
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Unsanitized version string injected into generated Swift source code

The version string is interpolated directly into a Swift string literal without escaping " or \:

contents: `public let sdkVersion = "${version}"\n`

version is user-supplied (e.g. via --version CLI flag or generators.yml). A value containing " or a newline breaks out of the Swift string literal and injects arbitrary Swift statements into the generated Version.swift. For example, --version '1.0.0"\npublic func backdoor() {}' would produce valid, compilable Swift with an injected declaration that is committed to the SDK repo and distributed to every SDK consumer.

This was flagged in the previous review pass; the prior thread became "outdated" when the letpublic let change landed without adding escaping.

Prompt To Fix With AI
In `generateVersionFile` in `generators/swift/sdk/src/SdkGeneratorCli.ts`, escape `\` and `"` before embedding the version in the Swift string literal.

```typescript
private generateVersionFile(context: SdkGeneratorContext): void {
    const spmDetails = context.getSPMDetails();
    const version = spmDetails.minVersion;
    if (version != null) {
        const escapedVersion = version.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
        context.project.addSourceAsIsFile({
            nameCandidateWithoutExtension: "Version",
            directory: RelativeFilePath.of(""),
            contents: `public let sdkVersion = "${escapedVersion}"\n`
        });
    }
}
```

This is the only change needed — `\` must be escaped first (to avoid double-escaping), then `"`.

Severity: low | Confidence: 85%

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 7, 2026

SDK Generation Benchmark Results

Comparing PR branch against latest nightly baseline on main (2026-04-07T04:47:12Z).

Full benchmark table (click to expand)
Generator Spec main (generator) main (E2E) PR (generator) Delta
swift-sdk square 142s 506s 149s +7s (+4.9%)

main (generator): generator-only time via --skip-scripts (includes Docker image build, container startup, IR parsing, and code generation — this is the same Docker-based flow customers use via fern generate). main (E2E): full customer-observable time including build/test scripts (nightly baseline, informational). Delta is computed against generator-only baseline.
⚠️ = generation exited with a non-zero exit code (timing may not reflect a successful run).
Baseline from nightly runs on main (latest: 2026-04-07T04:47:12Z). Trigger benchmark-baseline to refresh.

@Swimburger Swimburger changed the title feat(swift-sdk): generate Version.swift with sdkVersion constant feat(swift): generate Version.swift with sdkVersion constant Apr 7, 2026
Copy link
Copy Markdown
Member

@kafkas kafkas left a comment

Choose a reason for hiding this comment

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

All looks good

@kafkas kafkas merged commit 694a8cd into main Apr 8, 2026
74 of 76 checks passed
@kafkas kafkas deleted the devin/1775594200-swift-version-constant branch April 8, 2026 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants