apple / apple/swift-openapi-generator
Add a mechanism to generate Identifiable conformance when types include an id property
- Dominant language
- Swift
- Stars
- 2k
- Forks
- 182
- Avg merge
- 13h 28m
- Merged PRs (30d)
- 5
Description
### Motivation
I'm using this project to generate client and types for the App Store Connect API.
Every single object type from the API includes an ID property. When rendering results in SwiftUI, ForEach is our friend, but, the types are not identifiable by default. I have to create a conformance to Identifiable for everything by hand.
### Proposed solution
Provide a configuration option to allow a type to add Identifiable conformance in the generated code if it includes an `id` property with a supported Identifiable type.
This is supported by the CreateAPI tool and would be a good feature to replicate. I want to move to as little modifications as possible.
### Alternatives considered
Do things by hand and type this out. I'm only using a subset of the API and I still probably missed types that should conform.
```swift
extension Components.Schemas.AgeRatingDeclaration: Identifiable { }
extension Components.Schemas.AlternativeDistributionPackage: Identifiable { }
extension Components.Schemas.AppClipDefaultExperience: Identifiable { }
extension Components.Schemas.AppClip: Identifiable { }
extension Components.Schemas.AppCustomProductPage: Identifiable { }
extension Components.Schemas.AppEncryptionDeclaration: Identifiable { }
extension Components.Schemas.AppEvent: Identifiable { }
extension Components.Schemas.AppInfo: Identifiable { }
extension Components.Schemas.AppPreviewSet: Identifiable { }
extension Components.Schemas.AppScreenshotSet: Identifiable { }
extension Components.Schemas.AppStoreReviewDetail: Identifiable { }
extension Components.Schemas.AppStoreVersionExperimentV2: Identifiable { }
extension Components.Schemas.AppStoreVersionLocalization: Identifiable { }
extension Components.Schemas.AppStoreVersionPhasedRelease: Identifiable { }
extension Components.Schemas.AppStoreVersion: Identifiable { }
extension Components.Schemas.App: Identifiable { }
extension Components.Schemas.BetaAppLocalization: Identifiable { }
extension Components.Schemas.BetaAppReviewDetail: Identifiable { }
extension Components.Schemas.BetaAppReviewSubmission: Identifiable { }
extension Components.Schemas.BetaBuildLocalization: Identifiable { }
extension Components.Schemas.BetaCrashLog: Identifiable { }
extension Components.Schemas.BetaFeedbackCrashSubmission: Identifiable { }
extension Components.Schemas.BetaFeedbackScreenshotSubmission: Identifiable { }
extension Components.Schemas.BetaGroup: Identifiable { }
extension Components.Schemas.BetaLicenseAgreement: Identifiable { }
extension Components.Schemas.BetaTester: Identifiable { }
extension Components.Schemas.BuildBetaDetail: Identifiable { }
extension Components.Schemas.BuildBundle: Identifiable { }
extension Components.Schemas.BuildIcon: Identifiable { }
extension Components.Schemas.Build: Identifiable { }
extension Components.Schemas.BundleId: Identifiable { }
extension Components.Schemas.CiArtifact: Identifiable { }
extension Components.Schemas.CiBuildAction: Identifiable { }
extension Components.Schemas.CiBuildRun: Identifiable { }
extension Components.Schemas.CiMacOsVersion: Identifiable { }
extension Components.Schemas.CiProduct: Identifiable { }
extension Components.Schemas.CiWorkflow: Identifiable { }
extension Components.Schemas.CiXcodeVersion: Identifiable { }
extension Components.Schemas.EndUserLicenseAgreement: Identifiable { }
extension Components.Schemas.GameCenterAppVersion: Identifiable { }
extension Components.Schemas.GameCenterDetail: Identifiable { }
extension Components.Schemas.InAppPurchaseV2: Identifiable { }
extension Components.Schemas.PrereleaseVersion: Identifiable { }
extension Components.Schemas.PromotedPurchase: Identifiable { }
extension Components.Schemas.ReviewSubmission: Identifiable { }
extension Components.Schemas.RoutingAppCoverage: Identifiable { }
extension Components.Schemas.ScmGitReference: Identifiable { }
extension Components.Schemas.ScmPullRequest: Identifiable { }
extension Components.Schemas.SubscriptionGracePeriod: Identifiable { }
extension Components.Schemas.SubscriptionGroup: Identifiable { }
extension Components.Schemas.User: Identifiable { }
```
### Additional information
See CreateAPI and Swift Lee utilizing it in another App Store Connect client codebase:
- https://github.com/CreateAPI/CreateAPI/blob/main/Docs/ConfigOptions.md#entitiesincludeidentifiableconformance
- https://github.com/AvdLee/appstoreconnect-swift-sdk/blob/master/Sources/OpenAPI/create-api.yml#L44
Contributor guide
Research direction
Start with the linked CreateAPI ConfigOptions documentation and the referenced create-api.yml configuration entry. Compare the requested Identifiable option with the generator's existing configuration conventions; done means generated Swift types with supported id properties receive the conformance when enabled, while other types do not.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, swift
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100