Repository navigation
fix(native-codegen): escape schema string values in generated Kotlin/Swift/Dart source - #910
Merged
Merged
Conversation
…Swift/Dart source
- Kotlin: route schema-controlled strings (JSON keys, descriptions, patterns,
enum values, discriminator tags, method names, server URLs, defaults)
through a single-line string-literal escaper; `$` is emitted as `${'$'}`
to match KotlinPoet's %S form. Update two unit assertions to that form.
- Swift: escape the same values when emitting string literals and doc
comments in SwiftCodeGenerator and TransferableEmission.
- Dart: escape the same values when emitting string literals in the
blocks_codegen generator.
- Add the 28-escaping codegen fixture (spec + Dart/Kotlin/Swift goldens);
the existing 01-27 goldens are unchanged.
- Document the spec trust model in docs/native-clients/codegen-design.md.
- Add release notes for aws-blocks-kotlin, aws-blocks-swift (changesets)
and blocks_codegen (CHANGELOG Unreleased).
Tracking: V2380017102
|
…number formatting
cadivus
reviewed
Oct 21, 2026
…in Swift Restores the initializer default for format:time string fields, which the default type-gating had dropped; addresses review feedback.
cadivus
approved these changes
Oct 21, 2026
cadivus
left a comment
Contributor
There was a problem hiding this comment.
If you want, you can follow-up these improvements here.
This was referenced Oct 28, 2026
test(native): codegen fixtures 29-36 and 38, and the auth spec fixtures 18 and 23 (stack 05/14)
#854
Open
Open
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The native code generators (Kotlin, Swift, Dart) copy schema-controlled strings from
blocks.spec.jsoninto generated source. Several of those emission sites did not escape the value, so a spec value containing special characters (quotes, backslashes,$/interpolation sequences, line terminators) could produce generated code that does not compile or does not carry the value verbatim at runtime.Changes
Every schema-controlled string — field/parameter names used as JSON keys, descriptions, patterns, enum values, discriminator properties and tags, RPC method names, server URLs, and defaults — is now routed through a per-language string-literal escaper:
KotlinCodeGenerator.kt): single-line literal escaper matching KotlinPoet's%Sform ($→${'$'}, CR/LF/tab/control chars escaped, KotlinPoet layout markers U+00B7/U+2662 escaped). Validation messages use a variant that leaves benign$(e.g.^[A-Z]{3}$) unchanged. Two existing unit assertions inDeclaredTransferableBindingTest/UnboundTransferableTestare updated from\$to the equivalent${'$'}form.SwiftCodeGenerator.swift,TransferableEmission.swift): escape the same values in emitted string literals; method names in///doc lines are sanitized so they stay on one line.blocks_codegen/lib/src/generator.dart): escape the same values in emitted string literals.native/codegen-fixtures/28-escaping/(spec + Dart/Kotlin/Swift goldens) exercising these values. The existing 01–27 goldens are byte-identical.docs/native-clients/codegen-design.mddescribing where the spec comes from and what the generators guarantee.native/kotlin/.changeset/kotlin-codegen-escape-string-literals.md(aws-blocks-kotlin: patch),native/swift/.changeset/swift-codegen-escape-string-literals.md(aws-blocks-swift: patch), and an Unreleased entry innative/dart/packages/blocks_codegen/CHANGELOG.md.Out of scope / follow-ups:
Validation
28-escaping/is new, 01–27 unchanged../gradlew :codegen:test— 130/130 pass (CodegenFixturesTest 28/28).dart testinblocks_codegen— 185/185 pass (golden test 28/28);dart format --set-exit-if-changed .clean;dart analyze lib binno errors/warnings (pre-existing infos only).BlocksCodegen+BlocksCodegenTestsbuilt on Linux in an isolated package — 182/182 pass, includingGoldenFileTests. The full package (BlocksRuntime, build-plugin targets) is built and tested on macOS in CI.npx changeset status --since=origin/maininnative/kotlinandnative/swiftreports the expected patch bumps.Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.