feat: 生成コードを Autogen 名前空間へ移行する - #119
Open
masatoi wants to merge 2 commits into
Open
Conversation
pokepay-sdk-generator#77 で、ios-sdk の生成コードは Sources/Pokepay/Autogen/ と Autogen.* 型名前空間へ隔離された。生成器は旧位置 (Sources/Pokepay/BankAPI/<Tag>/ と Sources/Pokepay/Responses/) へ出力しなくなる。 旧位置に残る 50 ファイルは DO NOT EDIT ヘッダを持つため、そのままだと次の再生成で delete-all-generated-files に削除される。ヘッダを外して手書き扱いにし、既存の公開 API (BankAPI.Terminal.Get など) を保持する。名前空間が違うので Autogen. 版と共存でき、 ソース互換性は完全に保たれる。 この 50 件には Sources/Pokepay/BankAPI.swift が含まれる。生成器はこのファイルを 出力しなくなるので、凍結しないと手書き層の名前空間宣言が失われて手書き API が全滅する。 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
pokepay-server の api-response-validation-tests ブランチ (x-pokepay-mobile-sdk を 55 → 153 箇所に拡大) の spec から pokepay-sdk-generator#77 で再生成した。 Sources/Pokepay/Autogen/ 以下に 152 ファイル。型は Autogen.BankAPI.<Tag>.<Operator> と Autogen.Responses.<Schema> に入る。Swift には Java のパッケージに相当するスコープが無く 1 モジュール内の型名がフラットなので、ネストした caseless enum で手書きと分離している。 ファイル名に Autogen 接頭辞が付いているのは、SwiftPM が 1 ターゲット内で basename の 重複を許さないため (オブジェクトファイル名を basename から導く)。接頭辞が無いと Autogen/Responses/Account.swift と手書きの Responses/Account.swift が multiple producers エラーになる。ファイル名は Swift の API の一部ではないので公開 API への影響はない。 既存の公開 API は無傷。手書き 188 ファイルに変更・削除は一切なく、手書きの Pokepay.Client もそのまま動く。 pokepay-sdk-generator: pokepay/pokepay-sdk-generator#77 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
背景
ios-sdk の生成器は手書きコードと同じディレクトリ・同じ型名前空間に出力していました。pokepay-server の
api-response-validation-testsブランチ(x-pokepay-mobile-sdkを 55 → 153 箇所に拡大)で再生成すると、生成器が変更した 57 ファイルのうち 55 が手書きファイルの上書きになります。このリポジトリは 188 の swift ファイルのうち 50 だけが生成管理下(
DO NOT EDITヘッダ付き)で、残り 138 は手書きです。失われるはずだった API の例:public extension BankAPI.Account { struct CreateAccountCpmToken: BankRequest { - public enum Scope: Int { case PAYMENT = 1; case TOPUP = 2; case BOTH = 3 } - public let scopes: Int - public let metadata: [String:String]? - public typealias Response = AccountCpmToken - public init(accountId: String, scopes: Scope = .PAYMENT, ...) + public let scopes: [String]? + public let metadata: String? + public typealias Response = CpmToken + public init(scopes: [String]? = nil, ..., accountId: String)pokepay-sdk-generator#77 で生成器は
Sources/Pokepay/Autogen/の外へ一切書かなくなりました。この PR はその移行です。変更内容
1. 旧位置の生成物 50 ファイルを手書きに凍結(
fbbd0b9)DO NOT EDITヘッダを外し、delete-all-generated-filesの対象から外しました。削除行 50・追加行ゼロ(ヘッダ 1 行ずつ)です。この 50 件には
Sources/Pokepay/BankAPI.swiftが含まれます。生成器はこのファイルを出力しなくなるため、凍結しなければ次の再生成で削除され、手書き層の名前空間宣言が失われて手書き API が全滅していました。凍結により
BankAPI.Terminal.Get/BankAPI.CreditCard.GetCreditCardsなどの既存 API がそのまま残ります。2. 生成コードを
Sources/Pokepay/Autogen/に追加(667ce50)152 ファイル(
Autogen/Responses/に 71、Autogen/BankAPI/<Tag>/に 80、Autogen.swift1)。Swift には Java のパッケージに相当するスコープが無く 1 モジュール内の型名がフラットなので、ネストした caseless enum で手書きと分離しています。ファイル名に
Autogen接頭辞が付いているのは、SwiftPM が 1 ターゲット内で basename の重複を許さないため(オブジェクトファイル名を basename から導く)です。接頭辞が無いとAutogen/Responses/Account.swiftと手書きのResponses/Account.swiftがmultiple producersエラーになります。ファイル名は Swift の API の一部ではないので公開 API への影響はありません。互換性
既存の公開 API は無傷です。 手書き 188 ファイルへの変更・削除は一切ありません。
BankAPI.Terminal.Get()BankAPI.CreditCard.GetCreditCards(...)Autogen.BankAPI.Terminal.GetTerminal()Pokepay.Client同名のレスポンス型(
TerminalとAutogen.Responses.Terminal)は名前空間が違うので別型として共存します。検証
Autogen/外への出力swift build(SwiftPM / macOS ターゲット、生成 152 + 手書き 188 = 340 ファイル)dev 環境の実 API(17/17 成功)
生成型
Autogen.BankAPI.*/Autogen.Responses.*を参照してhttps://api-dev.pokepay.jpを叩きました。返金により dev の残高は検証前の状態に戻しています。
注: この環境には Xcode が無いため(CLT のみ)、検証は SwiftPM の macOS ターゲットで行っています。
Sources/配下に#if os(iOS)も UIKit 依存も無く全 340 ファイルがコンパイル対象になるため、検証手段として有効です。iOS シミュレータ/実機でのビルドは未検証です。既知の制限(この PR のスコープ外)
Xcode プロジェクトへのファイル登録
Pokepay.xcodeproj/project.pbxprojは .swift を個別列挙しており、この PR では生成 152 ファイルを登録していません。Carthage 利用者はこのままではビルドできません。ただしこれはこの PR で始まった問題ではありません。移行前の時点で pbxproj への登録は 190 件、ディスク上の
Sources/は 188 件+α で、以前から未登録が発生していました(直近では 2026-07-24 の "Added mission file references" で人手により補われています)。今回 152 件増えて未登録が 290 件規模になります。Pokepay.podspec)Sources/**/*.swiftの globPackage.swift)Pokepay.xcodeproj).gitattributesで*.pbxproj -diff指定のため差分レビューが効かず、290 件規模の変更をこの PR に混ぜるとレビュー不能になります。別 PR で一括対応するのが適切と判断しました。バージョン
SDKVersion.swiftとPokepay.podspecは2.1.0のままです。過去の運用に合わせ、bump はリリース作業として別途行ってください。既存 API の破壊は無いので semver 上は minor bump が妥当です。空スキーマの CodingKeys
プロパティを持たないスキーマは空の
CodingKeysを出力し Swift として不正になります(an enum with no cases cannot declare a raw type)。この PR による退行ではなく、旧実装でも同じ出力になることを確認済みです。現行スペックに該当スキーマが無いため顕在化していません。生成器側で別途対応する話です。🤖 Generated with Claude Code