From 5f3c9e9009f0bae6e916a1e64229d9b32c8100c8 Mon Sep 17 00:00:00 2001 From: Craig Siemens Date: Wed, 5 Jun 2024 16:02:31 -0600 Subject: [PATCH] Optimize build times (#182) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Avoids calling SwiftFormat on nested types. Added a format function to the base Renderer class so it’s now the only type that needs to import SwiftFormat. Generator now passes `shouldFormat: true` to the top level renderers so it’s only run once per file. * Updated the generators to create the Codable implementation. * Generated the models with the Codable implementation. * Added AnyCodingKey to use in all Codable implementations. * Generated the models using AnyCodingKey. * Added the API spec file to gitignore. * Updated tests to contain the Codable implementation. * Updated OneOfSchemaRenderer to be a Renderer and use renderEnum. * Removed try! when used in a throwing function. * Format rendered code in tests explicitly * Ignore code coverage of AnyCodingKey --------- Co-authored-by: Morten Bjerg Gregersen --- .gitignore | 1 + Sources/Bagbutik-Core/AnyCodingKey.swift | 26 + .../Bagbutik-Core/Models/DocumentLinks.swift | 12 +- .../Bagbutik-Core/Models/ErrorResponse.swift | 48 +- .../Bagbutik-Core/Models/JsonPointer.swift | 10 + .../Models/PagedDocumentLinks.swift | 22 +- .../Models/PagingInformation.swift | 22 + Sources/Bagbutik-Core/Models/Parameter.swift | 10 + .../Bagbutik-Core/Models/ResourceLinks.swift | 12 +- Sources/Bagbutik-Models/AppStore/Actor.swift | 47 +- .../AppStore/ActorResponse.swift | 12 + .../AppStore/ActorsResponse.swift | 14 + .../AppStore/AgeRatingDeclaration.swift | 73 +- .../AgeRatingDeclarationResponse.swift | 12 + .../AgeRatingDeclarationUpdateRequest.swift | 78 +- ...ngDeclarationWithoutIncludesResponse.swift | 12 + Sources/Bagbutik-Models/AppStore/App.swift | 1597 +++++++---------- .../AppStore/AppAvailability.swift | 167 +- .../AppAvailabilityCreateRequest.swift | 114 +- .../AppStore/AppAvailabilityResponse.swift | 18 +- .../AppStore/AppAvailabilityV2.swift | 112 +- .../AppAvailabilityV2CreateRequest.swift | 116 +- .../AppStore/AppAvailabilityV2Response.swift | 14 + .../AppStore/AppCategoriesResponse.swift | 16 + ...AppCategoriesWithoutIncludesResponse.swift | 14 + .../AppStore/AppCategory.swift | 167 +- .../AppStore/AppCategoryResponse.swift | 14 + .../AppCategoryWithoutIncludesResponse.swift | 12 + .../Bagbutik-Models/AppStore/AppClip.swift | 167 +- .../AppStore/AppClipAdvancedExperience.swift | 336 ++-- ...pClipAdvancedExperienceCreateRequest.swift | 255 ++- .../AppClipAdvancedExperienceImage.swift | 49 +- ...AdvancedExperienceImageCreateRequest.swift | 41 +- ...pClipAdvancedExperienceImageResponse.swift | 12 + ...AdvancedExperienceImageUpdateRequest.swift | 46 +- ...ppClipAdvancedExperienceLocalization.swift | 43 +- ...edExperienceLocalizationInlineCreate.swift | 38 +- .../AppClipAdvancedExperienceResponse.swift | 18 +- ...pClipAdvancedExperienceUpdateRequest.swift | 266 ++- .../AppClipAdvancedExperiencesResponse.swift | 20 +- .../AppClipAppStoreReviewDetail.swift | 107 +- ...lipAppStoreReviewDetailCreateRequest.swift | 83 +- .../AppClipAppStoreReviewDetailResponse.swift | 14 + ...lipAppStoreReviewDetailUpdateRequest.swift | 44 +- .../AppStore/AppClipDefaultExperience.swift | 277 ++- ...ppClipDefaultExperienceCreateRequest.swift | 149 +- ...AppClipDefaultExperienceLocalization.swift | 164 +- ...tExperienceLocalizationCreateRequest.swift | 85 +- ...efaultExperienceLocalizationResponse.swift | 18 +- ...tExperienceLocalizationUpdateRequest.swift | 44 +- ...faultExperienceLocalizationsResponse.swift | 20 +- ...aseWithAppStoreVersionLinkageRequest.swift | 31 +- ...seWithAppStoreVersionLinkageResponse.swift | 31 +- .../AppClipDefaultExperienceResponse.swift | 18 +- ...ppClipDefaultExperienceUpdateRequest.swift | 90 +- .../AppClipDefaultExperiencesResponse.swift | 20 +- .../AppStore/AppClipDomainStatus.swift | 57 +- .../AppClipDomainStatusResponse.swift | 12 + .../AppStore/AppClipHeaderImage.swift | 117 +- .../AppClipHeaderImageCreateRequest.swift | 85 +- .../AppStore/AppClipHeaderImageResponse.swift | 14 + .../AppClipHeaderImageUpdateRequest.swift | 46 +- .../AppStore/AppClipResponse.swift | 18 +- .../AppStore/AppClipsResponse.swift | 20 +- .../AppStore/AppCustomProductPage.swift | 171 +- .../AppCustomProductPageCreateRequest.swift | 188 +- .../AppCustomProductPageLocalization.swift | 229 ++- ...ProductPageLocalizationCreateRequest.swift | 85 +- ...mProductPageLocalizationInlineCreate.swift | 82 +- ...ustomProductPageLocalizationResponse.swift | 18 +- ...ProductPageLocalizationUpdateRequest.swift | 44 +- ...stomProductPageLocalizationsResponse.swift | 20 +- .../AppCustomProductPageResponse.swift | 18 +- .../AppCustomProductPageUpdateRequest.swift | 46 +- .../AppCustomProductPageVersion.swift | 169 +- ...ustomProductPageVersionCreateRequest.swift | 101 +- ...CustomProductPageVersionInlineCreate.swift | 98 +- .../AppCustomProductPageVersionResponse.swift | 18 +- ...AppCustomProductPageVersionsResponse.swift | 20 +- .../AppCustomProductPagesResponse.swift | 20 +- .../AppStore/AppEncryptionDeclaration.swift | 248 ++- ...tionDeclarationBuildsLinkagesRequest.swift | 29 +- .../AppEncryptionDeclarationDocument.swift | 51 +- ...tionDeclarationDocumentCreateRequest.swift | 85 +- ...ncryptionDeclarationDocumentResponse.swift | 12 + ...tionDeclarationDocumentUpdateRequest.swift | 46 +- .../AppEncryptionDeclarationResponse.swift | 18 +- ...onDeclarationWithoutIncludesResponse.swift | 12 + .../AppEncryptionDeclarationsResponse.swift | 20 +- .../Bagbutik-Models/AppStore/AppEvent.swift | 162 +- .../AppStore/AppEventCreateRequest.swift | 113 +- .../AppStore/AppEventLocalization.swift | 233 ++- .../AppEventLocalizationCreateRequest.swift | 89 +- .../AppEventLocalizationResponse.swift | 18 +- .../AppEventLocalizationUpdateRequest.swift | 48 +- .../AppEventLocalizationsResponse.swift | 20 +- .../AppStore/AppEventResponse.swift | 14 + .../AppStore/AppEventScreenshot.swift | 119 +- .../AppEventScreenshotCreateRequest.swift | 87 +- .../AppStore/AppEventScreenshotResponse.swift | 14 + .../AppEventScreenshotUpdateRequest.swift | 44 +- .../AppEventScreenshotsResponse.swift | 16 + .../AppStore/AppEventUpdateRequest.swift | 74 +- .../AppStore/AppEventVideoClip.swift | 121 +- .../AppEventVideoClipCreateRequest.swift | 89 +- .../AppStore/AppEventVideoClipResponse.swift | 14 + .../AppEventVideoClipUpdateRequest.swift | 46 +- .../AppStore/AppEventVideoClipsResponse.swift | 16 + .../AppStore/AppEventsResponse.swift | 16 + .../Bagbutik-Models/AppStore/AppInfo.swift | 562 +++--- .../AppStore/AppInfoLocalization.swift | 117 +- .../AppInfoLocalizationCreateRequest.swift | 93 +- .../AppInfoLocalizationResponse.swift | 14 + .../AppInfoLocalizationUpdateRequest.swift | 52 +- .../AppInfoLocalizationsResponse.swift | 16 + .../AppStore/AppInfoResponse.swift | 18 +- .../AppStore/AppInfoUpdateRequest.swift | 240 ++- .../AppStore/AppInfosResponse.swift | 20 +- .../AppStore/AppMediaAssetState.swift | 14 + .../AppStore/AppMediaStateError.swift | 12 + .../AppStore/AppPreOrder.swift | 109 +- .../AppStore/AppPreOrderCreateRequest.swift | 83 +- .../AppStore/AppPreOrderResponse.swift | 14 + .../AppStore/AppPreOrderUpdateRequest.swift | 44 +- .../AppPreOrderWithoutIncludesResponse.swift | 12 + .../Bagbutik-Models/AppStore/AppPreview.swift | 123 +- .../AppStore/AppPreviewCreateRequest.swift | 89 +- .../AppStore/AppPreviewResponse.swift | 14 + .../AppStore/AppPreviewSet.swift | 277 ++- ...PreviewSetAppPreviewsLinkagesRequest.swift | 29 +- ...reviewSetAppPreviewsLinkagesResponse.swift | 33 +- .../AppStore/AppPreviewSetCreateRequest.swift | 151 +- .../AppStore/AppPreviewSetResponse.swift | 18 +- .../AppStore/AppPreviewSetsResponse.swift | 20 +- .../AppStore/AppPreviewUpdateRequest.swift | 48 +- .../AppStore/AppPreviewsResponse.swift | 16 + .../Bagbutik-Models/AppStore/AppPrice.swift | 147 +- .../AppStore/AppPriceInlineCreate.swift | 19 +- .../AppStore/AppPricePoint.swift | 164 +- .../AppStore/AppPricePointResponse.swift | 18 +- .../AppStore/AppPricePointV2.swift | 219 +-- .../AppStore/AppPricePointV3.swift | 164 +- .../AppStore/AppPricePointV3Response.swift | 18 +- .../AppStore/AppPricePointsResponse.swift | 20 +- .../AppStore/AppPricePointsV2Response.swift | 20 +- .../AppStore/AppPricePointsV3Response.swift | 20 +- .../AppStore/AppPriceResponse.swift | 18 +- .../AppStore/AppPriceSchedule.swift | 267 ++- .../AppPriceScheduleCreateRequest.swift | 136 +- .../AppStore/AppPriceScheduleResponse.swift | 18 +- .../AppStore/AppPriceTier.swift | 97 +- .../AppStore/AppPriceTierResponse.swift | 14 + .../AppStore/AppPriceTiersResponse.swift | 16 + .../Bagbutik-Models/AppStore/AppPriceV2.swift | 166 +- .../AppStore/AppPriceV2InlineCreate.swift | 19 +- .../AppStore/AppPricesResponse.swift | 20 +- .../AppStore/AppPricesV2Response.swift | 20 +- .../AppPromotedPurchasesLinkagesRequest.swift | 29 +- ...AppPromotedPurchasesLinkagesResponse.swift | 33 +- .../AppStore/AppResponse.swift | 18 +- .../AppStore/AppScreenshot.swift | 121 +- .../AppStore/AppScreenshotCreateRequest.swift | 85 +- .../AppStore/AppScreenshotResponse.swift | 14 + .../AppStore/AppScreenshotSet.swift | 277 ++- ...shotSetAppScreenshotsLinkagesRequest.swift | 29 +- ...hotSetAppScreenshotsLinkagesResponse.swift | 33 +- .../AppScreenshotSetCreateRequest.swift | 151 +- .../AppStore/AppScreenshotSetResponse.swift | 18 +- .../AppStore/AppScreenshotSetsResponse.swift | 20 +- .../AppStore/AppScreenshotUpdateRequest.swift | 46 +- .../AppStore/AppScreenshotsResponse.swift | 16 + .../AppStore/AppStoreReviewAttachment.swift | 115 +- ...ppStoreReviewAttachmentCreateRequest.swift | 85 +- .../AppStoreReviewAttachmentResponse.swift | 14 + ...ppStoreReviewAttachmentUpdateRequest.swift | 46 +- .../AppStoreReviewAttachmentsResponse.swift | 16 + .../AppStore/AppStoreReviewDetail.swift | 181 +- .../AppStoreReviewDetailCreateRequest.swift | 97 +- .../AppStoreReviewDetailResponse.swift | 18 +- .../AppStoreReviewDetailUpdateRequest.swift | 58 +- .../AppStore/AppStoreVersion.swift | 745 ++++---- ...pClipDefaultExperienceLinkageRequest.swift | 31 +- ...ClipDefaultExperienceLinkageResponse.swift | 31 +- .../AppStoreVersionBuildLinkageRequest.swift | 31 +- .../AppStoreVersionBuildLinkageResponse.swift | 31 +- .../AppStoreVersionCreateRequest.swift | 159 +- .../AppStore/AppStoreVersionExperiment.swift | 177 +- ...pStoreVersionExperimentCreateRequest.swift | 85 +- .../AppStoreVersionExperimentResponse.swift | 18 +- .../AppStoreVersionExperimentTreatment.swift | 228 ++- ...sionExperimentTreatmentCreateRequest.swift | 118 +- ...rsionExperimentTreatmentLocalization.swift | 227 +-- ...ntTreatmentLocalizationCreateRequest.swift | 83 +- ...erimentTreatmentLocalizationResponse.swift | 18 +- ...rimentTreatmentLocalizationsResponse.swift | 20 +- ...reVersionExperimentTreatmentResponse.swift | 18 +- ...sionExperimentTreatmentUpdateRequest.swift | 46 +- ...eVersionExperimentTreatmentsResponse.swift | 20 +- ...pStoreVersionExperimentUpdateRequest.swift | 48 +- .../AppStoreVersionExperimentV2.swift | 294 ++- ...toreVersionExperimentV2CreateRequest.swift | 87 +- .../AppStoreVersionExperimentV2Response.swift | 18 +- ...toreVersionExperimentV2UpdateRequest.swift | 48 +- .../AppStoreVersionExperimentsResponse.swift | 20 +- ...AppStoreVersionExperimentsV2Response.swift | 20 +- .../AppStoreVersionLocalization.swift | 239 ++- ...toreVersionLocalizationCreateRequest.swift | 95 +- .../AppStoreVersionLocalizationResponse.swift | 18 +- ...toreVersionLocalizationUpdateRequest.swift | 54 +- ...AppStoreVersionLocalizationsResponse.swift | 20 +- .../AppStoreVersionPhasedRelease.swift | 45 +- ...oreVersionPhasedReleaseCreateRequest.swift | 83 +- ...AppStoreVersionPhasedReleaseResponse.swift | 12 + ...oreVersionPhasedReleaseUpdateRequest.swift | 44 +- ...PhasedReleaseWithoutIncludesResponse.swift | 12 + .../AppStore/AppStoreVersionPromotion.swift | 24 +- ...ppStoreVersionPromotionCreateRequest.swift | 99 +- .../AppStoreVersionPromotionResponse.swift | 12 + .../AppStoreVersionReleaseRequest.swift | 24 +- ...reVersionReleaseRequestCreateRequest.swift | 68 +- ...ppStoreVersionReleaseRequestResponse.swift | 12 + .../AppStore/AppStoreVersionResponse.swift | 18 +- .../AppStore/AppStoreVersionSubmission.swift | 92 +- ...pStoreVersionSubmissionCreateRequest.swift | 68 +- .../AppStoreVersionSubmissionResponse.swift | 14 + .../AppStoreVersionUpdateRequest.swift | 133 +- .../AppStore/AppStoreVersionsResponse.swift | 20 +- .../AppStore/AppUpdateRequest.swift | 139 +- .../AppStore/AppWithoutIncludesResponse.swift | 12 + .../AppStore/AppsResponse.swift | 20 +- .../AppsWithoutIncludesResponse.swift | 14 + .../BetaAppClipInvocationsResponse.swift | 16 + .../AppStore/BuildBundle.swift | 314 ++-- .../AppStore/BuildBundleFileSize.swift | 45 +- .../BuildBundleFileSizesResponse.swift | 14 + .../Bagbutik-Models/AppStore/BuildIcon.swift | 43 +- .../AppStore/BuildIconsResponse.swift | 14 + .../BuildIconsWithoutIncludesResponse.swift | 14 + Sources/Bagbutik-Models/AppStore/Csv.swift | 9 + .../AppStore/CustomerReview.swift | 117 +- .../AppStore/CustomerReviewResponse.swift | 14 + .../AppStore/CustomerReviewResponseV1.swift | 111 +- ...ustomerReviewResponseV1CreateRequest.swift | 83 +- .../CustomerReviewResponseV1Response.swift | 14 + .../AppStore/CustomerReviewsResponse.swift | 16 + .../AppStore/EndAppAvailabilityPreOrder.swift | 24 +- ...AppAvailabilityPreOrderCreateRequest.swift | 68 +- .../EndAppAvailabilityPreOrderResponse.swift | 12 + .../AppStore/EndUserLicenseAgreement.swift | 167 +- ...EndUserLicenseAgreementCreateRequest.swift | 114 +- .../EndUserLicenseAgreementResponse.swift | 18 +- ...EndUserLicenseAgreementUpdateRequest.swift | 90 +- ...enseAgreementWithoutIncludesResponse.swift | 12 + .../AppStore/GameCenterEnabledVersion.swift | 171 +- ...ionCompatibleVersionsLinkagesRequest.swift | 29 +- ...onCompatibleVersionsLinkagesResponse.swift | 33 +- .../GameCenterEnabledVersionsResponse.swift | 20 +- .../Bagbutik-Models/AppStore/HttpHeader.swift | 12 + .../AppStore/InAppPurchase.swift | 118 +- ...nAppPurchaseAppStoreReviewScreenshot.swift | 121 +- ...ppStoreReviewScreenshotCreateRequest.swift | 85 +- ...haseAppStoreReviewScreenshotResponse.swift | 14 + ...ppStoreReviewScreenshotUpdateRequest.swift | 46 +- .../AppStore/InAppPurchaseAvailability.swift | 112 +- ...AppPurchaseAvailabilityCreateRequest.swift | 114 +- .../InAppPurchaseAvailabilityResponse.swift | 14 + .../AppStore/InAppPurchaseContent.swift | 113 +- .../InAppPurchaseContentResponse.swift | 14 + .../AppStore/InAppPurchaseLocalization.swift | 113 +- ...AppPurchaseLocalizationCreateRequest.swift | 87 +- .../InAppPurchaseLocalizationResponse.swift | 14 + ...AppPurchaseLocalizationUpdateRequest.swift | 46 +- .../InAppPurchaseLocalizationsResponse.swift | 16 + .../AppStore/InAppPurchasePrice.swift | 166 +- .../InAppPurchasePriceInlineCreate.swift | 115 +- .../AppStore/InAppPurchasePricePoint.swift | 111 +- .../InAppPurchasePricePointsResponse.swift | 16 + .../AppStore/InAppPurchasePriceSchedule.swift | 267 ++- ...ppPurchasePriceScheduleCreateRequest.swift | 136 +- .../InAppPurchasePriceScheduleResponse.swift | 18 +- .../InAppPurchasePricesResponse.swift | 20 +- .../AppStore/InAppPurchaseResponse.swift | 14 + .../AppStore/InAppPurchaseSubmission.swift | 92 +- ...InAppPurchaseSubmissionCreateRequest.swift | 68 +- .../InAppPurchaseSubmissionResponse.swift | 14 + .../AppStore/InAppPurchaseV2.swift | 459 ++--- .../InAppPurchaseV2CreateRequest.swift | 91 +- .../AppStore/InAppPurchaseV2Response.swift | 18 +- .../InAppPurchaseV2UpdateRequest.swift | 48 +- .../AppStore/InAppPurchasesResponse.swift | 16 + .../AppStore/InAppPurchasesV2Response.swift | 20 +- .../AppStore/PromotedPurchase.swift | 226 ++- .../PromotedPurchaseCreateRequest.swift | 151 +- .../AppStore/PromotedPurchaseImage.swift | 121 +- .../PromotedPurchaseImageCreateRequest.swift | 85 +- .../PromotedPurchaseImageResponse.swift | 14 + .../PromotedPurchaseImageUpdateRequest.swift | 46 +- .../PromotedPurchaseImagesResponse.swift | 16 + .../AppStore/PromotedPurchaseResponse.swift | 18 +- .../PromotedPurchaseUpdateRequest.swift | 46 +- .../AppStore/PromotedPurchasesResponse.swift | 20 +- .../AppStore/ReviewSubmission.swift | 336 ++-- .../ReviewSubmissionCreateRequest.swift | 83 +- .../AppStore/ReviewSubmissionItem.swift | 327 ++-- .../ReviewSubmissionItemCreateRequest.swift | 233 ++- .../ReviewSubmissionItemResponse.swift | 18 +- .../ReviewSubmissionItemUpdateRequest.swift | 46 +- .../ReviewSubmissionItemsResponse.swift | 20 +- .../AppStore/ReviewSubmissionResponse.swift | 18 +- .../ReviewSubmissionUpdateRequest.swift | 46 +- .../AppStore/ReviewSubmissionsResponse.swift | 20 +- .../AppStore/RoutingAppCoverage.swift | 115 +- .../RoutingAppCoverageCreateRequest.swift | 85 +- .../AppStore/RoutingAppCoverageResponse.swift | 14 + .../RoutingAppCoverageUpdateRequest.swift | 46 +- ...ngAppCoverageWithoutIncludesResponse.swift | 12 + .../AppStore/SandboxTesterV2.swift | 51 +- .../AppStore/SandboxTesterV2Response.swift | 12 + .../SandboxTesterV2UpdateRequest.swift | 48 +- ...TestersClearPurchaseHistoryRequestV2.swift | 24 +- ...urchaseHistoryRequestV2CreateRequest.swift | 68 +- ...learPurchaseHistoryRequestV2Response.swift | 12 + .../AppStore/SandboxTestersV2Response.swift | 14 + .../AppStore/Subscription.swift | 584 +++--- ...SubscriptionAppStoreReviewScreenshot.swift | 121 +- ...ppStoreReviewScreenshotCreateRequest.swift | 85 +- ...tionAppStoreReviewScreenshotResponse.swift | 14 + ...ppStoreReviewScreenshotUpdateRequest.swift | 46 +- .../AppStore/SubscriptionAvailability.swift | 167 +- ...ubscriptionAvailabilityCreateRequest.swift | 114 +- .../SubscriptionAvailabilityResponse.swift | 18 +- .../AppStore/SubscriptionCreateRequest.swift | 93 +- .../AppStore/SubscriptionGracePeriod.swift | 45 +- .../SubscriptionGracePeriodResponse.swift | 12 + ...SubscriptionGracePeriodUpdateRequest.swift | 50 +- .../AppStore/SubscriptionGroup.swift | 172 +- .../SubscriptionGroupCreateRequest.swift | 83 +- .../SubscriptionGroupLocalization.swift | 113 +- ...iptionGroupLocalizationCreateRequest.swift | 87 +- ...ubscriptionGroupLocalizationResponse.swift | 14 + ...iptionGroupLocalizationUpdateRequest.swift | 46 +- ...bscriptionGroupLocalizationsResponse.swift | 16 + .../AppStore/SubscriptionGroupResponse.swift | 18 +- .../SubscriptionGroupSubmission.swift | 24 +- ...criptionGroupSubmissionCreateRequest.swift | 68 +- .../SubscriptionGroupSubmissionResponse.swift | 12 + .../SubscriptionGroupUpdateRequest.swift | 44 +- .../AppStore/SubscriptionGroupsResponse.swift | 20 +- .../SubscriptionIntroductoryOffer.swift | 225 ++- ...iptionIntroductoryOfferCreateRequest.swift | 159 +- ...riptionIntroductoryOfferInlineCreate.swift | 154 +- ...ubscriptionIntroductoryOfferResponse.swift | 18 +- ...iptionIntroductoryOfferUpdateRequest.swift | 44 +- ...ionIntroductoryOffersLinkagesRequest.swift | 29 +- ...onIntroductoryOffersLinkagesResponse.swift | 33 +- ...bscriptionIntroductoryOffersResponse.swift | 20 +- .../AppStore/SubscriptionLocalization.swift | 113 +- ...ubscriptionLocalizationCreateRequest.swift | 87 +- .../SubscriptionLocalizationResponse.swift | 14 + ...ubscriptionLocalizationUpdateRequest.swift | 46 +- .../SubscriptionLocalizationsResponse.swift | 16 + .../AppStore/SubscriptionOfferCode.swift | 301 ++-- .../SubscriptionOfferCodeCreateRequest.swift | 126 +- .../SubscriptionOfferCodeCustomCode.swift | 115 +- ...tionOfferCodeCustomCodeCreateRequest.swift | 87 +- ...scriptionOfferCodeCustomCodeResponse.swift | 14 + ...tionOfferCodeCustomCodeUpdateRequest.swift | 44 +- ...criptionOfferCodeCustomCodesResponse.swift | 16 + .../SubscriptionOfferCodeOneTimeUseCode.swift | 113 +- ...OfferCodeOneTimeUseCodeCreateRequest.swift | 85 +- ...ptionOfferCodeOneTimeUseCodeResponse.swift | 14 + ...OfferCodeOneTimeUseCodeUpdateRequest.swift | 44 +- ...criptionOfferCodeOneTimeUseCodeValue.swift | 24 +- ...tionOfferCodeOneTimeUseCodesResponse.swift | 16 + .../AppStore/SubscriptionOfferCodePrice.swift | 147 +- ...bscriptionOfferCodePriceInlineCreate.swift | 98 +- .../SubscriptionOfferCodePricesResponse.swift | 20 +- .../SubscriptionOfferCodeResponse.swift | 18 +- .../SubscriptionOfferCodeUpdateRequest.swift | 44 +- .../SubscriptionOfferCodesResponse.swift | 20 +- .../AppStore/SubscriptionPrice.swift | 164 +- .../SubscriptionPriceCreateRequest.swift | 149 +- .../SubscriptionPriceInlineCreate.swift | 148 +- .../AppStore/SubscriptionPricePoint.swift | 111 +- .../SubscriptionPricePointInlineCreate.swift | 19 +- .../SubscriptionPricePointResponse.swift | 14 + .../SubscriptionPricePointsResponse.swift | 16 + .../AppStore/SubscriptionPriceResponse.swift | 18 +- .../SubscriptionPricesLinkagesRequest.swift | 29 +- .../SubscriptionPricesLinkagesResponse.swift | 33 +- .../AppStore/SubscriptionPricesResponse.swift | 20 +- .../SubscriptionPromotionalOffer.swift | 175 +- ...riptionPromotionalOfferCreateRequest.swift | 124 +- ...criptionPromotionalOfferInlineCreate.swift | 121 +- .../SubscriptionPromotionalOfferPrice.swift | 147 +- ...ionPromotionalOfferPriceInlineCreate.swift | 98 +- ...iptionPromotionalOfferPricesResponse.swift | 20 +- ...SubscriptionPromotionalOfferResponse.swift | 18 +- ...riptionPromotionalOfferUpdateRequest.swift | 77 +- ...ubscriptionPromotionalOffersResponse.swift | 20 +- .../AppStore/SubscriptionResponse.swift | 18 +- .../AppStore/SubscriptionSubmission.swift | 92 +- .../SubscriptionSubmissionCreateRequest.swift | 68 +- .../SubscriptionSubmissionResponse.swift | 14 + .../AppStore/SubscriptionUpdateRequest.swift | 170 +- .../AppStore/SubscriptionsResponse.swift | 20 +- .../AppStore/TerritoriesResponse.swift | 14 + .../TerritoriesWithoutIncludesResponse.swift | 14 + .../Bagbutik-Models/AppStore/Territory.swift | 39 +- .../TerritoryAvailabilitiesResponse.swift | 16 + .../AppStore/TerritoryAvailability.swift | 115 +- .../TerritoryAvailabilityInlineCreate.swift | 19 +- .../TerritoryAvailabilityResponse.swift | 14 + .../TerritoryAvailabilityUpdateRequest.swift | 48 +- .../AppStore/TerritoryInlineCreate.swift | 19 +- .../AppStore/TerritoryResponse.swift | 12 + .../AppStore/UploadOperation.swift | 18 + .../GameCenter/GameCenterAchievement.swift | 347 ++-- .../GameCenterAchievementCreateRequest.swift | 126 +- ...vementGroupAchievementLinkageRequest.swift | 31 +- ...ementGroupAchievementLinkageResponse.swift | 31 +- .../GameCenterAchievementImage.swift | 115 +- ...eCenterAchievementImageCreateRequest.swift | 85 +- .../GameCenterAchievementImageResponse.swift | 14 + ...eCenterAchievementImageUpdateRequest.swift | 44 +- .../GameCenterAchievementLocalization.swift | 168 +- ...AchievementLocalizationCreateRequest.swift | 89 +- ...enterAchievementLocalizationResponse.swift | 18 +- ...AchievementLocalizationUpdateRequest.swift | 48 +- ...nterAchievementLocalizationsResponse.swift | 20 +- .../GameCenterAchievementRelease.swift | 162 +- ...enterAchievementReleaseCreateRequest.swift | 99 +- ...GameCenterAchievementReleaseResponse.swift | 18 +- ...ameCenterAchievementReleasesResponse.swift | 20 +- .../GameCenterAchievementResponse.swift | 18 +- .../GameCenterAchievementUpdateRequest.swift | 52 +- .../GameCenterAchievementsResponse.swift | 20 +- .../GameCenter/GameCenterAppVersion.swift | 167 +- ...CompatibilityVersionsLinkagesRequest.swift | 29 +- ...ompatibilityVersionsLinkagesResponse.swift | 33 +- .../GameCenterAppVersionCreateRequest.swift | 68 +- .../GameCenterAppVersionResponse.swift | 18 +- .../GameCenterAppVersionUpdateRequest.swift | 44 +- .../GameCenterAppVersionsResponse.swift | 20 +- .../GameCenter/GameCenterDetail.swift | 694 +++---- .../GameCenterDetailCreateRequest.swift | 83 +- ...ameCenterAchievementsLinkagesRequest.swift | 29 +- ...meCenterAchievementsLinkagesResponse.swift | 33 +- ...CenterLeaderboardSetsLinkagesRequest.swift | 29 +- ...enterLeaderboardSetsLinkagesResponse.swift | 33 +- ...ameCenterLeaderboardsLinkagesRequest.swift | 29 +- ...meCenterLeaderboardsLinkagesResponse.swift | 33 +- .../GameCenter/GameCenterDetailResponse.swift | 18 +- .../GameCenterDetailUpdateRequest.swift | 156 +- .../GameCenterDetailsResponse.swift | 20 +- .../GameCenter/GameCenterGroup.swift | 292 ++- .../GameCenterGroupCreateRequest.swift | 39 +- ...ameCenterAchievementsLinkagesRequest.swift | 29 +- ...meCenterAchievementsLinkagesResponse.swift | 33 +- ...CenterLeaderboardSetsLinkagesRequest.swift | 29 +- ...enterLeaderboardSetsLinkagesResponse.swift | 33 +- ...ameCenterLeaderboardsLinkagesRequest.swift | 29 +- ...meCenterLeaderboardsLinkagesResponse.swift | 33 +- .../GameCenter/GameCenterGroupResponse.swift | 18 +- .../GameCenterGroupUpdateRequest.swift | 44 +- .../GameCenter/GameCenterGroupsResponse.swift | 20 +- .../GameCenter/GameCenterLeaderboard.swift | 417 ++--- .../GameCenterLeaderboardCreateRequest.swift | 169 +- ...GameCenterLeaderboardEntrySubmission.swift | 51 +- ...derboardEntrySubmissionCreateRequest.swift | 51 +- ...erLeaderboardEntrySubmissionResponse.swift | 12 + ...rboardGroupLeaderboardLinkageRequest.swift | 31 +- ...boardGroupLeaderboardLinkageResponse.swift | 31 +- .../GameCenterLeaderboardImage.swift | 115 +- ...eCenterLeaderboardImageCreateRequest.swift | 85 +- .../GameCenterLeaderboardImageResponse.swift | 14 + ...eCenterLeaderboardImageUpdateRequest.swift | 44 +- .../GameCenterLeaderboardLocalization.swift | 170 +- ...LeaderboardLocalizationCreateRequest.swift | 91 +- ...enterLeaderboardLocalizationResponse.swift | 18 +- ...LeaderboardLocalizationUpdateRequest.swift | 50 +- ...nterLeaderboardLocalizationsResponse.swift | 20 +- .../GameCenterLeaderboardRelease.swift | 162 +- ...enterLeaderboardReleaseCreateRequest.swift | 99 +- ...GameCenterLeaderboardReleaseResponse.swift | 18 +- ...ameCenterLeaderboardReleasesResponse.swift | 20 +- .../GameCenterLeaderboardResponse.swift | 18 +- .../GameCenter/GameCenterLeaderboardSet.swift | 399 ++-- ...ameCenterLeaderboardSetCreateRequest.swift | 153 +- ...ameCenterLeaderboardsLinkagesRequest.swift | 29 +- ...meCenterLeaderboardsLinkagesResponse.swift | 33 +- ...SetGroupLeaderboardSetLinkageRequest.swift | 31 +- ...etGroupLeaderboardSetLinkageResponse.swift | 31 +- .../GameCenterLeaderboardSetImage.swift | 115 +- ...nterLeaderboardSetImageCreateRequest.swift | 85 +- ...ameCenterLeaderboardSetImageResponse.swift | 14 + ...nterLeaderboardSetImageUpdateRequest.swift | 44 +- ...GameCenterLeaderboardSetLocalization.swift | 164 +- ...derboardSetLocalizationCreateRequest.swift | 85 +- ...erLeaderboardSetLocalizationResponse.swift | 18 +- ...derboardSetLocalizationUpdateRequest.swift | 44 +- ...rLeaderboardSetLocalizationsResponse.swift | 20 +- ...nterLeaderboardSetMemberLocalization.swift | 164 +- ...rdSetMemberLocalizationCreateRequest.swift | 116 +- ...erboardSetMemberLocalizationResponse.swift | 18 +- ...rdSetMemberLocalizationUpdateRequest.swift | 44 +- ...rboardSetMemberLocalizationsResponse.swift | 20 +- .../GameCenterLeaderboardSetRelease.swift | 162 +- ...erLeaderboardSetReleaseCreateRequest.swift | 99 +- ...eCenterLeaderboardSetReleaseResponse.swift | 18 +- ...CenterLeaderboardSetReleasesResponse.swift | 20 +- .../GameCenterLeaderboardSetResponse.swift | 18 +- ...ameCenterLeaderboardSetUpdateRequest.swift | 44 +- .../GameCenterLeaderboardSetsResponse.swift | 20 +- .../GameCenterLeaderboardUpdateRequest.swift | 62 +- .../GameCenterLeaderboardsResponse.swift | 20 +- ...tchmakingAppRequestsV1MetricResponse.swift | 88 + ...ngBooleanRuleResultsV1MetricResponse.swift | 106 ++ ...ingNumberRuleResultsV1MetricResponse.swift | 90 + .../GameCenterMatchmakingQueue.swift | 164 +- ...eCenterMatchmakingQueueCreateRequest.swift | 118 +- ...hmakingQueueRequestsV1MetricResponse.swift | 112 ++ .../GameCenterMatchmakingQueueResponse.swift | 14 + ...atchmakingQueueSizesV1MetricResponse.swift | 56 + ...eCenterMatchmakingQueueUpdateRequest.swift | 123 +- .../GameCenterMatchmakingQueuesResponse.swift | 16 + .../GameCenterMatchmakingRule.swift | 47 +- ...meCenterMatchmakingRuleCreateRequest.swift | 91 +- ...atchmakingRuleErrorsV1MetricResponse.swift | 84 + .../GameCenterMatchmakingRuleResponse.swift | 12 + .../GameCenterMatchmakingRuleSet.swift | 238 ++- ...enterMatchmakingRuleSetCreateRequest.swift | 45 +- ...GameCenterMatchmakingRuleSetResponse.swift | 18 +- .../GameCenterMatchmakingRuleSetTest.swift | 51 +- ...rMatchmakingRuleSetTestCreateRequest.swift | 105 +- ...CenterMatchmakingRuleSetTestResponse.swift | 12 + ...enterMatchmakingRuleSetUpdateRequest.swift | 46 +- ...ameCenterMatchmakingRuleSetsResponse.swift | 20 +- ...meCenterMatchmakingRuleUpdateRequest.swift | 48 +- .../GameCenterMatchmakingRulesResponse.swift | 14 + ...rMatchmakingSessionsV1MetricResponse.swift | 56 + .../GameCenterMatchmakingTeam.swift | 43 +- .../GameCenterMatchmakingTeamAssignment.swift | 12 + ...meCenterMatchmakingTeamCreateRequest.swift | 87 +- .../GameCenterMatchmakingTeamResponse.swift | 12 + ...meCenterMatchmakingTeamUpdateRequest.swift | 46 +- .../GameCenterMatchmakingTeamsResponse.swift | 14 + ...makingTestPlayerPropertyInlineCreate.swift | 36 +- ...erMatchmakingTestRequestInlineCreate.swift | 98 +- ...ameCenterPlayerAchievementSubmission.swift | 49 +- ...erAchievementSubmissionCreateRequest.swift | 49 +- ...rPlayerAchievementSubmissionResponse.swift | 12 + .../Bagbutik-Models/GameCenter/Location.swift | 12 + .../Bagbutik-Models/GameCenter/Property.swift | 12 + .../AlternativeDistributionDomain.swift | 43 +- ...ativeDistributionDomainCreateRequest.swift | 41 +- ...lternativeDistributionDomainResponse.swift | 12 + ...ternativeDistributionDomainsResponse.swift | 14 + .../AlternativeDistributionKey.swift | 39 +- ...ernativeDistributionKeyCreateRequest.swift | 85 +- .../AlternativeDistributionKeyResponse.swift | 12 + .../AlternativeDistributionKeysResponse.swift | 14 + .../AlternativeDistributionPackage.swift | 97 +- ...tiveDistributionPackageCreateRequest.swift | 68 +- .../AlternativeDistributionPackageDelta.swift | 45 +- ...tiveDistributionPackageDeltaResponse.swift | 12 + ...iveDistributionPackageDeltasResponse.swift | 14 + ...ternativeDistributionPackageResponse.swift | 14 + ...lternativeDistributionPackageVariant.swift | 45 +- ...veDistributionPackageVariantResponse.swift | 12 + ...eDistributionPackageVariantsResponse.swift | 14 + ...lternativeDistributionPackageVersion.swift | 235 ++- ...veDistributionPackageVersionResponse.swift | 18 +- ...eDistributionPackageVersionsResponse.swift | 20 +- .../Marketplaces/MarketplaceDomain.swift | 43 +- .../MarketplaceDomainCreateRequest.swift | 41 +- .../MarketplaceDomainResponse.swift | 12 + .../MarketplaceDomainsResponse.swift | 14 + .../MarketplaceSearchDetail.swift | 39 +- ...MarketplaceSearchDetailCreateRequest.swift | 83 +- .../MarketplaceSearchDetailResponse.swift | 12 + ...MarketplaceSearchDetailUpdateRequest.swift | 44 +- .../Marketplaces/MarketplaceWebhook.swift | 39 +- .../MarketplaceWebhookCreateRequest.swift | 41 +- .../MarketplaceWebhookResponse.swift | 12 + .../MarketplaceWebhookUpdateRequest.swift | 46 +- .../MarketplaceWebhooksResponse.swift | 14 + .../Provisioning/BundleId.swift | 233 ++- .../BundleIdCapabilitiesResponse.swift | 14 + ...dCapabilitiesWithoutIncludesResponse.swift | 14 + .../Provisioning/BundleIdCapability.swift | 41 +- .../BundleIdCapabilityCreateRequest.swift | 85 +- .../BundleIdCapabilityResponse.swift | 12 + .../BundleIdCapabilityUpdateRequest.swift | 46 +- .../Provisioning/BundleIdCreateRequest.swift | 45 +- .../Provisioning/BundleIdResponse.swift | 18 +- .../Provisioning/BundleIdUpdateRequest.swift | 44 +- .../BundleIdWithoutIncludesResponse.swift | 12 + .../Provisioning/BundleIdsResponse.swift | 20 +- .../Provisioning/CapabilityOption.swift | 20 + .../Provisioning/CapabilitySetting.swift | 24 + .../Provisioning/Certificate.swift | 51 +- .../CertificateCreateRequest.swift | 41 +- .../Provisioning/CertificateResponse.swift | 12 + .../Provisioning/CertificatesResponse.swift | 14 + .../CertificatesWithoutIncludesResponse.swift | 14 + .../Bagbutik-Models/Provisioning/Device.swift | 51 +- .../Provisioning/DeviceCreateRequest.swift | 43 +- .../Provisioning/DeviceResponse.swift | 12 + .../Provisioning/DeviceUpdateRequest.swift | 46 +- .../Provisioning/DevicesResponse.swift | 14 + .../DevicesWithoutIncludesResponse.swift | 14 + .../Provisioning/Profile.swift | 241 ++- .../Provisioning/ProfileCreateRequest.swift | 149 +- .../Provisioning/ProfileResponse.swift | 18 +- .../Provisioning/ProfilesResponse.swift | 20 +- .../ProfilesWithoutIncludesResponse.swift | 14 + .../Reporting/AnalyticsReport.swift | 41 +- .../Reporting/AnalyticsReportInstance.swift | 41 +- .../AnalyticsReportInstanceResponse.swift | 12 + .../AnalyticsReportInstancesResponse.swift | 14 + .../Reporting/AnalyticsReportRequest.swift | 114 +- .../AnalyticsReportRequestCreateRequest.swift | 83 +- .../AnalyticsReportRequestResponse.swift | 14 + .../AnalyticsReportRequestsResponse.swift | 16 + .../Reporting/AnalyticsReportResponse.swift | 12 + .../Reporting/AnalyticsReportSegment.swift | 43 +- .../AnalyticsReportSegmentResponse.swift | 12 + .../AnalyticsReportSegmentsResponse.swift | 14 + .../Reporting/AnalyticsReportsResponse.swift | 14 + .../Reporting/DiagnosticLog.swift | 24 +- .../DiagnosticLogCallStackNode.swift | 34 + .../Reporting/DiagnosticLogs.swift | 100 ++ .../Reporting/DiagnosticSignature.swift | 43 +- .../DiagnosticSignaturesResponse.swift | 14 + Sources/Bagbutik-Models/Reporting/Gzip.swift | 9 + .../Reporting/MetricsInsight.swift | 46 + .../Reporting/PerfPowerMetric.swift | 43 +- .../Reporting/XcodeMetrics.swift | 148 ++ .../AppBetaTestersLinkagesRequest.swift | 29 +- ...AppsBetaTesterUsagesV1MetricResponse.swift | 88 + .../TestFlight/BetaAppClipInvocation.swift | 112 +- .../BetaAppClipInvocationCreateRequest.swift | 116 +- .../BetaAppClipInvocationLocalization.swift | 41 +- ...pInvocationLocalizationCreateRequest.swift | 85 +- ...ipInvocationLocalizationInlineCreate.swift | 82 +- ...ppClipInvocationLocalizationResponse.swift | 12 + ...pInvocationLocalizationUpdateRequest.swift | 44 +- .../BetaAppClipInvocationResponse.swift | 14 + .../BetaAppClipInvocationUpdateRequest.swift | 44 +- .../TestFlight/BetaAppLocalization.swift | 117 +- .../BetaAppLocalizationCreateRequest.swift | 93 +- .../BetaAppLocalizationResponse.swift | 14 + .../BetaAppLocalizationUpdateRequest.swift | 52 +- .../BetaAppLocalizationsResponse.swift | 16 + ...LocalizationsWithoutIncludesResponse.swift | 14 + .../TestFlight/BetaAppReviewDetail.swift | 121 +- .../BetaAppReviewDetailResponse.swift | 14 + .../BetaAppReviewDetailUpdateRequest.swift | 58 +- ...pReviewDetailWithoutIncludesResponse.swift | 12 + .../BetaAppReviewDetailsResponse.swift | 16 + .../TestFlight/BetaAppReviewSubmission.swift | 109 +- ...BetaAppReviewSubmissionCreateRequest.swift | 68 +- .../BetaAppReviewSubmissionResponse.swift | 14 + ...iewSubmissionWithoutIncludesResponse.swift | 12 + .../BetaAppReviewSubmissionsResponse.swift | 16 + .../TestFlight/BetaBuildLocalization.swift | 109 +- .../BetaBuildLocalizationCreateRequest.swift | 85 +- .../BetaBuildLocalizationResponse.swift | 14 + .../BetaBuildLocalizationUpdateRequest.swift | 44 +- .../BetaBuildLocalizationsResponse.swift | 16 + ...LocalizationsWithoutIncludesResponse.swift | 14 + .../BetaBuildUsagesV1MetricResponse.swift | 88 + .../TestFlight/BetaGroup.swift | 247 ++- .../BetaGroupBetaTestersLinkagesRequest.swift | 29 +- ...BetaGroupBetaTestersLinkagesResponse.swift | 33 +- .../BetaGroupBuildsLinkagesRequest.swift | 29 +- .../BetaGroupBuildsLinkagesResponse.swift | 33 +- .../TestFlight/BetaGroupCreateRequest.swift | 161 +- .../TestFlight/BetaGroupResponse.swift | 18 +- .../TestFlight/BetaGroupUpdateRequest.swift | 54 +- .../TestFlight/BetaGroupsResponse.swift | 20 +- .../BetaGroupsWithoutIncludesResponse.swift | 14 + .../TestFlight/BetaLicenseAgreement.swift | 107 +- .../BetaLicenseAgreementResponse.swift | 14 + .../BetaLicenseAgreementUpdateRequest.swift | 44 +- ...enseAgreementWithoutIncludesResponse.swift | 12 + .../BetaLicenseAgreementsResponse.swift | 16 + .../TestFlight/BetaTester.swift | 238 ++- .../BetaTesterAppsLinkagesRequest.swift | 29 +- .../BetaTesterAppsLinkagesResponse.swift | 33 +- .../BetaTesterBetaGroupsLinkagesRequest.swift | 29 +- ...BetaTesterBetaGroupsLinkagesResponse.swift | 33 +- .../BetaTesterBuildsLinkagesRequest.swift | 29 +- .../BetaTesterBuildsLinkagesResponse.swift | 33 +- .../TestFlight/BetaTesterCreateRequest.swift | 122 +- .../TestFlight/BetaTesterInvitation.swift | 24 +- .../BetaTesterInvitationCreateRequest.swift | 99 +- .../BetaTesterInvitationResponse.swift | 12 + .../TestFlight/BetaTesterResponse.swift | 18 +- .../BetaTesterUsagesV1MetricResponse.swift | 86 + .../TestFlight/BetaTestersResponse.swift | 20 +- .../BetaTestersWithoutIncludesResponse.swift | 14 + .../Bagbutik-Models/TestFlight/Build.swift | 702 +++----- ...pEncryptionDeclarationLinkageRequest.swift | 31 +- ...EncryptionDeclarationLinkageResponse.swift | 31 +- .../TestFlight/BuildBetaDetail.swift | 111 +- .../TestFlight/BuildBetaDetailResponse.swift | 14 + .../BuildBetaDetailUpdateRequest.swift | 44 +- .../TestFlight/BuildBetaDetailsResponse.swift | 16 + .../BuildBetaGroupsLinkagesRequest.swift | 29 +- .../TestFlight/BuildBetaNotification.swift | 24 +- .../BuildBetaNotificationCreateRequest.swift | 68 +- .../BuildBetaNotificationResponse.swift | 12 + ...uildIndividualTestersLinkagesRequest.swift | 29 +- ...ildIndividualTestersLinkagesResponse.swift | 33 +- .../TestFlight/BuildResponse.swift | 18 +- .../TestFlight/BuildUpdateRequest.swift | 92 +- .../BuildWithoutIncludesResponse.swift | 12 + .../TestFlight/BuildsResponse.swift | 20 +- .../BuildsWithoutIncludesResponse.swift | 14 + .../TestFlight/ImageAsset.swift | 14 + .../PreReleaseVersionsResponse.swift | 20 +- ...leaseVersionsWithoutIncludesResponse.swift | 14 + .../TestFlight/PrereleaseVersion.swift | 169 +- .../PrereleaseVersionResponse.swift | 18 +- ...eleaseVersionWithoutIncludesResponse.swift | 12 + Sources/Bagbutik-Models/Users/User.swift | 122 +- .../Users/UserInvitation.swift | 124 +- .../Users/UserInvitationCreateRequest.swift | 95 +- .../Users/UserInvitationResponse.swift | 14 + .../Users/UserInvitationsResponse.swift | 16 + .../Bagbutik-Models/Users/UserResponse.swift | 14 + .../Users/UserUpdateRequest.swift | 94 +- .../UserVisibleAppsLinkagesRequest.swift | 29 +- .../UserVisibleAppsLinkagesResponse.swift | 33 +- .../Bagbutik-Models/Users/UsersResponse.swift | 16 + .../Bagbutik-Models/XcodeCloud/CiAction.swift | 38 + .../XcodeCloud/CiArtifact.swift | 45 +- .../XcodeCloud/CiArtifactResponse.swift | 12 + .../XcodeCloud/CiArtifactsResponse.swift | 14 + .../XcodeCloud/CiBranchPatterns.swift | 24 + .../XcodeCloud/CiBranchStartCondition.swift | 14 + .../XcodeCloud/CiBuildAction.swift | 121 +- .../XcodeCloud/CiBuildActionResponse.swift | 14 + .../XcodeCloud/CiBuildActionsResponse.swift | 16 + .../XcodeCloud/CiBuildRun.swift | 445 +++-- .../XcodeCloud/CiBuildRunCreateRequest.swift | 184 +- .../XcodeCloud/CiBuildRunResponse.swift | 18 +- .../XcodeCloud/CiBuildRunsResponse.swift | 20 +- .../XcodeCloud/CiFilesAndFoldersRule.swift | 12 + .../XcodeCloud/CiGitUser.swift | 12 + .../Bagbutik-Models/XcodeCloud/CiIssue.swift | 45 +- .../XcodeCloud/CiIssueCounts.swift | 16 + .../XcodeCloud/CiIssueResponse.swift | 12 + .../XcodeCloud/CiIssuesResponse.swift | 14 + .../XcodeCloud/CiMacOsVersion.swift | 114 +- .../XcodeCloud/CiMacOsVersionResponse.swift | 14 + .../XcodeCloud/CiMacOsVersionsResponse.swift | 16 + .../CiManualBranchStartCondition.swift | 10 + .../CiManualPullRequestStartCondition.swift | 12 + .../CiManualTagStartCondition.swift | 10 + .../XcodeCloud/CiProduct.swift | 226 ++- .../XcodeCloud/CiProductResponse.swift | 18 +- .../XcodeCloud/CiProductsResponse.swift | 20 +- .../CiPullRequestStartCondition.swift | 16 + .../CiScheduledStartCondition.swift | 30 + .../CiStartConditionFileMatcher.swift | 14 + .../XcodeCloud/CiTagPatterns.swift | 24 + .../XcodeCloud/CiTagStartCondition.swift | 14 + .../XcodeCloud/CiTestDestination.swift | 18 + .../XcodeCloud/CiTestResult.swift | 67 +- .../XcodeCloud/CiTestResultResponse.swift | 12 + .../XcodeCloud/CiTestResultsResponse.swift | 14 + .../XcodeCloud/CiWorkflow.swift | 300 ++-- .../XcodeCloud/CiWorkflowCreateRequest.swift | 202 ++- .../XcodeCloud/CiWorkflowResponse.swift | 18 +- .../XcodeCloud/CiWorkflowUpdateRequest.swift | 149 +- .../XcodeCloud/CiWorkflowsResponse.swift | 20 +- .../XcodeCloud/CiXcodeVersion.swift | 144 +- .../XcodeCloud/CiXcodeVersionResponse.swift | 14 + .../XcodeCloud/CiXcodeVersionsResponse.swift | 16 + .../XcodeCloud/FileLocation.swift | 12 + .../XcodeCloud/ScmGitReference.swift | 113 +- .../XcodeCloud/ScmGitReferenceResponse.swift | 14 + .../XcodeCloud/ScmGitReferencesResponse.swift | 16 + .../XcodeCloud/ScmProvider.swift | 41 +- .../XcodeCloud/ScmProviderResponse.swift | 12 + .../XcodeCloud/ScmProviderType.swift | 14 + .../XcodeCloud/ScmProvidersResponse.swift | 14 + .../XcodeCloud/ScmPullRequest.swift | 127 +- .../XcodeCloud/ScmPullRequestResponse.swift | 14 + .../XcodeCloud/ScmPullRequestsResponse.swift | 16 + .../XcodeCloud/ScmRepositoriesResponse.swift | 20 +- .../XcodeCloud/ScmRepository.swift | 170 +- .../XcodeCloud/ScmRepositoryResponse.swift | 18 +- Sources/BagbutikGenerator/Generator.swift | 10 +- .../Renderers/BinarySchemaRenderer.swift | 15 +- .../Renderers/EnumSchemaRenderer.swift | 3 +- .../Renderers/ObjectSchemaRenderer.swift | 86 +- .../Renderers/OneOfSchemaRenderer.swift | 24 +- .../Renderers/OperationRenderer.swift | 13 +- .../Renderers/PlainTextSchemaRenderer.swift | 13 +- .../Renderers/Renderer.swift | 11 +- .../Renderers/BinarySchemaRendererTests.swift | 22 +- .../Renderers/EnumSchemaRendererTests.swift | 4 +- .../Renderers/ObjectSchemaRendererTests.swift | 369 ++-- .../Renderers/OneOfSchemaRendererTests.swift | 7 +- .../Renderers/OperationRendererTests.swift | 22 +- .../PlainTextSchemaRendererTests.swift | 22 +- .../Renderers/PropertyRendererTests.swift | 10 +- codecov.yml | 1 + 812 files changed, 31485 insertions(+), 22632 deletions(-) create mode 100644 Sources/Bagbutik-Core/AnyCodingKey.swift diff --git a/.gitignore b/.gitignore index 2b6ce311a..e20fb9736 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ xcuserdata .build coverage.lcov docs +app_store_connect_api_openapi.json diff --git a/Sources/Bagbutik-Core/AnyCodingKey.swift b/Sources/Bagbutik-Core/AnyCodingKey.swift new file mode 100644 index 000000000..92f000728 --- /dev/null +++ b/Sources/Bagbutik-Core/AnyCodingKey.swift @@ -0,0 +1,26 @@ +public struct AnyCodingKey: CodingKey { + public let stringValue: String + public let intValue: Int? = nil + + public init?(stringValue: String) { + self.stringValue = stringValue + } + + public init?(intValue: Int) { + nil // We are not using this, so just return nil + } +} + +extension AnyCodingKey: ExpressibleByStringLiteral { + public init(stringLiteral value: StringLiteralType) { + self.stringValue = value + } + + public init(unicodeScalarLiteral value: String) { + self.stringValue = value + } + + public init(extendedGraphemeClusterLiteral value: String) { + self.stringValue = value + } +} diff --git a/Sources/Bagbutik-Core/Models/DocumentLinks.swift b/Sources/Bagbutik-Core/Models/DocumentLinks.swift index 050e646a0..f6b702172 100644 --- a/Sources/Bagbutik-Core/Models/DocumentLinks.swift +++ b/Sources/Bagbutik-Core/Models/DocumentLinks.swift @@ -18,16 +18,12 @@ public struct DocumentLinks: Codable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - itself = try container.decode(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + itself = try container.decode(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(itself, forKey: "self") } } diff --git a/Sources/Bagbutik-Core/Models/ErrorResponse.swift b/Sources/Bagbutik-Core/Models/ErrorResponse.swift index 24c2a043e..17f3c13a0 100644 --- a/Sources/Bagbutik-Core/Models/ErrorResponse.swift +++ b/Sources/Bagbutik-Core/Models/ErrorResponse.swift @@ -15,6 +15,16 @@ public struct ErrorResponse: Codable { self.errors = errors } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + errors = try container.decodeIfPresent([Errors].self, forKey: "errors") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(errors, forKey: "errors") + } + /** # ErrorResponse.Errors The details about an error that are returned when an API request isn’t successful. @@ -56,6 +66,28 @@ public struct ErrorResponse: Codable { self.title = title } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + code = try container.decode(String.self, forKey: "code") + detail = try container.decodeIfPresent(String.self, forKey: "detail") + id = try container.decodeIfPresent(String.self, forKey: "id") + meta = try container.decodeIfPresent(Meta.self, forKey: "meta") + source = try container.decodeIfPresent(Source.self, forKey: "source") + status = try container.decode(String.self, forKey: "status") + title = try container.decode(String.self, forKey: "title") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(code, forKey: "code") + try container.encodeIfPresent(detail, forKey: "detail") + try container.encodeIfPresent(id, forKey: "id") + try container.encodeIfPresent(meta, forKey: "meta") + try container.encodeIfPresent(source, forKey: "source") + try container.encode(status, forKey: "status") + try container.encode(title, forKey: "title") + } + public struct Meta: Codable { public var additionalProperties: [String: String]? public var associatedErrors: [String: [Errors]]? @@ -66,6 +98,18 @@ public struct ErrorResponse: Codable { self.additionalProperties = additionalProperties self.associatedErrors = associatedErrors } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + additionalProperties = try container.decodeIfPresent([String: String].self, forKey: "additionalProperties") + associatedErrors = try container.decodeIfPresent([String: [Errors]].self, forKey: "associatedErrors") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(additionalProperties, forKey: "additionalProperties") + try container.encodeIfPresent(associatedErrors, forKey: "associatedErrors") + } } public enum Source: Codable { @@ -91,10 +135,6 @@ public struct ErrorResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } } diff --git a/Sources/Bagbutik-Core/Models/JsonPointer.swift b/Sources/Bagbutik-Core/Models/JsonPointer.swift index 41c83cfd1..0a4b16065 100644 --- a/Sources/Bagbutik-Core/Models/JsonPointer.swift +++ b/Sources/Bagbutik-Core/Models/JsonPointer.swift @@ -16,4 +16,14 @@ public struct JsonPointer: Codable { public init(pointer: String? = nil) { self.pointer = pointer } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + pointer = try container.decodeIfPresent(String.self, forKey: "pointer") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(pointer, forKey: "pointer") + } } diff --git a/Sources/Bagbutik-Core/Models/PagedDocumentLinks.swift b/Sources/Bagbutik-Core/Models/PagedDocumentLinks.swift index 7188350d8..78c13c195 100644 --- a/Sources/Bagbutik-Core/Models/PagedDocumentLinks.swift +++ b/Sources/Bagbutik-Core/Models/PagedDocumentLinks.swift @@ -27,22 +27,16 @@ public struct PagedDocumentLinks: Codable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - first = try container.decodeIfPresent(String.self, forKey: .first) - next = try container.decodeIfPresent(String.self, forKey: .next) - itself = try container.decode(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + first = try container.decodeIfPresent(String.self, forKey: "first") + next = try container.decodeIfPresent(String.self, forKey: "next") + itself = try container.decode(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(first, forKey: .first) - try container.encodeIfPresent(next, forKey: .next) - try container.encode(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case first - case itself = "self" - case next + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(first, forKey: "first") + try container.encodeIfPresent(next, forKey: "next") + try container.encode(itself, forKey: "self") } } diff --git a/Sources/Bagbutik-Core/Models/PagingInformation.swift b/Sources/Bagbutik-Core/Models/PagingInformation.swift index 676e41389..cab7c465f 100644 --- a/Sources/Bagbutik-Core/Models/PagingInformation.swift +++ b/Sources/Bagbutik-Core/Models/PagingInformation.swift @@ -15,6 +15,16 @@ public struct PagingInformation: Codable { self.paging = paging } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + paging = try container.decode(Paging.self, forKey: "paging") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(paging, forKey: "paging") + } + /** # PagingInformation.Paging Paging details such as the total number of resources and the per-page limit. @@ -39,5 +49,17 @@ public struct PagingInformation: Codable { self.limit = limit self.total = total } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + limit = try container.decode(Int.self, forKey: "limit") + total = try container.decodeIfPresent(Int.self, forKey: "total") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(limit, forKey: "limit") + try container.encodeIfPresent(total, forKey: "total") + } } } diff --git a/Sources/Bagbutik-Core/Models/Parameter.swift b/Sources/Bagbutik-Core/Models/Parameter.swift index 39ba68bab..6855d6272 100644 --- a/Sources/Bagbutik-Core/Models/Parameter.swift +++ b/Sources/Bagbutik-Core/Models/Parameter.swift @@ -14,4 +14,14 @@ public struct Parameter: Codable { public init(parameter: String? = nil) { self.parameter = parameter } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + parameter = try container.decodeIfPresent(String.self, forKey: "parameter") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(parameter, forKey: "parameter") + } } diff --git a/Sources/Bagbutik-Core/Models/ResourceLinks.swift b/Sources/Bagbutik-Core/Models/ResourceLinks.swift index 6c78a9866..561d00450 100644 --- a/Sources/Bagbutik-Core/Models/ResourceLinks.swift +++ b/Sources/Bagbutik-Core/Models/ResourceLinks.swift @@ -16,16 +16,12 @@ public struct ResourceLinks: Codable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(itself, forKey: "self") } } diff --git a/Sources/Bagbutik-Models/AppStore/Actor.swift b/Sources/Bagbutik-Models/AppStore/Actor.swift index 2e3ff5a7b..86045a855 100644 --- a/Sources/Bagbutik-Models/AppStore/Actor.swift +++ b/Sources/Bagbutik-Models/AppStore/Actor.swift @@ -17,28 +17,21 @@ public struct Actor: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } public struct Attributes: Codable { @@ -61,6 +54,24 @@ public struct Actor: Codable, Identifiable { self.userLastName = userLastName } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + actorType = try container.decodeIfPresent(ActorType.self, forKey: "actorType") + apiKeyId = try container.decodeIfPresent(String.self, forKey: "apiKeyId") + userEmail = try container.decodeIfPresent(String.self, forKey: "userEmail") + userFirstName = try container.decodeIfPresent(String.self, forKey: "userFirstName") + userLastName = try container.decodeIfPresent(String.self, forKey: "userLastName") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(actorType, forKey: "actorType") + try container.encodeIfPresent(apiKeyId, forKey: "apiKeyId") + try container.encodeIfPresent(userEmail, forKey: "userEmail") + try container.encodeIfPresent(userFirstName, forKey: "userFirstName") + try container.encodeIfPresent(userLastName, forKey: "userLastName") + } + public enum ActorType: String, Codable, CaseIterable { case apiKey = "API_KEY" case apple = "APPLE" diff --git a/Sources/Bagbutik-Models/AppStore/ActorResponse.swift b/Sources/Bagbutik-Models/AppStore/ActorResponse.swift index 47c28b3b7..3973e6343 100644 --- a/Sources/Bagbutik-Models/AppStore/ActorResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/ActorResponse.swift @@ -11,4 +11,16 @@ public struct ActorResponse: Codable { self.data = data self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Actor.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/AppStore/ActorsResponse.swift b/Sources/Bagbutik-Models/AppStore/ActorsResponse.swift index 341561dcd..d3a2a7f54 100644 --- a/Sources/Bagbutik-Models/AppStore/ActorsResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/ActorsResponse.swift @@ -16,4 +16,18 @@ public struct ActorsResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Actor].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/AppStore/AgeRatingDeclaration.swift b/Sources/Bagbutik-Models/AppStore/AgeRatingDeclaration.swift index 345055193..1562807f4 100644 --- a/Sources/Bagbutik-Models/AppStore/AgeRatingDeclaration.swift +++ b/Sources/Bagbutik-Models/AppStore/AgeRatingDeclaration.swift @@ -28,28 +28,21 @@ public struct AgeRatingDeclaration: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } /** @@ -173,6 +166,50 @@ public struct AgeRatingDeclaration: Codable, Identifiable { self.violenceRealisticProlongedGraphicOrSadistic = violenceRealisticProlongedGraphicOrSadistic } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + ageRatingOverride = try container.decodeIfPresent(AgeRatingOverride.self, forKey: "ageRatingOverride") + alcoholTobaccoOrDrugUseOrReferences = try container.decodeIfPresent(AlcoholTobaccoOrDrugUseOrReferences.self, forKey: "alcoholTobaccoOrDrugUseOrReferences") + contests = try container.decodeIfPresent(Contests.self, forKey: "contests") + gambling = try container.decodeIfPresent(Bool.self, forKey: "gambling") + gamblingAndContests = try container.decodeIfPresent(Bool.self, forKey: "gamblingAndContests") + gamblingSimulated = try container.decodeIfPresent(GamblingSimulated.self, forKey: "gamblingSimulated") + horrorOrFearThemes = try container.decodeIfPresent(HorrorOrFearThemes.self, forKey: "horrorOrFearThemes") + kidsAgeBand = try container.decodeIfPresent(KidsAgeBand.self, forKey: "kidsAgeBand") + matureOrSuggestiveThemes = try container.decodeIfPresent(MatureOrSuggestiveThemes.self, forKey: "matureOrSuggestiveThemes") + medicalOrTreatmentInformation = try container.decodeIfPresent(MedicalOrTreatmentInformation.self, forKey: "medicalOrTreatmentInformation") + profanityOrCrudeHumor = try container.decodeIfPresent(ProfanityOrCrudeHumor.self, forKey: "profanityOrCrudeHumor") + seventeenPlus = try container.decodeIfPresent(Bool.self, forKey: "seventeenPlus") + sexualContentGraphicAndNudity = try container.decodeIfPresent(SexualContentGraphicAndNudity.self, forKey: "sexualContentGraphicAndNudity") + sexualContentOrNudity = try container.decodeIfPresent(SexualContentOrNudity.self, forKey: "sexualContentOrNudity") + unrestrictedWebAccess = try container.decodeIfPresent(Bool.self, forKey: "unrestrictedWebAccess") + violenceCartoonOrFantasy = try container.decodeIfPresent(ViolenceCartoonOrFantasy.self, forKey: "violenceCartoonOrFantasy") + violenceRealistic = try container.decodeIfPresent(ViolenceRealistic.self, forKey: "violenceRealistic") + violenceRealisticProlongedGraphicOrSadistic = try container.decodeIfPresent(ViolenceRealisticProlongedGraphicOrSadistic.self, forKey: "violenceRealisticProlongedGraphicOrSadistic") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(ageRatingOverride, forKey: "ageRatingOverride") + try container.encodeIfPresent(alcoholTobaccoOrDrugUseOrReferences, forKey: "alcoholTobaccoOrDrugUseOrReferences") + try container.encodeIfPresent(contests, forKey: "contests") + try container.encodeIfPresent(gambling, forKey: "gambling") + try container.encodeIfPresent(gamblingAndContests, forKey: "gamblingAndContests") + try container.encodeIfPresent(gamblingSimulated, forKey: "gamblingSimulated") + try container.encodeIfPresent(horrorOrFearThemes, forKey: "horrorOrFearThemes") + try container.encodeIfPresent(kidsAgeBand, forKey: "kidsAgeBand") + try container.encodeIfPresent(matureOrSuggestiveThemes, forKey: "matureOrSuggestiveThemes") + try container.encodeIfPresent(medicalOrTreatmentInformation, forKey: "medicalOrTreatmentInformation") + try container.encodeIfPresent(profanityOrCrudeHumor, forKey: "profanityOrCrudeHumor") + try container.encodeIfPresent(seventeenPlus, forKey: "seventeenPlus") + try container.encodeIfPresent(sexualContentGraphicAndNudity, forKey: "sexualContentGraphicAndNudity") + try container.encodeIfPresent(sexualContentOrNudity, forKey: "sexualContentOrNudity") + try container.encodeIfPresent(unrestrictedWebAccess, forKey: "unrestrictedWebAccess") + try container.encodeIfPresent(violenceCartoonOrFantasy, forKey: "violenceCartoonOrFantasy") + try container.encodeIfPresent(violenceRealistic, forKey: "violenceRealistic") + try container.encodeIfPresent(violenceRealisticProlongedGraphicOrSadistic, forKey: "violenceRealisticProlongedGraphicOrSadistic") + } + public enum AgeRatingOverride: String, Codable, CaseIterable { case none = "NONE" case seventeenPlus = "SEVENTEEN_PLUS" diff --git a/Sources/Bagbutik-Models/AppStore/AgeRatingDeclarationResponse.swift b/Sources/Bagbutik-Models/AppStore/AgeRatingDeclarationResponse.swift index 05d68aeb6..eaadfdf2c 100644 --- a/Sources/Bagbutik-Models/AppStore/AgeRatingDeclarationResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AgeRatingDeclarationResponse.swift @@ -20,4 +20,16 @@ public struct AgeRatingDeclarationResponse: Codable { self.data = data self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AgeRatingDeclaration.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/AppStore/AgeRatingDeclarationUpdateRequest.swift b/Sources/Bagbutik-Models/AppStore/AgeRatingDeclarationUpdateRequest.swift index 7187c6256..0e56fb66a 100644 --- a/Sources/Bagbutik-Models/AppStore/AgeRatingDeclarationUpdateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AgeRatingDeclarationUpdateRequest.swift @@ -16,6 +16,16 @@ public struct AgeRatingDeclarationUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AgeRatingDeclarationUpdateRequest.Data The data element of the request body. @@ -39,25 +49,19 @@ public struct AgeRatingDeclarationUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } /** @@ -182,6 +186,50 @@ public struct AgeRatingDeclarationUpdateRequest: Codable, RequestBody { self.violenceRealistic = violenceRealistic self.violenceRealisticProlongedGraphicOrSadistic = violenceRealisticProlongedGraphicOrSadistic } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + ageRatingOverride = try container.decodeIfPresent(AgeRatingDeclaration.Attributes.AgeRatingOverride.self, forKey: "ageRatingOverride") + alcoholTobaccoOrDrugUseOrReferences = try container.decodeIfPresent(AgeRatingDeclaration.Attributes.AlcoholTobaccoOrDrugUseOrReferences.self, forKey: "alcoholTobaccoOrDrugUseOrReferences") + contests = try container.decodeIfPresent(AgeRatingDeclaration.Attributes.Contests.self, forKey: "contests") + gambling = try container.decodeIfPresent(Bool.self, forKey: "gambling") + gamblingAndContests = try container.decodeIfPresent(Bool.self, forKey: "gamblingAndContests") + gamblingSimulated = try container.decodeIfPresent(AgeRatingDeclaration.Attributes.GamblingSimulated.self, forKey: "gamblingSimulated") + horrorOrFearThemes = try container.decodeIfPresent(AgeRatingDeclaration.Attributes.HorrorOrFearThemes.self, forKey: "horrorOrFearThemes") + kidsAgeBand = try container.decodeIfPresent(KidsAgeBand.self, forKey: "kidsAgeBand") + matureOrSuggestiveThemes = try container.decodeIfPresent(AgeRatingDeclaration.Attributes.MatureOrSuggestiveThemes.self, forKey: "matureOrSuggestiveThemes") + medicalOrTreatmentInformation = try container.decodeIfPresent(AgeRatingDeclaration.Attributes.MedicalOrTreatmentInformation.self, forKey: "medicalOrTreatmentInformation") + profanityOrCrudeHumor = try container.decodeIfPresent(AgeRatingDeclaration.Attributes.ProfanityOrCrudeHumor.self, forKey: "profanityOrCrudeHumor") + seventeenPlus = try container.decodeIfPresent(Bool.self, forKey: "seventeenPlus") + sexualContentGraphicAndNudity = try container.decodeIfPresent(AgeRatingDeclaration.Attributes.SexualContentGraphicAndNudity.self, forKey: "sexualContentGraphicAndNudity") + sexualContentOrNudity = try container.decodeIfPresent(AgeRatingDeclaration.Attributes.SexualContentOrNudity.self, forKey: "sexualContentOrNudity") + unrestrictedWebAccess = try container.decodeIfPresent(Bool.self, forKey: "unrestrictedWebAccess") + violenceCartoonOrFantasy = try container.decodeIfPresent(AgeRatingDeclaration.Attributes.ViolenceCartoonOrFantasy.self, forKey: "violenceCartoonOrFantasy") + violenceRealistic = try container.decodeIfPresent(AgeRatingDeclaration.Attributes.ViolenceRealistic.self, forKey: "violenceRealistic") + violenceRealisticProlongedGraphicOrSadistic = try container.decodeIfPresent(AgeRatingDeclaration.Attributes.ViolenceRealisticProlongedGraphicOrSadistic.self, forKey: "violenceRealisticProlongedGraphicOrSadistic") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(ageRatingOverride, forKey: "ageRatingOverride") + try container.encodeIfPresent(alcoholTobaccoOrDrugUseOrReferences, forKey: "alcoholTobaccoOrDrugUseOrReferences") + try container.encodeIfPresent(contests, forKey: "contests") + try container.encodeIfPresent(gambling, forKey: "gambling") + try container.encodeIfPresent(gamblingAndContests, forKey: "gamblingAndContests") + try container.encodeIfPresent(gamblingSimulated, forKey: "gamblingSimulated") + try container.encodeIfPresent(horrorOrFearThemes, forKey: "horrorOrFearThemes") + try container.encodeIfPresent(kidsAgeBand, forKey: "kidsAgeBand") + try container.encodeIfPresent(matureOrSuggestiveThemes, forKey: "matureOrSuggestiveThemes") + try container.encodeIfPresent(medicalOrTreatmentInformation, forKey: "medicalOrTreatmentInformation") + try container.encodeIfPresent(profanityOrCrudeHumor, forKey: "profanityOrCrudeHumor") + try container.encodeIfPresent(seventeenPlus, forKey: "seventeenPlus") + try container.encodeIfPresent(sexualContentGraphicAndNudity, forKey: "sexualContentGraphicAndNudity") + try container.encodeIfPresent(sexualContentOrNudity, forKey: "sexualContentOrNudity") + try container.encodeIfPresent(unrestrictedWebAccess, forKey: "unrestrictedWebAccess") + try container.encodeIfPresent(violenceCartoonOrFantasy, forKey: "violenceCartoonOrFantasy") + try container.encodeIfPresent(violenceRealistic, forKey: "violenceRealistic") + try container.encodeIfPresent(violenceRealisticProlongedGraphicOrSadistic, forKey: "violenceRealisticProlongedGraphicOrSadistic") + } } } } diff --git a/Sources/Bagbutik-Models/AppStore/AgeRatingDeclarationWithoutIncludesResponse.swift b/Sources/Bagbutik-Models/AppStore/AgeRatingDeclarationWithoutIncludesResponse.swift index cd1dc50a3..be8543b1c 100644 --- a/Sources/Bagbutik-Models/AppStore/AgeRatingDeclarationWithoutIncludesResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AgeRatingDeclarationWithoutIncludesResponse.swift @@ -11,4 +11,16 @@ public struct AgeRatingDeclarationWithoutIncludesResponse: Codable { self.data = data self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AgeRatingDeclaration.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/AppStore/App.swift b/Sources/Bagbutik-Models/AppStore/App.swift index d73619f89..c47bba379 100644 --- a/Sources/Bagbutik-Models/AppStore/App.swift +++ b/Sources/Bagbutik-Models/AppStore/App.swift @@ -32,31 +32,23 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -133,6 +125,36 @@ public struct App: Codable, Identifiable { self.subscriptionStatusUrlVersionForSandbox = subscriptionStatusUrlVersionForSandbox } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + availableInNewTerritories = try container.decodeIfPresent(Bool.self, forKey: "availableInNewTerritories") + bundleId = try container.decodeIfPresent(String.self, forKey: "bundleId") + contentRightsDeclaration = try container.decodeIfPresent(ContentRightsDeclaration.self, forKey: "contentRightsDeclaration") + isOrEverWasMadeForKids = try container.decodeIfPresent(Bool.self, forKey: "isOrEverWasMadeForKids") + name = try container.decodeIfPresent(String.self, forKey: "name") + primaryLocale = try container.decodeIfPresent(String.self, forKey: "primaryLocale") + sku = try container.decodeIfPresent(String.self, forKey: "sku") + subscriptionStatusUrl = try container.decodeIfPresent(String.self, forKey: "subscriptionStatusUrl") + subscriptionStatusUrlForSandbox = try container.decodeIfPresent(String.self, forKey: "subscriptionStatusUrlForSandbox") + subscriptionStatusUrlVersion = try container.decodeIfPresent(SubscriptionStatusUrlVersion.self, forKey: "subscriptionStatusUrlVersion") + subscriptionStatusUrlVersionForSandbox = try container.decodeIfPresent(SubscriptionStatusUrlVersion.self, forKey: "subscriptionStatusUrlVersionForSandbox") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(availableInNewTerritories, forKey: "availableInNewTerritories") + try container.encodeIfPresent(bundleId, forKey: "bundleId") + try container.encodeIfPresent(contentRightsDeclaration, forKey: "contentRightsDeclaration") + try container.encodeIfPresent(isOrEverWasMadeForKids, forKey: "isOrEverWasMadeForKids") + try container.encodeIfPresent(name, forKey: "name") + try container.encodeIfPresent(primaryLocale, forKey: "primaryLocale") + try container.encodeIfPresent(sku, forKey: "sku") + try container.encodeIfPresent(subscriptionStatusUrl, forKey: "subscriptionStatusUrl") + try container.encodeIfPresent(subscriptionStatusUrlForSandbox, forKey: "subscriptionStatusUrlForSandbox") + try container.encodeIfPresent(subscriptionStatusUrlVersion, forKey: "subscriptionStatusUrlVersion") + try container.encodeIfPresent(subscriptionStatusUrlVersionForSandbox, forKey: "subscriptionStatusUrlVersionForSandbox") + } + public enum ContentRightsDeclaration: String, Codable, CaseIterable { case doesNotUseThirdPartyContent = "DOES_NOT_USE_THIRD_PARTY_CONTENT" case usesThirdPartyContent = "USES_THIRD_PARTY_CONTENT" @@ -298,6 +320,66 @@ public struct App: Codable, Identifiable { self.subscriptionGroups = subscriptionGroups } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appClips = try container.decodeIfPresent(AppClips.self, forKey: "appClips") + appCustomProductPages = try container.decodeIfPresent(AppCustomProductPages.self, forKey: "appCustomProductPages") + appEncryptionDeclarations = try container.decodeIfPresent(AppEncryptionDeclarations.self, forKey: "appEncryptionDeclarations") + appEvents = try container.decodeIfPresent(AppEvents.self, forKey: "appEvents") + appInfos = try container.decodeIfPresent(AppInfos.self, forKey: "appInfos") + appStoreVersionExperimentsV2 = try container.decodeIfPresent(AppStoreVersionExperimentsV2.self, forKey: "appStoreVersionExperimentsV2") + appStoreVersions = try container.decodeIfPresent(AppStoreVersions.self, forKey: "appStoreVersions") + availableTerritories = try container.decodeIfPresent(AvailableTerritories.self, forKey: "availableTerritories") + betaAppLocalizations = try container.decodeIfPresent(BetaAppLocalizations.self, forKey: "betaAppLocalizations") + betaAppReviewDetail = try container.decodeIfPresent(BetaAppReviewDetail.self, forKey: "betaAppReviewDetail") + betaGroups = try container.decodeIfPresent(BetaGroups.self, forKey: "betaGroups") + betaLicenseAgreement = try container.decodeIfPresent(BetaLicenseAgreement.self, forKey: "betaLicenseAgreement") + builds = try container.decodeIfPresent(Builds.self, forKey: "builds") + ciProduct = try container.decodeIfPresent(CiProduct.self, forKey: "ciProduct") + endUserLicenseAgreement = try container.decodeIfPresent(EndUserLicenseAgreement.self, forKey: "endUserLicenseAgreement") + gameCenterDetail = try container.decodeIfPresent(GameCenterDetail.self, forKey: "gameCenterDetail") + gameCenterEnabledVersions = try container.decodeIfPresent(GameCenterEnabledVersions.self, forKey: "gameCenterEnabledVersions") + inAppPurchases = try container.decodeIfPresent(InAppPurchases.self, forKey: "inAppPurchases") + inAppPurchasesV2 = try container.decodeIfPresent(InAppPurchasesV2.self, forKey: "inAppPurchasesV2") + preOrder = try container.decodeIfPresent(PreOrder.self, forKey: "preOrder") + preReleaseVersions = try container.decodeIfPresent(PreReleaseVersions.self, forKey: "preReleaseVersions") + prices = try container.decodeIfPresent(Prices.self, forKey: "prices") + promotedPurchases = try container.decodeIfPresent(PromotedPurchases.self, forKey: "promotedPurchases") + reviewSubmissions = try container.decodeIfPresent(ReviewSubmissions.self, forKey: "reviewSubmissions") + subscriptionGracePeriod = try container.decodeIfPresent(SubscriptionGracePeriod.self, forKey: "subscriptionGracePeriod") + subscriptionGroups = try container.decodeIfPresent(SubscriptionGroups.self, forKey: "subscriptionGroups") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(appClips, forKey: "appClips") + try container.encodeIfPresent(appCustomProductPages, forKey: "appCustomProductPages") + try container.encodeIfPresent(appEncryptionDeclarations, forKey: "appEncryptionDeclarations") + try container.encodeIfPresent(appEvents, forKey: "appEvents") + try container.encodeIfPresent(appInfos, forKey: "appInfos") + try container.encodeIfPresent(appStoreVersionExperimentsV2, forKey: "appStoreVersionExperimentsV2") + try container.encodeIfPresent(appStoreVersions, forKey: "appStoreVersions") + try container.encodeIfPresent(availableTerritories, forKey: "availableTerritories") + try container.encodeIfPresent(betaAppLocalizations, forKey: "betaAppLocalizations") + try container.encodeIfPresent(betaAppReviewDetail, forKey: "betaAppReviewDetail") + try container.encodeIfPresent(betaGroups, forKey: "betaGroups") + try container.encodeIfPresent(betaLicenseAgreement, forKey: "betaLicenseAgreement") + try container.encodeIfPresent(builds, forKey: "builds") + try container.encodeIfPresent(ciProduct, forKey: "ciProduct") + try container.encodeIfPresent(endUserLicenseAgreement, forKey: "endUserLicenseAgreement") + try container.encodeIfPresent(gameCenterDetail, forKey: "gameCenterDetail") + try container.encodeIfPresent(gameCenterEnabledVersions, forKey: "gameCenterEnabledVersions") + try container.encodeIfPresent(inAppPurchases, forKey: "inAppPurchases") + try container.encodeIfPresent(inAppPurchasesV2, forKey: "inAppPurchasesV2") + try container.encodeIfPresent(preOrder, forKey: "preOrder") + try container.encodeIfPresent(preReleaseVersions, forKey: "preReleaseVersions") + try container.encodeIfPresent(prices, forKey: "prices") + try container.encodeIfPresent(promotedPurchases, forKey: "promotedPurchases") + try container.encodeIfPresent(reviewSubmissions, forKey: "reviewSubmissions") + try container.encodeIfPresent(subscriptionGracePeriod, forKey: "subscriptionGracePeriod") + try container.encodeIfPresent(subscriptionGroups, forKey: "subscriptionGroups") + } + /** # App.Relationships.AppClips The data and links that describe the relationship between the Apps and the App Clips resources. @@ -323,23 +405,17 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } /** @@ -360,22 +436,17 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -400,20 +471,15 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -433,23 +499,17 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -461,22 +521,17 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -492,20 +547,15 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -532,23 +582,17 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } /** @@ -567,22 +611,17 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -598,20 +637,15 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -631,23 +665,17 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -659,22 +687,17 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -690,20 +713,15 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -730,23 +748,17 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } /** @@ -765,22 +777,17 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -803,20 +810,15 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -836,23 +838,17 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -864,22 +860,17 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -895,20 +886,15 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -935,23 +921,17 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } /** @@ -970,22 +950,17 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -1008,20 +983,15 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -1048,23 +1018,17 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } /** @@ -1083,22 +1047,17 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -1121,20 +1080,15 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -1161,23 +1115,17 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } /** @@ -1198,22 +1146,17 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -1236,20 +1179,15 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -1273,20 +1211,15 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -1307,22 +1240,17 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -1345,20 +1273,15 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -1385,23 +1308,17 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } /** @@ -1422,22 +1339,17 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -1460,20 +1372,15 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -1497,20 +1404,15 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -1531,22 +1433,17 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -1569,20 +1466,15 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -1609,23 +1501,17 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } /** @@ -1646,22 +1532,17 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -1684,20 +1565,15 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -1723,20 +1599,15 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -1757,22 +1628,17 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -1797,20 +1663,15 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -1834,20 +1695,15 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -1866,22 +1722,17 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -1904,20 +1755,15 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -1934,20 +1780,15 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -1959,22 +1800,17 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -1990,20 +1826,15 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -2030,23 +1861,17 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } /** @@ -2065,22 +1890,17 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -2103,20 +1923,15 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -2143,23 +1958,17 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } /** @@ -2178,22 +1987,17 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -2216,20 +2020,15 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -2249,23 +2048,17 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -2277,22 +2070,17 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -2308,20 +2096,15 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -2345,20 +2128,15 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -2377,22 +2155,17 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -2415,20 +2188,15 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -2455,23 +2223,17 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } /** @@ -2492,22 +2254,17 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -2530,20 +2287,15 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -2570,23 +2322,17 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } /** @@ -2605,22 +2351,17 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -2643,20 +2384,15 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -2676,23 +2412,17 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -2704,22 +2434,17 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -2735,20 +2460,15 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -2768,23 +2488,17 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -2796,22 +2510,17 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -2827,20 +2536,15 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -2857,20 +2561,15 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -2882,22 +2581,17 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -2913,20 +2607,15 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -2946,23 +2635,17 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -2974,22 +2657,17 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -3005,20 +2683,15 @@ public struct App: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppAvailability.swift b/Sources/Bagbutik-Models/AppStore/AppAvailability.swift index 467923d16..ececf45c7 100644 --- a/Sources/Bagbutik-Models/AppStore/AppAvailability.swift +++ b/Sources/Bagbutik-Models/AppStore/AppAvailability.swift @@ -20,31 +20,23 @@ public struct AppAvailability: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -53,6 +45,16 @@ public struct AppAvailability: Codable, Identifiable { public init(availableInNewTerritories: Bool? = nil) { self.availableInNewTerritories = availableInNewTerritories } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + availableInNewTerritories = try container.decodeIfPresent(Bool.self, forKey: "availableInNewTerritories") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(availableInNewTerritories, forKey: "availableInNewTerritories") + } } public struct Relationships: Codable { @@ -66,6 +68,18 @@ public struct AppAvailability: Codable, Identifiable { self.availableTerritories = availableTerritories } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + app = try container.decodeIfPresent(App.self, forKey: "app") + availableTerritories = try container.decodeIfPresent(AvailableTerritories.self, forKey: "availableTerritories") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(app, forKey: "app") + try container.encodeIfPresent(availableTerritories, forKey: "availableTerritories") + } + public struct App: Codable { @NullCodable public var data: Data? public var links: Links? @@ -78,20 +92,15 @@ public struct AppAvailability: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -103,22 +112,17 @@ public struct AppAvailability: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -134,20 +138,15 @@ public struct AppAvailability: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -167,23 +166,17 @@ public struct AppAvailability: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -195,22 +188,17 @@ public struct AppAvailability: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -226,20 +214,15 @@ public struct AppAvailability: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppAvailabilityCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppAvailabilityCreateRequest.swift index f0b4a6ebe..97cdf5617 100644 --- a/Sources/Bagbutik-Models/AppStore/AppAvailabilityCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppAvailabilityCreateRequest.swift @@ -8,6 +8,16 @@ public struct AppAvailabilityCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "appAvailabilities" } public let attributes: Attributes @@ -21,25 +31,19 @@ public struct AppAvailabilityCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -48,6 +52,16 @@ public struct AppAvailabilityCreateRequest: Codable, RequestBody { public init(availableInNewTerritories: Bool) { self.availableInNewTerritories = availableInNewTerritories } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + availableInNewTerritories = try container.decode(Bool.self, forKey: "availableInNewTerritories") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(availableInNewTerritories, forKey: "availableInNewTerritories") + } } public struct Relationships: Codable { @@ -61,6 +75,18 @@ public struct AppAvailabilityCreateRequest: Codable, RequestBody { self.availableTerritories = availableTerritories } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + app = try container.decode(App.self, forKey: "app") + availableTerritories = try container.decode(AvailableTerritories.self, forKey: "availableTerritories") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(app, forKey: "app") + try container.encode(availableTerritories, forKey: "availableTerritories") + } + public struct App: Codable { public let data: Data @@ -68,6 +94,16 @@ public struct AppAvailabilityCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "apps" } @@ -77,22 +113,17 @@ public struct AppAvailabilityCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -104,6 +135,16 @@ public struct AppAvailabilityCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "territories" } @@ -113,22 +154,17 @@ public struct AppAvailabilityCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppAvailabilityResponse.swift b/Sources/Bagbutik-Models/AppStore/AppAvailabilityResponse.swift index ce9ad3d4d..26709726b 100644 --- a/Sources/Bagbutik-Models/AppStore/AppAvailabilityResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppAvailabilityResponse.swift @@ -15,6 +15,20 @@ public struct AppAvailabilityResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AppAvailability.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getApp() -> App? { included?.compactMap { relationship -> App? in guard case let .app(app) = relationship else { return nil } @@ -57,9 +71,5 @@ public struct AppAvailabilityResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppAvailabilityV2.swift b/Sources/Bagbutik-Models/AppStore/AppAvailabilityV2.swift index ecf7bab00..6ab1026f1 100644 --- a/Sources/Bagbutik-Models/AppStore/AppAvailabilityV2.swift +++ b/Sources/Bagbutik-Models/AppStore/AppAvailabilityV2.swift @@ -27,31 +27,23 @@ public struct AppAvailabilityV2: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -60,6 +52,16 @@ public struct AppAvailabilityV2: Codable, Identifiable { public init(availableInNewTerritories: Bool? = nil) { self.availableInNewTerritories = availableInNewTerritories } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + availableInNewTerritories = try container.decodeIfPresent(Bool.self, forKey: "availableInNewTerritories") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(availableInNewTerritories, forKey: "availableInNewTerritories") + } } public struct Relationships: Codable { @@ -69,6 +71,16 @@ public struct AppAvailabilityV2: Codable, Identifiable { self.territoryAvailabilities = territoryAvailabilities } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + territoryAvailabilities = try container.decodeIfPresent(TerritoryAvailabilities.self, forKey: "territoryAvailabilities") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(territoryAvailabilities, forKey: "territoryAvailabilities") + } + public struct TerritoryAvailabilities: Codable { @NullCodable public var data: [Data]? public var links: Links? @@ -84,23 +96,17 @@ public struct AppAvailabilityV2: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -112,22 +118,17 @@ public struct AppAvailabilityV2: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -143,20 +144,15 @@ public struct AppAvailabilityV2: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppAvailabilityV2CreateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppAvailabilityV2CreateRequest.swift index 8f95f0035..0de70cf23 100644 --- a/Sources/Bagbutik-Models/AppStore/AppAvailabilityV2CreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppAvailabilityV2CreateRequest.swift @@ -19,6 +19,18 @@ public struct AppAvailabilityV2CreateRequest: Codable, RequestBody { self.included = included } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + included = try container.decodeIfPresent([TerritoryAvailabilityInlineCreate].self, forKey: "included") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + } + public struct Data: Codable { public var type: String { "appAvailabilities" } public let attributes: Attributes @@ -32,25 +44,19 @@ public struct AppAvailabilityV2CreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -59,6 +65,16 @@ public struct AppAvailabilityV2CreateRequest: Codable, RequestBody { public init(availableInNewTerritories: Bool) { self.availableInNewTerritories = availableInNewTerritories } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + availableInNewTerritories = try container.decode(Bool.self, forKey: "availableInNewTerritories") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(availableInNewTerritories, forKey: "availableInNewTerritories") + } } public struct Relationships: Codable { @@ -72,6 +88,18 @@ public struct AppAvailabilityV2CreateRequest: Codable, RequestBody { self.territoryAvailabilities = territoryAvailabilities } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + app = try container.decode(App.self, forKey: "app") + territoryAvailabilities = try container.decode(TerritoryAvailabilities.self, forKey: "territoryAvailabilities") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(app, forKey: "app") + try container.encode(territoryAvailabilities, forKey: "territoryAvailabilities") + } + public struct App: Codable { public let data: Data @@ -79,6 +107,16 @@ public struct AppAvailabilityV2CreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "apps" } @@ -88,22 +126,17 @@ public struct AppAvailabilityV2CreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -115,6 +148,16 @@ public struct AppAvailabilityV2CreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "territoryAvailabilities" } @@ -124,22 +167,17 @@ public struct AppAvailabilityV2CreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppAvailabilityV2Response.swift b/Sources/Bagbutik-Models/AppStore/AppAvailabilityV2Response.swift index b2b8096ef..057224c8b 100644 --- a/Sources/Bagbutik-Models/AppStore/AppAvailabilityV2Response.swift +++ b/Sources/Bagbutik-Models/AppStore/AppAvailabilityV2Response.swift @@ -21,4 +21,18 @@ public struct AppAvailabilityV2Response: Codable { self.included = included self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AppAvailabilityV2.self, forKey: "data") + included = try container.decodeIfPresent([TerritoryAvailability].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/AppStore/AppCategoriesResponse.swift b/Sources/Bagbutik-Models/AppStore/AppCategoriesResponse.swift index 22366f58d..ad487ec62 100644 --- a/Sources/Bagbutik-Models/AppStore/AppCategoriesResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppCategoriesResponse.swift @@ -26,4 +26,20 @@ public struct AppCategoriesResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([AppCategory].self, forKey: "data") + included = try container.decodeIfPresent([AppCategory].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/AppStore/AppCategoriesWithoutIncludesResponse.swift b/Sources/Bagbutik-Models/AppStore/AppCategoriesWithoutIncludesResponse.swift index 112776f82..b685ea302 100644 --- a/Sources/Bagbutik-Models/AppStore/AppCategoriesWithoutIncludesResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppCategoriesWithoutIncludesResponse.swift @@ -16,4 +16,18 @@ public struct AppCategoriesWithoutIncludesResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([AppCategory].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/AppStore/AppCategory.swift b/Sources/Bagbutik-Models/AppStore/AppCategory.swift index dfa359048..2001cca1e 100644 --- a/Sources/Bagbutik-Models/AppStore/AppCategory.swift +++ b/Sources/Bagbutik-Models/AppStore/AppCategory.swift @@ -27,31 +27,23 @@ public struct AppCategory: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -67,6 +59,16 @@ public struct AppCategory: Codable, Identifiable { public init(platforms: [Platform]? = nil) { self.platforms = platforms } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + platforms = try container.decodeIfPresent([Platform].self, forKey: "platforms") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(platforms, forKey: "platforms") + } } /** @@ -87,6 +89,18 @@ public struct AppCategory: Codable, Identifiable { self.subcategories = subcategories } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + parent = try container.decodeIfPresent(Parent.self, forKey: "parent") + subcategories = try container.decodeIfPresent(Subcategories.self, forKey: "subcategories") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(parent, forKey: "parent") + try container.encodeIfPresent(subcategories, forKey: "subcategories") + } + /** # AppCategory.Relationships.Parent The data and links that describe the relationship between the resources. @@ -106,20 +120,15 @@ public struct AppCategory: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -138,22 +147,17 @@ public struct AppCategory: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -176,20 +180,15 @@ public struct AppCategory: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -216,23 +215,17 @@ public struct AppCategory: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } /** @@ -251,22 +244,17 @@ public struct AppCategory: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -289,20 +277,15 @@ public struct AppCategory: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppCategoryResponse.swift b/Sources/Bagbutik-Models/AppStore/AppCategoryResponse.swift index dc192cdbd..9d2561247 100644 --- a/Sources/Bagbutik-Models/AppStore/AppCategoryResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppCategoryResponse.swift @@ -21,4 +21,18 @@ public struct AppCategoryResponse: Codable { self.included = included self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AppCategory.self, forKey: "data") + included = try container.decodeIfPresent([AppCategory].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/AppStore/AppCategoryWithoutIncludesResponse.swift b/Sources/Bagbutik-Models/AppStore/AppCategoryWithoutIncludesResponse.swift index ecbef4f6c..74376c0b3 100644 --- a/Sources/Bagbutik-Models/AppStore/AppCategoryWithoutIncludesResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppCategoryWithoutIncludesResponse.swift @@ -11,4 +11,16 @@ public struct AppCategoryWithoutIncludesResponse: Codable { self.data = data self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AppCategory.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/AppStore/AppClip.swift b/Sources/Bagbutik-Models/AppStore/AppClip.swift index 51d1b8b69..91eaa0a4c 100644 --- a/Sources/Bagbutik-Models/AppStore/AppClip.swift +++ b/Sources/Bagbutik-Models/AppStore/AppClip.swift @@ -32,31 +32,23 @@ public struct AppClip: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -73,6 +65,16 @@ public struct AppClip: Codable, Identifiable { public init(bundleId: String? = nil) { self.bundleId = bundleId } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + bundleId = try container.decodeIfPresent(String.self, forKey: "bundleId") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(bundleId, forKey: "bundleId") + } } /** @@ -95,6 +97,18 @@ public struct AppClip: Codable, Identifiable { self.appClipDefaultExperiences = appClipDefaultExperiences } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + app = try container.decodeIfPresent(App.self, forKey: "app") + appClipDefaultExperiences = try container.decodeIfPresent(AppClipDefaultExperiences.self, forKey: "appClipDefaultExperiences") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(app, forKey: "app") + try container.encodeIfPresent(appClipDefaultExperiences, forKey: "appClipDefaultExperiences") + } + /** # AppClip.Relationships.App The data and links that describe the relationship between the App Clips and the Apps resource. @@ -116,20 +130,15 @@ public struct AppClip: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -150,22 +159,17 @@ public struct AppClip: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -190,20 +194,15 @@ public struct AppClip: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -233,23 +232,17 @@ public struct AppClip: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } /** @@ -270,22 +263,17 @@ public struct AppClip: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -310,20 +298,15 @@ public struct AppClip: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppClipAdvancedExperience.swift b/Sources/Bagbutik-Models/AppStore/AppClipAdvancedExperience.swift index 776c7f71f..87ced6899 100644 --- a/Sources/Bagbutik-Models/AppStore/AppClipAdvancedExperience.swift +++ b/Sources/Bagbutik-Models/AppStore/AppClipAdvancedExperience.swift @@ -32,31 +32,23 @@ public struct AppClipAdvancedExperience: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -107,6 +99,32 @@ public struct AppClipAdvancedExperience: Codable, Identifiable { self.version = version } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + action = try container.decodeIfPresent(AppClipAction.self, forKey: "action") + businessCategory = try container.decodeIfPresent(BusinessCategory.self, forKey: "businessCategory") + defaultLanguage = try container.decodeIfPresent(AppClipAdvancedExperienceLanguage.self, forKey: "defaultLanguage") + isPoweredBy = try container.decodeIfPresent(Bool.self, forKey: "isPoweredBy") + link = try container.decodeIfPresent(String.self, forKey: "link") + place = try container.decodeIfPresent(Place.self, forKey: "place") + placeStatus = try container.decodeIfPresent(PlaceStatus.self, forKey: "placeStatus") + status = try container.decodeIfPresent(Status.self, forKey: "status") + version = try container.decodeIfPresent(Int.self, forKey: "version") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(action, forKey: "action") + try container.encodeIfPresent(businessCategory, forKey: "businessCategory") + try container.encodeIfPresent(defaultLanguage, forKey: "defaultLanguage") + try container.encodeIfPresent(isPoweredBy, forKey: "isPoweredBy") + try container.encodeIfPresent(link, forKey: "link") + try container.encodeIfPresent(place, forKey: "place") + try container.encodeIfPresent(placeStatus, forKey: "placeStatus") + try container.encodeIfPresent(status, forKey: "status") + try container.encodeIfPresent(version, forKey: "version") + } + public enum BusinessCategory: String, Codable, CaseIterable { case automotive = "AUTOMOTIVE" case beauty = "BEAUTY" @@ -185,6 +203,32 @@ public struct AppClipAdvancedExperience: Codable, Identifiable { self.relationship = relationship } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + categories = try container.decodeIfPresent([String].self, forKey: "categories") + displayPoint = try container.decodeIfPresent(DisplayPoint.self, forKey: "displayPoint") + homePage = try container.decodeIfPresent(String.self, forKey: "homePage") + mainAddress = try container.decodeIfPresent(MainAddress.self, forKey: "mainAddress") + mapAction = try container.decodeIfPresent(MapAction.self, forKey: "mapAction") + names = try container.decodeIfPresent([String].self, forKey: "names") + phoneNumber = try container.decodeIfPresent(PhoneNumber.self, forKey: "phoneNumber") + placeId = try container.decodeIfPresent(String.self, forKey: "placeId") + relationship = try container.decodeIfPresent(Relationship.self, forKey: "relationship") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(categories, forKey: "categories") + try container.encodeIfPresent(displayPoint, forKey: "displayPoint") + try container.encodeIfPresent(homePage, forKey: "homePage") + try container.encodeIfPresent(mainAddress, forKey: "mainAddress") + try container.encodeIfPresent(mapAction, forKey: "mapAction") + try container.encodeIfPresent(names, forKey: "names") + try container.encodeIfPresent(phoneNumber, forKey: "phoneNumber") + try container.encodeIfPresent(placeId, forKey: "placeId") + try container.encodeIfPresent(relationship, forKey: "relationship") + } + /** # AppClipAdvancedExperience.Attributes.Place.DisplayPoint A point-based representation of a place in Apple Maps. @@ -205,6 +249,18 @@ public struct AppClipAdvancedExperience: Codable, Identifiable { self.source = source } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + coordinates = try container.decodeIfPresent(Coordinates.self, forKey: "coordinates") + source = try container.decodeIfPresent(Source.self, forKey: "source") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(coordinates, forKey: "coordinates") + try container.encodeIfPresent(source, forKey: "source") + } + /** # AppClipAdvancedExperience.Attributes.Place.DisplayPoint.Coordinates The coordinates for a point of interest or business in Apple Maps. @@ -224,6 +280,18 @@ public struct AppClipAdvancedExperience: Codable, Identifiable { self.latitude = latitude self.longitude = longitude } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + latitude = try container.decodeIfPresent(Double.self, forKey: "latitude") + longitude = try container.decodeIfPresent(Double.self, forKey: "longitude") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(latitude, forKey: "latitude") + try container.encodeIfPresent(longitude, forKey: "longitude") + } } public enum Source: String, Codable, CaseIterable { @@ -252,6 +320,18 @@ public struct AppClipAdvancedExperience: Codable, Identifiable { self.structuredAddress = structuredAddress } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + fullAddress = try container.decodeIfPresent(String.self, forKey: "fullAddress") + structuredAddress = try container.decodeIfPresent(StructuredAddress.self, forKey: "structuredAddress") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(fullAddress, forKey: "fullAddress") + try container.encodeIfPresent(structuredAddress, forKey: "structuredAddress") + } + /** # AppClipAdvancedExperience.Attributes.Place.MainAddress.StructuredAddress The structured address information for a point of interest or business in Apple Maps. @@ -291,6 +371,28 @@ public struct AppClipAdvancedExperience: Codable, Identifiable { self.stateProvince = stateProvince self.streetAddress = streetAddress } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + countryCode = try container.decodeIfPresent(String.self, forKey: "countryCode") + floor = try container.decodeIfPresent(String.self, forKey: "floor") + locality = try container.decodeIfPresent(String.self, forKey: "locality") + neighborhood = try container.decodeIfPresent(String.self, forKey: "neighborhood") + postalCode = try container.decodeIfPresent(String.self, forKey: "postalCode") + stateProvince = try container.decodeIfPresent(String.self, forKey: "stateProvince") + streetAddress = try container.decodeIfPresent([String].self, forKey: "streetAddress") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(countryCode, forKey: "countryCode") + try container.encodeIfPresent(floor, forKey: "floor") + try container.encodeIfPresent(locality, forKey: "locality") + try container.encodeIfPresent(neighborhood, forKey: "neighborhood") + try container.encodeIfPresent(postalCode, forKey: "postalCode") + try container.encodeIfPresent(stateProvince, forKey: "stateProvince") + try container.encodeIfPresent(streetAddress, forKey: "streetAddress") + } } } @@ -334,6 +436,20 @@ public struct AppClipAdvancedExperience: Codable, Identifiable { self.type = type } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + intent = try container.decodeIfPresent(String.self, forKey: "intent") + number = try container.decodeIfPresent(String.self, forKey: "number") + type = try container.decode(PhoneNumberType.self, forKey: "type") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(intent, forKey: "intent") + try container.encodeIfPresent(number, forKey: "number") + try container.encode(type, forKey: "type") + } + public enum PhoneNumberType: String, Codable, CaseIterable { case fax = "FAX" case landline = "LANDLINE" @@ -386,6 +502,20 @@ public struct AppClipAdvancedExperience: Codable, Identifiable { self.localizations = localizations } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appClip = try container.decodeIfPresent(AppClip.self, forKey: "appClip") + headerImage = try container.decodeIfPresent(HeaderImage.self, forKey: "headerImage") + localizations = try container.decodeIfPresent(Localizations.self, forKey: "localizations") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(appClip, forKey: "appClip") + try container.encodeIfPresent(headerImage, forKey: "headerImage") + try container.encodeIfPresent(localizations, forKey: "localizations") + } + /** # AppClipAdvancedExperience.Relationships.AppClip The data and links that describe the relationship between the Advanced App Clip Experiences and the App Clips resources. @@ -407,20 +537,15 @@ public struct AppClipAdvancedExperience: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -441,22 +566,17 @@ public struct AppClipAdvancedExperience: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -481,20 +601,15 @@ public struct AppClipAdvancedExperience: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -520,20 +635,15 @@ public struct AppClipAdvancedExperience: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -554,22 +664,17 @@ public struct AppClipAdvancedExperience: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -594,20 +699,15 @@ public struct AppClipAdvancedExperience: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -637,23 +737,17 @@ public struct AppClipAdvancedExperience: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } /** @@ -674,22 +768,17 @@ public struct AppClipAdvancedExperience: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -714,20 +803,15 @@ public struct AppClipAdvancedExperience: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppClipAdvancedExperienceCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppClipAdvancedExperienceCreateRequest.swift index 7a1ec7304..8457cd15d 100644 --- a/Sources/Bagbutik-Models/AppStore/AppClipAdvancedExperienceCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppClipAdvancedExperienceCreateRequest.swift @@ -21,6 +21,18 @@ public struct AppClipAdvancedExperienceCreateRequest: Codable, RequestBody { self.included = included } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + included = try container.decodeIfPresent([AppClipAdvancedExperienceLocalizationInlineCreate].self, forKey: "included") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + } + /** # AppClipAdvancedExperienceCreateRequest.Data The data element of the request body. @@ -44,25 +56,19 @@ public struct AppClipAdvancedExperienceCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } /** @@ -101,6 +107,26 @@ public struct AppClipAdvancedExperienceCreateRequest: Codable, RequestBody { self.place = place } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + action = try container.decodeIfPresent(AppClipAction.self, forKey: "action") + businessCategory = try container.decodeIfPresent(AppClipAdvancedExperience.Attributes.BusinessCategory.self, forKey: "businessCategory") + defaultLanguage = try container.decode(AppClipAdvancedExperienceLanguage.self, forKey: "defaultLanguage") + isPoweredBy = try container.decode(Bool.self, forKey: "isPoweredBy") + link = try container.decode(String.self, forKey: "link") + place = try container.decodeIfPresent(Place.self, forKey: "place") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(action, forKey: "action") + try container.encodeIfPresent(businessCategory, forKey: "businessCategory") + try container.encode(defaultLanguage, forKey: "defaultLanguage") + try container.encode(isPoweredBy, forKey: "isPoweredBy") + try container.encode(link, forKey: "link") + try container.encodeIfPresent(place, forKey: "place") + } + /** # AppClipAdvancedExperienceCreateRequest.Data.Attributes.Place The place information of an advanced App Clip experience you create with this request. @@ -151,6 +177,32 @@ public struct AppClipAdvancedExperienceCreateRequest: Codable, RequestBody { self.relationship = relationship } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + categories = try container.decodeIfPresent([String].self, forKey: "categories") + displayPoint = try container.decodeIfPresent(DisplayPoint.self, forKey: "displayPoint") + homePage = try container.decodeIfPresent(String.self, forKey: "homePage") + mainAddress = try container.decodeIfPresent(MainAddress.self, forKey: "mainAddress") + mapAction = try container.decodeIfPresent(MapAction.self, forKey: "mapAction") + names = try container.decodeIfPresent([String].self, forKey: "names") + phoneNumber = try container.decodeIfPresent(PhoneNumber.self, forKey: "phoneNumber") + placeId = try container.decodeIfPresent(String.self, forKey: "placeId") + relationship = try container.decodeIfPresent(Relationship.self, forKey: "relationship") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(categories, forKey: "categories") + try container.encodeIfPresent(displayPoint, forKey: "displayPoint") + try container.encodeIfPresent(homePage, forKey: "homePage") + try container.encodeIfPresent(mainAddress, forKey: "mainAddress") + try container.encodeIfPresent(mapAction, forKey: "mapAction") + try container.encodeIfPresent(names, forKey: "names") + try container.encodeIfPresent(phoneNumber, forKey: "phoneNumber") + try container.encodeIfPresent(placeId, forKey: "placeId") + try container.encodeIfPresent(relationship, forKey: "relationship") + } + /** # AppClipAdvancedExperienceCreateRequest.Data.Attributes.Place.DisplayPoint A point-based representation of a place in Apple Maps. @@ -171,6 +223,18 @@ public struct AppClipAdvancedExperienceCreateRequest: Codable, RequestBody { self.source = source } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + coordinates = try container.decodeIfPresent(Coordinates.self, forKey: "coordinates") + source = try container.decodeIfPresent(Source.self, forKey: "source") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(coordinates, forKey: "coordinates") + try container.encodeIfPresent(source, forKey: "source") + } + /** # AppClipAdvancedExperienceCreateRequest.Data.Attributes.Place.DisplayPoint.Coordinates The coordinates for a point of interest or business in Apple Maps. @@ -190,6 +254,18 @@ public struct AppClipAdvancedExperienceCreateRequest: Codable, RequestBody { self.latitude = latitude self.longitude = longitude } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + latitude = try container.decodeIfPresent(Double.self, forKey: "latitude") + longitude = try container.decodeIfPresent(Double.self, forKey: "longitude") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(latitude, forKey: "latitude") + try container.encodeIfPresent(longitude, forKey: "longitude") + } } public enum Source: String, Codable, CaseIterable { @@ -218,6 +294,18 @@ public struct AppClipAdvancedExperienceCreateRequest: Codable, RequestBody { self.structuredAddress = structuredAddress } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + fullAddress = try container.decodeIfPresent(String.self, forKey: "fullAddress") + structuredAddress = try container.decodeIfPresent(StructuredAddress.self, forKey: "structuredAddress") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(fullAddress, forKey: "fullAddress") + try container.encodeIfPresent(structuredAddress, forKey: "structuredAddress") + } + /** # AppClipAdvancedExperienceCreateRequest.Data.Attributes.Place.MainAddress.StructuredAddress The structured address information for a point of interest or business in Apple Maps. @@ -257,6 +345,28 @@ public struct AppClipAdvancedExperienceCreateRequest: Codable, RequestBody { self.stateProvince = stateProvince self.streetAddress = streetAddress } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + countryCode = try container.decodeIfPresent(String.self, forKey: "countryCode") + floor = try container.decodeIfPresent(String.self, forKey: "floor") + locality = try container.decodeIfPresent(String.self, forKey: "locality") + neighborhood = try container.decodeIfPresent(String.self, forKey: "neighborhood") + postalCode = try container.decodeIfPresent(String.self, forKey: "postalCode") + stateProvince = try container.decodeIfPresent(String.self, forKey: "stateProvince") + streetAddress = try container.decodeIfPresent([String].self, forKey: "streetAddress") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(countryCode, forKey: "countryCode") + try container.encodeIfPresent(floor, forKey: "floor") + try container.encodeIfPresent(locality, forKey: "locality") + try container.encodeIfPresent(neighborhood, forKey: "neighborhood") + try container.encodeIfPresent(postalCode, forKey: "postalCode") + try container.encodeIfPresent(stateProvince, forKey: "stateProvince") + try container.encodeIfPresent(streetAddress, forKey: "streetAddress") + } } } @@ -300,6 +410,20 @@ public struct AppClipAdvancedExperienceCreateRequest: Codable, RequestBody { self.type = type } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + intent = try container.decodeIfPresent(String.self, forKey: "intent") + number = try container.decodeIfPresent(String.self, forKey: "number") + type = try container.decode(PhoneNumberType.self, forKey: "type") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(intent, forKey: "intent") + try container.encodeIfPresent(number, forKey: "number") + try container.encode(type, forKey: "type") + } + public enum PhoneNumberType: String, Codable, CaseIterable { case fax = "FAX" case landline = "LANDLINE" @@ -340,6 +464,20 @@ public struct AppClipAdvancedExperienceCreateRequest: Codable, RequestBody { self.localizations = localizations } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appClip = try container.decode(AppClip.self, forKey: "appClip") + headerImage = try container.decode(HeaderImage.self, forKey: "headerImage") + localizations = try container.decode(Localizations.self, forKey: "localizations") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(appClip, forKey: "appClip") + try container.encode(headerImage, forKey: "headerImage") + try container.encode(localizations, forKey: "localizations") + } + /** # AppClipAdvancedExperienceCreateRequest.Data.Relationships.AppClip The relationship to the App Clips resource you set with the request that creates an Advanced App Clip Experiences resource. @@ -355,6 +493,16 @@ public struct AppClipAdvancedExperienceCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AppClipAdvancedExperienceCreateRequest.Data.Relationships.AppClip.Data The type and ID of the App Clips resource that you’re relating with the Advanced App Clip Experiences resource you’re creating. @@ -373,22 +521,17 @@ public struct AppClipAdvancedExperienceCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -408,6 +551,16 @@ public struct AppClipAdvancedExperienceCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AppClipAdvancedExperienceCreateRequest.Data.Relationships.HeaderImage.Data The type and ID of the App Clip Header Images resource that you’re relating with the Advanced App Clip Experiences resource you’re creating. @@ -426,22 +579,17 @@ public struct AppClipAdvancedExperienceCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -461,6 +609,16 @@ public struct AppClipAdvancedExperienceCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AppClipAdvancedExperienceCreateRequest.Data.Relationships.Localizations.Data The type and ID of the Advanced App Clips Experience Localizations resource that you’re relating with the Advanced App Clip Experiences resource you’re creating. @@ -479,22 +637,17 @@ public struct AppClipAdvancedExperienceCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppClipAdvancedExperienceImage.swift b/Sources/Bagbutik-Models/AppStore/AppClipAdvancedExperienceImage.swift index 95c425c23..d6f453956 100644 --- a/Sources/Bagbutik-Models/AppStore/AppClipAdvancedExperienceImage.swift +++ b/Sources/Bagbutik-Models/AppStore/AppClipAdvancedExperienceImage.swift @@ -28,28 +28,21 @@ public struct AppClipAdvancedExperienceImage: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } /** @@ -87,5 +80,25 @@ public struct AppClipAdvancedExperienceImage: Codable, Identifiable { self.sourceFileChecksum = sourceFileChecksum self.uploadOperations = uploadOperations } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + assetDeliveryState = try container.decodeIfPresent(AppMediaAssetState.self, forKey: "assetDeliveryState") + fileName = try container.decodeIfPresent(String.self, forKey: "fileName") + fileSize = try container.decodeIfPresent(Int.self, forKey: "fileSize") + imageAsset = try container.decodeIfPresent(ImageAsset.self, forKey: "imageAsset") + sourceFileChecksum = try container.decodeIfPresent(String.self, forKey: "sourceFileChecksum") + uploadOperations = try container.decodeIfPresent([UploadOperation].self, forKey: "uploadOperations") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(assetDeliveryState, forKey: "assetDeliveryState") + try container.encodeIfPresent(fileName, forKey: "fileName") + try container.encodeIfPresent(fileSize, forKey: "fileSize") + try container.encodeIfPresent(imageAsset, forKey: "imageAsset") + try container.encodeIfPresent(sourceFileChecksum, forKey: "sourceFileChecksum") + try container.encodeIfPresent(uploadOperations, forKey: "uploadOperations") + } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppClipAdvancedExperienceImageCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppClipAdvancedExperienceImageCreateRequest.swift index a1bde65c0..383cf8a1b 100644 --- a/Sources/Bagbutik-Models/AppStore/AppClipAdvancedExperienceImageCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppClipAdvancedExperienceImageCreateRequest.swift @@ -16,6 +16,16 @@ public struct AppClipAdvancedExperienceImageCreateRequest: Codable, RequestBody self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AppClipAdvancedExperienceImageCreateRequest.Data The data element of the request body. @@ -34,22 +44,17 @@ public struct AppClipAdvancedExperienceImageCreateRequest: Codable, RequestBody } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") } /** @@ -71,6 +76,18 @@ public struct AppClipAdvancedExperienceImageCreateRequest: Codable, RequestBody self.fileName = fileName self.fileSize = fileSize } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + fileName = try container.decode(String.self, forKey: "fileName") + fileSize = try container.decode(Int.self, forKey: "fileSize") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(fileName, forKey: "fileName") + try container.encode(fileSize, forKey: "fileSize") + } } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppClipAdvancedExperienceImageResponse.swift b/Sources/Bagbutik-Models/AppStore/AppClipAdvancedExperienceImageResponse.swift index c95e3c14f..096bb9e2a 100644 --- a/Sources/Bagbutik-Models/AppStore/AppClipAdvancedExperienceImageResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppClipAdvancedExperienceImageResponse.swift @@ -20,4 +20,16 @@ public struct AppClipAdvancedExperienceImageResponse: Codable { self.data = data self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AppClipAdvancedExperienceImage.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/AppStore/AppClipAdvancedExperienceImageUpdateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppClipAdvancedExperienceImageUpdateRequest.swift index 122ab1d81..b546e39cb 100644 --- a/Sources/Bagbutik-Models/AppStore/AppClipAdvancedExperienceImageUpdateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppClipAdvancedExperienceImageUpdateRequest.swift @@ -16,6 +16,16 @@ public struct AppClipAdvancedExperienceImageUpdateRequest: Codable, RequestBody self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AppClipAdvancedExperienceImageUpdateRequest.Data The data element of the request body. @@ -39,25 +49,19 @@ public struct AppClipAdvancedExperienceImageUpdateRequest: Codable, RequestBody } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } /** @@ -79,6 +83,18 @@ public struct AppClipAdvancedExperienceImageUpdateRequest: Codable, RequestBody self.sourceFileChecksum = sourceFileChecksum self.uploaded = uploaded } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + sourceFileChecksum = try container.decodeIfPresent(String.self, forKey: "sourceFileChecksum") + uploaded = try container.decodeIfPresent(Bool.self, forKey: "uploaded") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(sourceFileChecksum, forKey: "sourceFileChecksum") + try container.encodeIfPresent(uploaded, forKey: "uploaded") + } } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppClipAdvancedExperienceLocalization.swift b/Sources/Bagbutik-Models/AppStore/AppClipAdvancedExperienceLocalization.swift index bd8f69cd7..56d56e3b3 100644 --- a/Sources/Bagbutik-Models/AppStore/AppClipAdvancedExperienceLocalization.swift +++ b/Sources/Bagbutik-Models/AppStore/AppClipAdvancedExperienceLocalization.swift @@ -28,28 +28,21 @@ public struct AppClipAdvancedExperienceLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } /** @@ -75,5 +68,19 @@ public struct AppClipAdvancedExperienceLocalization: Codable, Identifiable { self.subtitle = subtitle self.title = title } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + language = try container.decodeIfPresent(AppClipAdvancedExperienceLanguage.self, forKey: "language") + subtitle = try container.decodeIfPresent(String.self, forKey: "subtitle") + title = try container.decodeIfPresent(String.self, forKey: "title") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(language, forKey: "language") + try container.encodeIfPresent(subtitle, forKey: "subtitle") + try container.encodeIfPresent(title, forKey: "title") + } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppClipAdvancedExperienceLocalizationInlineCreate.swift b/Sources/Bagbutik-Models/AppStore/AppClipAdvancedExperienceLocalizationInlineCreate.swift index 75b408de6..139def6b9 100644 --- a/Sources/Bagbutik-Models/AppStore/AppClipAdvancedExperienceLocalizationInlineCreate.swift +++ b/Sources/Bagbutik-Models/AppStore/AppClipAdvancedExperienceLocalizationInlineCreate.swift @@ -24,25 +24,19 @@ public struct AppClipAdvancedExperienceLocalizationInlineCreate: Codable, Identi } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decodeIfPresent(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decodeIfPresent(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } /** @@ -68,5 +62,19 @@ public struct AppClipAdvancedExperienceLocalizationInlineCreate: Codable, Identi self.subtitle = subtitle self.title = title } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + language = try container.decodeIfPresent(AppClipAdvancedExperienceLanguage.self, forKey: "language") + subtitle = try container.decodeIfPresent(String.self, forKey: "subtitle") + title = try container.decodeIfPresent(String.self, forKey: "title") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(language, forKey: "language") + try container.encodeIfPresent(subtitle, forKey: "subtitle") + try container.encodeIfPresent(title, forKey: "title") + } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppClipAdvancedExperienceResponse.swift b/Sources/Bagbutik-Models/AppStore/AppClipAdvancedExperienceResponse.swift index 570bbf36f..c0db251b8 100644 --- a/Sources/Bagbutik-Models/AppStore/AppClipAdvancedExperienceResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppClipAdvancedExperienceResponse.swift @@ -25,6 +25,20 @@ public struct AppClipAdvancedExperienceResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AppClipAdvancedExperience.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getAppClip() -> AppClip? { included?.compactMap { relationship -> AppClip? in guard case let .appClip(appClip) = relationship else { return nil } @@ -79,9 +93,5 @@ public struct AppClipAdvancedExperienceResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppClipAdvancedExperienceUpdateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppClipAdvancedExperienceUpdateRequest.swift index bfc26dd88..3d6408edd 100644 --- a/Sources/Bagbutik-Models/AppStore/AppClipAdvancedExperienceUpdateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppClipAdvancedExperienceUpdateRequest.swift @@ -21,6 +21,18 @@ public struct AppClipAdvancedExperienceUpdateRequest: Codable, RequestBody { self.included = included } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + included = try container.decodeIfPresent([AppClipAdvancedExperienceLocalizationInlineCreate].self, forKey: "included") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + } + /** # AppClipAdvancedExperienceUpdateRequest.Data The data element of the request body. @@ -48,28 +60,21 @@ public struct AppClipAdvancedExperienceUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -108,6 +113,26 @@ public struct AppClipAdvancedExperienceUpdateRequest: Codable, RequestBody { self.removed = removed } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + action = try container.decodeIfPresent(AppClipAction.self, forKey: "action") + businessCategory = try container.decodeIfPresent(AppClipAdvancedExperience.Attributes.BusinessCategory.self, forKey: "businessCategory") + defaultLanguage = try container.decodeIfPresent(AppClipAdvancedExperienceLanguage.self, forKey: "defaultLanguage") + isPoweredBy = try container.decodeIfPresent(Bool.self, forKey: "isPoweredBy") + place = try container.decodeIfPresent(Place.self, forKey: "place") + removed = try container.decodeIfPresent(Bool.self, forKey: "removed") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(action, forKey: "action") + try container.encodeIfPresent(businessCategory, forKey: "businessCategory") + try container.encodeIfPresent(defaultLanguage, forKey: "defaultLanguage") + try container.encodeIfPresent(isPoweredBy, forKey: "isPoweredBy") + try container.encodeIfPresent(place, forKey: "place") + try container.encodeIfPresent(removed, forKey: "removed") + } + /** # AppClipAdvancedExperienceUpdateRequest.Data.Attributes.Place The place information of an advanced App Clip experience you create with this request. @@ -156,6 +181,32 @@ public struct AppClipAdvancedExperienceUpdateRequest: Codable, RequestBody { self.relationship = relationship } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + categories = try container.decodeIfPresent([String].self, forKey: "categories") + displayPoint = try container.decodeIfPresent(DisplayPoint.self, forKey: "displayPoint") + homePage = try container.decodeIfPresent(String.self, forKey: "homePage") + mainAddress = try container.decodeIfPresent(MainAddress.self, forKey: "mainAddress") + mapAction = try container.decodeIfPresent(MapAction.self, forKey: "mapAction") + names = try container.decodeIfPresent([String].self, forKey: "names") + phoneNumber = try container.decodeIfPresent(PhoneNumber.self, forKey: "phoneNumber") + placeId = try container.decodeIfPresent(String.self, forKey: "placeId") + relationship = try container.decodeIfPresent(Relationship.self, forKey: "relationship") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(categories, forKey: "categories") + try container.encodeIfPresent(displayPoint, forKey: "displayPoint") + try container.encodeIfPresent(homePage, forKey: "homePage") + try container.encodeIfPresent(mainAddress, forKey: "mainAddress") + try container.encodeIfPresent(mapAction, forKey: "mapAction") + try container.encodeIfPresent(names, forKey: "names") + try container.encodeIfPresent(phoneNumber, forKey: "phoneNumber") + try container.encodeIfPresent(placeId, forKey: "placeId") + try container.encodeIfPresent(relationship, forKey: "relationship") + } + /** # AppClipAdvancedExperienceUpdateRequest.Data.Attributes.Place.DisplayPoint A point-based representation of a place in Apple Maps. @@ -176,6 +227,18 @@ public struct AppClipAdvancedExperienceUpdateRequest: Codable, RequestBody { self.source = source } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + coordinates = try container.decodeIfPresent(Coordinates.self, forKey: "coordinates") + source = try container.decodeIfPresent(Source.self, forKey: "source") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(coordinates, forKey: "coordinates") + try container.encodeIfPresent(source, forKey: "source") + } + /** # AppClipAdvancedExperienceUpdateRequest.Data.Attributes.Place.DisplayPoint.Coordinates The coordinates for a point of interest or business in Apple Maps. @@ -195,6 +258,18 @@ public struct AppClipAdvancedExperienceUpdateRequest: Codable, RequestBody { self.latitude = latitude self.longitude = longitude } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + latitude = try container.decodeIfPresent(Double.self, forKey: "latitude") + longitude = try container.decodeIfPresent(Double.self, forKey: "longitude") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(latitude, forKey: "latitude") + try container.encodeIfPresent(longitude, forKey: "longitude") + } } public enum Source: String, Codable, CaseIterable { @@ -223,6 +298,18 @@ public struct AppClipAdvancedExperienceUpdateRequest: Codable, RequestBody { self.structuredAddress = structuredAddress } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + fullAddress = try container.decodeIfPresent(String.self, forKey: "fullAddress") + structuredAddress = try container.decodeIfPresent(StructuredAddress.self, forKey: "structuredAddress") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(fullAddress, forKey: "fullAddress") + try container.encodeIfPresent(structuredAddress, forKey: "structuredAddress") + } + /** # AppClipAdvancedExperienceUpdateRequest.Data.Attributes.Place.MainAddress.StructuredAddress The structured address information for a point of interest or business in Apple Maps. @@ -262,6 +349,28 @@ public struct AppClipAdvancedExperienceUpdateRequest: Codable, RequestBody { self.stateProvince = stateProvince self.streetAddress = streetAddress } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + countryCode = try container.decodeIfPresent(String.self, forKey: "countryCode") + floor = try container.decodeIfPresent(String.self, forKey: "floor") + locality = try container.decodeIfPresent(String.self, forKey: "locality") + neighborhood = try container.decodeIfPresent(String.self, forKey: "neighborhood") + postalCode = try container.decodeIfPresent(String.self, forKey: "postalCode") + stateProvince = try container.decodeIfPresent(String.self, forKey: "stateProvince") + streetAddress = try container.decodeIfPresent([String].self, forKey: "streetAddress") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(countryCode, forKey: "countryCode") + try container.encodeIfPresent(floor, forKey: "floor") + try container.encodeIfPresent(locality, forKey: "locality") + try container.encodeIfPresent(neighborhood, forKey: "neighborhood") + try container.encodeIfPresent(postalCode, forKey: "postalCode") + try container.encodeIfPresent(stateProvince, forKey: "stateProvince") + try container.encodeIfPresent(streetAddress, forKey: "streetAddress") + } } } @@ -305,6 +414,20 @@ public struct AppClipAdvancedExperienceUpdateRequest: Codable, RequestBody { self.type = type } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + intent = try container.decodeIfPresent(String.self, forKey: "intent") + number = try container.decodeIfPresent(String.self, forKey: "number") + type = try container.decode(PhoneNumberType.self, forKey: "type") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(intent, forKey: "intent") + try container.encodeIfPresent(number, forKey: "number") + try container.encode(type, forKey: "type") + } + public enum PhoneNumberType: String, Codable, CaseIterable { case fax = "FAX" case landline = "LANDLINE" @@ -345,6 +468,20 @@ public struct AppClipAdvancedExperienceUpdateRequest: Codable, RequestBody { self.localizations = localizations } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appClip = try container.decodeIfPresent(AppClip.self, forKey: "appClip") + headerImage = try container.decodeIfPresent(HeaderImage.self, forKey: "headerImage") + localizations = try container.decodeIfPresent(Localizations.self, forKey: "localizations") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(appClip, forKey: "appClip") + try container.encodeIfPresent(headerImage, forKey: "headerImage") + try container.encodeIfPresent(localizations, forKey: "localizations") + } + /** # AppClipAdvancedExperienceUpdateRequest.Data.Relationships.AppClip The relationship to the App Clips resource you set with the request that updates an Advanced App Clip Experiences resource. @@ -361,17 +498,13 @@ public struct AppClipAdvancedExperienceUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } /** @@ -392,22 +525,17 @@ public struct AppClipAdvancedExperienceUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -428,17 +556,13 @@ public struct AppClipAdvancedExperienceUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } /** @@ -459,22 +583,17 @@ public struct AppClipAdvancedExperienceUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -495,17 +614,13 @@ public struct AppClipAdvancedExperienceUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } /** @@ -526,22 +641,17 @@ public struct AppClipAdvancedExperienceUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppClipAdvancedExperiencesResponse.swift b/Sources/Bagbutik-Models/AppStore/AppClipAdvancedExperiencesResponse.swift index e27a958fe..3d7827494 100644 --- a/Sources/Bagbutik-Models/AppStore/AppClipAdvancedExperiencesResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppClipAdvancedExperiencesResponse.swift @@ -31,6 +31,22 @@ public struct AppClipAdvancedExperiencesResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([AppClipAdvancedExperience].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getAppClip(for appClipAdvancedExperience: AppClipAdvancedExperience) -> AppClip? { included?.compactMap { relationship -> AppClip? in guard case let .appClip(appClip) = relationship else { return nil } @@ -85,9 +101,5 @@ public struct AppClipAdvancedExperiencesResponse: Codable, PagedResponse { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppClipAppStoreReviewDetail.swift b/Sources/Bagbutik-Models/AppStore/AppClipAppStoreReviewDetail.swift index 02e40b25f..5ae6584af 100644 --- a/Sources/Bagbutik-Models/AppStore/AppClipAppStoreReviewDetail.swift +++ b/Sources/Bagbutik-Models/AppStore/AppClipAppStoreReviewDetail.swift @@ -32,31 +32,23 @@ public struct AppClipAppStoreReviewDetail: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -73,6 +65,16 @@ public struct AppClipAppStoreReviewDetail: Codable, Identifiable { public init(invocationUrls: [String]? = nil) { self.invocationUrls = invocationUrls } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + invocationUrls = try container.decodeIfPresent([String].self, forKey: "invocationUrls") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(invocationUrls, forKey: "invocationUrls") + } } /** @@ -90,6 +92,16 @@ public struct AppClipAppStoreReviewDetail: Codable, Identifiable { self.appClipDefaultExperience = appClipDefaultExperience } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appClipDefaultExperience = try container.decodeIfPresent(AppClipDefaultExperience.self, forKey: "appClipDefaultExperience") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(appClipDefaultExperience, forKey: "appClipDefaultExperience") + } + /** # AppClipAppStoreReviewDetail.Relationships.AppClipDefaultExperience The data and links that describe the relationship between the App Clip App Store Review Details and the Default App Clip Experiences resources. @@ -111,20 +123,15 @@ public struct AppClipAppStoreReviewDetail: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -145,22 +152,17 @@ public struct AppClipAppStoreReviewDetail: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -185,20 +187,15 @@ public struct AppClipAppStoreReviewDetail: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppClipAppStoreReviewDetailCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppClipAppStoreReviewDetailCreateRequest.swift index 40c400656..beaf8a99e 100644 --- a/Sources/Bagbutik-Models/AppStore/AppClipAppStoreReviewDetailCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppClipAppStoreReviewDetailCreateRequest.swift @@ -16,6 +16,16 @@ public struct AppClipAppStoreReviewDetailCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AppClipAppStoreReviewDetailCreateRequest.Data The data element of the request body. @@ -39,25 +49,19 @@ public struct AppClipAppStoreReviewDetailCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } /** @@ -74,6 +78,16 @@ public struct AppClipAppStoreReviewDetailCreateRequest: Codable, RequestBody { public init(invocationUrls: [String]? = nil) { self.invocationUrls = invocationUrls } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + invocationUrls = try container.decodeIfPresent([String].self, forKey: "invocationUrls") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(invocationUrls, forKey: "invocationUrls") + } } /** @@ -91,6 +105,16 @@ public struct AppClipAppStoreReviewDetailCreateRequest: Codable, RequestBody { self.appClipDefaultExperience = appClipDefaultExperience } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appClipDefaultExperience = try container.decode(AppClipDefaultExperience.self, forKey: "appClipDefaultExperience") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(appClipDefaultExperience, forKey: "appClipDefaultExperience") + } + /** # AppClipAppStoreReviewDetailCreateRequest.Data.Relationships.AppClipDefaultExperience The relationship to the Default App Clip Experiences resource you set with the request that creates an App Clip App Store Review Details resource. @@ -106,6 +130,16 @@ public struct AppClipAppStoreReviewDetailCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AppClipAppStoreReviewDetailCreateRequest.Data.Relationships.AppClipDefaultExperience.Data The type and ID of the Default App Clip Experiences resource that you’re relating with the App Clip App Store Review Details resource you’re creating. @@ -124,22 +158,17 @@ public struct AppClipAppStoreReviewDetailCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppClipAppStoreReviewDetailResponse.swift b/Sources/Bagbutik-Models/AppStore/AppClipAppStoreReviewDetailResponse.swift index f1d7178dd..226d7501d 100644 --- a/Sources/Bagbutik-Models/AppStore/AppClipAppStoreReviewDetailResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppClipAppStoreReviewDetailResponse.swift @@ -24,4 +24,18 @@ public struct AppClipAppStoreReviewDetailResponse: Codable { self.included = included self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AppClipAppStoreReviewDetail.self, forKey: "data") + included = try container.decodeIfPresent([AppClipDefaultExperience].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/AppStore/AppClipAppStoreReviewDetailUpdateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppClipAppStoreReviewDetailUpdateRequest.swift index 80ddde05d..ed8148cee 100644 --- a/Sources/Bagbutik-Models/AppStore/AppClipAppStoreReviewDetailUpdateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppClipAppStoreReviewDetailUpdateRequest.swift @@ -16,6 +16,16 @@ public struct AppClipAppStoreReviewDetailUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AppClipAppStoreReviewDetailUpdateRequest.Data The data element of the request body. @@ -39,25 +49,19 @@ public struct AppClipAppStoreReviewDetailUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } /** @@ -74,6 +78,16 @@ public struct AppClipAppStoreReviewDetailUpdateRequest: Codable, RequestBody { public init(invocationUrls: [String]? = nil) { self.invocationUrls = invocationUrls } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + invocationUrls = try container.decodeIfPresent([String].self, forKey: "invocationUrls") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(invocationUrls, forKey: "invocationUrls") + } } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppClipDefaultExperience.swift b/Sources/Bagbutik-Models/AppStore/AppClipDefaultExperience.swift index 0dc614fce..dae985b2d 100644 --- a/Sources/Bagbutik-Models/AppStore/AppClipDefaultExperience.swift +++ b/Sources/Bagbutik-Models/AppStore/AppClipDefaultExperience.swift @@ -32,31 +32,23 @@ public struct AppClipDefaultExperience: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -73,6 +65,16 @@ public struct AppClipDefaultExperience: Codable, Identifiable { public init(action: AppClipAction? = nil) { self.action = action } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + action = try container.decodeIfPresent(AppClipAction.self, forKey: "action") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(action, forKey: "action") + } } /** @@ -103,6 +105,22 @@ public struct AppClipDefaultExperience: Codable, Identifiable { self.releaseWithAppStoreVersion = releaseWithAppStoreVersion } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appClip = try container.decodeIfPresent(AppClip.self, forKey: "appClip") + appClipAppStoreReviewDetail = try container.decodeIfPresent(AppClipAppStoreReviewDetail.self, forKey: "appClipAppStoreReviewDetail") + appClipDefaultExperienceLocalizations = try container.decodeIfPresent(AppClipDefaultExperienceLocalizations.self, forKey: "appClipDefaultExperienceLocalizations") + releaseWithAppStoreVersion = try container.decodeIfPresent(ReleaseWithAppStoreVersion.self, forKey: "releaseWithAppStoreVersion") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(appClip, forKey: "appClip") + try container.encodeIfPresent(appClipAppStoreReviewDetail, forKey: "appClipAppStoreReviewDetail") + try container.encodeIfPresent(appClipDefaultExperienceLocalizations, forKey: "appClipDefaultExperienceLocalizations") + try container.encodeIfPresent(releaseWithAppStoreVersion, forKey: "releaseWithAppStoreVersion") + } + /** # AppClipDefaultExperience.Relationships.AppClip The data and links that describe the relationship between the Default App Clip Experiences and the App Clips resources. @@ -124,20 +142,15 @@ public struct AppClipDefaultExperience: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -158,22 +171,17 @@ public struct AppClipDefaultExperience: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -198,20 +206,15 @@ public struct AppClipDefaultExperience: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -237,20 +240,15 @@ public struct AppClipDefaultExperience: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -271,22 +269,17 @@ public struct AppClipDefaultExperience: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -311,20 +304,15 @@ public struct AppClipDefaultExperience: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -354,23 +342,17 @@ public struct AppClipDefaultExperience: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } /** @@ -391,22 +373,17 @@ public struct AppClipDefaultExperience: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -431,20 +408,15 @@ public struct AppClipDefaultExperience: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -470,20 +442,15 @@ public struct AppClipDefaultExperience: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -504,22 +471,17 @@ public struct AppClipDefaultExperience: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -544,20 +506,15 @@ public struct AppClipDefaultExperience: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppClipDefaultExperienceCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppClipDefaultExperienceCreateRequest.swift index abc29e487..d3db17e95 100644 --- a/Sources/Bagbutik-Models/AppStore/AppClipDefaultExperienceCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppClipDefaultExperienceCreateRequest.swift @@ -16,6 +16,16 @@ public struct AppClipDefaultExperienceCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AppClipDefaultExperienceCreateRequest.Data The data element of the request body. @@ -39,25 +49,19 @@ public struct AppClipDefaultExperienceCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } /** @@ -74,6 +78,16 @@ public struct AppClipDefaultExperienceCreateRequest: Codable, RequestBody { public init(action: AppClipAction? = nil) { self.action = action } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + action = try container.decodeIfPresent(AppClipAction.self, forKey: "action") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(action, forKey: "action") + } } /** @@ -100,6 +114,20 @@ public struct AppClipDefaultExperienceCreateRequest: Codable, RequestBody { self.releaseWithAppStoreVersion = releaseWithAppStoreVersion } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appClip = try container.decode(AppClip.self, forKey: "appClip") + appClipDefaultExperienceTemplate = try container.decodeIfPresent(AppClipDefaultExperienceTemplate.self, forKey: "appClipDefaultExperienceTemplate") + releaseWithAppStoreVersion = try container.decodeIfPresent(ReleaseWithAppStoreVersion.self, forKey: "releaseWithAppStoreVersion") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(appClip, forKey: "appClip") + try container.encodeIfPresent(appClipDefaultExperienceTemplate, forKey: "appClipDefaultExperienceTemplate") + try container.encodeIfPresent(releaseWithAppStoreVersion, forKey: "releaseWithAppStoreVersion") + } + /** # AppClipDefaultExperienceCreateRequest.Data.Relationships.AppClip The relationship to the App Clips resource you set with the request that creates a Default App Clip Experiences resource. @@ -115,6 +143,16 @@ public struct AppClipDefaultExperienceCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AppClipDefaultExperienceCreateRequest.Data.Relationships.AppClip.Data The type and ID of the App Clips resource that you’re relating with the Default App Clip Experiences resource you’re creating. @@ -133,22 +171,17 @@ public struct AppClipDefaultExperienceCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -169,17 +202,13 @@ public struct AppClipDefaultExperienceCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } /** @@ -200,22 +229,17 @@ public struct AppClipDefaultExperienceCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -236,17 +260,13 @@ public struct AppClipDefaultExperienceCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } /** @@ -267,22 +287,17 @@ public struct AppClipDefaultExperienceCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppClipDefaultExperienceLocalization.swift b/Sources/Bagbutik-Models/AppStore/AppClipDefaultExperienceLocalization.swift index ebda2f14b..5a3d88232 100644 --- a/Sources/Bagbutik-Models/AppStore/AppClipDefaultExperienceLocalization.swift +++ b/Sources/Bagbutik-Models/AppStore/AppClipDefaultExperienceLocalization.swift @@ -32,31 +32,23 @@ public struct AppClipDefaultExperienceLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -78,6 +70,18 @@ public struct AppClipDefaultExperienceLocalization: Codable, Identifiable { self.locale = locale self.subtitle = subtitle } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + locale = try container.decodeIfPresent(String.self, forKey: "locale") + subtitle = try container.decodeIfPresent(String.self, forKey: "subtitle") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(locale, forKey: "locale") + try container.encodeIfPresent(subtitle, forKey: "subtitle") + } } /** @@ -100,6 +104,18 @@ public struct AppClipDefaultExperienceLocalization: Codable, Identifiable { self.appClipHeaderImage = appClipHeaderImage } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appClipDefaultExperience = try container.decodeIfPresent(AppClipDefaultExperience.self, forKey: "appClipDefaultExperience") + appClipHeaderImage = try container.decodeIfPresent(AppClipHeaderImage.self, forKey: "appClipHeaderImage") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(appClipDefaultExperience, forKey: "appClipDefaultExperience") + try container.encodeIfPresent(appClipHeaderImage, forKey: "appClipHeaderImage") + } + /** # AppClipDefaultExperienceLocalization.Relationships.AppClipDefaultExperience The data and links that describe the relationship between the Default App Clip Experience Localizations and the Default App Clip Experiences resources. @@ -121,20 +137,15 @@ public struct AppClipDefaultExperienceLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -155,22 +166,17 @@ public struct AppClipDefaultExperienceLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -195,20 +201,15 @@ public struct AppClipDefaultExperienceLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -234,20 +235,15 @@ public struct AppClipDefaultExperienceLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -268,22 +264,17 @@ public struct AppClipDefaultExperienceLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -308,20 +299,15 @@ public struct AppClipDefaultExperienceLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppClipDefaultExperienceLocalizationCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppClipDefaultExperienceLocalizationCreateRequest.swift index d16611124..62bca6e06 100644 --- a/Sources/Bagbutik-Models/AppStore/AppClipDefaultExperienceLocalizationCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppClipDefaultExperienceLocalizationCreateRequest.swift @@ -16,6 +16,16 @@ public struct AppClipDefaultExperienceLocalizationCreateRequest: Codable, Reques self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AppClipDefaultExperienceLocalizationCreateRequest.Data The data element of the request body. @@ -39,25 +49,19 @@ public struct AppClipDefaultExperienceLocalizationCreateRequest: Codable, Reques } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } /** @@ -79,6 +83,18 @@ public struct AppClipDefaultExperienceLocalizationCreateRequest: Codable, Reques self.locale = locale self.subtitle = subtitle } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + locale = try container.decode(String.self, forKey: "locale") + subtitle = try container.decodeIfPresent(String.self, forKey: "subtitle") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(locale, forKey: "locale") + try container.encodeIfPresent(subtitle, forKey: "subtitle") + } } /** @@ -96,6 +112,16 @@ public struct AppClipDefaultExperienceLocalizationCreateRequest: Codable, Reques self.appClipDefaultExperience = appClipDefaultExperience } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appClipDefaultExperience = try container.decode(AppClipDefaultExperience.self, forKey: "appClipDefaultExperience") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(appClipDefaultExperience, forKey: "appClipDefaultExperience") + } + /** # AppClipDefaultExperienceLocalizationCreateRequest.Data.Relationships.AppClipDefaultExperience The relationship to the Default App Clip Experiences resource you set with the request that creates a Default App Clip Experience Localizations resource. @@ -111,6 +137,16 @@ public struct AppClipDefaultExperienceLocalizationCreateRequest: Codable, Reques self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AppClipDefaultExperienceLocalizationCreateRequest.Data.Relationships.AppClipDefaultExperience.Data The type and ID of the Default App Clip Experiences resource that you’re relating with the Default App Clip Experience Localizations resource you’re creating. @@ -129,22 +165,17 @@ public struct AppClipDefaultExperienceLocalizationCreateRequest: Codable, Reques } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppClipDefaultExperienceLocalizationResponse.swift b/Sources/Bagbutik-Models/AppStore/AppClipDefaultExperienceLocalizationResponse.swift index ff26448f6..df6273619 100644 --- a/Sources/Bagbutik-Models/AppStore/AppClipDefaultExperienceLocalizationResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppClipDefaultExperienceLocalizationResponse.swift @@ -25,6 +25,20 @@ public struct AppClipDefaultExperienceLocalizationResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AppClipDefaultExperienceLocalization.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getAppClipDefaultExperience() -> AppClipDefaultExperience? { included?.compactMap { relationship -> AppClipDefaultExperience? in guard case let .appClipDefaultExperience(appClipDefaultExperience) = relationship else { return nil } @@ -62,9 +76,5 @@ public struct AppClipDefaultExperienceLocalizationResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppClipDefaultExperienceLocalizationUpdateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppClipDefaultExperienceLocalizationUpdateRequest.swift index 0dc1c7046..585bb1b52 100644 --- a/Sources/Bagbutik-Models/AppStore/AppClipDefaultExperienceLocalizationUpdateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppClipDefaultExperienceLocalizationUpdateRequest.swift @@ -16,6 +16,16 @@ public struct AppClipDefaultExperienceLocalizationUpdateRequest: Codable, Reques self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AppClipDefaultExperienceLocalizationUpdateRequest.Data The data element of the request body. @@ -39,25 +49,19 @@ public struct AppClipDefaultExperienceLocalizationUpdateRequest: Codable, Reques } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } /** @@ -74,6 +78,16 @@ public struct AppClipDefaultExperienceLocalizationUpdateRequest: Codable, Reques public init(subtitle: String? = nil) { self.subtitle = subtitle } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + subtitle = try container.decodeIfPresent(String.self, forKey: "subtitle") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(subtitle, forKey: "subtitle") + } } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppClipDefaultExperienceLocalizationsResponse.swift b/Sources/Bagbutik-Models/AppStore/AppClipDefaultExperienceLocalizationsResponse.swift index c7501625a..86a8bd741 100644 --- a/Sources/Bagbutik-Models/AppStore/AppClipDefaultExperienceLocalizationsResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppClipDefaultExperienceLocalizationsResponse.swift @@ -31,6 +31,22 @@ public struct AppClipDefaultExperienceLocalizationsResponse: Codable, PagedRespo self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([AppClipDefaultExperienceLocalization].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getAppClipDefaultExperience(for appClipDefaultExperienceLocalization: AppClipDefaultExperienceLocalization) -> AppClipDefaultExperience? { included?.compactMap { relationship -> AppClipDefaultExperience? in guard case let .appClipDefaultExperience(appClipDefaultExperience) = relationship else { return nil } @@ -68,9 +84,5 @@ public struct AppClipDefaultExperienceLocalizationsResponse: Codable, PagedRespo try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppClipDefaultExperienceReleaseWithAppStoreVersionLinkageRequest.swift b/Sources/Bagbutik-Models/AppStore/AppClipDefaultExperienceReleaseWithAppStoreVersionLinkageRequest.swift index cde95c3c3..0386f8a59 100644 --- a/Sources/Bagbutik-Models/AppStore/AppClipDefaultExperienceReleaseWithAppStoreVersionLinkageRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppClipDefaultExperienceReleaseWithAppStoreVersionLinkageRequest.swift @@ -17,17 +17,13 @@ public struct AppClipDefaultExperienceReleaseWithAppStoreVersionLinkageRequest: } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } /** @@ -48,22 +44,17 @@ public struct AppClipDefaultExperienceReleaseWithAppStoreVersionLinkageRequest: } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppClipDefaultExperienceReleaseWithAppStoreVersionLinkageResponse.swift b/Sources/Bagbutik-Models/AppStore/AppClipDefaultExperienceReleaseWithAppStoreVersionLinkageResponse.swift index 5253ddced..8f94744ca 100644 --- a/Sources/Bagbutik-Models/AppStore/AppClipDefaultExperienceReleaseWithAppStoreVersionLinkageResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppClipDefaultExperienceReleaseWithAppStoreVersionLinkageResponse.swift @@ -21,6 +21,18 @@ public struct AppClipDefaultExperienceReleaseWithAppStoreVersionLinkageResponse: self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } + /** # AppClipDefaultExperienceReleaseWithAppStoreVersionLinkageResponse.Data The data element of the response body. @@ -39,22 +51,17 @@ public struct AppClipDefaultExperienceReleaseWithAppStoreVersionLinkageResponse: } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppClipDefaultExperienceResponse.swift b/Sources/Bagbutik-Models/AppStore/AppClipDefaultExperienceResponse.swift index 022c007c8..c709b4d90 100644 --- a/Sources/Bagbutik-Models/AppStore/AppClipDefaultExperienceResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppClipDefaultExperienceResponse.swift @@ -25,6 +25,20 @@ public struct AppClipDefaultExperienceResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AppClipDefaultExperience.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getAppClip() -> AppClip? { included?.compactMap { relationship -> AppClip? in guard case let .appClip(appClip) = relationship else { return nil } @@ -91,9 +105,5 @@ public struct AppClipDefaultExperienceResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppClipDefaultExperienceUpdateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppClipDefaultExperienceUpdateRequest.swift index f1df398ad..e9ff7ef8b 100644 --- a/Sources/Bagbutik-Models/AppStore/AppClipDefaultExperienceUpdateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppClipDefaultExperienceUpdateRequest.swift @@ -16,6 +16,16 @@ public struct AppClipDefaultExperienceUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AppClipDefaultExperienceUpdateRequest.Data The data element of the request body. @@ -43,28 +53,21 @@ public struct AppClipDefaultExperienceUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -81,6 +84,16 @@ public struct AppClipDefaultExperienceUpdateRequest: Codable, RequestBody { public init(action: AppClipAction? = nil) { self.action = action } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + action = try container.decodeIfPresent(AppClipAction.self, forKey: "action") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(action, forKey: "action") + } } /** @@ -98,6 +111,16 @@ public struct AppClipDefaultExperienceUpdateRequest: Codable, RequestBody { self.releaseWithAppStoreVersion = releaseWithAppStoreVersion } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + releaseWithAppStoreVersion = try container.decodeIfPresent(ReleaseWithAppStoreVersion.self, forKey: "releaseWithAppStoreVersion") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(releaseWithAppStoreVersion, forKey: "releaseWithAppStoreVersion") + } + /** # AppClipDefaultExperienceUpdateRequest.Data.Relationships.ReleaseWithAppStoreVersion The relationship to the App Store Versions resource you set with the request that updates a Default App Clip Experiences resource. @@ -114,17 +137,13 @@ public struct AppClipDefaultExperienceUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } /** @@ -145,22 +164,17 @@ public struct AppClipDefaultExperienceUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppClipDefaultExperiencesResponse.swift b/Sources/Bagbutik-Models/AppStore/AppClipDefaultExperiencesResponse.swift index f19945d38..33cf45722 100644 --- a/Sources/Bagbutik-Models/AppStore/AppClipDefaultExperiencesResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppClipDefaultExperiencesResponse.swift @@ -31,6 +31,22 @@ public struct AppClipDefaultExperiencesResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([AppClipDefaultExperience].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getAppClip(for appClipDefaultExperience: AppClipDefaultExperience) -> AppClip? { included?.compactMap { relationship -> AppClip? in guard case let .appClip(appClip) = relationship else { return nil } @@ -97,9 +113,5 @@ public struct AppClipDefaultExperiencesResponse: Codable, PagedResponse { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppClipDomainStatus.swift b/Sources/Bagbutik-Models/AppStore/AppClipDomainStatus.swift index 8dd65fb06..c175f65aa 100644 --- a/Sources/Bagbutik-Models/AppStore/AppClipDomainStatus.swift +++ b/Sources/Bagbutik-Models/AppStore/AppClipDomainStatus.swift @@ -28,28 +28,21 @@ public struct AppClipDomainStatus: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } /** @@ -72,6 +65,18 @@ public struct AppClipDomainStatus: Codable, Identifiable { self.lastUpdatedDate = lastUpdatedDate } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + domains = try container.decodeIfPresent([Domains].self, forKey: "domains") + lastUpdatedDate = try container.decodeIfPresent(Date.self, forKey: "lastUpdatedDate") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(domains, forKey: "domains") + try container.encodeIfPresent(lastUpdatedDate, forKey: "lastUpdatedDate") + } + /** # AppClipDomainStatus.Attributes.Domains Domains you associated with your App Clip. @@ -100,6 +105,22 @@ public struct AppClipDomainStatus: Codable, Identifiable { self.lastUpdatedDate = lastUpdatedDate } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + domain = try container.decodeIfPresent(String.self, forKey: "domain") + errorCode = try container.decodeIfPresent(ErrorCode.self, forKey: "errorCode") + isValid = try container.decodeIfPresent(Bool.self, forKey: "isValid") + lastUpdatedDate = try container.decodeIfPresent(Date.self, forKey: "lastUpdatedDate") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(domain, forKey: "domain") + try container.encodeIfPresent(errorCode, forKey: "errorCode") + try container.encodeIfPresent(isValid, forKey: "isValid") + try container.encodeIfPresent(lastUpdatedDate, forKey: "lastUpdatedDate") + } + public enum ErrorCode: String, Codable, CaseIterable { case badHttpResponse = "BAD_HTTP_RESPONSE" case badJsonContent = "BAD_JSON_CONTENT" diff --git a/Sources/Bagbutik-Models/AppStore/AppClipDomainStatusResponse.swift b/Sources/Bagbutik-Models/AppStore/AppClipDomainStatusResponse.swift index d3dabe867..46bd81b27 100644 --- a/Sources/Bagbutik-Models/AppStore/AppClipDomainStatusResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppClipDomainStatusResponse.swift @@ -20,4 +20,16 @@ public struct AppClipDomainStatusResponse: Codable { self.data = data self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AppClipDomainStatus.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/AppStore/AppClipHeaderImage.swift b/Sources/Bagbutik-Models/AppStore/AppClipHeaderImage.swift index ec96fb56e..e57f287c2 100644 --- a/Sources/Bagbutik-Models/AppStore/AppClipHeaderImage.swift +++ b/Sources/Bagbutik-Models/AppStore/AppClipHeaderImage.swift @@ -32,31 +32,23 @@ public struct AppClipHeaderImage: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -94,6 +86,26 @@ public struct AppClipHeaderImage: Codable, Identifiable { self.sourceFileChecksum = sourceFileChecksum self.uploadOperations = uploadOperations } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + assetDeliveryState = try container.decodeIfPresent(AppMediaAssetState.self, forKey: "assetDeliveryState") + fileName = try container.decodeIfPresent(String.self, forKey: "fileName") + fileSize = try container.decodeIfPresent(Int.self, forKey: "fileSize") + imageAsset = try container.decodeIfPresent(ImageAsset.self, forKey: "imageAsset") + sourceFileChecksum = try container.decodeIfPresent(String.self, forKey: "sourceFileChecksum") + uploadOperations = try container.decodeIfPresent([UploadOperation].self, forKey: "uploadOperations") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(assetDeliveryState, forKey: "assetDeliveryState") + try container.encodeIfPresent(fileName, forKey: "fileName") + try container.encodeIfPresent(fileSize, forKey: "fileSize") + try container.encodeIfPresent(imageAsset, forKey: "imageAsset") + try container.encodeIfPresent(sourceFileChecksum, forKey: "sourceFileChecksum") + try container.encodeIfPresent(uploadOperations, forKey: "uploadOperations") + } } /** @@ -111,6 +123,16 @@ public struct AppClipHeaderImage: Codable, Identifiable { self.appClipDefaultExperienceLocalization = appClipDefaultExperienceLocalization } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appClipDefaultExperienceLocalization = try container.decodeIfPresent(AppClipDefaultExperienceLocalization.self, forKey: "appClipDefaultExperienceLocalization") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(appClipDefaultExperienceLocalization, forKey: "appClipDefaultExperienceLocalization") + } + /** # AppClipHeaderImage.Relationships.AppClipDefaultExperienceLocalization The data and links that describe the relationship between the App Clip Header Images and the Default App Clip Experiences resources. @@ -132,20 +154,15 @@ public struct AppClipHeaderImage: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -166,22 +183,17 @@ public struct AppClipHeaderImage: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -206,20 +218,15 @@ public struct AppClipHeaderImage: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppClipHeaderImageCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppClipHeaderImageCreateRequest.swift index 0f11967e3..a7f53c6d2 100644 --- a/Sources/Bagbutik-Models/AppStore/AppClipHeaderImageCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppClipHeaderImageCreateRequest.swift @@ -16,6 +16,16 @@ public struct AppClipHeaderImageCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AppClipHeaderImageCreateRequest.Data The data element of the request body. @@ -39,25 +49,19 @@ public struct AppClipHeaderImageCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } /** @@ -79,6 +83,18 @@ public struct AppClipHeaderImageCreateRequest: Codable, RequestBody { self.fileName = fileName self.fileSize = fileSize } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + fileName = try container.decode(String.self, forKey: "fileName") + fileSize = try container.decode(Int.self, forKey: "fileSize") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(fileName, forKey: "fileName") + try container.encode(fileSize, forKey: "fileSize") + } } /** @@ -96,6 +112,16 @@ public struct AppClipHeaderImageCreateRequest: Codable, RequestBody { self.appClipDefaultExperienceLocalization = appClipDefaultExperienceLocalization } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appClipDefaultExperienceLocalization = try container.decode(AppClipDefaultExperienceLocalization.self, forKey: "appClipDefaultExperienceLocalization") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(appClipDefaultExperienceLocalization, forKey: "appClipDefaultExperienceLocalization") + } + /** # AppClipHeaderImageCreateRequest.Data.Relationships.AppClipDefaultExperienceLocalization The relationship to the Default App Clip Experience Localizations resource you set with the request that creates an App Clip Header Images resource. @@ -111,6 +137,16 @@ public struct AppClipHeaderImageCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AppClipHeaderImageCreateRequest.Data.Relationships.AppClipDefaultExperienceLocalization.Data The type and ID of the Default App Clip Localizations resource that you’re relating with the App Clip Header Images resource you’re creating. @@ -129,22 +165,17 @@ public struct AppClipHeaderImageCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppClipHeaderImageResponse.swift b/Sources/Bagbutik-Models/AppStore/AppClipHeaderImageResponse.swift index 71d5ced7b..0d6c368cf 100644 --- a/Sources/Bagbutik-Models/AppStore/AppClipHeaderImageResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppClipHeaderImageResponse.swift @@ -24,4 +24,18 @@ public struct AppClipHeaderImageResponse: Codable { self.included = included self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AppClipHeaderImage.self, forKey: "data") + included = try container.decodeIfPresent([AppClipDefaultExperienceLocalization].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/AppStore/AppClipHeaderImageUpdateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppClipHeaderImageUpdateRequest.swift index 0a1c97991..e4ec869ea 100644 --- a/Sources/Bagbutik-Models/AppStore/AppClipHeaderImageUpdateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppClipHeaderImageUpdateRequest.swift @@ -16,6 +16,16 @@ public struct AppClipHeaderImageUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AppClipHeaderImageUpdateRequest.Data The data element of the request body. @@ -39,25 +49,19 @@ public struct AppClipHeaderImageUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } /** @@ -79,6 +83,18 @@ public struct AppClipHeaderImageUpdateRequest: Codable, RequestBody { self.sourceFileChecksum = sourceFileChecksum self.uploaded = uploaded } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + sourceFileChecksum = try container.decodeIfPresent(String.self, forKey: "sourceFileChecksum") + uploaded = try container.decodeIfPresent(Bool.self, forKey: "uploaded") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(sourceFileChecksum, forKey: "sourceFileChecksum") + try container.encodeIfPresent(uploaded, forKey: "uploaded") + } } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppClipResponse.swift b/Sources/Bagbutik-Models/AppStore/AppClipResponse.swift index 5d98df376..c0ef2c36f 100644 --- a/Sources/Bagbutik-Models/AppStore/AppClipResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppClipResponse.swift @@ -25,6 +25,20 @@ public struct AppClipResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AppClip.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getApp() -> App? { included?.compactMap { relationship -> App? in guard case let .app(app) = relationship else { return nil } @@ -67,9 +81,5 @@ public struct AppClipResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppClipsResponse.swift b/Sources/Bagbutik-Models/AppStore/AppClipsResponse.swift index 46becc61f..80a636842 100644 --- a/Sources/Bagbutik-Models/AppStore/AppClipsResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppClipsResponse.swift @@ -31,6 +31,22 @@ public struct AppClipsResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([AppClip].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getApp(for appClip: AppClip) -> App? { included?.compactMap { relationship -> App? in guard case let .app(app) = relationship else { return nil } @@ -73,9 +89,5 @@ public struct AppClipsResponse: Codable, PagedResponse { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppCustomProductPage.swift b/Sources/Bagbutik-Models/AppStore/AppCustomProductPage.swift index ac94b84b4..203a5a5cb 100644 --- a/Sources/Bagbutik-Models/AppStore/AppCustomProductPage.swift +++ b/Sources/Bagbutik-Models/AppStore/AppCustomProductPage.swift @@ -20,31 +20,23 @@ public struct AppCustomProductPage: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -60,6 +52,20 @@ public struct AppCustomProductPage: Codable, Identifiable { self.url = url self.visible = visible } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + name = try container.decodeIfPresent(String.self, forKey: "name") + url = try container.decodeIfPresent(String.self, forKey: "url") + visible = try container.decodeIfPresent(Bool.self, forKey: "visible") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(name, forKey: "name") + try container.encodeIfPresent(url, forKey: "url") + try container.encodeIfPresent(visible, forKey: "visible") + } } public struct Relationships: Codable { @@ -73,6 +79,18 @@ public struct AppCustomProductPage: Codable, Identifiable { self.appCustomProductPageVersions = appCustomProductPageVersions } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + app = try container.decodeIfPresent(App.self, forKey: "app") + appCustomProductPageVersions = try container.decodeIfPresent(AppCustomProductPageVersions.self, forKey: "appCustomProductPageVersions") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(app, forKey: "app") + try container.encodeIfPresent(appCustomProductPageVersions, forKey: "appCustomProductPageVersions") + } + public struct App: Codable { @NullCodable public var data: Data? public var links: Links? @@ -85,20 +103,15 @@ public struct AppCustomProductPage: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -110,22 +123,17 @@ public struct AppCustomProductPage: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -141,20 +149,15 @@ public struct AppCustomProductPage: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -174,23 +177,17 @@ public struct AppCustomProductPage: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -202,22 +199,17 @@ public struct AppCustomProductPage: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -233,20 +225,15 @@ public struct AppCustomProductPage: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppCustomProductPageCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppCustomProductPageCreateRequest.swift index f78f9414b..d8a00e829 100644 --- a/Sources/Bagbutik-Models/AppStore/AppCustomProductPageCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppCustomProductPageCreateRequest.swift @@ -12,6 +12,18 @@ public struct AppCustomProductPageCreateRequest: Codable, RequestBody { self.included = included } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + } + public struct Data: Codable { public var type: String { "appCustomProductPages" } public let attributes: Attributes @@ -25,25 +37,19 @@ public struct AppCustomProductPageCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -52,6 +58,16 @@ public struct AppCustomProductPageCreateRequest: Codable, RequestBody { public init(name: String) { self.name = name } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + name = try container.decode(String.self, forKey: "name") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(name, forKey: "name") + } } public struct Relationships: Codable { @@ -71,6 +87,22 @@ public struct AppCustomProductPageCreateRequest: Codable, RequestBody { self.customProductPageTemplate = customProductPageTemplate } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + app = try container.decode(App.self, forKey: "app") + appCustomProductPageVersions = try container.decodeIfPresent(AppCustomProductPageVersions.self, forKey: "appCustomProductPageVersions") + appStoreVersionTemplate = try container.decodeIfPresent(AppStoreVersionTemplate.self, forKey: "appStoreVersionTemplate") + customProductPageTemplate = try container.decodeIfPresent(CustomProductPageTemplate.self, forKey: "customProductPageTemplate") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(app, forKey: "app") + try container.encodeIfPresent(appCustomProductPageVersions, forKey: "appCustomProductPageVersions") + try container.encodeIfPresent(appStoreVersionTemplate, forKey: "appStoreVersionTemplate") + try container.encodeIfPresent(customProductPageTemplate, forKey: "customProductPageTemplate") + } + public struct App: Codable { public let data: Data @@ -78,6 +110,16 @@ public struct AppCustomProductPageCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "apps" } @@ -87,22 +129,17 @@ public struct AppCustomProductPageCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -115,17 +152,13 @@ public struct AppCustomProductPageCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } public struct Data: Codable, Identifiable { @@ -137,22 +170,17 @@ public struct AppCustomProductPageCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -165,17 +193,13 @@ public struct AppCustomProductPageCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } public struct Data: Codable, Identifiable { @@ -187,22 +211,17 @@ public struct AppCustomProductPageCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -215,17 +234,13 @@ public struct AppCustomProductPageCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } public struct Data: Codable, Identifiable { @@ -237,22 +252,17 @@ public struct AppCustomProductPageCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -282,9 +292,5 @@ public struct AppCustomProductPageCreateRequest: Codable, RequestBody { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppCustomProductPageLocalization.swift b/Sources/Bagbutik-Models/AppStore/AppCustomProductPageLocalization.swift index 0318a89e0..1356fc3da 100644 --- a/Sources/Bagbutik-Models/AppStore/AppCustomProductPageLocalization.swift +++ b/Sources/Bagbutik-Models/AppStore/AppCustomProductPageLocalization.swift @@ -20,31 +20,23 @@ public struct AppCustomProductPageLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -57,6 +49,18 @@ public struct AppCustomProductPageLocalization: Codable, Identifiable { self.locale = locale self.promotionalText = promotionalText } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + locale = try container.decodeIfPresent(String.self, forKey: "locale") + promotionalText = try container.decodeIfPresent(String.self, forKey: "promotionalText") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(locale, forKey: "locale") + try container.encodeIfPresent(promotionalText, forKey: "promotionalText") + } } public struct Relationships: Codable { @@ -73,6 +77,20 @@ public struct AppCustomProductPageLocalization: Codable, Identifiable { self.appScreenshotSets = appScreenshotSets } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appCustomProductPageVersion = try container.decodeIfPresent(AppCustomProductPageVersion.self, forKey: "appCustomProductPageVersion") + appPreviewSets = try container.decodeIfPresent(AppPreviewSets.self, forKey: "appPreviewSets") + appScreenshotSets = try container.decodeIfPresent(AppScreenshotSets.self, forKey: "appScreenshotSets") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(appCustomProductPageVersion, forKey: "appCustomProductPageVersion") + try container.encodeIfPresent(appPreviewSets, forKey: "appPreviewSets") + try container.encodeIfPresent(appScreenshotSets, forKey: "appScreenshotSets") + } + public struct AppCustomProductPageVersion: Codable { @NullCodable public var data: Data? public var links: Links? @@ -85,20 +103,15 @@ public struct AppCustomProductPageLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -110,22 +123,17 @@ public struct AppCustomProductPageLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -141,20 +149,15 @@ public struct AppCustomProductPageLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -174,23 +177,17 @@ public struct AppCustomProductPageLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -202,22 +199,17 @@ public struct AppCustomProductPageLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -233,20 +225,15 @@ public struct AppCustomProductPageLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -266,23 +253,17 @@ public struct AppCustomProductPageLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -294,22 +275,17 @@ public struct AppCustomProductPageLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -325,20 +301,15 @@ public struct AppCustomProductPageLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppCustomProductPageLocalizationCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppCustomProductPageLocalizationCreateRequest.swift index 036d5f6d6..6a4953527 100644 --- a/Sources/Bagbutik-Models/AppStore/AppCustomProductPageLocalizationCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppCustomProductPageLocalizationCreateRequest.swift @@ -8,6 +8,16 @@ public struct AppCustomProductPageLocalizationCreateRequest: Codable, RequestBod self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "appCustomProductPageLocalizations" } public let attributes: Attributes @@ -21,25 +31,19 @@ public struct AppCustomProductPageLocalizationCreateRequest: Codable, RequestBod } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -52,6 +56,18 @@ public struct AppCustomProductPageLocalizationCreateRequest: Codable, RequestBod self.locale = locale self.promotionalText = promotionalText } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + locale = try container.decode(String.self, forKey: "locale") + promotionalText = try container.decodeIfPresent(String.self, forKey: "promotionalText") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(locale, forKey: "locale") + try container.encodeIfPresent(promotionalText, forKey: "promotionalText") + } } public struct Relationships: Codable { @@ -61,6 +77,16 @@ public struct AppCustomProductPageLocalizationCreateRequest: Codable, RequestBod self.appCustomProductPageVersion = appCustomProductPageVersion } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appCustomProductPageVersion = try container.decode(AppCustomProductPageVersion.self, forKey: "appCustomProductPageVersion") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(appCustomProductPageVersion, forKey: "appCustomProductPageVersion") + } + public struct AppCustomProductPageVersion: Codable { public let data: Data @@ -68,6 +94,16 @@ public struct AppCustomProductPageLocalizationCreateRequest: Codable, RequestBod self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "appCustomProductPageVersions" } @@ -77,22 +113,17 @@ public struct AppCustomProductPageLocalizationCreateRequest: Codable, RequestBod } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppCustomProductPageLocalizationInlineCreate.swift b/Sources/Bagbutik-Models/AppStore/AppCustomProductPageLocalizationInlineCreate.swift index badcefb5f..57a813f13 100644 --- a/Sources/Bagbutik-Models/AppStore/AppCustomProductPageLocalizationInlineCreate.swift +++ b/Sources/Bagbutik-Models/AppStore/AppCustomProductPageLocalizationInlineCreate.swift @@ -17,28 +17,21 @@ public struct AppCustomProductPageLocalizationInlineCreate: Codable, Identifiabl } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decodeIfPresent(String.self, forKey: .id) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decodeIfPresent(String.self, forKey: "id") + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -51,6 +44,18 @@ public struct AppCustomProductPageLocalizationInlineCreate: Codable, Identifiabl self.locale = locale self.promotionalText = promotionalText } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + locale = try container.decode(String.self, forKey: "locale") + promotionalText = try container.decodeIfPresent(String.self, forKey: "promotionalText") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(locale, forKey: "locale") + try container.encodeIfPresent(promotionalText, forKey: "promotionalText") + } } public struct Relationships: Codable { @@ -60,6 +65,16 @@ public struct AppCustomProductPageLocalizationInlineCreate: Codable, Identifiabl self.appCustomProductPageVersion = appCustomProductPageVersion } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appCustomProductPageVersion = try container.decodeIfPresent(AppCustomProductPageVersion.self, forKey: "appCustomProductPageVersion") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(appCustomProductPageVersion, forKey: "appCustomProductPageVersion") + } + public struct AppCustomProductPageVersion: Codable { @NullCodable public var data: Data? @@ -68,17 +83,13 @@ public struct AppCustomProductPageLocalizationInlineCreate: Codable, Identifiabl } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } public struct Data: Codable, Identifiable { @@ -90,22 +101,17 @@ public struct AppCustomProductPageLocalizationInlineCreate: Codable, Identifiabl } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppCustomProductPageLocalizationResponse.swift b/Sources/Bagbutik-Models/AppStore/AppCustomProductPageLocalizationResponse.swift index 49cf4239b..95c2099f0 100644 --- a/Sources/Bagbutik-Models/AppStore/AppCustomProductPageLocalizationResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppCustomProductPageLocalizationResponse.swift @@ -15,6 +15,20 @@ public struct AppCustomProductPageLocalizationResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AppCustomProductPageLocalization.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getAppCustomProductPageVersion() -> AppCustomProductPageVersion? { included?.compactMap { relationship -> AppCustomProductPageVersion? in guard case let .appCustomProductPageVersion(appCustomProductPageVersion) = relationship else { return nil } @@ -74,9 +88,5 @@ public struct AppCustomProductPageLocalizationResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppCustomProductPageLocalizationUpdateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppCustomProductPageLocalizationUpdateRequest.swift index fad0bae2c..12bb03bc9 100644 --- a/Sources/Bagbutik-Models/AppStore/AppCustomProductPageLocalizationUpdateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppCustomProductPageLocalizationUpdateRequest.swift @@ -8,6 +8,16 @@ public struct AppCustomProductPageLocalizationUpdateRequest: Codable, RequestBod self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "appCustomProductPageLocalizations" } @@ -21,25 +31,19 @@ public struct AppCustomProductPageLocalizationUpdateRequest: Codable, RequestBod } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } public struct Attributes: Codable { @@ -48,6 +52,16 @@ public struct AppCustomProductPageLocalizationUpdateRequest: Codable, RequestBod public init(promotionalText: String? = nil) { self.promotionalText = promotionalText } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + promotionalText = try container.decodeIfPresent(String.self, forKey: "promotionalText") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(promotionalText, forKey: "promotionalText") + } } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppCustomProductPageLocalizationsResponse.swift b/Sources/Bagbutik-Models/AppStore/AppCustomProductPageLocalizationsResponse.swift index b7e0899c6..26f620777 100644 --- a/Sources/Bagbutik-Models/AppStore/AppCustomProductPageLocalizationsResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppCustomProductPageLocalizationsResponse.swift @@ -20,6 +20,22 @@ public struct AppCustomProductPageLocalizationsResponse: Codable, PagedResponse self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([AppCustomProductPageLocalization].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getAppCustomProductPageVersion(for appCustomProductPageLocalization: AppCustomProductPageLocalization) -> AppCustomProductPageVersion? { included?.compactMap { relationship -> AppCustomProductPageVersion? in guard case let .appCustomProductPageVersion(appCustomProductPageVersion) = relationship else { return nil } @@ -79,9 +95,5 @@ public struct AppCustomProductPageLocalizationsResponse: Codable, PagedResponse try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppCustomProductPageResponse.swift b/Sources/Bagbutik-Models/AppStore/AppCustomProductPageResponse.swift index 3dec238dc..2e4cf88fa 100644 --- a/Sources/Bagbutik-Models/AppStore/AppCustomProductPageResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppCustomProductPageResponse.swift @@ -15,6 +15,20 @@ public struct AppCustomProductPageResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AppCustomProductPage.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getApp() -> App? { included?.compactMap { relationship -> App? in guard case let .app(app) = relationship else { return nil } @@ -57,9 +71,5 @@ public struct AppCustomProductPageResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppCustomProductPageUpdateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppCustomProductPageUpdateRequest.swift index d938b138b..aea60b0bd 100644 --- a/Sources/Bagbutik-Models/AppStore/AppCustomProductPageUpdateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppCustomProductPageUpdateRequest.swift @@ -8,6 +8,16 @@ public struct AppCustomProductPageUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "appCustomProductPages" } @@ -21,25 +31,19 @@ public struct AppCustomProductPageUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } public struct Attributes: Codable { @@ -52,6 +56,18 @@ public struct AppCustomProductPageUpdateRequest: Codable, RequestBody { self.name = name self.visible = visible } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + name = try container.decodeIfPresent(String.self, forKey: "name") + visible = try container.decodeIfPresent(Bool.self, forKey: "visible") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(name, forKey: "name") + try container.encodeIfPresent(visible, forKey: "visible") + } } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppCustomProductPageVersion.swift b/Sources/Bagbutik-Models/AppStore/AppCustomProductPageVersion.swift index 77e2e1bac..fd3b07015 100644 --- a/Sources/Bagbutik-Models/AppStore/AppCustomProductPageVersion.swift +++ b/Sources/Bagbutik-Models/AppStore/AppCustomProductPageVersion.swift @@ -20,31 +20,23 @@ public struct AppCustomProductPageVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -58,6 +50,18 @@ public struct AppCustomProductPageVersion: Codable, Identifiable { self.version = version } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + state = try container.decodeIfPresent(State.self, forKey: "state") + version = try container.decodeIfPresent(String.self, forKey: "version") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(state, forKey: "state") + try container.encodeIfPresent(version, forKey: "version") + } + public enum State: String, Codable, CaseIterable { case accepted = "ACCEPTED" case approved = "APPROVED" @@ -81,6 +85,18 @@ public struct AppCustomProductPageVersion: Codable, Identifiable { self.appCustomProductPageLocalizations = appCustomProductPageLocalizations } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appCustomProductPage = try container.decodeIfPresent(AppCustomProductPage.self, forKey: "appCustomProductPage") + appCustomProductPageLocalizations = try container.decodeIfPresent(AppCustomProductPageLocalizations.self, forKey: "appCustomProductPageLocalizations") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(appCustomProductPage, forKey: "appCustomProductPage") + try container.encodeIfPresent(appCustomProductPageLocalizations, forKey: "appCustomProductPageLocalizations") + } + public struct AppCustomProductPage: Codable { @NullCodable public var data: Data? public var links: Links? @@ -93,20 +109,15 @@ public struct AppCustomProductPageVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -118,22 +129,17 @@ public struct AppCustomProductPageVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -149,20 +155,15 @@ public struct AppCustomProductPageVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -182,23 +183,17 @@ public struct AppCustomProductPageVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -210,22 +205,17 @@ public struct AppCustomProductPageVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -241,20 +231,15 @@ public struct AppCustomProductPageVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppCustomProductPageVersionCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppCustomProductPageVersionCreateRequest.swift index b0a39f03e..e299c599f 100644 --- a/Sources/Bagbutik-Models/AppStore/AppCustomProductPageVersionCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppCustomProductPageVersionCreateRequest.swift @@ -8,6 +8,16 @@ public struct AppCustomProductPageVersionCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "appCustomProductPageVersions" } public let relationships: Relationships @@ -17,22 +27,17 @@ public struct AppCustomProductPageVersionCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(relationships, forKey: "relationships") } public struct Relationships: Codable { @@ -46,6 +51,18 @@ public struct AppCustomProductPageVersionCreateRequest: Codable, RequestBody { self.appCustomProductPageLocalizations = appCustomProductPageLocalizations } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appCustomProductPage = try container.decode(AppCustomProductPage.self, forKey: "appCustomProductPage") + appCustomProductPageLocalizations = try container.decodeIfPresent(AppCustomProductPageLocalizations.self, forKey: "appCustomProductPageLocalizations") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(appCustomProductPage, forKey: "appCustomProductPage") + try container.encodeIfPresent(appCustomProductPageLocalizations, forKey: "appCustomProductPageLocalizations") + } + public struct AppCustomProductPage: Codable { public let data: Data @@ -53,6 +70,16 @@ public struct AppCustomProductPageVersionCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "appCustomProductPages" } @@ -62,22 +89,17 @@ public struct AppCustomProductPageVersionCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -90,17 +112,13 @@ public struct AppCustomProductPageVersionCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } public struct Data: Codable, Identifiable { @@ -112,22 +130,17 @@ public struct AppCustomProductPageVersionCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppCustomProductPageVersionInlineCreate.swift b/Sources/Bagbutik-Models/AppStore/AppCustomProductPageVersionInlineCreate.swift index 216a35693..f72a85b04 100644 --- a/Sources/Bagbutik-Models/AppStore/AppCustomProductPageVersionInlineCreate.swift +++ b/Sources/Bagbutik-Models/AppStore/AppCustomProductPageVersionInlineCreate.swift @@ -14,25 +14,19 @@ public struct AppCustomProductPageVersionInlineCreate: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decodeIfPresent(String.self, forKey: .id) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decodeIfPresent(String.self, forKey: "id") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case id - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Relationships: Codable { @@ -46,6 +40,18 @@ public struct AppCustomProductPageVersionInlineCreate: Codable, Identifiable { self.appCustomProductPageLocalizations = appCustomProductPageLocalizations } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appCustomProductPage = try container.decodeIfPresent(AppCustomProductPage.self, forKey: "appCustomProductPage") + appCustomProductPageLocalizations = try container.decodeIfPresent(AppCustomProductPageLocalizations.self, forKey: "appCustomProductPageLocalizations") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(appCustomProductPage, forKey: "appCustomProductPage") + try container.encodeIfPresent(appCustomProductPageLocalizations, forKey: "appCustomProductPageLocalizations") + } + public struct AppCustomProductPage: Codable { @NullCodable public var data: Data? @@ -54,17 +60,13 @@ public struct AppCustomProductPageVersionInlineCreate: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } public struct Data: Codable, Identifiable { @@ -76,22 +78,17 @@ public struct AppCustomProductPageVersionInlineCreate: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -104,17 +101,13 @@ public struct AppCustomProductPageVersionInlineCreate: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } public struct Data: Codable, Identifiable { @@ -126,22 +119,17 @@ public struct AppCustomProductPageVersionInlineCreate: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppCustomProductPageVersionResponse.swift b/Sources/Bagbutik-Models/AppStore/AppCustomProductPageVersionResponse.swift index 33647d608..01b61b365 100644 --- a/Sources/Bagbutik-Models/AppStore/AppCustomProductPageVersionResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppCustomProductPageVersionResponse.swift @@ -15,6 +15,20 @@ public struct AppCustomProductPageVersionResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AppCustomProductPageVersion.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getAppCustomProductPage() -> AppCustomProductPage? { included?.compactMap { relationship -> AppCustomProductPage? in guard case let .appCustomProductPage(appCustomProductPage) = relationship else { return nil } @@ -57,9 +71,5 @@ public struct AppCustomProductPageVersionResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppCustomProductPageVersionsResponse.swift b/Sources/Bagbutik-Models/AppStore/AppCustomProductPageVersionsResponse.swift index 37d829326..2bfedab7f 100644 --- a/Sources/Bagbutik-Models/AppStore/AppCustomProductPageVersionsResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppCustomProductPageVersionsResponse.swift @@ -20,6 +20,22 @@ public struct AppCustomProductPageVersionsResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([AppCustomProductPageVersion].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getAppCustomProductPage(for appCustomProductPageVersion: AppCustomProductPageVersion) -> AppCustomProductPage? { included?.compactMap { relationship -> AppCustomProductPage? in guard case let .appCustomProductPage(appCustomProductPage) = relationship else { return nil } @@ -62,9 +78,5 @@ public struct AppCustomProductPageVersionsResponse: Codable, PagedResponse { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppCustomProductPagesResponse.swift b/Sources/Bagbutik-Models/AppStore/AppCustomProductPagesResponse.swift index 07268ff26..2c4ba171b 100644 --- a/Sources/Bagbutik-Models/AppStore/AppCustomProductPagesResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppCustomProductPagesResponse.swift @@ -20,6 +20,22 @@ public struct AppCustomProductPagesResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([AppCustomProductPage].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getApp(for appCustomProductPage: AppCustomProductPage) -> App? { included?.compactMap { relationship -> App? in guard case let .app(app) = relationship else { return nil } @@ -62,9 +78,5 @@ public struct AppCustomProductPagesResponse: Codable, PagedResponse { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppEncryptionDeclaration.swift b/Sources/Bagbutik-Models/AppStore/AppEncryptionDeclaration.swift index 3581dfe0f..d29a33546 100644 --- a/Sources/Bagbutik-Models/AppStore/AppEncryptionDeclaration.swift +++ b/Sources/Bagbutik-Models/AppStore/AppEncryptionDeclaration.swift @@ -32,31 +32,23 @@ public struct AppEncryptionDeclaration: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -150,6 +142,42 @@ public struct AppEncryptionDeclaration: Codable, Identifiable { self.createdDate = createdDate self.exempt = exempt } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appDescription = try container.decodeIfPresent(String.self, forKey: "appDescription") + appEncryptionDeclarationState = try container.decodeIfPresent(AppEncryptionDeclarationState.self, forKey: "appEncryptionDeclarationState") + availableOnFrenchStore = try container.decodeIfPresent(Bool.self, forKey: "availableOnFrenchStore") + codeValue = try container.decodeIfPresent(String.self, forKey: "codeValue") + containsProprietaryCryptography = try container.decodeIfPresent(Bool.self, forKey: "containsProprietaryCryptography") + containsThirdPartyCryptography = try container.decodeIfPresent(Bool.self, forKey: "containsThirdPartyCryptography") + createdDate = try container.decodeIfPresent(Date.self, forKey: "createdDate") + documentName = try container.decodeIfPresent(String.self, forKey: "documentName") + documentType = try container.decodeIfPresent(String.self, forKey: "documentType") + documentUrl = try container.decodeIfPresent(String.self, forKey: "documentUrl") + exempt = try container.decodeIfPresent(Bool.self, forKey: "exempt") + platform = try container.decodeIfPresent(Platform.self, forKey: "platform") + uploadedDate = try container.decodeIfPresent(Date.self, forKey: "uploadedDate") + usesEncryption = try container.decodeIfPresent(Bool.self, forKey: "usesEncryption") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(appDescription, forKey: "appDescription") + try container.encodeIfPresent(appEncryptionDeclarationState, forKey: "appEncryptionDeclarationState") + try container.encodeIfPresent(availableOnFrenchStore, forKey: "availableOnFrenchStore") + try container.encodeIfPresent(codeValue, forKey: "codeValue") + try container.encodeIfPresent(containsProprietaryCryptography, forKey: "containsProprietaryCryptography") + try container.encodeIfPresent(containsThirdPartyCryptography, forKey: "containsThirdPartyCryptography") + try container.encodeIfPresent(createdDate, forKey: "createdDate") + try container.encodeIfPresent(documentName, forKey: "documentName") + try container.encodeIfPresent(documentType, forKey: "documentType") + try container.encodeIfPresent(documentUrl, forKey: "documentUrl") + try container.encodeIfPresent(exempt, forKey: "exempt") + try container.encodeIfPresent(platform, forKey: "platform") + try container.encodeIfPresent(uploadedDate, forKey: "uploadedDate") + try container.encodeIfPresent(usesEncryption, forKey: "usesEncryption") + } } /** @@ -182,6 +210,20 @@ public struct AppEncryptionDeclaration: Codable, Identifiable { self.appEncryptionDeclarationDocument = appEncryptionDeclarationDocument } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + app = try container.decodeIfPresent(App.self, forKey: "app") + appEncryptionDeclarationDocument = try container.decodeIfPresent(AppEncryptionDeclarationDocument.self, forKey: "appEncryptionDeclarationDocument") + builds = try container.decodeIfPresent(Builds.self, forKey: "builds") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(app, forKey: "app") + try container.encodeIfPresent(appEncryptionDeclarationDocument, forKey: "appEncryptionDeclarationDocument") + try container.encodeIfPresent(builds, forKey: "builds") + } + /** # AppEncryptionDeclaration.Relationships.App The data and links that describe the relationship between the resources. @@ -201,20 +243,15 @@ public struct AppEncryptionDeclaration: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -235,22 +272,17 @@ public struct AppEncryptionDeclaration: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -273,20 +305,15 @@ public struct AppEncryptionDeclaration: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -303,20 +330,15 @@ public struct AppEncryptionDeclaration: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -328,22 +350,17 @@ public struct AppEncryptionDeclaration: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -359,20 +376,15 @@ public struct AppEncryptionDeclaration: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -392,23 +404,17 @@ public struct AppEncryptionDeclaration: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -420,22 +426,17 @@ public struct AppEncryptionDeclaration: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -451,20 +452,15 @@ public struct AppEncryptionDeclaration: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppEncryptionDeclarationBuildsLinkagesRequest.swift b/Sources/Bagbutik-Models/AppStore/AppEncryptionDeclarationBuildsLinkagesRequest.swift index f02a8efd6..4e0f4be16 100644 --- a/Sources/Bagbutik-Models/AppStore/AppEncryptionDeclarationBuildsLinkagesRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppEncryptionDeclarationBuildsLinkagesRequest.swift @@ -16,6 +16,16 @@ public struct AppEncryptionDeclarationBuildsLinkagesRequest: Codable, RequestBod self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AppEncryptionDeclarationBuildsLinkagesRequest.Data The data element of the request body. @@ -34,22 +44,17 @@ public struct AppEncryptionDeclarationBuildsLinkagesRequest: Codable, RequestBod } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppEncryptionDeclarationDocument.swift b/Sources/Bagbutik-Models/AppStore/AppEncryptionDeclarationDocument.swift index 74dfd7b3a..d08e4e9de 100644 --- a/Sources/Bagbutik-Models/AppStore/AppEncryptionDeclarationDocument.swift +++ b/Sources/Bagbutik-Models/AppStore/AppEncryptionDeclarationDocument.swift @@ -17,28 +17,21 @@ public struct AppEncryptionDeclarationDocument: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } public struct Attributes: Codable { @@ -66,5 +59,27 @@ public struct AppEncryptionDeclarationDocument: Codable, Identifiable { self.sourceFileChecksum = sourceFileChecksum self.uploadOperations = uploadOperations } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + assetDeliveryState = try container.decodeIfPresent(AppMediaAssetState.self, forKey: "assetDeliveryState") + assetToken = try container.decodeIfPresent(String.self, forKey: "assetToken") + downloadUrl = try container.decodeIfPresent(String.self, forKey: "downloadUrl") + fileName = try container.decodeIfPresent(String.self, forKey: "fileName") + fileSize = try container.decodeIfPresent(Int.self, forKey: "fileSize") + sourceFileChecksum = try container.decodeIfPresent(String.self, forKey: "sourceFileChecksum") + uploadOperations = try container.decodeIfPresent([UploadOperation].self, forKey: "uploadOperations") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(assetDeliveryState, forKey: "assetDeliveryState") + try container.encodeIfPresent(assetToken, forKey: "assetToken") + try container.encodeIfPresent(downloadUrl, forKey: "downloadUrl") + try container.encodeIfPresent(fileName, forKey: "fileName") + try container.encodeIfPresent(fileSize, forKey: "fileSize") + try container.encodeIfPresent(sourceFileChecksum, forKey: "sourceFileChecksum") + try container.encodeIfPresent(uploadOperations, forKey: "uploadOperations") + } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppEncryptionDeclarationDocumentCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppEncryptionDeclarationDocumentCreateRequest.swift index 40f8fb7f5..84927dbe6 100644 --- a/Sources/Bagbutik-Models/AppStore/AppEncryptionDeclarationDocumentCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppEncryptionDeclarationDocumentCreateRequest.swift @@ -8,6 +8,16 @@ public struct AppEncryptionDeclarationDocumentCreateRequest: Codable, RequestBod self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "appEncryptionDeclarationDocuments" } public let attributes: Attributes @@ -21,25 +31,19 @@ public struct AppEncryptionDeclarationDocumentCreateRequest: Codable, RequestBod } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -52,6 +56,18 @@ public struct AppEncryptionDeclarationDocumentCreateRequest: Codable, RequestBod self.fileName = fileName self.fileSize = fileSize } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + fileName = try container.decode(String.self, forKey: "fileName") + fileSize = try container.decode(Int.self, forKey: "fileSize") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(fileName, forKey: "fileName") + try container.encode(fileSize, forKey: "fileSize") + } } public struct Relationships: Codable { @@ -61,6 +77,16 @@ public struct AppEncryptionDeclarationDocumentCreateRequest: Codable, RequestBod self.appEncryptionDeclaration = appEncryptionDeclaration } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appEncryptionDeclaration = try container.decode(AppEncryptionDeclaration.self, forKey: "appEncryptionDeclaration") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(appEncryptionDeclaration, forKey: "appEncryptionDeclaration") + } + public struct AppEncryptionDeclaration: Codable { public let data: Data @@ -68,6 +94,16 @@ public struct AppEncryptionDeclarationDocumentCreateRequest: Codable, RequestBod self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "appEncryptionDeclarations" } @@ -77,22 +113,17 @@ public struct AppEncryptionDeclarationDocumentCreateRequest: Codable, RequestBod } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppEncryptionDeclarationDocumentResponse.swift b/Sources/Bagbutik-Models/AppStore/AppEncryptionDeclarationDocumentResponse.swift index 773dfa91e..15bfbac89 100644 --- a/Sources/Bagbutik-Models/AppStore/AppEncryptionDeclarationDocumentResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppEncryptionDeclarationDocumentResponse.swift @@ -11,4 +11,16 @@ public struct AppEncryptionDeclarationDocumentResponse: Codable { self.data = data self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AppEncryptionDeclarationDocument.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/AppStore/AppEncryptionDeclarationDocumentUpdateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppEncryptionDeclarationDocumentUpdateRequest.swift index 1aeae57b0..28a54c28e 100644 --- a/Sources/Bagbutik-Models/AppStore/AppEncryptionDeclarationDocumentUpdateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppEncryptionDeclarationDocumentUpdateRequest.swift @@ -8,6 +8,16 @@ public struct AppEncryptionDeclarationDocumentUpdateRequest: Codable, RequestBod self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "appEncryptionDeclarationDocuments" } @@ -21,25 +31,19 @@ public struct AppEncryptionDeclarationDocumentUpdateRequest: Codable, RequestBod } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } public struct Attributes: Codable { @@ -52,6 +56,18 @@ public struct AppEncryptionDeclarationDocumentUpdateRequest: Codable, RequestBod self.sourceFileChecksum = sourceFileChecksum self.uploaded = uploaded } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + sourceFileChecksum = try container.decodeIfPresent(String.self, forKey: "sourceFileChecksum") + uploaded = try container.decodeIfPresent(Bool.self, forKey: "uploaded") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(sourceFileChecksum, forKey: "sourceFileChecksum") + try container.encodeIfPresent(uploaded, forKey: "uploaded") + } } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppEncryptionDeclarationResponse.swift b/Sources/Bagbutik-Models/AppStore/AppEncryptionDeclarationResponse.swift index a415a26cf..857cb69d3 100644 --- a/Sources/Bagbutik-Models/AppStore/AppEncryptionDeclarationResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppEncryptionDeclarationResponse.swift @@ -24,6 +24,20 @@ public struct AppEncryptionDeclarationResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AppEncryptionDeclaration.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getApp() -> App? { included?.compactMap { relationship -> App? in guard case let .app(app) = relationship else { return nil } @@ -66,9 +80,5 @@ public struct AppEncryptionDeclarationResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppEncryptionDeclarationWithoutIncludesResponse.swift b/Sources/Bagbutik-Models/AppStore/AppEncryptionDeclarationWithoutIncludesResponse.swift index 5573ab544..22ec31a32 100644 --- a/Sources/Bagbutik-Models/AppStore/AppEncryptionDeclarationWithoutIncludesResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppEncryptionDeclarationWithoutIncludesResponse.swift @@ -11,4 +11,16 @@ public struct AppEncryptionDeclarationWithoutIncludesResponse: Codable { self.data = data self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AppEncryptionDeclaration.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/AppStore/AppEncryptionDeclarationsResponse.swift b/Sources/Bagbutik-Models/AppStore/AppEncryptionDeclarationsResponse.swift index 8b6c96e4e..95aeadccf 100644 --- a/Sources/Bagbutik-Models/AppStore/AppEncryptionDeclarationsResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppEncryptionDeclarationsResponse.swift @@ -30,6 +30,22 @@ public struct AppEncryptionDeclarationsResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([AppEncryptionDeclaration].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getApp(for appEncryptionDeclaration: AppEncryptionDeclaration) -> App? { included?.compactMap { relationship -> App? in guard case let .app(app) = relationship else { return nil } @@ -72,9 +88,5 @@ public struct AppEncryptionDeclarationsResponse: Codable, PagedResponse { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppEvent.swift b/Sources/Bagbutik-Models/AppStore/AppEvent.swift index 44191be64..70a898993 100644 --- a/Sources/Bagbutik-Models/AppStore/AppEvent.swift +++ b/Sources/Bagbutik-Models/AppStore/AppEvent.swift @@ -20,31 +20,23 @@ public struct AppEvent: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -82,6 +74,34 @@ public struct AppEvent: Codable, Identifiable { self.territorySchedules = territorySchedules } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + archivedTerritorySchedules = try container.decodeIfPresent([ArchivedTerritorySchedules].self, forKey: "archivedTerritorySchedules") + badge = try container.decodeIfPresent(Badge.self, forKey: "badge") + deepLink = try container.decodeIfPresent(String.self, forKey: "deepLink") + eventState = try container.decodeIfPresent(EventState.self, forKey: "eventState") + primaryLocale = try container.decodeIfPresent(String.self, forKey: "primaryLocale") + priority = try container.decodeIfPresent(Priority.self, forKey: "priority") + purchaseRequirement = try container.decodeIfPresent(PurchaseRequirement.self, forKey: "purchaseRequirement") + purpose = try container.decodeIfPresent(Purpose.self, forKey: "purpose") + referenceName = try container.decodeIfPresent(String.self, forKey: "referenceName") + territorySchedules = try container.decodeIfPresent([TerritorySchedules].self, forKey: "territorySchedules") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(archivedTerritorySchedules, forKey: "archivedTerritorySchedules") + try container.encodeIfPresent(badge, forKey: "badge") + try container.encodeIfPresent(deepLink, forKey: "deepLink") + try container.encodeIfPresent(eventState, forKey: "eventState") + try container.encodeIfPresent(primaryLocale, forKey: "primaryLocale") + try container.encodeIfPresent(priority, forKey: "priority") + try container.encodeIfPresent(purchaseRequirement, forKey: "purchaseRequirement") + try container.encodeIfPresent(purpose, forKey: "purpose") + try container.encodeIfPresent(referenceName, forKey: "referenceName") + try container.encodeIfPresent(territorySchedules, forKey: "territorySchedules") + } + public struct ArchivedTerritorySchedules: Codable { public var eventEnd: Date? public var eventStart: Date? @@ -98,6 +118,22 @@ public struct AppEvent: Codable, Identifiable { self.publishStart = publishStart self.territories = territories } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + eventEnd = try container.decodeIfPresent(Date.self, forKey: "eventEnd") + eventStart = try container.decodeIfPresent(Date.self, forKey: "eventStart") + publishStart = try container.decodeIfPresent(Date.self, forKey: "publishStart") + territories = try container.decodeIfPresent([String].self, forKey: "territories") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(eventEnd, forKey: "eventEnd") + try container.encodeIfPresent(eventStart, forKey: "eventStart") + try container.encodeIfPresent(publishStart, forKey: "publishStart") + try container.encodeIfPresent(territories, forKey: "territories") + } } public enum Badge: String, Codable, CaseIterable { @@ -159,6 +195,22 @@ public struct AppEvent: Codable, Identifiable { self.publishStart = publishStart self.territories = territories } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + eventEnd = try container.decodeIfPresent(Date.self, forKey: "eventEnd") + eventStart = try container.decodeIfPresent(Date.self, forKey: "eventStart") + publishStart = try container.decodeIfPresent(Date.self, forKey: "publishStart") + territories = try container.decodeIfPresent([String].self, forKey: "territories") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(eventEnd, forKey: "eventEnd") + try container.encodeIfPresent(eventStart, forKey: "eventStart") + try container.encodeIfPresent(publishStart, forKey: "publishStart") + try container.encodeIfPresent(territories, forKey: "territories") + } } } @@ -169,6 +221,16 @@ public struct AppEvent: Codable, Identifiable { self.localizations = localizations } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + localizations = try container.decodeIfPresent(Localizations.self, forKey: "localizations") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(localizations, forKey: "localizations") + } + public struct Localizations: Codable { @NullCodable public var data: [Data]? public var links: Links? @@ -184,23 +246,17 @@ public struct AppEvent: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -212,22 +268,17 @@ public struct AppEvent: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -243,20 +294,15 @@ public struct AppEvent: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppEventCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppEventCreateRequest.swift index 84caa5879..7d2b909ba 100644 --- a/Sources/Bagbutik-Models/AppStore/AppEventCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppEventCreateRequest.swift @@ -8,6 +8,16 @@ public struct AppEventCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "appEvents" } public let attributes: Attributes @@ -21,25 +31,19 @@ public struct AppEventCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -71,6 +75,30 @@ public struct AppEventCreateRequest: Codable, RequestBody { self.territorySchedules = territorySchedules } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + badge = try container.decodeIfPresent(AppEvent.Attributes.Badge.self, forKey: "badge") + deepLink = try container.decodeIfPresent(String.self, forKey: "deepLink") + primaryLocale = try container.decodeIfPresent(String.self, forKey: "primaryLocale") + priority = try container.decodeIfPresent(AppEvent.Attributes.Priority.self, forKey: "priority") + purchaseRequirement = try container.decodeIfPresent(AppEvent.Attributes.PurchaseRequirement.self, forKey: "purchaseRequirement") + purpose = try container.decodeIfPresent(AppEvent.Attributes.Purpose.self, forKey: "purpose") + referenceName = try container.decode(String.self, forKey: "referenceName") + territorySchedules = try container.decodeIfPresent([TerritorySchedules].self, forKey: "territorySchedules") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(badge, forKey: "badge") + try container.encodeIfPresent(deepLink, forKey: "deepLink") + try container.encodeIfPresent(primaryLocale, forKey: "primaryLocale") + try container.encodeIfPresent(priority, forKey: "priority") + try container.encodeIfPresent(purchaseRequirement, forKey: "purchaseRequirement") + try container.encodeIfPresent(purpose, forKey: "purpose") + try container.encode(referenceName, forKey: "referenceName") + try container.encodeIfPresent(territorySchedules, forKey: "territorySchedules") + } + public struct TerritorySchedules: Codable { public var eventEnd: Date? public var eventStart: Date? @@ -87,6 +115,22 @@ public struct AppEventCreateRequest: Codable, RequestBody { self.publishStart = publishStart self.territories = territories } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + eventEnd = try container.decodeIfPresent(Date.self, forKey: "eventEnd") + eventStart = try container.decodeIfPresent(Date.self, forKey: "eventStart") + publishStart = try container.decodeIfPresent(Date.self, forKey: "publishStart") + territories = try container.decodeIfPresent([String].self, forKey: "territories") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(eventEnd, forKey: "eventEnd") + try container.encodeIfPresent(eventStart, forKey: "eventStart") + try container.encodeIfPresent(publishStart, forKey: "publishStart") + try container.encodeIfPresent(territories, forKey: "territories") + } } } @@ -97,6 +141,16 @@ public struct AppEventCreateRequest: Codable, RequestBody { self.app = app } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + app = try container.decode(App.self, forKey: "app") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(app, forKey: "app") + } + public struct App: Codable { public let data: Data @@ -104,6 +158,16 @@ public struct AppEventCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "apps" } @@ -113,22 +177,17 @@ public struct AppEventCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppEventLocalization.swift b/Sources/Bagbutik-Models/AppStore/AppEventLocalization.swift index b174b59d3..3c2709e33 100644 --- a/Sources/Bagbutik-Models/AppStore/AppEventLocalization.swift +++ b/Sources/Bagbutik-Models/AppStore/AppEventLocalization.swift @@ -20,31 +20,23 @@ public struct AppEventLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -63,6 +55,22 @@ public struct AppEventLocalization: Codable, Identifiable { self.name = name self.shortDescription = shortDescription } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + locale = try container.decodeIfPresent(String.self, forKey: "locale") + longDescription = try container.decodeIfPresent(String.self, forKey: "longDescription") + name = try container.decodeIfPresent(String.self, forKey: "name") + shortDescription = try container.decodeIfPresent(String.self, forKey: "shortDescription") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(locale, forKey: "locale") + try container.encodeIfPresent(longDescription, forKey: "longDescription") + try container.encodeIfPresent(name, forKey: "name") + try container.encodeIfPresent(shortDescription, forKey: "shortDescription") + } } public struct Relationships: Codable { @@ -79,6 +87,20 @@ public struct AppEventLocalization: Codable, Identifiable { self.appEventVideoClips = appEventVideoClips } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appEvent = try container.decodeIfPresent(AppEvent.self, forKey: "appEvent") + appEventScreenshots = try container.decodeIfPresent(AppEventScreenshots.self, forKey: "appEventScreenshots") + appEventVideoClips = try container.decodeIfPresent(AppEventVideoClips.self, forKey: "appEventVideoClips") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(appEvent, forKey: "appEvent") + try container.encodeIfPresent(appEventScreenshots, forKey: "appEventScreenshots") + try container.encodeIfPresent(appEventVideoClips, forKey: "appEventVideoClips") + } + public struct AppEvent: Codable { @NullCodable public var data: Data? public var links: Links? @@ -91,20 +113,15 @@ public struct AppEventLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -116,22 +133,17 @@ public struct AppEventLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -147,20 +159,15 @@ public struct AppEventLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -180,23 +187,17 @@ public struct AppEventLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -208,22 +209,17 @@ public struct AppEventLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -239,20 +235,15 @@ public struct AppEventLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -272,23 +263,17 @@ public struct AppEventLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -300,22 +285,17 @@ public struct AppEventLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -331,20 +311,15 @@ public struct AppEventLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppEventLocalizationCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppEventLocalizationCreateRequest.swift index e02acd55c..5e735e791 100644 --- a/Sources/Bagbutik-Models/AppStore/AppEventLocalizationCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppEventLocalizationCreateRequest.swift @@ -8,6 +8,16 @@ public struct AppEventLocalizationCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "appEventLocalizations" } public let attributes: Attributes @@ -21,25 +31,19 @@ public struct AppEventLocalizationCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -58,6 +62,22 @@ public struct AppEventLocalizationCreateRequest: Codable, RequestBody { self.name = name self.shortDescription = shortDescription } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + locale = try container.decode(String.self, forKey: "locale") + longDescription = try container.decodeIfPresent(String.self, forKey: "longDescription") + name = try container.decodeIfPresent(String.self, forKey: "name") + shortDescription = try container.decodeIfPresent(String.self, forKey: "shortDescription") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(locale, forKey: "locale") + try container.encodeIfPresent(longDescription, forKey: "longDescription") + try container.encodeIfPresent(name, forKey: "name") + try container.encodeIfPresent(shortDescription, forKey: "shortDescription") + } } public struct Relationships: Codable { @@ -67,6 +87,16 @@ public struct AppEventLocalizationCreateRequest: Codable, RequestBody { self.appEvent = appEvent } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appEvent = try container.decode(AppEvent.self, forKey: "appEvent") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(appEvent, forKey: "appEvent") + } + public struct AppEvent: Codable { public let data: Data @@ -74,6 +104,16 @@ public struct AppEventLocalizationCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "appEvents" } @@ -83,22 +123,17 @@ public struct AppEventLocalizationCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppEventLocalizationResponse.swift b/Sources/Bagbutik-Models/AppStore/AppEventLocalizationResponse.swift index 85ea63dcd..2c4ab331a 100644 --- a/Sources/Bagbutik-Models/AppStore/AppEventLocalizationResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppEventLocalizationResponse.swift @@ -15,6 +15,20 @@ public struct AppEventLocalizationResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AppEventLocalization.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getAppEvent() -> AppEvent? { included?.compactMap { relationship -> AppEvent? in guard case let .appEvent(appEvent) = relationship else { return nil } @@ -74,9 +88,5 @@ public struct AppEventLocalizationResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppEventLocalizationUpdateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppEventLocalizationUpdateRequest.swift index 9285d8463..9c9901323 100644 --- a/Sources/Bagbutik-Models/AppStore/AppEventLocalizationUpdateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppEventLocalizationUpdateRequest.swift @@ -8,6 +8,16 @@ public struct AppEventLocalizationUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "appEventLocalizations" } @@ -21,25 +31,19 @@ public struct AppEventLocalizationUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } public struct Attributes: Codable { @@ -55,6 +59,20 @@ public struct AppEventLocalizationUpdateRequest: Codable, RequestBody { self.name = name self.shortDescription = shortDescription } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + longDescription = try container.decodeIfPresent(String.self, forKey: "longDescription") + name = try container.decodeIfPresent(String.self, forKey: "name") + shortDescription = try container.decodeIfPresent(String.self, forKey: "shortDescription") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(longDescription, forKey: "longDescription") + try container.encodeIfPresent(name, forKey: "name") + try container.encodeIfPresent(shortDescription, forKey: "shortDescription") + } } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppEventLocalizationsResponse.swift b/Sources/Bagbutik-Models/AppStore/AppEventLocalizationsResponse.swift index 11284d475..569df23da 100644 --- a/Sources/Bagbutik-Models/AppStore/AppEventLocalizationsResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppEventLocalizationsResponse.swift @@ -20,6 +20,22 @@ public struct AppEventLocalizationsResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([AppEventLocalization].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getAppEvent(for appEventLocalization: AppEventLocalization) -> AppEvent? { included?.compactMap { relationship -> AppEvent? in guard case let .appEvent(appEvent) = relationship else { return nil } @@ -79,9 +95,5 @@ public struct AppEventLocalizationsResponse: Codable, PagedResponse { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppEventResponse.swift b/Sources/Bagbutik-Models/AppStore/AppEventResponse.swift index 58cf66c81..a9e973938 100644 --- a/Sources/Bagbutik-Models/AppStore/AppEventResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppEventResponse.swift @@ -14,4 +14,18 @@ public struct AppEventResponse: Codable { self.included = included self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AppEvent.self, forKey: "data") + included = try container.decodeIfPresent([AppEventLocalization].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/AppStore/AppEventScreenshot.swift b/Sources/Bagbutik-Models/AppStore/AppEventScreenshot.swift index 1f41b5ac9..9dd2fb289 100644 --- a/Sources/Bagbutik-Models/AppStore/AppEventScreenshot.swift +++ b/Sources/Bagbutik-Models/AppStore/AppEventScreenshot.swift @@ -20,31 +20,23 @@ public struct AppEventScreenshot: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -72,6 +64,28 @@ public struct AppEventScreenshot: Codable, Identifiable { self.imageAsset = imageAsset self.uploadOperations = uploadOperations } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appEventAssetType = try container.decodeIfPresent(AppEventAssetType.self, forKey: "appEventAssetType") + assetDeliveryState = try container.decodeIfPresent(AppMediaAssetState.self, forKey: "assetDeliveryState") + assetToken = try container.decodeIfPresent(String.self, forKey: "assetToken") + fileName = try container.decodeIfPresent(String.self, forKey: "fileName") + fileSize = try container.decodeIfPresent(Int.self, forKey: "fileSize") + imageAsset = try container.decodeIfPresent(ImageAsset.self, forKey: "imageAsset") + uploadOperations = try container.decodeIfPresent([UploadOperation].self, forKey: "uploadOperations") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(appEventAssetType, forKey: "appEventAssetType") + try container.encodeIfPresent(assetDeliveryState, forKey: "assetDeliveryState") + try container.encodeIfPresent(assetToken, forKey: "assetToken") + try container.encodeIfPresent(fileName, forKey: "fileName") + try container.encodeIfPresent(fileSize, forKey: "fileSize") + try container.encodeIfPresent(imageAsset, forKey: "imageAsset") + try container.encodeIfPresent(uploadOperations, forKey: "uploadOperations") + } } public struct Relationships: Codable { @@ -81,6 +95,16 @@ public struct AppEventScreenshot: Codable, Identifiable { self.appEventLocalization = appEventLocalization } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appEventLocalization = try container.decodeIfPresent(AppEventLocalization.self, forKey: "appEventLocalization") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(appEventLocalization, forKey: "appEventLocalization") + } + public struct AppEventLocalization: Codable { @NullCodable public var data: Data? public var links: Links? @@ -93,20 +117,15 @@ public struct AppEventScreenshot: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -118,22 +137,17 @@ public struct AppEventScreenshot: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -149,20 +163,15 @@ public struct AppEventScreenshot: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppEventScreenshotCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppEventScreenshotCreateRequest.swift index 4a4f67ba8..df80db04d 100644 --- a/Sources/Bagbutik-Models/AppStore/AppEventScreenshotCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppEventScreenshotCreateRequest.swift @@ -8,6 +8,16 @@ public struct AppEventScreenshotCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "appEventScreenshots" } public let attributes: Attributes @@ -21,25 +31,19 @@ public struct AppEventScreenshotCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -55,6 +59,20 @@ public struct AppEventScreenshotCreateRequest: Codable, RequestBody { self.fileName = fileName self.fileSize = fileSize } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appEventAssetType = try container.decode(AppEventAssetType.self, forKey: "appEventAssetType") + fileName = try container.decode(String.self, forKey: "fileName") + fileSize = try container.decode(Int.self, forKey: "fileSize") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(appEventAssetType, forKey: "appEventAssetType") + try container.encode(fileName, forKey: "fileName") + try container.encode(fileSize, forKey: "fileSize") + } } public struct Relationships: Codable { @@ -64,6 +82,16 @@ public struct AppEventScreenshotCreateRequest: Codable, RequestBody { self.appEventLocalization = appEventLocalization } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appEventLocalization = try container.decode(AppEventLocalization.self, forKey: "appEventLocalization") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(appEventLocalization, forKey: "appEventLocalization") + } + public struct AppEventLocalization: Codable { public let data: Data @@ -71,6 +99,16 @@ public struct AppEventScreenshotCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "appEventLocalizations" } @@ -80,22 +118,17 @@ public struct AppEventScreenshotCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppEventScreenshotResponse.swift b/Sources/Bagbutik-Models/AppStore/AppEventScreenshotResponse.swift index 0962ac01d..5d2a683a2 100644 --- a/Sources/Bagbutik-Models/AppStore/AppEventScreenshotResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppEventScreenshotResponse.swift @@ -14,4 +14,18 @@ public struct AppEventScreenshotResponse: Codable { self.included = included self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AppEventScreenshot.self, forKey: "data") + included = try container.decodeIfPresent([AppEventLocalization].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/AppStore/AppEventScreenshotUpdateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppEventScreenshotUpdateRequest.swift index 0c39576d5..5955d2a8c 100644 --- a/Sources/Bagbutik-Models/AppStore/AppEventScreenshotUpdateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppEventScreenshotUpdateRequest.swift @@ -8,6 +8,16 @@ public struct AppEventScreenshotUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "appEventScreenshots" } @@ -21,25 +31,19 @@ public struct AppEventScreenshotUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } public struct Attributes: Codable { @@ -48,6 +52,16 @@ public struct AppEventScreenshotUpdateRequest: Codable, RequestBody { public init(uploaded: Bool? = nil) { self.uploaded = uploaded } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + uploaded = try container.decodeIfPresent(Bool.self, forKey: "uploaded") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(uploaded, forKey: "uploaded") + } } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppEventScreenshotsResponse.swift b/Sources/Bagbutik-Models/AppStore/AppEventScreenshotsResponse.swift index 229eeae0e..969fbcdea 100644 --- a/Sources/Bagbutik-Models/AppStore/AppEventScreenshotsResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppEventScreenshotsResponse.swift @@ -19,4 +19,20 @@ public struct AppEventScreenshotsResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([AppEventScreenshot].self, forKey: "data") + included = try container.decodeIfPresent([AppEventLocalization].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/AppStore/AppEventUpdateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppEventUpdateRequest.swift index 0f9496c2f..ebee4bc37 100644 --- a/Sources/Bagbutik-Models/AppStore/AppEventUpdateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppEventUpdateRequest.swift @@ -8,6 +8,16 @@ public struct AppEventUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "appEvents" } @@ -21,25 +31,19 @@ public struct AppEventUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } public struct Attributes: Codable { @@ -71,6 +75,30 @@ public struct AppEventUpdateRequest: Codable, RequestBody { self.territorySchedules = territorySchedules } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + badge = try container.decodeIfPresent(AppEvent.Attributes.Badge.self, forKey: "badge") + deepLink = try container.decodeIfPresent(String.self, forKey: "deepLink") + primaryLocale = try container.decodeIfPresent(String.self, forKey: "primaryLocale") + priority = try container.decodeIfPresent(AppEvent.Attributes.Priority.self, forKey: "priority") + purchaseRequirement = try container.decodeIfPresent(AppEvent.Attributes.PurchaseRequirement.self, forKey: "purchaseRequirement") + purpose = try container.decodeIfPresent(AppEvent.Attributes.Purpose.self, forKey: "purpose") + referenceName = try container.decodeIfPresent(String.self, forKey: "referenceName") + territorySchedules = try container.decodeIfPresent([TerritorySchedules].self, forKey: "territorySchedules") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(badge, forKey: "badge") + try container.encodeIfPresent(deepLink, forKey: "deepLink") + try container.encodeIfPresent(primaryLocale, forKey: "primaryLocale") + try container.encodeIfPresent(priority, forKey: "priority") + try container.encodeIfPresent(purchaseRequirement, forKey: "purchaseRequirement") + try container.encodeIfPresent(purpose, forKey: "purpose") + try container.encodeIfPresent(referenceName, forKey: "referenceName") + try container.encodeIfPresent(territorySchedules, forKey: "territorySchedules") + } + public struct TerritorySchedules: Codable { public var eventEnd: Date? public var eventStart: Date? @@ -87,6 +115,22 @@ public struct AppEventUpdateRequest: Codable, RequestBody { self.publishStart = publishStart self.territories = territories } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + eventEnd = try container.decodeIfPresent(Date.self, forKey: "eventEnd") + eventStart = try container.decodeIfPresent(Date.self, forKey: "eventStart") + publishStart = try container.decodeIfPresent(Date.self, forKey: "publishStart") + territories = try container.decodeIfPresent([String].self, forKey: "territories") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(eventEnd, forKey: "eventEnd") + try container.encodeIfPresent(eventStart, forKey: "eventStart") + try container.encodeIfPresent(publishStart, forKey: "publishStart") + try container.encodeIfPresent(territories, forKey: "territories") + } } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppEventVideoClip.swift b/Sources/Bagbutik-Models/AppStore/AppEventVideoClip.swift index 6a81d8e0d..b51e41cff 100644 --- a/Sources/Bagbutik-Models/AppStore/AppEventVideoClip.swift +++ b/Sources/Bagbutik-Models/AppStore/AppEventVideoClip.swift @@ -20,31 +20,23 @@ public struct AppEventVideoClip: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -75,6 +67,30 @@ public struct AppEventVideoClip: Codable, Identifiable { self.uploadOperations = uploadOperations self.videoUrl = videoUrl } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appEventAssetType = try container.decodeIfPresent(AppEventAssetType.self, forKey: "appEventAssetType") + assetDeliveryState = try container.decodeIfPresent(AppMediaAssetState.self, forKey: "assetDeliveryState") + fileName = try container.decodeIfPresent(String.self, forKey: "fileName") + fileSize = try container.decodeIfPresent(Int.self, forKey: "fileSize") + previewFrameTimeCode = try container.decodeIfPresent(String.self, forKey: "previewFrameTimeCode") + previewImage = try container.decodeIfPresent(ImageAsset.self, forKey: "previewImage") + uploadOperations = try container.decodeIfPresent([UploadOperation].self, forKey: "uploadOperations") + videoUrl = try container.decodeIfPresent(String.self, forKey: "videoUrl") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(appEventAssetType, forKey: "appEventAssetType") + try container.encodeIfPresent(assetDeliveryState, forKey: "assetDeliveryState") + try container.encodeIfPresent(fileName, forKey: "fileName") + try container.encodeIfPresent(fileSize, forKey: "fileSize") + try container.encodeIfPresent(previewFrameTimeCode, forKey: "previewFrameTimeCode") + try container.encodeIfPresent(previewImage, forKey: "previewImage") + try container.encodeIfPresent(uploadOperations, forKey: "uploadOperations") + try container.encodeIfPresent(videoUrl, forKey: "videoUrl") + } } public struct Relationships: Codable { @@ -84,6 +100,16 @@ public struct AppEventVideoClip: Codable, Identifiable { self.appEventLocalization = appEventLocalization } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appEventLocalization = try container.decodeIfPresent(AppEventLocalization.self, forKey: "appEventLocalization") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(appEventLocalization, forKey: "appEventLocalization") + } + public struct AppEventLocalization: Codable { @NullCodable public var data: Data? public var links: Links? @@ -96,20 +122,15 @@ public struct AppEventVideoClip: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -121,22 +142,17 @@ public struct AppEventVideoClip: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -152,20 +168,15 @@ public struct AppEventVideoClip: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppEventVideoClipCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppEventVideoClipCreateRequest.swift index e1b5df85f..a6c11fd74 100644 --- a/Sources/Bagbutik-Models/AppStore/AppEventVideoClipCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppEventVideoClipCreateRequest.swift @@ -8,6 +8,16 @@ public struct AppEventVideoClipCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "appEventVideoClips" } public let attributes: Attributes @@ -21,25 +31,19 @@ public struct AppEventVideoClipCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -58,6 +62,22 @@ public struct AppEventVideoClipCreateRequest: Codable, RequestBody { self.fileSize = fileSize self.previewFrameTimeCode = previewFrameTimeCode } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appEventAssetType = try container.decode(AppEventAssetType.self, forKey: "appEventAssetType") + fileName = try container.decode(String.self, forKey: "fileName") + fileSize = try container.decode(Int.self, forKey: "fileSize") + previewFrameTimeCode = try container.decodeIfPresent(String.self, forKey: "previewFrameTimeCode") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(appEventAssetType, forKey: "appEventAssetType") + try container.encode(fileName, forKey: "fileName") + try container.encode(fileSize, forKey: "fileSize") + try container.encodeIfPresent(previewFrameTimeCode, forKey: "previewFrameTimeCode") + } } public struct Relationships: Codable { @@ -67,6 +87,16 @@ public struct AppEventVideoClipCreateRequest: Codable, RequestBody { self.appEventLocalization = appEventLocalization } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appEventLocalization = try container.decode(AppEventLocalization.self, forKey: "appEventLocalization") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(appEventLocalization, forKey: "appEventLocalization") + } + public struct AppEventLocalization: Codable { public let data: Data @@ -74,6 +104,16 @@ public struct AppEventVideoClipCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "appEventLocalizations" } @@ -83,22 +123,17 @@ public struct AppEventVideoClipCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppEventVideoClipResponse.swift b/Sources/Bagbutik-Models/AppStore/AppEventVideoClipResponse.swift index c23695f29..76a92265e 100644 --- a/Sources/Bagbutik-Models/AppStore/AppEventVideoClipResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppEventVideoClipResponse.swift @@ -14,4 +14,18 @@ public struct AppEventVideoClipResponse: Codable { self.included = included self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AppEventVideoClip.self, forKey: "data") + included = try container.decodeIfPresent([AppEventLocalization].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/AppStore/AppEventVideoClipUpdateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppEventVideoClipUpdateRequest.swift index 3c786f200..b2171d72a 100644 --- a/Sources/Bagbutik-Models/AppStore/AppEventVideoClipUpdateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppEventVideoClipUpdateRequest.swift @@ -8,6 +8,16 @@ public struct AppEventVideoClipUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "appEventVideoClips" } @@ -21,25 +31,19 @@ public struct AppEventVideoClipUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } public struct Attributes: Codable { @@ -52,6 +56,18 @@ public struct AppEventVideoClipUpdateRequest: Codable, RequestBody { self.previewFrameTimeCode = previewFrameTimeCode self.uploaded = uploaded } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + previewFrameTimeCode = try container.decodeIfPresent(String.self, forKey: "previewFrameTimeCode") + uploaded = try container.decodeIfPresent(Bool.self, forKey: "uploaded") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(previewFrameTimeCode, forKey: "previewFrameTimeCode") + try container.encodeIfPresent(uploaded, forKey: "uploaded") + } } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppEventVideoClipsResponse.swift b/Sources/Bagbutik-Models/AppStore/AppEventVideoClipsResponse.swift index 56754532e..f9ebcab53 100644 --- a/Sources/Bagbutik-Models/AppStore/AppEventVideoClipsResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppEventVideoClipsResponse.swift @@ -19,4 +19,20 @@ public struct AppEventVideoClipsResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([AppEventVideoClip].self, forKey: "data") + included = try container.decodeIfPresent([AppEventLocalization].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/AppStore/AppEventsResponse.swift b/Sources/Bagbutik-Models/AppStore/AppEventsResponse.swift index 88bfeb0fd..a6ee37e9a 100644 --- a/Sources/Bagbutik-Models/AppStore/AppEventsResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppEventsResponse.swift @@ -19,4 +19,20 @@ public struct AppEventsResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([AppEvent].self, forKey: "data") + included = try container.decodeIfPresent([AppEventLocalization].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/AppStore/AppInfo.swift b/Sources/Bagbutik-Models/AppStore/AppInfo.swift index af4feceb1..7a310a4e7 100644 --- a/Sources/Bagbutik-Models/AppStore/AppInfo.swift +++ b/Sources/Bagbutik-Models/AppStore/AppInfo.swift @@ -32,31 +32,23 @@ public struct AppInfo: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -107,6 +99,26 @@ public struct AppInfo: Codable, Identifiable { self.state = state } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appStoreAgeRating = try container.decodeIfPresent(AppStoreAgeRating.self, forKey: "appStoreAgeRating") + appStoreState = try container.decodeIfPresent(AppStoreVersionState.self, forKey: "appStoreState") + brazilAgeRating = try container.decodeIfPresent(BrazilAgeRating.self, forKey: "brazilAgeRating") + brazilAgeRatingV2 = try container.decodeIfPresent(BrazilAgeRatingV2.self, forKey: "brazilAgeRatingV2") + kidsAgeBand = try container.decodeIfPresent(KidsAgeBand.self, forKey: "kidsAgeBand") + state = try container.decodeIfPresent(State.self, forKey: "state") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(appStoreAgeRating, forKey: "appStoreAgeRating") + try container.encodeIfPresent(appStoreState, forKey: "appStoreState") + try container.encodeIfPresent(brazilAgeRating, forKey: "brazilAgeRating") + try container.encodeIfPresent(brazilAgeRatingV2, forKey: "brazilAgeRatingV2") + try container.encodeIfPresent(kidsAgeBand, forKey: "kidsAgeBand") + try container.encodeIfPresent(state, forKey: "state") + } + public enum BrazilAgeRatingV2: String, Codable, CaseIterable { case officialEighteen = "OFFICIAL_EIGHTEEN" case officialFourteen = "OFFICIAL_FOURTEEN" @@ -175,6 +187,32 @@ public struct AppInfo: Codable, Identifiable { self.secondarySubcategoryTwo = secondarySubcategoryTwo } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + ageRatingDeclaration = try container.decodeIfPresent(AgeRatingDeclaration.self, forKey: "ageRatingDeclaration") + app = try container.decodeIfPresent(App.self, forKey: "app") + appInfoLocalizations = try container.decodeIfPresent(AppInfoLocalizations.self, forKey: "appInfoLocalizations") + primaryCategory = try container.decodeIfPresent(PrimaryCategory.self, forKey: "primaryCategory") + primarySubcategoryOne = try container.decodeIfPresent(PrimarySubcategoryOne.self, forKey: "primarySubcategoryOne") + primarySubcategoryTwo = try container.decodeIfPresent(PrimarySubcategoryTwo.self, forKey: "primarySubcategoryTwo") + secondaryCategory = try container.decodeIfPresent(SecondaryCategory.self, forKey: "secondaryCategory") + secondarySubcategoryOne = try container.decodeIfPresent(SecondarySubcategoryOne.self, forKey: "secondarySubcategoryOne") + secondarySubcategoryTwo = try container.decodeIfPresent(SecondarySubcategoryTwo.self, forKey: "secondarySubcategoryTwo") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(ageRatingDeclaration, forKey: "ageRatingDeclaration") + try container.encodeIfPresent(app, forKey: "app") + try container.encodeIfPresent(appInfoLocalizations, forKey: "appInfoLocalizations") + try container.encodeIfPresent(primaryCategory, forKey: "primaryCategory") + try container.encodeIfPresent(primarySubcategoryOne, forKey: "primarySubcategoryOne") + try container.encodeIfPresent(primarySubcategoryTwo, forKey: "primarySubcategoryTwo") + try container.encodeIfPresent(secondaryCategory, forKey: "secondaryCategory") + try container.encodeIfPresent(secondarySubcategoryOne, forKey: "secondarySubcategoryOne") + try container.encodeIfPresent(secondarySubcategoryTwo, forKey: "secondarySubcategoryTwo") + } + /** # AppInfo.Relationships.AgeRatingDeclaration The data and links that describe the relationship between the resources. @@ -194,20 +232,15 @@ public struct AppInfo: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -226,22 +259,17 @@ public struct AppInfo: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -264,20 +292,15 @@ public struct AppInfo: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -301,20 +324,15 @@ public struct AppInfo: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -335,22 +353,17 @@ public struct AppInfo: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -375,20 +388,15 @@ public struct AppInfo: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -415,23 +423,17 @@ public struct AppInfo: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } /** @@ -452,22 +454,17 @@ public struct AppInfo: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -492,20 +489,15 @@ public struct AppInfo: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -529,20 +521,15 @@ public struct AppInfo: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -563,22 +550,17 @@ public struct AppInfo: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -603,20 +585,15 @@ public struct AppInfo: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -640,20 +617,15 @@ public struct AppInfo: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -674,22 +646,17 @@ public struct AppInfo: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -714,20 +681,15 @@ public struct AppInfo: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -751,20 +713,15 @@ public struct AppInfo: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -785,22 +742,17 @@ public struct AppInfo: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -825,20 +777,15 @@ public struct AppInfo: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -862,20 +809,15 @@ public struct AppInfo: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -896,22 +838,17 @@ public struct AppInfo: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -936,20 +873,15 @@ public struct AppInfo: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -973,20 +905,15 @@ public struct AppInfo: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -1007,22 +934,17 @@ public struct AppInfo: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -1047,20 +969,15 @@ public struct AppInfo: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -1084,20 +1001,15 @@ public struct AppInfo: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -1118,22 +1030,17 @@ public struct AppInfo: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -1158,20 +1065,15 @@ public struct AppInfo: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppInfoLocalization.swift b/Sources/Bagbutik-Models/AppStore/AppInfoLocalization.swift index 958bbaf4f..ded0b4509 100644 --- a/Sources/Bagbutik-Models/AppStore/AppInfoLocalization.swift +++ b/Sources/Bagbutik-Models/AppStore/AppInfoLocalization.swift @@ -27,31 +27,23 @@ public struct AppInfoLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -83,6 +75,26 @@ public struct AppInfoLocalization: Codable, Identifiable { self.privacyPolicyUrl = privacyPolicyUrl self.subtitle = subtitle } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + locale = try container.decodeIfPresent(String.self, forKey: "locale") + name = try container.decodeIfPresent(String.self, forKey: "name") + privacyChoicesUrl = try container.decodeIfPresent(String.self, forKey: "privacyChoicesUrl") + privacyPolicyText = try container.decodeIfPresent(String.self, forKey: "privacyPolicyText") + privacyPolicyUrl = try container.decodeIfPresent(String.self, forKey: "privacyPolicyUrl") + subtitle = try container.decodeIfPresent(String.self, forKey: "subtitle") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(locale, forKey: "locale") + try container.encodeIfPresent(name, forKey: "name") + try container.encodeIfPresent(privacyChoicesUrl, forKey: "privacyChoicesUrl") + try container.encodeIfPresent(privacyPolicyText, forKey: "privacyPolicyText") + try container.encodeIfPresent(privacyPolicyUrl, forKey: "privacyPolicyUrl") + try container.encodeIfPresent(subtitle, forKey: "subtitle") + } } /** @@ -99,6 +111,16 @@ public struct AppInfoLocalization: Codable, Identifiable { self.appInfo = appInfo } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appInfo = try container.decodeIfPresent(AppInfo.self, forKey: "appInfo") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(appInfo, forKey: "appInfo") + } + /** # AppInfoLocalization.Relationships.AppInfo The data and links that describe the relationship between the resources. @@ -118,20 +140,15 @@ public struct AppInfoLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -150,22 +167,17 @@ public struct AppInfoLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -188,20 +200,15 @@ public struct AppInfoLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppInfoLocalizationCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppInfoLocalizationCreateRequest.swift index 8739b6cdd..ccffc6676 100644 --- a/Sources/Bagbutik-Models/AppStore/AppInfoLocalizationCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppInfoLocalizationCreateRequest.swift @@ -15,6 +15,16 @@ public struct AppInfoLocalizationCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AppInfoLocalizationCreateRequest.Data The data element of the request body. @@ -35,25 +45,19 @@ public struct AppInfoLocalizationCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } /** @@ -85,6 +89,26 @@ public struct AppInfoLocalizationCreateRequest: Codable, RequestBody { self.privacyPolicyUrl = privacyPolicyUrl self.subtitle = subtitle } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + locale = try container.decode(String.self, forKey: "locale") + name = try container.decodeIfPresent(String.self, forKey: "name") + privacyChoicesUrl = try container.decodeIfPresent(String.self, forKey: "privacyChoicesUrl") + privacyPolicyText = try container.decodeIfPresent(String.self, forKey: "privacyPolicyText") + privacyPolicyUrl = try container.decodeIfPresent(String.self, forKey: "privacyPolicyUrl") + subtitle = try container.decodeIfPresent(String.self, forKey: "subtitle") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(locale, forKey: "locale") + try container.encodeIfPresent(name, forKey: "name") + try container.encodeIfPresent(privacyChoicesUrl, forKey: "privacyChoicesUrl") + try container.encodeIfPresent(privacyPolicyText, forKey: "privacyPolicyText") + try container.encodeIfPresent(privacyPolicyUrl, forKey: "privacyPolicyUrl") + try container.encodeIfPresent(subtitle, forKey: "subtitle") + } } /** @@ -101,6 +125,16 @@ public struct AppInfoLocalizationCreateRequest: Codable, RequestBody { self.appInfo = appInfo } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appInfo = try container.decode(AppInfo.self, forKey: "appInfo") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(appInfo, forKey: "appInfo") + } + /** # AppInfoLocalizationCreateRequest.Data.Relationships.AppInfo The relationships to other resources that you can set with this request. @@ -115,6 +149,16 @@ public struct AppInfoLocalizationCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AppInfoLocalizationCreateRequest.Data.Relationships.AppInfo.Data The type and ID of the resource that you're relating with the resource you're creating. @@ -131,22 +175,17 @@ public struct AppInfoLocalizationCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppInfoLocalizationResponse.swift b/Sources/Bagbutik-Models/AppStore/AppInfoLocalizationResponse.swift index d629388ef..6137efa87 100644 --- a/Sources/Bagbutik-Models/AppStore/AppInfoLocalizationResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppInfoLocalizationResponse.swift @@ -21,4 +21,18 @@ public struct AppInfoLocalizationResponse: Codable { self.included = included self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AppInfoLocalization.self, forKey: "data") + included = try container.decodeIfPresent([AppInfo].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/AppStore/AppInfoLocalizationUpdateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppInfoLocalizationUpdateRequest.swift index 6ce8a2fc8..f00013ed0 100644 --- a/Sources/Bagbutik-Models/AppStore/AppInfoLocalizationUpdateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppInfoLocalizationUpdateRequest.swift @@ -15,6 +15,16 @@ public struct AppInfoLocalizationUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AppInfoLocalizationUpdateRequest.Data The data element of the request body. @@ -35,25 +45,19 @@ public struct AppInfoLocalizationUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } /** @@ -82,6 +86,24 @@ public struct AppInfoLocalizationUpdateRequest: Codable, RequestBody { self.privacyPolicyUrl = privacyPolicyUrl self.subtitle = subtitle } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + name = try container.decodeIfPresent(String.self, forKey: "name") + privacyChoicesUrl = try container.decodeIfPresent(String.self, forKey: "privacyChoicesUrl") + privacyPolicyText = try container.decodeIfPresent(String.self, forKey: "privacyPolicyText") + privacyPolicyUrl = try container.decodeIfPresent(String.self, forKey: "privacyPolicyUrl") + subtitle = try container.decodeIfPresent(String.self, forKey: "subtitle") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(name, forKey: "name") + try container.encodeIfPresent(privacyChoicesUrl, forKey: "privacyChoicesUrl") + try container.encodeIfPresent(privacyPolicyText, forKey: "privacyPolicyText") + try container.encodeIfPresent(privacyPolicyUrl, forKey: "privacyPolicyUrl") + try container.encodeIfPresent(subtitle, forKey: "subtitle") + } } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppInfoLocalizationsResponse.swift b/Sources/Bagbutik-Models/AppStore/AppInfoLocalizationsResponse.swift index ab03ff772..0edfaddd0 100644 --- a/Sources/Bagbutik-Models/AppStore/AppInfoLocalizationsResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppInfoLocalizationsResponse.swift @@ -26,4 +26,20 @@ public struct AppInfoLocalizationsResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([AppInfoLocalization].self, forKey: "data") + included = try container.decodeIfPresent([AppInfo].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/AppStore/AppInfoResponse.swift b/Sources/Bagbutik-Models/AppStore/AppInfoResponse.swift index 013daf71f..c3a06a34c 100644 --- a/Sources/Bagbutik-Models/AppStore/AppInfoResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppInfoResponse.swift @@ -24,6 +24,20 @@ public struct AppInfoResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AppInfo.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getAgeRatingDeclaration() -> AgeRatingDeclaration? { included?.compactMap { relationship -> AgeRatingDeclaration? in guard case let .ageRatingDeclaration(ageRatingDeclaration) = relationship else { return nil } @@ -125,9 +139,5 @@ public struct AppInfoResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppInfoUpdateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppInfoUpdateRequest.swift index 980cc7f13..ff9a41aa8 100644 --- a/Sources/Bagbutik-Models/AppStore/AppInfoUpdateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppInfoUpdateRequest.swift @@ -16,6 +16,16 @@ public struct AppInfoUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AppInfoUpdateRequest.Data The data element of the request body. @@ -39,25 +49,19 @@ public struct AppInfoUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case id - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -90,6 +94,26 @@ public struct AppInfoUpdateRequest: Codable, RequestBody { self.secondarySubcategoryTwo = secondarySubcategoryTwo } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + primaryCategory = try container.decodeIfPresent(PrimaryCategory.self, forKey: "primaryCategory") + primarySubcategoryOne = try container.decodeIfPresent(PrimarySubcategoryOne.self, forKey: "primarySubcategoryOne") + primarySubcategoryTwo = try container.decodeIfPresent(PrimarySubcategoryTwo.self, forKey: "primarySubcategoryTwo") + secondaryCategory = try container.decodeIfPresent(SecondaryCategory.self, forKey: "secondaryCategory") + secondarySubcategoryOne = try container.decodeIfPresent(SecondarySubcategoryOne.self, forKey: "secondarySubcategoryOne") + secondarySubcategoryTwo = try container.decodeIfPresent(SecondarySubcategoryTwo.self, forKey: "secondarySubcategoryTwo") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(primaryCategory, forKey: "primaryCategory") + try container.encodeIfPresent(primarySubcategoryOne, forKey: "primarySubcategoryOne") + try container.encodeIfPresent(primarySubcategoryTwo, forKey: "primarySubcategoryTwo") + try container.encodeIfPresent(secondaryCategory, forKey: "secondaryCategory") + try container.encodeIfPresent(secondarySubcategoryOne, forKey: "secondarySubcategoryOne") + try container.encodeIfPresent(secondarySubcategoryTwo, forKey: "secondarySubcategoryTwo") + } + /** # AppInfoUpdateRequest.Data.Relationships.PrimaryCategory The data and links that describe the relationship between the resources. @@ -105,17 +129,13 @@ public struct AppInfoUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } /** @@ -136,22 +156,17 @@ public struct AppInfoUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -171,17 +186,13 @@ public struct AppInfoUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } /** @@ -202,22 +213,17 @@ public struct AppInfoUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -237,17 +243,13 @@ public struct AppInfoUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } /** @@ -268,22 +270,17 @@ public struct AppInfoUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -303,17 +300,13 @@ public struct AppInfoUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } /** @@ -334,22 +327,17 @@ public struct AppInfoUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -369,17 +357,13 @@ public struct AppInfoUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } /** @@ -400,22 +384,17 @@ public struct AppInfoUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -435,17 +414,13 @@ public struct AppInfoUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } /** @@ -466,22 +441,17 @@ public struct AppInfoUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppInfosResponse.swift b/Sources/Bagbutik-Models/AppStore/AppInfosResponse.swift index f1db0da78..1b7636118 100644 --- a/Sources/Bagbutik-Models/AppStore/AppInfosResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppInfosResponse.swift @@ -30,6 +30,22 @@ public struct AppInfosResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([AppInfo].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getAgeRatingDeclaration(for appInfo: AppInfo) -> AgeRatingDeclaration? { included?.compactMap { relationship -> AgeRatingDeclaration? in guard case let .ageRatingDeclaration(ageRatingDeclaration) = relationship else { return nil } @@ -131,9 +147,5 @@ public struct AppInfosResponse: Codable, PagedResponse { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppMediaAssetState.swift b/Sources/Bagbutik-Models/AppStore/AppMediaAssetState.swift index f4552e4f0..e4bacab5c 100644 --- a/Sources/Bagbutik-Models/AppStore/AppMediaAssetState.swift +++ b/Sources/Bagbutik-Models/AppStore/AppMediaAssetState.swift @@ -22,6 +22,20 @@ public struct AppMediaAssetState: Codable { self.warnings = warnings } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + errors = try container.decodeIfPresent([AppMediaStateError].self, forKey: "errors") + state = try container.decodeIfPresent(State.self, forKey: "state") + warnings = try container.decodeIfPresent([AppMediaStateError].self, forKey: "warnings") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(errors, forKey: "errors") + try container.encodeIfPresent(state, forKey: "state") + try container.encodeIfPresent(warnings, forKey: "warnings") + } + public enum State: String, Codable, CaseIterable { case awaitingUpload = "AWAITING_UPLOAD" case complete = "COMPLETE" diff --git a/Sources/Bagbutik-Models/AppStore/AppMediaStateError.swift b/Sources/Bagbutik-Models/AppStore/AppMediaStateError.swift index fa01f38fe..932cd199d 100644 --- a/Sources/Bagbutik-Models/AppStore/AppMediaStateError.swift +++ b/Sources/Bagbutik-Models/AppStore/AppMediaStateError.swift @@ -18,4 +18,16 @@ public struct AppMediaStateError: Codable { self.code = code self.description = description } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + code = try container.decodeIfPresent(String.self, forKey: "code") + description = try container.decodeIfPresent(String.self, forKey: "description") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(code, forKey: "code") + try container.encodeIfPresent(description, forKey: "description") + } } diff --git a/Sources/Bagbutik-Models/AppStore/AppPreOrder.swift b/Sources/Bagbutik-Models/AppStore/AppPreOrder.swift index ddfbbb655..de8d133de 100644 --- a/Sources/Bagbutik-Models/AppStore/AppPreOrder.swift +++ b/Sources/Bagbutik-Models/AppStore/AppPreOrder.swift @@ -27,31 +27,23 @@ public struct AppPreOrder: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -71,6 +63,18 @@ public struct AppPreOrder: Codable, Identifiable { self.appReleaseDate = appReleaseDate self.preOrderAvailableDate = preOrderAvailableDate } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appReleaseDate = try container.decodeIfPresent(String.self, forKey: "appReleaseDate") + preOrderAvailableDate = try container.decodeIfPresent(String.self, forKey: "preOrderAvailableDate") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(appReleaseDate, forKey: "appReleaseDate") + try container.encodeIfPresent(preOrderAvailableDate, forKey: "preOrderAvailableDate") + } } /** @@ -87,6 +91,16 @@ public struct AppPreOrder: Codable, Identifiable { self.app = app } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + app = try container.decodeIfPresent(App.self, forKey: "app") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(app, forKey: "app") + } + /** # AppPreOrder.Relationships.App The data and links that describe the relationship between the resources. @@ -106,20 +120,15 @@ public struct AppPreOrder: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -138,22 +147,17 @@ public struct AppPreOrder: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -176,20 +180,15 @@ public struct AppPreOrder: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppPreOrderCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppPreOrderCreateRequest.swift index 63901eb3c..6d2b3acfc 100644 --- a/Sources/Bagbutik-Models/AppStore/AppPreOrderCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppPreOrderCreateRequest.swift @@ -15,6 +15,16 @@ public struct AppPreOrderCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AppPreOrderCreateRequest.Data The data element of the request body. @@ -35,25 +45,19 @@ public struct AppPreOrderCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } /** @@ -69,6 +73,16 @@ public struct AppPreOrderCreateRequest: Codable, RequestBody { public init(appReleaseDate: String? = nil) { self.appReleaseDate = appReleaseDate } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appReleaseDate = try container.decodeIfPresent(String.self, forKey: "appReleaseDate") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(appReleaseDate, forKey: "appReleaseDate") + } } /** @@ -85,6 +99,16 @@ public struct AppPreOrderCreateRequest: Codable, RequestBody { self.app = app } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + app = try container.decode(App.self, forKey: "app") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(app, forKey: "app") + } + /** # AppPreOrderCreateRequest.Data.Relationships.App The relationships to other resources that you can set with this request. @@ -99,6 +123,16 @@ public struct AppPreOrderCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AppPreOrderCreateRequest.Data.Relationships.App.Data The type and ID of the resource that you're relating with the resource you're creating. @@ -115,22 +149,17 @@ public struct AppPreOrderCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppPreOrderResponse.swift b/Sources/Bagbutik-Models/AppStore/AppPreOrderResponse.swift index 6dbc9a08d..cee074b8a 100644 --- a/Sources/Bagbutik-Models/AppStore/AppPreOrderResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppPreOrderResponse.swift @@ -21,4 +21,18 @@ public struct AppPreOrderResponse: Codable { self.included = included self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AppPreOrder.self, forKey: "data") + included = try container.decodeIfPresent([App].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/AppStore/AppPreOrderUpdateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppPreOrderUpdateRequest.swift index 8a5954c0a..75b6d6882 100644 --- a/Sources/Bagbutik-Models/AppStore/AppPreOrderUpdateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppPreOrderUpdateRequest.swift @@ -15,6 +15,16 @@ public struct AppPreOrderUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AppPreOrderUpdateRequest.Data The data element of the request body. @@ -35,25 +45,19 @@ public struct AppPreOrderUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } /** @@ -69,6 +73,16 @@ public struct AppPreOrderUpdateRequest: Codable, RequestBody { public init(appReleaseDate: String? = nil) { self.appReleaseDate = appReleaseDate } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appReleaseDate = try container.decodeIfPresent(String.self, forKey: "appReleaseDate") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(appReleaseDate, forKey: "appReleaseDate") + } } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppPreOrderWithoutIncludesResponse.swift b/Sources/Bagbutik-Models/AppStore/AppPreOrderWithoutIncludesResponse.swift index 3acc822eb..47a010f4d 100644 --- a/Sources/Bagbutik-Models/AppStore/AppPreOrderWithoutIncludesResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppPreOrderWithoutIncludesResponse.swift @@ -11,4 +11,16 @@ public struct AppPreOrderWithoutIncludesResponse: Codable { self.data = data self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AppPreOrder.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/AppStore/AppPreview.swift b/Sources/Bagbutik-Models/AppStore/AppPreview.swift index 04140fc48..77fb62ab8 100644 --- a/Sources/Bagbutik-Models/AppStore/AppPreview.swift +++ b/Sources/Bagbutik-Models/AppStore/AppPreview.swift @@ -27,31 +27,23 @@ public struct AppPreview: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -92,6 +84,32 @@ public struct AppPreview: Codable, Identifiable { self.uploadOperations = uploadOperations self.videoUrl = videoUrl } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + assetDeliveryState = try container.decodeIfPresent(AppMediaAssetState.self, forKey: "assetDeliveryState") + fileName = try container.decodeIfPresent(String.self, forKey: "fileName") + fileSize = try container.decodeIfPresent(Int.self, forKey: "fileSize") + mimeType = try container.decodeIfPresent(String.self, forKey: "mimeType") + previewFrameTimeCode = try container.decodeIfPresent(String.self, forKey: "previewFrameTimeCode") + previewImage = try container.decodeIfPresent(ImageAsset.self, forKey: "previewImage") + sourceFileChecksum = try container.decodeIfPresent(String.self, forKey: "sourceFileChecksum") + uploadOperations = try container.decodeIfPresent([UploadOperation].self, forKey: "uploadOperations") + videoUrl = try container.decodeIfPresent(String.self, forKey: "videoUrl") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(assetDeliveryState, forKey: "assetDeliveryState") + try container.encodeIfPresent(fileName, forKey: "fileName") + try container.encodeIfPresent(fileSize, forKey: "fileSize") + try container.encodeIfPresent(mimeType, forKey: "mimeType") + try container.encodeIfPresent(previewFrameTimeCode, forKey: "previewFrameTimeCode") + try container.encodeIfPresent(previewImage, forKey: "previewImage") + try container.encodeIfPresent(sourceFileChecksum, forKey: "sourceFileChecksum") + try container.encodeIfPresent(uploadOperations, forKey: "uploadOperations") + try container.encodeIfPresent(videoUrl, forKey: "videoUrl") + } } /** @@ -108,6 +126,16 @@ public struct AppPreview: Codable, Identifiable { self.appPreviewSet = appPreviewSet } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appPreviewSet = try container.decodeIfPresent(AppPreviewSet.self, forKey: "appPreviewSet") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(appPreviewSet, forKey: "appPreviewSet") + } + /** # AppPreview.Relationships.AppPreviewSet The data and links that describe the relationship between the resources. @@ -127,20 +155,15 @@ public struct AppPreview: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -159,22 +182,17 @@ public struct AppPreview: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -197,20 +215,15 @@ public struct AppPreview: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppPreviewCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppPreviewCreateRequest.swift index dfa953f3b..1f5ac8b16 100644 --- a/Sources/Bagbutik-Models/AppStore/AppPreviewCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppPreviewCreateRequest.swift @@ -15,6 +15,16 @@ public struct AppPreviewCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AppPreviewCreateRequest.Data The data element of the request body. @@ -35,25 +45,19 @@ public struct AppPreviewCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } /** @@ -79,6 +83,22 @@ public struct AppPreviewCreateRequest: Codable, RequestBody { self.mimeType = mimeType self.previewFrameTimeCode = previewFrameTimeCode } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + fileName = try container.decode(String.self, forKey: "fileName") + fileSize = try container.decode(Int.self, forKey: "fileSize") + mimeType = try container.decodeIfPresent(String.self, forKey: "mimeType") + previewFrameTimeCode = try container.decodeIfPresent(String.self, forKey: "previewFrameTimeCode") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(fileName, forKey: "fileName") + try container.encode(fileSize, forKey: "fileSize") + try container.encodeIfPresent(mimeType, forKey: "mimeType") + try container.encodeIfPresent(previewFrameTimeCode, forKey: "previewFrameTimeCode") + } } /** @@ -95,6 +115,16 @@ public struct AppPreviewCreateRequest: Codable, RequestBody { self.appPreviewSet = appPreviewSet } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appPreviewSet = try container.decode(AppPreviewSet.self, forKey: "appPreviewSet") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(appPreviewSet, forKey: "appPreviewSet") + } + /** # AppPreviewCreateRequest.Data.Relationships.AppPreviewSet The relationships to other resources that you can set with this request. @@ -109,6 +139,16 @@ public struct AppPreviewCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AppPreviewCreateRequest.Data.Relationships.AppPreviewSet.Data The type and ID of the resource that you're relating with the resource you're creating. @@ -125,22 +165,17 @@ public struct AppPreviewCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppPreviewResponse.swift b/Sources/Bagbutik-Models/AppStore/AppPreviewResponse.swift index 5929422c2..f89d88115 100644 --- a/Sources/Bagbutik-Models/AppStore/AppPreviewResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppPreviewResponse.swift @@ -21,4 +21,18 @@ public struct AppPreviewResponse: Codable { self.included = included self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AppPreview.self, forKey: "data") + included = try container.decodeIfPresent([AppPreviewSet].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/AppStore/AppPreviewSet.swift b/Sources/Bagbutik-Models/AppStore/AppPreviewSet.swift index f72b0baf6..7cdcbda93 100644 --- a/Sources/Bagbutik-Models/AppStore/AppPreviewSet.swift +++ b/Sources/Bagbutik-Models/AppStore/AppPreviewSet.swift @@ -27,31 +27,23 @@ public struct AppPreviewSet: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -67,6 +59,16 @@ public struct AppPreviewSet: Codable, Identifiable { public init(previewType: PreviewType? = nil) { self.previewType = previewType } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + previewType = try container.decodeIfPresent(PreviewType.self, forKey: "previewType") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(previewType, forKey: "previewType") + } } /** @@ -93,6 +95,22 @@ public struct AppPreviewSet: Codable, Identifiable { self.appStoreVersionLocalization = appStoreVersionLocalization } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appCustomProductPageLocalization = try container.decodeIfPresent(AppCustomProductPageLocalization.self, forKey: "appCustomProductPageLocalization") + appPreviews = try container.decodeIfPresent(AppPreviews.self, forKey: "appPreviews") + appStoreVersionExperimentTreatmentLocalization = try container.decodeIfPresent(AppStoreVersionExperimentTreatmentLocalization.self, forKey: "appStoreVersionExperimentTreatmentLocalization") + appStoreVersionLocalization = try container.decodeIfPresent(AppStoreVersionLocalization.self, forKey: "appStoreVersionLocalization") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(appCustomProductPageLocalization, forKey: "appCustomProductPageLocalization") + try container.encodeIfPresent(appPreviews, forKey: "appPreviews") + try container.encodeIfPresent(appStoreVersionExperimentTreatmentLocalization, forKey: "appStoreVersionExperimentTreatmentLocalization") + try container.encodeIfPresent(appStoreVersionLocalization, forKey: "appStoreVersionLocalization") + } + public struct AppCustomProductPageLocalization: Codable { @NullCodable public var data: Data? public var links: Links? @@ -105,20 +123,15 @@ public struct AppPreviewSet: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -130,22 +143,17 @@ public struct AppPreviewSet: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -161,20 +169,15 @@ public struct AppPreviewSet: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -201,23 +204,17 @@ public struct AppPreviewSet: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } /** @@ -236,22 +233,17 @@ public struct AppPreviewSet: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -274,20 +266,15 @@ public struct AppPreviewSet: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -304,20 +291,15 @@ public struct AppPreviewSet: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -329,22 +311,17 @@ public struct AppPreviewSet: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -360,20 +337,15 @@ public struct AppPreviewSet: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -397,20 +369,15 @@ public struct AppPreviewSet: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -429,22 +396,17 @@ public struct AppPreviewSet: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -467,20 +429,15 @@ public struct AppPreviewSet: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppPreviewSetAppPreviewsLinkagesRequest.swift b/Sources/Bagbutik-Models/AppStore/AppPreviewSetAppPreviewsLinkagesRequest.swift index 768ceece0..142ca2673 100644 --- a/Sources/Bagbutik-Models/AppStore/AppPreviewSetAppPreviewsLinkagesRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppPreviewSetAppPreviewsLinkagesRequest.swift @@ -15,6 +15,16 @@ public struct AppPreviewSetAppPreviewsLinkagesRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AppPreviewSetAppPreviewsLinkagesRequest.Data The data element of the request body. @@ -31,22 +41,17 @@ public struct AppPreviewSetAppPreviewsLinkagesRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppPreviewSetAppPreviewsLinkagesResponse.swift b/Sources/Bagbutik-Models/AppStore/AppPreviewSetAppPreviewsLinkagesResponse.swift index a2cbdf4b8..ca99a29e6 100644 --- a/Sources/Bagbutik-Models/AppStore/AppPreviewSetAppPreviewsLinkagesResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppPreviewSetAppPreviewsLinkagesResponse.swift @@ -22,6 +22,20 @@ public struct AppPreviewSetAppPreviewsLinkagesResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + /** # AppPreviewSetAppPreviewsLinkagesResponse.Data The data element of the response body. @@ -38,22 +52,17 @@ public struct AppPreviewSetAppPreviewsLinkagesResponse: Codable, PagedResponse { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppPreviewSetCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppPreviewSetCreateRequest.swift index 21c243cb4..716519493 100644 --- a/Sources/Bagbutik-Models/AppStore/AppPreviewSetCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppPreviewSetCreateRequest.swift @@ -15,6 +15,16 @@ public struct AppPreviewSetCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AppPreviewSetCreateRequest.Data The data element of the request body. @@ -35,25 +45,19 @@ public struct AppPreviewSetCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -69,6 +73,16 @@ public struct AppPreviewSetCreateRequest: Codable, RequestBody { public init(previewType: PreviewType) { self.previewType = previewType } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + previewType = try container.decode(PreviewType.self, forKey: "previewType") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(previewType, forKey: "previewType") + } } /** @@ -92,6 +106,20 @@ public struct AppPreviewSetCreateRequest: Codable, RequestBody { self.appStoreVersionLocalization = appStoreVersionLocalization } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appCustomProductPageLocalization = try container.decodeIfPresent(AppCustomProductPageLocalization.self, forKey: "appCustomProductPageLocalization") + appStoreVersionExperimentTreatmentLocalization = try container.decodeIfPresent(AppStoreVersionExperimentTreatmentLocalization.self, forKey: "appStoreVersionExperimentTreatmentLocalization") + appStoreVersionLocalization = try container.decodeIfPresent(AppStoreVersionLocalization.self, forKey: "appStoreVersionLocalization") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(appCustomProductPageLocalization, forKey: "appCustomProductPageLocalization") + try container.encodeIfPresent(appStoreVersionExperimentTreatmentLocalization, forKey: "appStoreVersionExperimentTreatmentLocalization") + try container.encodeIfPresent(appStoreVersionLocalization, forKey: "appStoreVersionLocalization") + } + public struct AppCustomProductPageLocalization: Codable { @NullCodable public var data: Data? @@ -100,17 +128,13 @@ public struct AppPreviewSetCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } public struct Data: Codable, Identifiable { @@ -122,22 +146,17 @@ public struct AppPreviewSetCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -150,17 +169,13 @@ public struct AppPreviewSetCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } public struct Data: Codable, Identifiable { @@ -172,22 +187,17 @@ public struct AppPreviewSetCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -207,17 +217,13 @@ public struct AppPreviewSetCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } /** @@ -236,22 +242,17 @@ public struct AppPreviewSetCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppPreviewSetResponse.swift b/Sources/Bagbutik-Models/AppStore/AppPreviewSetResponse.swift index 64633180b..c7b22e043 100644 --- a/Sources/Bagbutik-Models/AppStore/AppPreviewSetResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppPreviewSetResponse.swift @@ -22,6 +22,20 @@ public struct AppPreviewSetResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AppPreviewSet.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getAppCustomProductPageLocalization() -> AppCustomProductPageLocalization? { included?.compactMap { relationship -> AppCustomProductPageLocalization? in guard case let .appCustomProductPageLocalization(appCustomProductPageLocalization) = relationship else { return nil } @@ -88,9 +102,5 @@ public struct AppPreviewSetResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppPreviewSetsResponse.swift b/Sources/Bagbutik-Models/AppStore/AppPreviewSetsResponse.swift index c869d8fea..885a17171 100644 --- a/Sources/Bagbutik-Models/AppStore/AppPreviewSetsResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppPreviewSetsResponse.swift @@ -27,6 +27,22 @@ public struct AppPreviewSetsResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([AppPreviewSet].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getAppCustomProductPageLocalization(for appPreviewSet: AppPreviewSet) -> AppCustomProductPageLocalization? { included?.compactMap { relationship -> AppCustomProductPageLocalization? in guard case let .appCustomProductPageLocalization(appCustomProductPageLocalization) = relationship else { return nil } @@ -93,9 +109,5 @@ public struct AppPreviewSetsResponse: Codable, PagedResponse { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppPreviewUpdateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppPreviewUpdateRequest.swift index a741965b9..a10aa61dc 100644 --- a/Sources/Bagbutik-Models/AppStore/AppPreviewUpdateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppPreviewUpdateRequest.swift @@ -15,6 +15,16 @@ public struct AppPreviewUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AppPreviewUpdateRequest.Data The data element of the request body. @@ -35,25 +45,19 @@ public struct AppPreviewUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } /** @@ -76,6 +80,20 @@ public struct AppPreviewUpdateRequest: Codable, RequestBody { self.sourceFileChecksum = sourceFileChecksum self.uploaded = uploaded } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + previewFrameTimeCode = try container.decodeIfPresent(String.self, forKey: "previewFrameTimeCode") + sourceFileChecksum = try container.decodeIfPresent(String.self, forKey: "sourceFileChecksum") + uploaded = try container.decodeIfPresent(Bool.self, forKey: "uploaded") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(previewFrameTimeCode, forKey: "previewFrameTimeCode") + try container.encodeIfPresent(sourceFileChecksum, forKey: "sourceFileChecksum") + try container.encodeIfPresent(uploaded, forKey: "uploaded") + } } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppPreviewsResponse.swift b/Sources/Bagbutik-Models/AppStore/AppPreviewsResponse.swift index 593973bd7..b7b4747ec 100644 --- a/Sources/Bagbutik-Models/AppStore/AppPreviewsResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppPreviewsResponse.swift @@ -26,4 +26,20 @@ public struct AppPreviewsResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([AppPreview].self, forKey: "data") + included = try container.decodeIfPresent([AppPreviewSet].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/AppStore/AppPrice.swift b/Sources/Bagbutik-Models/AppStore/AppPrice.swift index cc8c4e1c2..526e4b40a 100644 --- a/Sources/Bagbutik-Models/AppStore/AppPrice.swift +++ b/Sources/Bagbutik-Models/AppStore/AppPrice.swift @@ -28,28 +28,21 @@ public struct AppPrice: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -70,6 +63,18 @@ public struct AppPrice: Codable, Identifiable { self.priceTier = priceTier } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + app = try container.decodeIfPresent(App.self, forKey: "app") + priceTier = try container.decodeIfPresent(PriceTier.self, forKey: "priceTier") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(app, forKey: "app") + try container.encodeIfPresent(priceTier, forKey: "priceTier") + } + /** # AppPrice.Relationships.App The data and links that describe the relationship between the resources. @@ -89,20 +94,15 @@ public struct AppPrice: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -121,22 +121,17 @@ public struct AppPrice: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -159,20 +154,15 @@ public struct AppPrice: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -196,20 +186,15 @@ public struct AppPrice: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -228,22 +213,17 @@ public struct AppPrice: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -266,20 +246,15 @@ public struct AppPrice: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppPriceInlineCreate.swift b/Sources/Bagbutik-Models/AppStore/AppPriceInlineCreate.swift index 993a6a004..04734c9d9 100644 --- a/Sources/Bagbutik-Models/AppStore/AppPriceInlineCreate.swift +++ b/Sources/Bagbutik-Models/AppStore/AppPriceInlineCreate.swift @@ -17,21 +17,16 @@ public struct AppPriceInlineCreate: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decodeIfPresent(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decodeIfPresent(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(id, forKey: "id") + try container.encode(type, forKey: "type") } } diff --git a/Sources/Bagbutik-Models/AppStore/AppPricePoint.swift b/Sources/Bagbutik-Models/AppStore/AppPricePoint.swift index 37a26587f..42d7a1925 100644 --- a/Sources/Bagbutik-Models/AppStore/AppPricePoint.swift +++ b/Sources/Bagbutik-Models/AppStore/AppPricePoint.swift @@ -32,31 +32,23 @@ public struct AppPricePoint: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -76,6 +68,18 @@ public struct AppPricePoint: Codable, Identifiable { self.customerPrice = customerPrice self.proceeds = proceeds } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + customerPrice = try container.decodeIfPresent(String.self, forKey: "customerPrice") + proceeds = try container.decodeIfPresent(String.self, forKey: "proceeds") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(customerPrice, forKey: "customerPrice") + try container.encodeIfPresent(proceeds, forKey: "proceeds") + } } /** @@ -96,6 +100,18 @@ public struct AppPricePoint: Codable, Identifiable { self.territory = territory } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + priceTier = try container.decodeIfPresent(PriceTier.self, forKey: "priceTier") + territory = try container.decodeIfPresent(Territory.self, forKey: "territory") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(priceTier, forKey: "priceTier") + try container.encodeIfPresent(territory, forKey: "territory") + } + /** # AppPricePoint.Relationships.PriceTier The data and links that describe the relationship between the resources. @@ -115,20 +131,15 @@ public struct AppPricePoint: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -147,22 +158,17 @@ public struct AppPricePoint: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -185,20 +191,15 @@ public struct AppPricePoint: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -222,20 +223,15 @@ public struct AppPricePoint: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -254,22 +250,17 @@ public struct AppPricePoint: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -292,20 +283,15 @@ public struct AppPricePoint: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppPricePointResponse.swift b/Sources/Bagbutik-Models/AppStore/AppPricePointResponse.swift index a7937fbb0..3556241e3 100644 --- a/Sources/Bagbutik-Models/AppStore/AppPricePointResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppPricePointResponse.swift @@ -22,6 +22,20 @@ public struct AppPricePointResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AppPricePoint.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getPriceTier() -> AppPriceTier? { included?.compactMap { relationship -> AppPriceTier? in guard case let .appPriceTier(priceTier) = relationship else { return nil } @@ -59,9 +73,5 @@ public struct AppPricePointResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppPricePointV2.swift b/Sources/Bagbutik-Models/AppStore/AppPricePointV2.swift index 964876678..6c2f76782 100644 --- a/Sources/Bagbutik-Models/AppStore/AppPricePointV2.swift +++ b/Sources/Bagbutik-Models/AppStore/AppPricePointV2.swift @@ -32,31 +32,23 @@ public struct AppPricePointV2: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -78,6 +70,18 @@ public struct AppPricePointV2: Codable, Identifiable { self.customerPrice = customerPrice self.proceeds = proceeds } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + customerPrice = try container.decodeIfPresent(String.self, forKey: "customerPrice") + proceeds = try container.decodeIfPresent(String.self, forKey: "proceeds") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(customerPrice, forKey: "customerPrice") + try container.encodeIfPresent(proceeds, forKey: "proceeds") + } } /** @@ -101,6 +105,20 @@ public struct AppPricePointV2: Codable, Identifiable { self.territory = territory } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + app = try container.decodeIfPresent(App.self, forKey: "app") + priceTier = try container.decodeIfPresent(PriceTier.self, forKey: "priceTier") + territory = try container.decodeIfPresent(Territory.self, forKey: "territory") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(app, forKey: "app") + try container.encodeIfPresent(priceTier, forKey: "priceTier") + try container.encodeIfPresent(territory, forKey: "territory") + } + /** # AppPricePointV2.Relationships.App The data and links that describe the relationship between the resources. @@ -120,20 +138,15 @@ public struct AppPricePointV2: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -154,22 +167,17 @@ public struct AppPricePointV2: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -192,20 +200,15 @@ public struct AppPricePointV2: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -229,20 +232,15 @@ public struct AppPricePointV2: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -261,22 +259,17 @@ public struct AppPricePointV2: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -299,20 +292,15 @@ public struct AppPricePointV2: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -336,20 +324,15 @@ public struct AppPricePointV2: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -368,22 +351,17 @@ public struct AppPricePointV2: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -406,20 +384,15 @@ public struct AppPricePointV2: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppPricePointV3.swift b/Sources/Bagbutik-Models/AppStore/AppPricePointV3.swift index 147216ac1..e2576ef85 100644 --- a/Sources/Bagbutik-Models/AppStore/AppPricePointV3.swift +++ b/Sources/Bagbutik-Models/AppStore/AppPricePointV3.swift @@ -27,31 +27,23 @@ public struct AppPricePointV3: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -64,6 +56,18 @@ public struct AppPricePointV3: Codable, Identifiable { self.customerPrice = customerPrice self.proceeds = proceeds } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + customerPrice = try container.decodeIfPresent(String.self, forKey: "customerPrice") + proceeds = try container.decodeIfPresent(String.self, forKey: "proceeds") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(customerPrice, forKey: "customerPrice") + try container.encodeIfPresent(proceeds, forKey: "proceeds") + } } public struct Relationships: Codable { @@ -77,6 +81,18 @@ public struct AppPricePointV3: Codable, Identifiable { self.territory = territory } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + app = try container.decodeIfPresent(App.self, forKey: "app") + territory = try container.decodeIfPresent(Territory.self, forKey: "territory") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(app, forKey: "app") + try container.encodeIfPresent(territory, forKey: "territory") + } + public struct App: Codable { @NullCodable public var data: Data? public var links: Links? @@ -89,20 +105,15 @@ public struct AppPricePointV3: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -114,22 +125,17 @@ public struct AppPricePointV3: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -145,20 +151,15 @@ public struct AppPricePointV3: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -175,20 +176,15 @@ public struct AppPricePointV3: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -200,22 +196,17 @@ public struct AppPricePointV3: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -231,20 +222,15 @@ public struct AppPricePointV3: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppPricePointV3Response.swift b/Sources/Bagbutik-Models/AppStore/AppPricePointV3Response.swift index 6f58109e4..ae28b6839 100644 --- a/Sources/Bagbutik-Models/AppStore/AppPricePointV3Response.swift +++ b/Sources/Bagbutik-Models/AppStore/AppPricePointV3Response.swift @@ -15,6 +15,20 @@ public struct AppPricePointV3Response: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AppPricePointV3.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getApp() -> App? { included?.compactMap { relationship -> App? in guard case let .app(app) = relationship else { return nil } @@ -52,9 +66,5 @@ public struct AppPricePointV3Response: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppPricePointsResponse.swift b/Sources/Bagbutik-Models/AppStore/AppPricePointsResponse.swift index 634fa70a8..4924aa14a 100644 --- a/Sources/Bagbutik-Models/AppStore/AppPricePointsResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppPricePointsResponse.swift @@ -27,6 +27,22 @@ public struct AppPricePointsResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([AppPricePoint].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getPriceTier(for appPricePoint: AppPricePoint) -> AppPriceTier? { included?.compactMap { relationship -> AppPriceTier? in guard case let .appPriceTier(priceTier) = relationship else { return nil } @@ -64,9 +80,5 @@ public struct AppPricePointsResponse: Codable, PagedResponse { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppPricePointsV2Response.swift b/Sources/Bagbutik-Models/AppStore/AppPricePointsV2Response.swift index 5f93c7e5a..7458d5c68 100644 --- a/Sources/Bagbutik-Models/AppStore/AppPricePointsV2Response.swift +++ b/Sources/Bagbutik-Models/AppStore/AppPricePointsV2Response.swift @@ -31,6 +31,22 @@ public struct AppPricePointsV2Response: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([AppPricePointV2].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getApp(for appPricePointV2: AppPricePointV2) -> App? { included?.compactMap { relationship -> App? in guard case let .app(app) = relationship else { return nil } @@ -80,9 +96,5 @@ public struct AppPricePointsV2Response: Codable, PagedResponse { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppPricePointsV3Response.swift b/Sources/Bagbutik-Models/AppStore/AppPricePointsV3Response.swift index db54baac7..e1b72477c 100644 --- a/Sources/Bagbutik-Models/AppStore/AppPricePointsV3Response.swift +++ b/Sources/Bagbutik-Models/AppStore/AppPricePointsV3Response.swift @@ -20,6 +20,22 @@ public struct AppPricePointsV3Response: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([AppPricePointV3].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getApp(for appPricePointV3: AppPricePointV3) -> App? { included?.compactMap { relationship -> App? in guard case let .app(app) = relationship else { return nil } @@ -57,9 +73,5 @@ public struct AppPricePointsV3Response: Codable, PagedResponse { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppPriceResponse.swift b/Sources/Bagbutik-Models/AppStore/AppPriceResponse.swift index 7d3ae7a87..b7ac4413d 100644 --- a/Sources/Bagbutik-Models/AppStore/AppPriceResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppPriceResponse.swift @@ -25,6 +25,20 @@ public struct AppPriceResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AppPrice.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getApp() -> App? { included?.compactMap { relationship -> App? in guard case let .app(app) = relationship else { return nil } @@ -62,9 +76,5 @@ public struct AppPriceResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppPriceSchedule.swift b/Sources/Bagbutik-Models/AppStore/AppPriceSchedule.swift index df274038c..6f6ad4e53 100644 --- a/Sources/Bagbutik-Models/AppStore/AppPriceSchedule.swift +++ b/Sources/Bagbutik-Models/AppStore/AppPriceSchedule.swift @@ -17,28 +17,21 @@ public struct AppPriceSchedule: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Relationships: Codable { @@ -58,6 +51,22 @@ public struct AppPriceSchedule: Codable, Identifiable { self.manualPrices = manualPrices } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + app = try container.decodeIfPresent(App.self, forKey: "app") + automaticPrices = try container.decodeIfPresent(AutomaticPrices.self, forKey: "automaticPrices") + baseTerritory = try container.decodeIfPresent(BaseTerritory.self, forKey: "baseTerritory") + manualPrices = try container.decodeIfPresent(ManualPrices.self, forKey: "manualPrices") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(app, forKey: "app") + try container.encodeIfPresent(automaticPrices, forKey: "automaticPrices") + try container.encodeIfPresent(baseTerritory, forKey: "baseTerritory") + try container.encodeIfPresent(manualPrices, forKey: "manualPrices") + } + public struct App: Codable { @NullCodable public var data: Data? public var links: Links? @@ -70,20 +79,15 @@ public struct AppPriceSchedule: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -95,22 +99,17 @@ public struct AppPriceSchedule: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -126,20 +125,15 @@ public struct AppPriceSchedule: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -159,23 +153,17 @@ public struct AppPriceSchedule: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -187,22 +175,17 @@ public struct AppPriceSchedule: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -218,20 +201,15 @@ public struct AppPriceSchedule: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -248,20 +226,15 @@ public struct AppPriceSchedule: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -273,22 +246,17 @@ public struct AppPriceSchedule: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -304,20 +272,15 @@ public struct AppPriceSchedule: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -337,23 +300,17 @@ public struct AppPriceSchedule: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -365,22 +322,17 @@ public struct AppPriceSchedule: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -396,20 +348,15 @@ public struct AppPriceSchedule: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppPriceScheduleCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppPriceScheduleCreateRequest.swift index ad2fa28b4..b221433ec 100644 --- a/Sources/Bagbutik-Models/AppStore/AppPriceScheduleCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppPriceScheduleCreateRequest.swift @@ -12,6 +12,18 @@ public struct AppPriceScheduleCreateRequest: Codable, RequestBody { self.included = included } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + } + public struct Data: Codable { public var type: String { "appPriceSchedules" } public let relationships: Relationships @@ -21,22 +33,17 @@ public struct AppPriceScheduleCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(relationships, forKey: "relationships") } public struct Relationships: Codable { @@ -53,6 +60,20 @@ public struct AppPriceScheduleCreateRequest: Codable, RequestBody { self.manualPrices = manualPrices } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + app = try container.decode(App.self, forKey: "app") + baseTerritory = try container.decode(BaseTerritory.self, forKey: "baseTerritory") + manualPrices = try container.decode(ManualPrices.self, forKey: "manualPrices") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(app, forKey: "app") + try container.encode(baseTerritory, forKey: "baseTerritory") + try container.encode(manualPrices, forKey: "manualPrices") + } + public struct App: Codable { public let data: Data @@ -60,6 +81,16 @@ public struct AppPriceScheduleCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "apps" } @@ -69,22 +100,17 @@ public struct AppPriceScheduleCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -96,6 +122,16 @@ public struct AppPriceScheduleCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "territories" } @@ -105,22 +141,17 @@ public struct AppPriceScheduleCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -132,6 +163,16 @@ public struct AppPriceScheduleCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "appPrices" } @@ -141,22 +182,17 @@ public struct AppPriceScheduleCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -186,9 +222,5 @@ public struct AppPriceScheduleCreateRequest: Codable, RequestBody { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppPriceScheduleResponse.swift b/Sources/Bagbutik-Models/AppStore/AppPriceScheduleResponse.swift index 76fbcd834..fd714dd6a 100644 --- a/Sources/Bagbutik-Models/AppStore/AppPriceScheduleResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppPriceScheduleResponse.swift @@ -15,6 +15,20 @@ public struct AppPriceScheduleResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AppPriceSchedule.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getApp() -> App? { included?.compactMap { relationship -> App? in guard case let .app(app) = relationship else { return nil } @@ -81,9 +95,5 @@ public struct AppPriceScheduleResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppPriceTier.swift b/Sources/Bagbutik-Models/AppStore/AppPriceTier.swift index c4d8de8a0..05d7c131d 100644 --- a/Sources/Bagbutik-Models/AppStore/AppPriceTier.swift +++ b/Sources/Bagbutik-Models/AppStore/AppPriceTier.swift @@ -28,28 +28,21 @@ public struct AppPriceTier: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -70,6 +63,16 @@ public struct AppPriceTier: Codable, Identifiable { public init() {} + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + pricePoints = try container.decodeIfPresent(PricePoints.self, forKey: "pricePoints") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(pricePoints, forKey: "pricePoints") + } + /** # AppPriceTier.Relationships.PricePoints The data and links that describe the relationship between the resources. @@ -92,23 +95,17 @@ public struct AppPriceTier: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } /** @@ -127,22 +124,17 @@ public struct AppPriceTier: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -165,20 +157,15 @@ public struct AppPriceTier: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppPriceTierResponse.swift b/Sources/Bagbutik-Models/AppStore/AppPriceTierResponse.swift index 384e33887..fc03330fb 100644 --- a/Sources/Bagbutik-Models/AppStore/AppPriceTierResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppPriceTierResponse.swift @@ -24,4 +24,18 @@ public struct AppPriceTierResponse: Codable { self.included = included self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AppPriceTier.self, forKey: "data") + included = try container.decodeIfPresent([AppPricePoint].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/AppStore/AppPriceTiersResponse.swift b/Sources/Bagbutik-Models/AppStore/AppPriceTiersResponse.swift index 2c47da8c2..09e875ae0 100644 --- a/Sources/Bagbutik-Models/AppStore/AppPriceTiersResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppPriceTiersResponse.swift @@ -30,4 +30,20 @@ public struct AppPriceTiersResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([AppPriceTier].self, forKey: "data") + included = try container.decodeIfPresent([AppPricePoint].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/AppStore/AppPriceV2.swift b/Sources/Bagbutik-Models/AppStore/AppPriceV2.swift index cec4a4261..13a9f551d 100644 --- a/Sources/Bagbutik-Models/AppStore/AppPriceV2.swift +++ b/Sources/Bagbutik-Models/AppStore/AppPriceV2.swift @@ -20,31 +20,23 @@ public struct AppPriceV2: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -60,6 +52,20 @@ public struct AppPriceV2: Codable, Identifiable { self.manual = manual self.startDate = startDate } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + endDate = try container.decodeIfPresent(String.self, forKey: "endDate") + manual = try container.decodeIfPresent(Bool.self, forKey: "manual") + startDate = try container.decodeIfPresent(String.self, forKey: "startDate") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(endDate, forKey: "endDate") + try container.encodeIfPresent(manual, forKey: "manual") + try container.encodeIfPresent(startDate, forKey: "startDate") + } } public struct Relationships: Codable { @@ -73,6 +79,18 @@ public struct AppPriceV2: Codable, Identifiable { self.territory = territory } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appPricePoint = try container.decodeIfPresent(AppPricePoint.self, forKey: "appPricePoint") + territory = try container.decodeIfPresent(Territory.self, forKey: "territory") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(appPricePoint, forKey: "appPricePoint") + try container.encodeIfPresent(territory, forKey: "territory") + } + public struct AppPricePoint: Codable { @NullCodable public var data: Data? public var links: Links? @@ -85,20 +103,15 @@ public struct AppPriceV2: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -110,22 +123,17 @@ public struct AppPriceV2: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -141,20 +149,15 @@ public struct AppPriceV2: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -171,20 +174,15 @@ public struct AppPriceV2: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -196,22 +194,17 @@ public struct AppPriceV2: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -227,20 +220,15 @@ public struct AppPriceV2: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppPriceV2InlineCreate.swift b/Sources/Bagbutik-Models/AppStore/AppPriceV2InlineCreate.swift index 73ad02c01..be0487b8d 100644 --- a/Sources/Bagbutik-Models/AppStore/AppPriceV2InlineCreate.swift +++ b/Sources/Bagbutik-Models/AppStore/AppPriceV2InlineCreate.swift @@ -17,21 +17,16 @@ public struct AppPriceV2InlineCreate: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decodeIfPresent(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decodeIfPresent(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(id, forKey: "id") + try container.encode(type, forKey: "type") } } diff --git a/Sources/Bagbutik-Models/AppStore/AppPricesResponse.swift b/Sources/Bagbutik-Models/AppStore/AppPricesResponse.swift index 1fd6256a9..bc154a72a 100644 --- a/Sources/Bagbutik-Models/AppStore/AppPricesResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppPricesResponse.swift @@ -31,6 +31,22 @@ public struct AppPricesResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([AppPrice].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getApp(for appPrice: AppPrice) -> App? { included?.compactMap { relationship -> App? in guard case let .app(app) = relationship else { return nil } @@ -68,9 +84,5 @@ public struct AppPricesResponse: Codable, PagedResponse { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppPricesV2Response.swift b/Sources/Bagbutik-Models/AppStore/AppPricesV2Response.swift index 5cce2284d..e57b7b8ef 100644 --- a/Sources/Bagbutik-Models/AppStore/AppPricesV2Response.swift +++ b/Sources/Bagbutik-Models/AppStore/AppPricesV2Response.swift @@ -20,6 +20,22 @@ public struct AppPricesV2Response: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([AppPriceV2].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getAppPricePoint(for appPriceV2: AppPriceV2) -> AppPricePointV3? { included?.compactMap { relationship -> AppPricePointV3? in guard case let .appPricePointV3(appPricePoint) = relationship else { return nil } @@ -57,9 +73,5 @@ public struct AppPricesV2Response: Codable, PagedResponse { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppPromotedPurchasesLinkagesRequest.swift b/Sources/Bagbutik-Models/AppStore/AppPromotedPurchasesLinkagesRequest.swift index 74def1137..538d3136a 100644 --- a/Sources/Bagbutik-Models/AppStore/AppPromotedPurchasesLinkagesRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppPromotedPurchasesLinkagesRequest.swift @@ -8,6 +8,16 @@ public struct AppPromotedPurchasesLinkagesRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "promotedPurchases" } @@ -17,22 +27,17 @@ public struct AppPromotedPurchasesLinkagesRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppPromotedPurchasesLinkagesResponse.swift b/Sources/Bagbutik-Models/AppStore/AppPromotedPurchasesLinkagesResponse.swift index 072ee7f97..6b26f3181 100644 --- a/Sources/Bagbutik-Models/AppStore/AppPromotedPurchasesLinkagesResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppPromotedPurchasesLinkagesResponse.swift @@ -15,6 +15,20 @@ public struct AppPromotedPurchasesLinkagesResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "promotedPurchases" } @@ -24,22 +38,17 @@ public struct AppPromotedPurchasesLinkagesResponse: Codable, PagedResponse { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppResponse.swift b/Sources/Bagbutik-Models/AppStore/AppResponse.swift index 519c754d2..ada94cfe0 100644 --- a/Sources/Bagbutik-Models/AppStore/AppResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppResponse.swift @@ -24,6 +24,20 @@ public struct AppResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(App.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getAppClips() -> [AppClip] { guard let appClipIds = data.relationships?.appClips?.data?.map(\.id), let appClips = included?.compactMap({ relationship -> AppClip? in @@ -408,9 +422,5 @@ public struct AppResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppScreenshot.swift b/Sources/Bagbutik-Models/AppStore/AppScreenshot.swift index a548dc927..cd5c32fdc 100644 --- a/Sources/Bagbutik-Models/AppStore/AppScreenshot.swift +++ b/Sources/Bagbutik-Models/AppStore/AppScreenshot.swift @@ -27,31 +27,23 @@ public struct AppScreenshot: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -89,6 +81,30 @@ public struct AppScreenshot: Codable, Identifiable { self.sourceFileChecksum = sourceFileChecksum self.uploadOperations = uploadOperations } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + assetDeliveryState = try container.decodeIfPresent(AppMediaAssetState.self, forKey: "assetDeliveryState") + assetToken = try container.decodeIfPresent(String.self, forKey: "assetToken") + assetType = try container.decodeIfPresent(String.self, forKey: "assetType") + fileName = try container.decodeIfPresent(String.self, forKey: "fileName") + fileSize = try container.decodeIfPresent(Int.self, forKey: "fileSize") + imageAsset = try container.decodeIfPresent(ImageAsset.self, forKey: "imageAsset") + sourceFileChecksum = try container.decodeIfPresent(String.self, forKey: "sourceFileChecksum") + uploadOperations = try container.decodeIfPresent([UploadOperation].self, forKey: "uploadOperations") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(assetDeliveryState, forKey: "assetDeliveryState") + try container.encodeIfPresent(assetToken, forKey: "assetToken") + try container.encodeIfPresent(assetType, forKey: "assetType") + try container.encodeIfPresent(fileName, forKey: "fileName") + try container.encodeIfPresent(fileSize, forKey: "fileSize") + try container.encodeIfPresent(imageAsset, forKey: "imageAsset") + try container.encodeIfPresent(sourceFileChecksum, forKey: "sourceFileChecksum") + try container.encodeIfPresent(uploadOperations, forKey: "uploadOperations") + } } /** @@ -105,6 +121,16 @@ public struct AppScreenshot: Codable, Identifiable { self.appScreenshotSet = appScreenshotSet } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appScreenshotSet = try container.decodeIfPresent(AppScreenshotSet.self, forKey: "appScreenshotSet") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(appScreenshotSet, forKey: "appScreenshotSet") + } + /** # AppScreenshot.Relationships.AppScreenshotSet The data and links that describe the relationship between the resources. @@ -124,20 +150,15 @@ public struct AppScreenshot: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -156,22 +177,17 @@ public struct AppScreenshot: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -194,20 +210,15 @@ public struct AppScreenshot: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppScreenshotCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppScreenshotCreateRequest.swift index e2c6ccbf1..1dff5df08 100644 --- a/Sources/Bagbutik-Models/AppStore/AppScreenshotCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppScreenshotCreateRequest.swift @@ -15,6 +15,16 @@ public struct AppScreenshotCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AppScreenshotCreateRequest.Data The data element of the request body. @@ -35,25 +45,19 @@ public struct AppScreenshotCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } /** @@ -73,6 +77,18 @@ public struct AppScreenshotCreateRequest: Codable, RequestBody { self.fileName = fileName self.fileSize = fileSize } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + fileName = try container.decode(String.self, forKey: "fileName") + fileSize = try container.decode(Int.self, forKey: "fileSize") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(fileName, forKey: "fileName") + try container.encode(fileSize, forKey: "fileSize") + } } /** @@ -89,6 +105,16 @@ public struct AppScreenshotCreateRequest: Codable, RequestBody { self.appScreenshotSet = appScreenshotSet } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appScreenshotSet = try container.decode(AppScreenshotSet.self, forKey: "appScreenshotSet") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(appScreenshotSet, forKey: "appScreenshotSet") + } + /** # AppScreenshotCreateRequest.Data.Relationships.AppScreenshotSet The relationships to other resources that you can set with this request. @@ -103,6 +129,16 @@ public struct AppScreenshotCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AppScreenshotCreateRequest.Data.Relationships.AppScreenshotSet.Data The type and ID of the resource that you're relating with the resource you're creating. @@ -119,22 +155,17 @@ public struct AppScreenshotCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppScreenshotResponse.swift b/Sources/Bagbutik-Models/AppStore/AppScreenshotResponse.swift index 315818c8e..3ab62b384 100644 --- a/Sources/Bagbutik-Models/AppStore/AppScreenshotResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppScreenshotResponse.swift @@ -21,4 +21,18 @@ public struct AppScreenshotResponse: Codable { self.included = included self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AppScreenshot.self, forKey: "data") + included = try container.decodeIfPresent([AppScreenshotSet].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/AppStore/AppScreenshotSet.swift b/Sources/Bagbutik-Models/AppStore/AppScreenshotSet.swift index fb7f72d9a..0356f97a2 100644 --- a/Sources/Bagbutik-Models/AppStore/AppScreenshotSet.swift +++ b/Sources/Bagbutik-Models/AppStore/AppScreenshotSet.swift @@ -27,31 +27,23 @@ public struct AppScreenshotSet: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -67,6 +59,16 @@ public struct AppScreenshotSet: Codable, Identifiable { public init(screenshotDisplayType: ScreenshotDisplayType? = nil) { self.screenshotDisplayType = screenshotDisplayType } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + screenshotDisplayType = try container.decodeIfPresent(ScreenshotDisplayType.self, forKey: "screenshotDisplayType") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(screenshotDisplayType, forKey: "screenshotDisplayType") + } } /** @@ -93,6 +95,22 @@ public struct AppScreenshotSet: Codable, Identifiable { self.appStoreVersionLocalization = appStoreVersionLocalization } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appCustomProductPageLocalization = try container.decodeIfPresent(AppCustomProductPageLocalization.self, forKey: "appCustomProductPageLocalization") + appScreenshots = try container.decodeIfPresent(AppScreenshots.self, forKey: "appScreenshots") + appStoreVersionExperimentTreatmentLocalization = try container.decodeIfPresent(AppStoreVersionExperimentTreatmentLocalization.self, forKey: "appStoreVersionExperimentTreatmentLocalization") + appStoreVersionLocalization = try container.decodeIfPresent(AppStoreVersionLocalization.self, forKey: "appStoreVersionLocalization") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(appCustomProductPageLocalization, forKey: "appCustomProductPageLocalization") + try container.encodeIfPresent(appScreenshots, forKey: "appScreenshots") + try container.encodeIfPresent(appStoreVersionExperimentTreatmentLocalization, forKey: "appStoreVersionExperimentTreatmentLocalization") + try container.encodeIfPresent(appStoreVersionLocalization, forKey: "appStoreVersionLocalization") + } + public struct AppCustomProductPageLocalization: Codable { @NullCodable public var data: Data? public var links: Links? @@ -105,20 +123,15 @@ public struct AppScreenshotSet: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -130,22 +143,17 @@ public struct AppScreenshotSet: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -161,20 +169,15 @@ public struct AppScreenshotSet: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -201,23 +204,17 @@ public struct AppScreenshotSet: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } /** @@ -236,22 +233,17 @@ public struct AppScreenshotSet: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -274,20 +266,15 @@ public struct AppScreenshotSet: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -304,20 +291,15 @@ public struct AppScreenshotSet: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -329,22 +311,17 @@ public struct AppScreenshotSet: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -360,20 +337,15 @@ public struct AppScreenshotSet: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -397,20 +369,15 @@ public struct AppScreenshotSet: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -429,22 +396,17 @@ public struct AppScreenshotSet: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -467,20 +429,15 @@ public struct AppScreenshotSet: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppScreenshotSetAppScreenshotsLinkagesRequest.swift b/Sources/Bagbutik-Models/AppStore/AppScreenshotSetAppScreenshotsLinkagesRequest.swift index 79dbbccc0..ac42c7f74 100644 --- a/Sources/Bagbutik-Models/AppStore/AppScreenshotSetAppScreenshotsLinkagesRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppScreenshotSetAppScreenshotsLinkagesRequest.swift @@ -15,6 +15,16 @@ public struct AppScreenshotSetAppScreenshotsLinkagesRequest: Codable, RequestBod self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AppScreenshotSetAppScreenshotsLinkagesRequest.Data The data element of the request body. @@ -31,22 +41,17 @@ public struct AppScreenshotSetAppScreenshotsLinkagesRequest: Codable, RequestBod } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppScreenshotSetAppScreenshotsLinkagesResponse.swift b/Sources/Bagbutik-Models/AppStore/AppScreenshotSetAppScreenshotsLinkagesResponse.swift index e8f76eade..642c1b40b 100644 --- a/Sources/Bagbutik-Models/AppStore/AppScreenshotSetAppScreenshotsLinkagesResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppScreenshotSetAppScreenshotsLinkagesResponse.swift @@ -22,6 +22,20 @@ public struct AppScreenshotSetAppScreenshotsLinkagesResponse: Codable, PagedResp self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + /** # AppScreenshotSetAppScreenshotsLinkagesResponse.Data The data element of the response body. @@ -38,22 +52,17 @@ public struct AppScreenshotSetAppScreenshotsLinkagesResponse: Codable, PagedResp } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppScreenshotSetCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppScreenshotSetCreateRequest.swift index ad9a39901..29240d2bb 100644 --- a/Sources/Bagbutik-Models/AppStore/AppScreenshotSetCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppScreenshotSetCreateRequest.swift @@ -15,6 +15,16 @@ public struct AppScreenshotSetCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AppScreenshotSetCreateRequest.Data The data element of the request body. @@ -35,25 +45,19 @@ public struct AppScreenshotSetCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -69,6 +73,16 @@ public struct AppScreenshotSetCreateRequest: Codable, RequestBody { public init(screenshotDisplayType: ScreenshotDisplayType) { self.screenshotDisplayType = screenshotDisplayType } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + screenshotDisplayType = try container.decode(ScreenshotDisplayType.self, forKey: "screenshotDisplayType") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(screenshotDisplayType, forKey: "screenshotDisplayType") + } } /** @@ -92,6 +106,20 @@ public struct AppScreenshotSetCreateRequest: Codable, RequestBody { self.appStoreVersionLocalization = appStoreVersionLocalization } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appCustomProductPageLocalization = try container.decodeIfPresent(AppCustomProductPageLocalization.self, forKey: "appCustomProductPageLocalization") + appStoreVersionExperimentTreatmentLocalization = try container.decodeIfPresent(AppStoreVersionExperimentTreatmentLocalization.self, forKey: "appStoreVersionExperimentTreatmentLocalization") + appStoreVersionLocalization = try container.decodeIfPresent(AppStoreVersionLocalization.self, forKey: "appStoreVersionLocalization") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(appCustomProductPageLocalization, forKey: "appCustomProductPageLocalization") + try container.encodeIfPresent(appStoreVersionExperimentTreatmentLocalization, forKey: "appStoreVersionExperimentTreatmentLocalization") + try container.encodeIfPresent(appStoreVersionLocalization, forKey: "appStoreVersionLocalization") + } + public struct AppCustomProductPageLocalization: Codable { @NullCodable public var data: Data? @@ -100,17 +128,13 @@ public struct AppScreenshotSetCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } public struct Data: Codable, Identifiable { @@ -122,22 +146,17 @@ public struct AppScreenshotSetCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -150,17 +169,13 @@ public struct AppScreenshotSetCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } public struct Data: Codable, Identifiable { @@ -172,22 +187,17 @@ public struct AppScreenshotSetCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -207,17 +217,13 @@ public struct AppScreenshotSetCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } /** @@ -236,22 +242,17 @@ public struct AppScreenshotSetCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppScreenshotSetResponse.swift b/Sources/Bagbutik-Models/AppStore/AppScreenshotSetResponse.swift index ab363e0dd..17f72eb91 100644 --- a/Sources/Bagbutik-Models/AppStore/AppScreenshotSetResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppScreenshotSetResponse.swift @@ -22,6 +22,20 @@ public struct AppScreenshotSetResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AppScreenshotSet.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getAppCustomProductPageLocalization() -> AppCustomProductPageLocalization? { included?.compactMap { relationship -> AppCustomProductPageLocalization? in guard case let .appCustomProductPageLocalization(appCustomProductPageLocalization) = relationship else { return nil } @@ -88,9 +102,5 @@ public struct AppScreenshotSetResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppScreenshotSetsResponse.swift b/Sources/Bagbutik-Models/AppStore/AppScreenshotSetsResponse.swift index 226e78180..2c0eddfab 100644 --- a/Sources/Bagbutik-Models/AppStore/AppScreenshotSetsResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppScreenshotSetsResponse.swift @@ -27,6 +27,22 @@ public struct AppScreenshotSetsResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([AppScreenshotSet].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getAppCustomProductPageLocalization(for appScreenshotSet: AppScreenshotSet) -> AppCustomProductPageLocalization? { included?.compactMap { relationship -> AppCustomProductPageLocalization? in guard case let .appCustomProductPageLocalization(appCustomProductPageLocalization) = relationship else { return nil } @@ -93,9 +109,5 @@ public struct AppScreenshotSetsResponse: Codable, PagedResponse { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppScreenshotUpdateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppScreenshotUpdateRequest.swift index a65eb5a73..5efedff61 100644 --- a/Sources/Bagbutik-Models/AppStore/AppScreenshotUpdateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppScreenshotUpdateRequest.swift @@ -15,6 +15,16 @@ public struct AppScreenshotUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AppScreenshotUpdateRequest.Data The data element of the request body. @@ -35,25 +45,19 @@ public struct AppScreenshotUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } /** @@ -73,6 +77,18 @@ public struct AppScreenshotUpdateRequest: Codable, RequestBody { self.sourceFileChecksum = sourceFileChecksum self.uploaded = uploaded } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + sourceFileChecksum = try container.decodeIfPresent(String.self, forKey: "sourceFileChecksum") + uploaded = try container.decodeIfPresent(Bool.self, forKey: "uploaded") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(sourceFileChecksum, forKey: "sourceFileChecksum") + try container.encodeIfPresent(uploaded, forKey: "uploaded") + } } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppScreenshotsResponse.swift b/Sources/Bagbutik-Models/AppStore/AppScreenshotsResponse.swift index 4f0b7634f..a284fe378 100644 --- a/Sources/Bagbutik-Models/AppStore/AppScreenshotsResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppScreenshotsResponse.swift @@ -26,4 +26,20 @@ public struct AppScreenshotsResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([AppScreenshot].self, forKey: "data") + included = try container.decodeIfPresent([AppScreenshotSet].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/AppStore/AppStoreReviewAttachment.swift b/Sources/Bagbutik-Models/AppStore/AppStoreReviewAttachment.swift index 5838c58c4..8821d5184 100644 --- a/Sources/Bagbutik-Models/AppStore/AppStoreReviewAttachment.swift +++ b/Sources/Bagbutik-Models/AppStore/AppStoreReviewAttachment.swift @@ -27,31 +27,23 @@ public struct AppStoreReviewAttachment: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -80,6 +72,24 @@ public struct AppStoreReviewAttachment: Codable, Identifiable { self.sourceFileChecksum = sourceFileChecksum self.uploadOperations = uploadOperations } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + assetDeliveryState = try container.decodeIfPresent(AppMediaAssetState.self, forKey: "assetDeliveryState") + fileName = try container.decodeIfPresent(String.self, forKey: "fileName") + fileSize = try container.decodeIfPresent(Int.self, forKey: "fileSize") + sourceFileChecksum = try container.decodeIfPresent(String.self, forKey: "sourceFileChecksum") + uploadOperations = try container.decodeIfPresent([UploadOperation].self, forKey: "uploadOperations") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(assetDeliveryState, forKey: "assetDeliveryState") + try container.encodeIfPresent(fileName, forKey: "fileName") + try container.encodeIfPresent(fileSize, forKey: "fileSize") + try container.encodeIfPresent(sourceFileChecksum, forKey: "sourceFileChecksum") + try container.encodeIfPresent(uploadOperations, forKey: "uploadOperations") + } } /** @@ -96,6 +106,16 @@ public struct AppStoreReviewAttachment: Codable, Identifiable { self.appStoreReviewDetail = appStoreReviewDetail } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appStoreReviewDetail = try container.decodeIfPresent(AppStoreReviewDetail.self, forKey: "appStoreReviewDetail") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(appStoreReviewDetail, forKey: "appStoreReviewDetail") + } + /** # AppStoreReviewAttachment.Relationships.AppStoreReviewDetail The data and links that describe the relationship between the resources. @@ -115,20 +135,15 @@ public struct AppStoreReviewAttachment: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -147,22 +162,17 @@ public struct AppStoreReviewAttachment: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -185,20 +195,15 @@ public struct AppStoreReviewAttachment: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppStoreReviewAttachmentCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppStoreReviewAttachmentCreateRequest.swift index 567c73770..734c7d35d 100644 --- a/Sources/Bagbutik-Models/AppStore/AppStoreReviewAttachmentCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppStoreReviewAttachmentCreateRequest.swift @@ -15,6 +15,16 @@ public struct AppStoreReviewAttachmentCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AppStoreReviewAttachmentCreateRequest.Data The data element of the request body. @@ -35,25 +45,19 @@ public struct AppStoreReviewAttachmentCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } /** @@ -73,6 +77,18 @@ public struct AppStoreReviewAttachmentCreateRequest: Codable, RequestBody { self.fileName = fileName self.fileSize = fileSize } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + fileName = try container.decode(String.self, forKey: "fileName") + fileSize = try container.decode(Int.self, forKey: "fileSize") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(fileName, forKey: "fileName") + try container.encode(fileSize, forKey: "fileSize") + } } /** @@ -89,6 +105,16 @@ public struct AppStoreReviewAttachmentCreateRequest: Codable, RequestBody { self.appStoreReviewDetail = appStoreReviewDetail } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appStoreReviewDetail = try container.decode(AppStoreReviewDetail.self, forKey: "appStoreReviewDetail") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(appStoreReviewDetail, forKey: "appStoreReviewDetail") + } + /** # AppStoreReviewAttachmentCreateRequest.Data.Relationships.AppStoreReviewDetail The relationships to other resources that you can set with this request. @@ -103,6 +129,16 @@ public struct AppStoreReviewAttachmentCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AppStoreReviewAttachmentCreateRequest.Data.Relationships.AppStoreReviewDetail.Data The type and ID of the resource that you're relating with the resource you're creating. @@ -119,22 +155,17 @@ public struct AppStoreReviewAttachmentCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppStoreReviewAttachmentResponse.swift b/Sources/Bagbutik-Models/AppStore/AppStoreReviewAttachmentResponse.swift index b0a6480ba..ef5beeded 100644 --- a/Sources/Bagbutik-Models/AppStore/AppStoreReviewAttachmentResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppStoreReviewAttachmentResponse.swift @@ -21,4 +21,18 @@ public struct AppStoreReviewAttachmentResponse: Codable { self.included = included self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AppStoreReviewAttachment.self, forKey: "data") + included = try container.decodeIfPresent([AppStoreReviewDetail].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/AppStore/AppStoreReviewAttachmentUpdateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppStoreReviewAttachmentUpdateRequest.swift index ba327e05f..bf5fcf384 100644 --- a/Sources/Bagbutik-Models/AppStore/AppStoreReviewAttachmentUpdateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppStoreReviewAttachmentUpdateRequest.swift @@ -15,6 +15,16 @@ public struct AppStoreReviewAttachmentUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AppStoreReviewAttachmentUpdateRequest.Data The data element of the request body. @@ -35,25 +45,19 @@ public struct AppStoreReviewAttachmentUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } /** @@ -73,6 +77,18 @@ public struct AppStoreReviewAttachmentUpdateRequest: Codable, RequestBody { self.sourceFileChecksum = sourceFileChecksum self.uploaded = uploaded } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + sourceFileChecksum = try container.decodeIfPresent(String.self, forKey: "sourceFileChecksum") + uploaded = try container.decodeIfPresent(Bool.self, forKey: "uploaded") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(sourceFileChecksum, forKey: "sourceFileChecksum") + try container.encodeIfPresent(uploaded, forKey: "uploaded") + } } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppStoreReviewAttachmentsResponse.swift b/Sources/Bagbutik-Models/AppStore/AppStoreReviewAttachmentsResponse.swift index 69b5d6cdf..32986dc4b 100644 --- a/Sources/Bagbutik-Models/AppStore/AppStoreReviewAttachmentsResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppStoreReviewAttachmentsResponse.swift @@ -26,4 +26,20 @@ public struct AppStoreReviewAttachmentsResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([AppStoreReviewAttachment].self, forKey: "data") + included = try container.decodeIfPresent([AppStoreReviewDetail].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/AppStore/AppStoreReviewDetail.swift b/Sources/Bagbutik-Models/AppStore/AppStoreReviewDetail.swift index b405df5e1..2e5dbc25f 100644 --- a/Sources/Bagbutik-Models/AppStore/AppStoreReviewDetail.swift +++ b/Sources/Bagbutik-Models/AppStore/AppStoreReviewDetail.swift @@ -27,31 +27,23 @@ public struct AppStoreReviewDetail: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -89,6 +81,30 @@ public struct AppStoreReviewDetail: Codable, Identifiable { self.demoAccountRequired = demoAccountRequired self.notes = notes } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + contactEmail = try container.decodeIfPresent(String.self, forKey: "contactEmail") + contactFirstName = try container.decodeIfPresent(String.self, forKey: "contactFirstName") + contactLastName = try container.decodeIfPresent(String.self, forKey: "contactLastName") + contactPhone = try container.decodeIfPresent(String.self, forKey: "contactPhone") + demoAccountName = try container.decodeIfPresent(String.self, forKey: "demoAccountName") + demoAccountPassword = try container.decodeIfPresent(String.self, forKey: "demoAccountPassword") + demoAccountRequired = try container.decodeIfPresent(Bool.self, forKey: "demoAccountRequired") + notes = try container.decodeIfPresent(String.self, forKey: "notes") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(contactEmail, forKey: "contactEmail") + try container.encodeIfPresent(contactFirstName, forKey: "contactFirstName") + try container.encodeIfPresent(contactLastName, forKey: "contactLastName") + try container.encodeIfPresent(contactPhone, forKey: "contactPhone") + try container.encodeIfPresent(demoAccountName, forKey: "demoAccountName") + try container.encodeIfPresent(demoAccountPassword, forKey: "demoAccountPassword") + try container.encodeIfPresent(demoAccountRequired, forKey: "demoAccountRequired") + try container.encodeIfPresent(notes, forKey: "notes") + } } /** @@ -109,6 +125,18 @@ public struct AppStoreReviewDetail: Codable, Identifiable { self.appStoreVersion = appStoreVersion } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appStoreReviewAttachments = try container.decodeIfPresent(AppStoreReviewAttachments.self, forKey: "appStoreReviewAttachments") + appStoreVersion = try container.decodeIfPresent(AppStoreVersion.self, forKey: "appStoreVersion") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(appStoreReviewAttachments, forKey: "appStoreReviewAttachments") + try container.encodeIfPresent(appStoreVersion, forKey: "appStoreVersion") + } + /** # AppStoreReviewDetail.Relationships.AppStoreReviewAttachments The data and links that describe the relationship between the resources. @@ -131,23 +159,17 @@ public struct AppStoreReviewDetail: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } /** @@ -166,22 +188,17 @@ public struct AppStoreReviewDetail: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -204,20 +221,15 @@ public struct AppStoreReviewDetail: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -241,20 +253,15 @@ public struct AppStoreReviewDetail: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -273,22 +280,17 @@ public struct AppStoreReviewDetail: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -311,20 +313,15 @@ public struct AppStoreReviewDetail: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppStoreReviewDetailCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppStoreReviewDetailCreateRequest.swift index 1b4e98c48..9d4d9383e 100644 --- a/Sources/Bagbutik-Models/AppStore/AppStoreReviewDetailCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppStoreReviewDetailCreateRequest.swift @@ -15,6 +15,16 @@ public struct AppStoreReviewDetailCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AppStoreReviewDetailCreateRequest.Data The data element of the request body. @@ -35,25 +45,19 @@ public struct AppStoreReviewDetailCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } /** @@ -91,6 +95,30 @@ public struct AppStoreReviewDetailCreateRequest: Codable, RequestBody { self.demoAccountRequired = demoAccountRequired self.notes = notes } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + contactEmail = try container.decodeIfPresent(String.self, forKey: "contactEmail") + contactFirstName = try container.decodeIfPresent(String.self, forKey: "contactFirstName") + contactLastName = try container.decodeIfPresent(String.self, forKey: "contactLastName") + contactPhone = try container.decodeIfPresent(String.self, forKey: "contactPhone") + demoAccountName = try container.decodeIfPresent(String.self, forKey: "demoAccountName") + demoAccountPassword = try container.decodeIfPresent(String.self, forKey: "demoAccountPassword") + demoAccountRequired = try container.decodeIfPresent(Bool.self, forKey: "demoAccountRequired") + notes = try container.decodeIfPresent(String.self, forKey: "notes") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(contactEmail, forKey: "contactEmail") + try container.encodeIfPresent(contactFirstName, forKey: "contactFirstName") + try container.encodeIfPresent(contactLastName, forKey: "contactLastName") + try container.encodeIfPresent(contactPhone, forKey: "contactPhone") + try container.encodeIfPresent(demoAccountName, forKey: "demoAccountName") + try container.encodeIfPresent(demoAccountPassword, forKey: "demoAccountPassword") + try container.encodeIfPresent(demoAccountRequired, forKey: "demoAccountRequired") + try container.encodeIfPresent(notes, forKey: "notes") + } } /** @@ -107,6 +135,16 @@ public struct AppStoreReviewDetailCreateRequest: Codable, RequestBody { self.appStoreVersion = appStoreVersion } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appStoreVersion = try container.decode(AppStoreVersion.self, forKey: "appStoreVersion") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(appStoreVersion, forKey: "appStoreVersion") + } + /** # AppStoreReviewDetailCreateRequest.Data.Relationships.AppStoreVersion The relationships to other resources that you can set with this request. @@ -121,6 +159,16 @@ public struct AppStoreReviewDetailCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AppStoreReviewDetailCreateRequest.Data.Relationships.AppStoreVersion.Data The type and ID of the resource that you're relating with the resource you're creating. @@ -137,22 +185,17 @@ public struct AppStoreReviewDetailCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppStoreReviewDetailResponse.swift b/Sources/Bagbutik-Models/AppStore/AppStoreReviewDetailResponse.swift index cb736e3be..099d291e5 100644 --- a/Sources/Bagbutik-Models/AppStore/AppStoreReviewDetailResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppStoreReviewDetailResponse.swift @@ -22,6 +22,20 @@ public struct AppStoreReviewDetailResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AppStoreReviewDetail.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getAppStoreReviewAttachments() -> [AppStoreReviewAttachment] { guard let appStoreReviewAttachmentIds = data.relationships?.appStoreReviewAttachments?.data?.map(\.id), let appStoreReviewAttachments = included?.compactMap({ relationship -> AppStoreReviewAttachment? in @@ -64,9 +78,5 @@ public struct AppStoreReviewDetailResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppStoreReviewDetailUpdateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppStoreReviewDetailUpdateRequest.swift index 016f2ad2a..8df3973c0 100644 --- a/Sources/Bagbutik-Models/AppStore/AppStoreReviewDetailUpdateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppStoreReviewDetailUpdateRequest.swift @@ -15,6 +15,16 @@ public struct AppStoreReviewDetailUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AppStoreReviewDetailUpdateRequest.Data The data element of the request body. @@ -35,25 +45,19 @@ public struct AppStoreReviewDetailUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } /** @@ -91,6 +95,30 @@ public struct AppStoreReviewDetailUpdateRequest: Codable, RequestBody { self.demoAccountRequired = demoAccountRequired self.notes = notes } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + contactEmail = try container.decodeIfPresent(String.self, forKey: "contactEmail") + contactFirstName = try container.decodeIfPresent(String.self, forKey: "contactFirstName") + contactLastName = try container.decodeIfPresent(String.self, forKey: "contactLastName") + contactPhone = try container.decodeIfPresent(String.self, forKey: "contactPhone") + demoAccountName = try container.decodeIfPresent(String.self, forKey: "demoAccountName") + demoAccountPassword = try container.decodeIfPresent(String.self, forKey: "demoAccountPassword") + demoAccountRequired = try container.decodeIfPresent(Bool.self, forKey: "demoAccountRequired") + notes = try container.decodeIfPresent(String.self, forKey: "notes") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(contactEmail, forKey: "contactEmail") + try container.encodeIfPresent(contactFirstName, forKey: "contactFirstName") + try container.encodeIfPresent(contactLastName, forKey: "contactLastName") + try container.encodeIfPresent(contactPhone, forKey: "contactPhone") + try container.encodeIfPresent(demoAccountName, forKey: "demoAccountName") + try container.encodeIfPresent(demoAccountPassword, forKey: "demoAccountPassword") + try container.encodeIfPresent(demoAccountRequired, forKey: "demoAccountRequired") + try container.encodeIfPresent(notes, forKey: "notes") + } } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppStoreVersion.swift b/Sources/Bagbutik-Models/AppStore/AppStoreVersion.swift index 054f3540b..fd3652800 100644 --- a/Sources/Bagbutik-Models/AppStore/AppStoreVersion.swift +++ b/Sources/Bagbutik-Models/AppStore/AppStoreVersion.swift @@ -27,31 +27,23 @@ public struct AppStoreVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -119,6 +111,34 @@ public struct AppStoreVersion: Codable, Identifiable { self.versionString = versionString } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appStoreState = try container.decodeIfPresent(AppStoreVersionState.self, forKey: "appStoreState") + appVersionState = try container.decodeIfPresent(AppVersionState.self, forKey: "appVersionState") + copyright = try container.decodeIfPresent(String.self, forKey: "copyright") + createdDate = try container.decodeIfPresent(Date.self, forKey: "createdDate") + downloadable = try container.decodeIfPresent(Bool.self, forKey: "downloadable") + earliestReleaseDate = try container.decodeIfPresent(Date.self, forKey: "earliestReleaseDate") + platform = try container.decodeIfPresent(Platform.self, forKey: "platform") + releaseType = try container.decodeIfPresent(ReleaseType.self, forKey: "releaseType") + reviewType = try container.decodeIfPresent(ReviewType.self, forKey: "reviewType") + versionString = try container.decodeIfPresent(String.self, forKey: "versionString") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(appStoreState, forKey: "appStoreState") + try container.encodeIfPresent(appVersionState, forKey: "appVersionState") + try container.encodeIfPresent(copyright, forKey: "copyright") + try container.encodeIfPresent(createdDate, forKey: "createdDate") + try container.encodeIfPresent(downloadable, forKey: "downloadable") + try container.encodeIfPresent(earliestReleaseDate, forKey: "earliestReleaseDate") + try container.encodeIfPresent(platform, forKey: "platform") + try container.encodeIfPresent(releaseType, forKey: "releaseType") + try container.encodeIfPresent(reviewType, forKey: "reviewType") + try container.encodeIfPresent(versionString, forKey: "versionString") + } + public enum ReleaseType: String, Codable, CaseIterable { case afterApproval = "AFTER_APPROVAL" case manual = "MANUAL" @@ -207,6 +227,38 @@ public struct AppStoreVersion: Codable, Identifiable { self.routingAppCoverage = routingAppCoverage } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + ageRatingDeclaration = try container.decodeIfPresent(AgeRatingDeclaration.self, forKey: "ageRatingDeclaration") + alternativeDistributionPackage = try container.decodeIfPresent(AlternativeDistributionPackage.self, forKey: "alternativeDistributionPackage") + app = try container.decodeIfPresent(App.self, forKey: "app") + appClipDefaultExperience = try container.decodeIfPresent(AppClipDefaultExperience.self, forKey: "appClipDefaultExperience") + appStoreReviewDetail = try container.decodeIfPresent(AppStoreReviewDetail.self, forKey: "appStoreReviewDetail") + appStoreVersionExperiments = try container.decodeIfPresent(AppStoreVersionExperiments.self, forKey: "appStoreVersionExperiments") + appStoreVersionExperimentsV2 = try container.decodeIfPresent(AppStoreVersionExperimentsV2.self, forKey: "appStoreVersionExperimentsV2") + appStoreVersionLocalizations = try container.decodeIfPresent(AppStoreVersionLocalizations.self, forKey: "appStoreVersionLocalizations") + appStoreVersionPhasedRelease = try container.decodeIfPresent(AppStoreVersionPhasedRelease.self, forKey: "appStoreVersionPhasedRelease") + appStoreVersionSubmission = try container.decodeIfPresent(AppStoreVersionSubmission.self, forKey: "appStoreVersionSubmission") + build = try container.decodeIfPresent(Build.self, forKey: "build") + routingAppCoverage = try container.decodeIfPresent(RoutingAppCoverage.self, forKey: "routingAppCoverage") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(ageRatingDeclaration, forKey: "ageRatingDeclaration") + try container.encodeIfPresent(alternativeDistributionPackage, forKey: "alternativeDistributionPackage") + try container.encodeIfPresent(app, forKey: "app") + try container.encodeIfPresent(appClipDefaultExperience, forKey: "appClipDefaultExperience") + try container.encodeIfPresent(appStoreReviewDetail, forKey: "appStoreReviewDetail") + try container.encodeIfPresent(appStoreVersionExperiments, forKey: "appStoreVersionExperiments") + try container.encodeIfPresent(appStoreVersionExperimentsV2, forKey: "appStoreVersionExperimentsV2") + try container.encodeIfPresent(appStoreVersionLocalizations, forKey: "appStoreVersionLocalizations") + try container.encodeIfPresent(appStoreVersionPhasedRelease, forKey: "appStoreVersionPhasedRelease") + try container.encodeIfPresent(appStoreVersionSubmission, forKey: "appStoreVersionSubmission") + try container.encodeIfPresent(build, forKey: "build") + try container.encodeIfPresent(routingAppCoverage, forKey: "routingAppCoverage") + } + /** # AppStoreVersion.Relationships.AgeRatingDeclaration The data and links that describe the relationship between the resources. @@ -226,20 +278,15 @@ public struct AppStoreVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -258,22 +305,17 @@ public struct AppStoreVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -296,20 +338,15 @@ public struct AppStoreVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -326,20 +363,15 @@ public struct AppStoreVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -351,22 +383,17 @@ public struct AppStoreVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -382,20 +409,15 @@ public struct AppStoreVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -419,20 +441,15 @@ public struct AppStoreVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -451,22 +468,17 @@ public struct AppStoreVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -489,20 +501,15 @@ public struct AppStoreVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -528,20 +535,15 @@ public struct AppStoreVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -562,22 +564,17 @@ public struct AppStoreVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -602,20 +599,15 @@ public struct AppStoreVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -639,20 +631,15 @@ public struct AppStoreVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -671,22 +658,17 @@ public struct AppStoreVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -709,20 +691,15 @@ public struct AppStoreVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -742,23 +719,17 @@ public struct AppStoreVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -770,22 +741,17 @@ public struct AppStoreVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -801,20 +767,15 @@ public struct AppStoreVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -834,23 +795,17 @@ public struct AppStoreVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -862,22 +817,17 @@ public struct AppStoreVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -893,20 +843,15 @@ public struct AppStoreVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -933,23 +878,17 @@ public struct AppStoreVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } /** @@ -968,22 +907,17 @@ public struct AppStoreVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -1006,20 +940,15 @@ public struct AppStoreVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -1043,20 +972,15 @@ public struct AppStoreVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -1075,22 +999,17 @@ public struct AppStoreVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -1113,20 +1032,15 @@ public struct AppStoreVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -1150,20 +1064,15 @@ public struct AppStoreVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -1182,22 +1091,17 @@ public struct AppStoreVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -1220,20 +1124,15 @@ public struct AppStoreVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -1257,20 +1156,15 @@ public struct AppStoreVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -1289,22 +1183,17 @@ public struct AppStoreVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -1327,20 +1216,15 @@ public struct AppStoreVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -1364,20 +1248,15 @@ public struct AppStoreVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -1396,22 +1275,17 @@ public struct AppStoreVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -1434,20 +1308,15 @@ public struct AppStoreVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppStoreVersionAppClipDefaultExperienceLinkageRequest.swift b/Sources/Bagbutik-Models/AppStore/AppStoreVersionAppClipDefaultExperienceLinkageRequest.swift index 1825bbdc9..3bf046fc4 100644 --- a/Sources/Bagbutik-Models/AppStore/AppStoreVersionAppClipDefaultExperienceLinkageRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppStoreVersionAppClipDefaultExperienceLinkageRequest.swift @@ -17,17 +17,13 @@ public struct AppStoreVersionAppClipDefaultExperienceLinkageRequest: Codable, Re } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } /** @@ -48,22 +44,17 @@ public struct AppStoreVersionAppClipDefaultExperienceLinkageRequest: Codable, Re } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppStoreVersionAppClipDefaultExperienceLinkageResponse.swift b/Sources/Bagbutik-Models/AppStore/AppStoreVersionAppClipDefaultExperienceLinkageResponse.swift index 40662dfde..fdd9146df 100644 --- a/Sources/Bagbutik-Models/AppStore/AppStoreVersionAppClipDefaultExperienceLinkageResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppStoreVersionAppClipDefaultExperienceLinkageResponse.swift @@ -21,6 +21,18 @@ public struct AppStoreVersionAppClipDefaultExperienceLinkageResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } + /** # AppStoreVersionAppClipDefaultExperienceLinkageResponse.Data The data element of the response body. @@ -39,22 +51,17 @@ public struct AppStoreVersionAppClipDefaultExperienceLinkageResponse: Codable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppStoreVersionBuildLinkageRequest.swift b/Sources/Bagbutik-Models/AppStore/AppStoreVersionBuildLinkageRequest.swift index 1e9df5827..805d35297 100644 --- a/Sources/Bagbutik-Models/AppStore/AppStoreVersionBuildLinkageRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppStoreVersionBuildLinkageRequest.swift @@ -16,17 +16,13 @@ public struct AppStoreVersionBuildLinkageRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } /** @@ -45,22 +41,17 @@ public struct AppStoreVersionBuildLinkageRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppStoreVersionBuildLinkageResponse.swift b/Sources/Bagbutik-Models/AppStore/AppStoreVersionBuildLinkageResponse.swift index 9baac1402..b9a8b9f78 100644 --- a/Sources/Bagbutik-Models/AppStore/AppStoreVersionBuildLinkageResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppStoreVersionBuildLinkageResponse.swift @@ -19,6 +19,18 @@ public struct AppStoreVersionBuildLinkageResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } + /** # AppStoreVersionBuildLinkageResponse.Data The data element of the response body. @@ -35,22 +47,17 @@ public struct AppStoreVersionBuildLinkageResponse: Codable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppStoreVersionCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppStoreVersionCreateRequest.swift index b20a3d285..337ad9b43 100644 --- a/Sources/Bagbutik-Models/AppStore/AppStoreVersionCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppStoreVersionCreateRequest.swift @@ -15,6 +15,16 @@ public struct AppStoreVersionCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AppStoreVersionCreateRequest.Data The data element of the request body. @@ -35,25 +45,19 @@ public struct AppStoreVersionCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } /** @@ -85,6 +89,26 @@ public struct AppStoreVersionCreateRequest: Codable, RequestBody { self.reviewType = reviewType self.versionString = versionString } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + copyright = try container.decodeIfPresent(String.self, forKey: "copyright") + earliestReleaseDate = try container.decodeIfPresent(Date.self, forKey: "earliestReleaseDate") + platform = try container.decode(Platform.self, forKey: "platform") + releaseType = try container.decodeIfPresent(AppStoreVersion.Attributes.ReleaseType.self, forKey: "releaseType") + reviewType = try container.decodeIfPresent(AppStoreVersion.Attributes.ReviewType.self, forKey: "reviewType") + versionString = try container.decode(String.self, forKey: "versionString") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(copyright, forKey: "copyright") + try container.encodeIfPresent(earliestReleaseDate, forKey: "earliestReleaseDate") + try container.encode(platform, forKey: "platform") + try container.encodeIfPresent(releaseType, forKey: "releaseType") + try container.encodeIfPresent(reviewType, forKey: "reviewType") + try container.encode(versionString, forKey: "versionString") + } } /** @@ -108,6 +132,20 @@ public struct AppStoreVersionCreateRequest: Codable, RequestBody { self.build = build } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + app = try container.decode(App.self, forKey: "app") + appStoreVersionLocalizations = try container.decodeIfPresent(AppStoreVersionLocalizations.self, forKey: "appStoreVersionLocalizations") + build = try container.decodeIfPresent(Build.self, forKey: "build") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(app, forKey: "app") + try container.encodeIfPresent(appStoreVersionLocalizations, forKey: "appStoreVersionLocalizations") + try container.encodeIfPresent(build, forKey: "build") + } + /** # AppStoreVersionCreateRequest.Data.Relationships.App The relationships to other resources that you can set with this request. @@ -122,6 +160,16 @@ public struct AppStoreVersionCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AppStoreVersionCreateRequest.Data.Relationships.App.Data The type and ID of the resource that you're relating with the resource you're creating. @@ -138,22 +186,17 @@ public struct AppStoreVersionCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -166,17 +209,13 @@ public struct AppStoreVersionCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } public struct Data: Codable, Identifiable { @@ -188,22 +227,17 @@ public struct AppStoreVersionCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -223,17 +257,13 @@ public struct AppStoreVersionCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } /** @@ -252,22 +282,17 @@ public struct AppStoreVersionCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperiment.swift b/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperiment.swift index 7e214864c..ec0f7a915 100644 --- a/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperiment.swift +++ b/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperiment.swift @@ -20,31 +20,23 @@ public struct AppStoreVersionExperiment: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -70,6 +62,26 @@ public struct AppStoreVersionExperiment: Codable, Identifiable { self.trafficProportion = trafficProportion } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + endDate = try container.decodeIfPresent(Date.self, forKey: "endDate") + name = try container.decodeIfPresent(String.self, forKey: "name") + reviewRequired = try container.decodeIfPresent(Bool.self, forKey: "reviewRequired") + startDate = try container.decodeIfPresent(Date.self, forKey: "startDate") + state = try container.decodeIfPresent(State.self, forKey: "state") + trafficProportion = try container.decodeIfPresent(Int.self, forKey: "trafficProportion") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(endDate, forKey: "endDate") + try container.encodeIfPresent(name, forKey: "name") + try container.encodeIfPresent(reviewRequired, forKey: "reviewRequired") + try container.encodeIfPresent(startDate, forKey: "startDate") + try container.encodeIfPresent(state, forKey: "state") + try container.encodeIfPresent(trafficProportion, forKey: "trafficProportion") + } + public enum State: String, Codable, CaseIterable { case accepted = "ACCEPTED" case approved = "APPROVED" @@ -94,6 +106,18 @@ public struct AppStoreVersionExperiment: Codable, Identifiable { self.appStoreVersionExperimentTreatments = appStoreVersionExperimentTreatments } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appStoreVersion = try container.decodeIfPresent(AppStoreVersion.self, forKey: "appStoreVersion") + appStoreVersionExperimentTreatments = try container.decodeIfPresent(AppStoreVersionExperimentTreatments.self, forKey: "appStoreVersionExperimentTreatments") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(appStoreVersion, forKey: "appStoreVersion") + try container.encodeIfPresent(appStoreVersionExperimentTreatments, forKey: "appStoreVersionExperimentTreatments") + } + public struct AppStoreVersion: Codable { @NullCodable public var data: Data? public var links: Links? @@ -106,20 +130,15 @@ public struct AppStoreVersionExperiment: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -131,22 +150,17 @@ public struct AppStoreVersionExperiment: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -162,20 +176,15 @@ public struct AppStoreVersionExperiment: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -195,23 +204,17 @@ public struct AppStoreVersionExperiment: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -223,22 +226,17 @@ public struct AppStoreVersionExperiment: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -254,20 +252,15 @@ public struct AppStoreVersionExperiment: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentCreateRequest.swift index 484d495cb..64b719527 100644 --- a/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentCreateRequest.swift @@ -8,6 +8,16 @@ public struct AppStoreVersionExperimentCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "appStoreVersionExperiments" } public let attributes: Attributes @@ -21,25 +31,19 @@ public struct AppStoreVersionExperimentCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -52,6 +56,18 @@ public struct AppStoreVersionExperimentCreateRequest: Codable, RequestBody { self.name = name self.trafficProportion = trafficProportion } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + name = try container.decode(String.self, forKey: "name") + trafficProportion = try container.decode(Int.self, forKey: "trafficProportion") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(name, forKey: "name") + try container.encode(trafficProportion, forKey: "trafficProportion") + } } public struct Relationships: Codable { @@ -61,6 +77,16 @@ public struct AppStoreVersionExperimentCreateRequest: Codable, RequestBody { self.appStoreVersion = appStoreVersion } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appStoreVersion = try container.decode(AppStoreVersion.self, forKey: "appStoreVersion") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(appStoreVersion, forKey: "appStoreVersion") + } + public struct AppStoreVersion: Codable { public let data: Data @@ -68,6 +94,16 @@ public struct AppStoreVersionExperimentCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "appStoreVersions" } @@ -77,22 +113,17 @@ public struct AppStoreVersionExperimentCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentResponse.swift b/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentResponse.swift index 745f00c17..a86439ac5 100644 --- a/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentResponse.swift @@ -15,6 +15,20 @@ public struct AppStoreVersionExperimentResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AppStoreVersionExperiment.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getAppStoreVersion() -> AppStoreVersion? { included?.compactMap { relationship -> AppStoreVersion? in guard case let .appStoreVersion(appStoreVersion) = relationship else { return nil } @@ -57,9 +71,5 @@ public struct AppStoreVersionExperimentResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentTreatment.swift b/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentTreatment.swift index 245948ba0..19661a397 100644 --- a/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentTreatment.swift +++ b/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentTreatment.swift @@ -20,31 +20,23 @@ public struct AppStoreVersionExperimentTreatment: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -63,6 +55,22 @@ public struct AppStoreVersionExperimentTreatment: Codable, Identifiable { self.name = name self.promotedDate = promotedDate } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appIcon = try container.decodeIfPresent(ImageAsset.self, forKey: "appIcon") + appIconName = try container.decodeIfPresent(String.self, forKey: "appIconName") + name = try container.decodeIfPresent(String.self, forKey: "name") + promotedDate = try container.decodeIfPresent(Date.self, forKey: "promotedDate") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(appIcon, forKey: "appIcon") + try container.encodeIfPresent(appIconName, forKey: "appIconName") + try container.encodeIfPresent(name, forKey: "name") + try container.encodeIfPresent(promotedDate, forKey: "promotedDate") + } } public struct Relationships: Codable { @@ -79,6 +87,20 @@ public struct AppStoreVersionExperimentTreatment: Codable, Identifiable { self.appStoreVersionExperimentV2 = appStoreVersionExperimentV2 } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appStoreVersionExperiment = try container.decodeIfPresent(AppStoreVersionExperiment.self, forKey: "appStoreVersionExperiment") + appStoreVersionExperimentTreatmentLocalizations = try container.decodeIfPresent(AppStoreVersionExperimentTreatmentLocalizations.self, forKey: "appStoreVersionExperimentTreatmentLocalizations") + appStoreVersionExperimentV2 = try container.decodeIfPresent(AppStoreVersionExperimentV2.self, forKey: "appStoreVersionExperimentV2") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(appStoreVersionExperiment, forKey: "appStoreVersionExperiment") + try container.encodeIfPresent(appStoreVersionExperimentTreatmentLocalizations, forKey: "appStoreVersionExperimentTreatmentLocalizations") + try container.encodeIfPresent(appStoreVersionExperimentV2, forKey: "appStoreVersionExperimentV2") + } + public struct AppStoreVersionExperiment: Codable { @NullCodable public var data: Data? public var links: Links? @@ -91,20 +113,15 @@ public struct AppStoreVersionExperimentTreatment: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -116,22 +133,17 @@ public struct AppStoreVersionExperimentTreatment: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -147,20 +159,15 @@ public struct AppStoreVersionExperimentTreatment: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -180,23 +187,17 @@ public struct AppStoreVersionExperimentTreatment: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -208,22 +209,17 @@ public struct AppStoreVersionExperimentTreatment: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -239,20 +235,15 @@ public struct AppStoreVersionExperimentTreatment: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -269,20 +260,15 @@ public struct AppStoreVersionExperimentTreatment: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -294,22 +280,17 @@ public struct AppStoreVersionExperimentTreatment: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -325,20 +306,15 @@ public struct AppStoreVersionExperimentTreatment: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentTreatmentCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentTreatmentCreateRequest.swift index fab6b8d90..05a15989a 100644 --- a/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentTreatmentCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentTreatmentCreateRequest.swift @@ -8,6 +8,16 @@ public struct AppStoreVersionExperimentTreatmentCreateRequest: Codable, RequestB self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "appStoreVersionExperimentTreatments" } public let attributes: Attributes @@ -21,25 +31,19 @@ public struct AppStoreVersionExperimentTreatmentCreateRequest: Codable, RequestB } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -52,6 +56,18 @@ public struct AppStoreVersionExperimentTreatmentCreateRequest: Codable, RequestB self.appIconName = appIconName self.name = name } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appIconName = try container.decodeIfPresent(String.self, forKey: "appIconName") + name = try container.decode(String.self, forKey: "name") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(appIconName, forKey: "appIconName") + try container.encode(name, forKey: "name") + } } public struct Relationships: Codable { @@ -65,6 +81,18 @@ public struct AppStoreVersionExperimentTreatmentCreateRequest: Codable, RequestB self.appStoreVersionExperimentV2 = appStoreVersionExperimentV2 } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appStoreVersionExperiment = try container.decode(AppStoreVersionExperiment.self, forKey: "appStoreVersionExperiment") + appStoreVersionExperimentV2 = try container.decodeIfPresent(AppStoreVersionExperimentV2.self, forKey: "appStoreVersionExperimentV2") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(appStoreVersionExperiment, forKey: "appStoreVersionExperiment") + try container.encodeIfPresent(appStoreVersionExperimentV2, forKey: "appStoreVersionExperimentV2") + } + public struct AppStoreVersionExperiment: Codable { public let data: Data @@ -72,6 +100,16 @@ public struct AppStoreVersionExperimentTreatmentCreateRequest: Codable, RequestB self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "appStoreVersionExperiments" } @@ -81,22 +119,17 @@ public struct AppStoreVersionExperimentTreatmentCreateRequest: Codable, RequestB } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -109,17 +142,13 @@ public struct AppStoreVersionExperimentTreatmentCreateRequest: Codable, RequestB } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } public struct Data: Codable, Identifiable { @@ -131,22 +160,17 @@ public struct AppStoreVersionExperimentTreatmentCreateRequest: Codable, RequestB } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentTreatmentLocalization.swift b/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentTreatmentLocalization.swift index 9f1c2c47f..9b357ca4a 100644 --- a/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentTreatmentLocalization.swift +++ b/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentTreatmentLocalization.swift @@ -20,31 +20,23 @@ public struct AppStoreVersionExperimentTreatmentLocalization: Codable, Identifia } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -53,6 +45,16 @@ public struct AppStoreVersionExperimentTreatmentLocalization: Codable, Identifia public init(locale: String? = nil) { self.locale = locale } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + locale = try container.decodeIfPresent(String.self, forKey: "locale") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(locale, forKey: "locale") + } } public struct Relationships: Codable { @@ -69,6 +71,20 @@ public struct AppStoreVersionExperimentTreatmentLocalization: Codable, Identifia self.appStoreVersionExperimentTreatment = appStoreVersionExperimentTreatment } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appPreviewSets = try container.decodeIfPresent(AppPreviewSets.self, forKey: "appPreviewSets") + appScreenshotSets = try container.decodeIfPresent(AppScreenshotSets.self, forKey: "appScreenshotSets") + appStoreVersionExperimentTreatment = try container.decodeIfPresent(AppStoreVersionExperimentTreatment.self, forKey: "appStoreVersionExperimentTreatment") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(appPreviewSets, forKey: "appPreviewSets") + try container.encodeIfPresent(appScreenshotSets, forKey: "appScreenshotSets") + try container.encodeIfPresent(appStoreVersionExperimentTreatment, forKey: "appStoreVersionExperimentTreatment") + } + public struct AppPreviewSets: Codable { @NullCodable public var data: [Data]? public var links: Links? @@ -84,23 +100,17 @@ public struct AppStoreVersionExperimentTreatmentLocalization: Codable, Identifia } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -112,22 +122,17 @@ public struct AppStoreVersionExperimentTreatmentLocalization: Codable, Identifia } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -143,20 +148,15 @@ public struct AppStoreVersionExperimentTreatmentLocalization: Codable, Identifia } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -176,23 +176,17 @@ public struct AppStoreVersionExperimentTreatmentLocalization: Codable, Identifia } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -204,22 +198,17 @@ public struct AppStoreVersionExperimentTreatmentLocalization: Codable, Identifia } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -235,20 +224,15 @@ public struct AppStoreVersionExperimentTreatmentLocalization: Codable, Identifia } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -265,20 +249,15 @@ public struct AppStoreVersionExperimentTreatmentLocalization: Codable, Identifia } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -290,22 +269,17 @@ public struct AppStoreVersionExperimentTreatmentLocalization: Codable, Identifia } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -321,20 +295,15 @@ public struct AppStoreVersionExperimentTreatmentLocalization: Codable, Identifia } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentTreatmentLocalizationCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentTreatmentLocalizationCreateRequest.swift index 542c52c8f..2fe7fc23d 100644 --- a/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentTreatmentLocalizationCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentTreatmentLocalizationCreateRequest.swift @@ -8,6 +8,16 @@ public struct AppStoreVersionExperimentTreatmentLocalizationCreateRequest: Codab self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "appStoreVersionExperimentTreatmentLocalizations" } public let attributes: Attributes @@ -21,25 +31,19 @@ public struct AppStoreVersionExperimentTreatmentLocalizationCreateRequest: Codab } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -48,6 +52,16 @@ public struct AppStoreVersionExperimentTreatmentLocalizationCreateRequest: Codab public init(locale: String) { self.locale = locale } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + locale = try container.decode(String.self, forKey: "locale") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(locale, forKey: "locale") + } } public struct Relationships: Codable { @@ -57,6 +71,16 @@ public struct AppStoreVersionExperimentTreatmentLocalizationCreateRequest: Codab self.appStoreVersionExperimentTreatment = appStoreVersionExperimentTreatment } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appStoreVersionExperimentTreatment = try container.decode(AppStoreVersionExperimentTreatment.self, forKey: "appStoreVersionExperimentTreatment") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(appStoreVersionExperimentTreatment, forKey: "appStoreVersionExperimentTreatment") + } + public struct AppStoreVersionExperimentTreatment: Codable { public let data: Data @@ -64,6 +88,16 @@ public struct AppStoreVersionExperimentTreatmentLocalizationCreateRequest: Codab self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "appStoreVersionExperimentTreatments" } @@ -73,22 +107,17 @@ public struct AppStoreVersionExperimentTreatmentLocalizationCreateRequest: Codab } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentTreatmentLocalizationResponse.swift b/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentTreatmentLocalizationResponse.swift index 8483cd0fe..2438f5c9e 100644 --- a/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentTreatmentLocalizationResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentTreatmentLocalizationResponse.swift @@ -15,6 +15,20 @@ public struct AppStoreVersionExperimentTreatmentLocalizationResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AppStoreVersionExperimentTreatmentLocalization.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getAppPreviewSets() -> [AppPreviewSet] { guard let appPreviewSetIds = data.relationships?.appPreviewSets?.data?.map(\.id), let appPreviewSets = included?.compactMap({ relationship -> AppPreviewSet? in @@ -74,9 +88,5 @@ public struct AppStoreVersionExperimentTreatmentLocalizationResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentTreatmentLocalizationsResponse.swift b/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentTreatmentLocalizationsResponse.swift index 9f846d82a..9dfd6fb2f 100644 --- a/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentTreatmentLocalizationsResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentTreatmentLocalizationsResponse.swift @@ -20,6 +20,22 @@ public struct AppStoreVersionExperimentTreatmentLocalizationsResponse: Codable, self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([AppStoreVersionExperimentTreatmentLocalization].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getAppPreviewSets(for appStoreVersionExperimentTreatmentLocalization: AppStoreVersionExperimentTreatmentLocalization) -> [AppPreviewSet] { guard let appPreviewSetIds = appStoreVersionExperimentTreatmentLocalization.relationships?.appPreviewSets?.data?.map(\.id), let appPreviewSets = included?.compactMap({ relationship -> AppPreviewSet? in @@ -79,9 +95,5 @@ public struct AppStoreVersionExperimentTreatmentLocalizationsResponse: Codable, try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentTreatmentResponse.swift b/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentTreatmentResponse.swift index 1965511c8..93e1788d6 100644 --- a/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentTreatmentResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentTreatmentResponse.swift @@ -15,6 +15,20 @@ public struct AppStoreVersionExperimentTreatmentResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AppStoreVersionExperimentTreatment.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getAppStoreVersionExperiment() -> AppStoreVersionExperiment? { included?.compactMap { relationship -> AppStoreVersionExperiment? in guard case let .appStoreVersionExperiment(appStoreVersionExperiment) = relationship else { return nil } @@ -69,9 +83,5 @@ public struct AppStoreVersionExperimentTreatmentResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentTreatmentUpdateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentTreatmentUpdateRequest.swift index bb4a72e06..279b8b7c5 100644 --- a/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentTreatmentUpdateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentTreatmentUpdateRequest.swift @@ -8,6 +8,16 @@ public struct AppStoreVersionExperimentTreatmentUpdateRequest: Codable, RequestB self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "appStoreVersionExperimentTreatments" } @@ -21,25 +31,19 @@ public struct AppStoreVersionExperimentTreatmentUpdateRequest: Codable, RequestB } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } public struct Attributes: Codable { @@ -52,6 +56,18 @@ public struct AppStoreVersionExperimentTreatmentUpdateRequest: Codable, RequestB self.appIconName = appIconName self.name = name } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appIconName = try container.decodeIfPresent(String.self, forKey: "appIconName") + name = try container.decodeIfPresent(String.self, forKey: "name") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(appIconName, forKey: "appIconName") + try container.encodeIfPresent(name, forKey: "name") + } } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentTreatmentsResponse.swift b/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentTreatmentsResponse.swift index 8284bbe29..7c23d59b7 100644 --- a/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentTreatmentsResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentTreatmentsResponse.swift @@ -20,6 +20,22 @@ public struct AppStoreVersionExperimentTreatmentsResponse: Codable, PagedRespons self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([AppStoreVersionExperimentTreatment].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getAppStoreVersionExperiment(for appStoreVersionExperimentTreatment: AppStoreVersionExperimentTreatment) -> AppStoreVersionExperiment? { included?.compactMap { relationship -> AppStoreVersionExperiment? in guard case let .appStoreVersionExperiment(appStoreVersionExperiment) = relationship else { return nil } @@ -74,9 +90,5 @@ public struct AppStoreVersionExperimentTreatmentsResponse: Codable, PagedRespons try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentUpdateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentUpdateRequest.swift index 0153d35cf..ecf67da8e 100644 --- a/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentUpdateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentUpdateRequest.swift @@ -8,6 +8,16 @@ public struct AppStoreVersionExperimentUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "appStoreVersionExperiments" } @@ -21,25 +31,19 @@ public struct AppStoreVersionExperimentUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } public struct Attributes: Codable { @@ -55,6 +59,20 @@ public struct AppStoreVersionExperimentUpdateRequest: Codable, RequestBody { self.started = started self.trafficProportion = trafficProportion } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + name = try container.decodeIfPresent(String.self, forKey: "name") + started = try container.decodeIfPresent(Bool.self, forKey: "started") + trafficProportion = try container.decodeIfPresent(Int.self, forKey: "trafficProportion") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(name, forKey: "name") + try container.encodeIfPresent(started, forKey: "started") + try container.encodeIfPresent(trafficProportion, forKey: "trafficProportion") + } } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentV2.swift b/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentV2.swift index 1fd4da458..94f3834ea 100644 --- a/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentV2.swift +++ b/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentV2.swift @@ -20,31 +20,23 @@ public struct AppStoreVersionExperimentV2: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -73,6 +65,28 @@ public struct AppStoreVersionExperimentV2: Codable, Identifiable { self.trafficProportion = trafficProportion } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + endDate = try container.decodeIfPresent(Date.self, forKey: "endDate") + name = try container.decodeIfPresent(String.self, forKey: "name") + platform = try container.decodeIfPresent(Platform.self, forKey: "platform") + reviewRequired = try container.decodeIfPresent(Bool.self, forKey: "reviewRequired") + startDate = try container.decodeIfPresent(Date.self, forKey: "startDate") + state = try container.decodeIfPresent(State.self, forKey: "state") + trafficProportion = try container.decodeIfPresent(Int.self, forKey: "trafficProportion") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(endDate, forKey: "endDate") + try container.encodeIfPresent(name, forKey: "name") + try container.encodeIfPresent(platform, forKey: "platform") + try container.encodeIfPresent(reviewRequired, forKey: "reviewRequired") + try container.encodeIfPresent(startDate, forKey: "startDate") + try container.encodeIfPresent(state, forKey: "state") + try container.encodeIfPresent(trafficProportion, forKey: "trafficProportion") + } + public enum State: String, Codable, CaseIterable { case accepted = "ACCEPTED" case approved = "APPROVED" @@ -103,6 +117,22 @@ public struct AppStoreVersionExperimentV2: Codable, Identifiable { self.latestControlVersion = latestControlVersion } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + app = try container.decodeIfPresent(App.self, forKey: "app") + appStoreVersionExperimentTreatments = try container.decodeIfPresent(AppStoreVersionExperimentTreatments.self, forKey: "appStoreVersionExperimentTreatments") + controlVersions = try container.decodeIfPresent(ControlVersions.self, forKey: "controlVersions") + latestControlVersion = try container.decodeIfPresent(LatestControlVersion.self, forKey: "latestControlVersion") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(app, forKey: "app") + try container.encodeIfPresent(appStoreVersionExperimentTreatments, forKey: "appStoreVersionExperimentTreatments") + try container.encodeIfPresent(controlVersions, forKey: "controlVersions") + try container.encodeIfPresent(latestControlVersion, forKey: "latestControlVersion") + } + public struct App: Codable { @NullCodable public var data: Data? public var links: Links? @@ -115,20 +145,15 @@ public struct AppStoreVersionExperimentV2: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -140,22 +165,17 @@ public struct AppStoreVersionExperimentV2: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -171,20 +191,15 @@ public struct AppStoreVersionExperimentV2: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -204,23 +219,17 @@ public struct AppStoreVersionExperimentV2: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -232,22 +241,17 @@ public struct AppStoreVersionExperimentV2: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -263,20 +267,15 @@ public struct AppStoreVersionExperimentV2: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -296,23 +295,17 @@ public struct AppStoreVersionExperimentV2: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -324,22 +317,17 @@ public struct AppStoreVersionExperimentV2: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -355,20 +343,15 @@ public struct AppStoreVersionExperimentV2: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -385,20 +368,15 @@ public struct AppStoreVersionExperimentV2: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -410,22 +388,17 @@ public struct AppStoreVersionExperimentV2: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -441,20 +414,15 @@ public struct AppStoreVersionExperimentV2: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentV2CreateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentV2CreateRequest.swift index 497d67650..abd618737 100644 --- a/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentV2CreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentV2CreateRequest.swift @@ -8,6 +8,16 @@ public struct AppStoreVersionExperimentV2CreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "appStoreVersionExperiments" } public let attributes: Attributes @@ -21,25 +31,19 @@ public struct AppStoreVersionExperimentV2CreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -55,6 +59,20 @@ public struct AppStoreVersionExperimentV2CreateRequest: Codable, RequestBody { self.platform = platform self.trafficProportion = trafficProportion } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + name = try container.decode(String.self, forKey: "name") + platform = try container.decode(Platform.self, forKey: "platform") + trafficProportion = try container.decode(Int.self, forKey: "trafficProportion") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(name, forKey: "name") + try container.encode(platform, forKey: "platform") + try container.encode(trafficProportion, forKey: "trafficProportion") + } } public struct Relationships: Codable { @@ -64,6 +82,16 @@ public struct AppStoreVersionExperimentV2CreateRequest: Codable, RequestBody { self.app = app } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + app = try container.decode(App.self, forKey: "app") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(app, forKey: "app") + } + public struct App: Codable { public let data: Data @@ -71,6 +99,16 @@ public struct AppStoreVersionExperimentV2CreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "apps" } @@ -80,22 +118,17 @@ public struct AppStoreVersionExperimentV2CreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentV2Response.swift b/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentV2Response.swift index 05bf26c38..3bd361ee3 100644 --- a/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentV2Response.swift +++ b/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentV2Response.swift @@ -15,6 +15,20 @@ public struct AppStoreVersionExperimentV2Response: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AppStoreVersionExperimentV2.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getApp() -> App? { included?.compactMap { relationship -> App? in guard case let .app(app) = relationship else { return nil } @@ -81,9 +95,5 @@ public struct AppStoreVersionExperimentV2Response: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentV2UpdateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentV2UpdateRequest.swift index 98f5f2f1c..54f6238d9 100644 --- a/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentV2UpdateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentV2UpdateRequest.swift @@ -8,6 +8,16 @@ public struct AppStoreVersionExperimentV2UpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "appStoreVersionExperiments" } @@ -21,25 +31,19 @@ public struct AppStoreVersionExperimentV2UpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } public struct Attributes: Codable { @@ -55,6 +59,20 @@ public struct AppStoreVersionExperimentV2UpdateRequest: Codable, RequestBody { self.started = started self.trafficProportion = trafficProportion } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + name = try container.decodeIfPresent(String.self, forKey: "name") + started = try container.decodeIfPresent(Bool.self, forKey: "started") + trafficProportion = try container.decodeIfPresent(Int.self, forKey: "trafficProportion") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(name, forKey: "name") + try container.encodeIfPresent(started, forKey: "started") + try container.encodeIfPresent(trafficProportion, forKey: "trafficProportion") + } } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentsResponse.swift b/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentsResponse.swift index b9bd7b0a4..fb4d26dcf 100644 --- a/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentsResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentsResponse.swift @@ -20,6 +20,22 @@ public struct AppStoreVersionExperimentsResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([AppStoreVersionExperiment].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getAppStoreVersion(for appStoreVersionExperiment: AppStoreVersionExperiment) -> AppStoreVersion? { included?.compactMap { relationship -> AppStoreVersion? in guard case let .appStoreVersion(appStoreVersion) = relationship else { return nil } @@ -62,9 +78,5 @@ public struct AppStoreVersionExperimentsResponse: Codable, PagedResponse { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentsV2Response.swift b/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentsV2Response.swift index 9c3a610e4..d58339c37 100644 --- a/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentsV2Response.swift +++ b/Sources/Bagbutik-Models/AppStore/AppStoreVersionExperimentsV2Response.swift @@ -20,6 +20,22 @@ public struct AppStoreVersionExperimentsV2Response: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([AppStoreVersionExperimentV2].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getApp(for appStoreVersionExperimentV2: AppStoreVersionExperimentV2) -> App? { included?.compactMap { relationship -> App? in guard case let .app(app) = relationship else { return nil } @@ -86,9 +102,5 @@ public struct AppStoreVersionExperimentsV2Response: Codable, PagedResponse { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppStoreVersionLocalization.swift b/Sources/Bagbutik-Models/AppStore/AppStoreVersionLocalization.swift index 2bf05abed..597f49ebb 100644 --- a/Sources/Bagbutik-Models/AppStore/AppStoreVersionLocalization.swift +++ b/Sources/Bagbutik-Models/AppStore/AppStoreVersionLocalization.swift @@ -27,31 +27,23 @@ public struct AppStoreVersionLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -86,6 +78,28 @@ public struct AppStoreVersionLocalization: Codable, Identifiable { self.supportUrl = supportUrl self.whatsNew = whatsNew } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + description = try container.decodeIfPresent(String.self, forKey: "description") + keywords = try container.decodeIfPresent(String.self, forKey: "keywords") + locale = try container.decodeIfPresent(String.self, forKey: "locale") + marketingUrl = try container.decodeIfPresent(String.self, forKey: "marketingUrl") + promotionalText = try container.decodeIfPresent(String.self, forKey: "promotionalText") + supportUrl = try container.decodeIfPresent(String.self, forKey: "supportUrl") + whatsNew = try container.decodeIfPresent(String.self, forKey: "whatsNew") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(description, forKey: "description") + try container.encodeIfPresent(keywords, forKey: "keywords") + try container.encodeIfPresent(locale, forKey: "locale") + try container.encodeIfPresent(marketingUrl, forKey: "marketingUrl") + try container.encodeIfPresent(promotionalText, forKey: "promotionalText") + try container.encodeIfPresent(supportUrl, forKey: "supportUrl") + try container.encodeIfPresent(whatsNew, forKey: "whatsNew") + } } /** @@ -109,6 +123,20 @@ public struct AppStoreVersionLocalization: Codable, Identifiable { self.appStoreVersion = appStoreVersion } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appPreviewSets = try container.decodeIfPresent(AppPreviewSets.self, forKey: "appPreviewSets") + appScreenshotSets = try container.decodeIfPresent(AppScreenshotSets.self, forKey: "appScreenshotSets") + appStoreVersion = try container.decodeIfPresent(AppStoreVersion.self, forKey: "appStoreVersion") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(appPreviewSets, forKey: "appPreviewSets") + try container.encodeIfPresent(appScreenshotSets, forKey: "appScreenshotSets") + try container.encodeIfPresent(appStoreVersion, forKey: "appStoreVersion") + } + /** # AppStoreVersionLocalization.Relationships.AppPreviewSets The data and links that describe the relationship between the resources. @@ -131,23 +159,17 @@ public struct AppStoreVersionLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } /** @@ -166,22 +188,17 @@ public struct AppStoreVersionLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -204,20 +221,15 @@ public struct AppStoreVersionLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -244,23 +256,17 @@ public struct AppStoreVersionLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } /** @@ -279,22 +285,17 @@ public struct AppStoreVersionLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -317,20 +318,15 @@ public struct AppStoreVersionLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -354,20 +350,15 @@ public struct AppStoreVersionLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -386,22 +377,17 @@ public struct AppStoreVersionLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -424,20 +410,15 @@ public struct AppStoreVersionLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppStoreVersionLocalizationCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppStoreVersionLocalizationCreateRequest.swift index c189f9a9c..260765e24 100644 --- a/Sources/Bagbutik-Models/AppStore/AppStoreVersionLocalizationCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppStoreVersionLocalizationCreateRequest.swift @@ -15,6 +15,16 @@ public struct AppStoreVersionLocalizationCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AppStoreVersionLocalizationCreateRequest.Data The data element of the request body. @@ -35,25 +45,19 @@ public struct AppStoreVersionLocalizationCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } /** @@ -88,6 +92,28 @@ public struct AppStoreVersionLocalizationCreateRequest: Codable, RequestBody { self.supportUrl = supportUrl self.whatsNew = whatsNew } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + description = try container.decodeIfPresent(String.self, forKey: "description") + keywords = try container.decodeIfPresent(String.self, forKey: "keywords") + locale = try container.decode(String.self, forKey: "locale") + marketingUrl = try container.decodeIfPresent(String.self, forKey: "marketingUrl") + promotionalText = try container.decodeIfPresent(String.self, forKey: "promotionalText") + supportUrl = try container.decodeIfPresent(String.self, forKey: "supportUrl") + whatsNew = try container.decodeIfPresent(String.self, forKey: "whatsNew") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(description, forKey: "description") + try container.encodeIfPresent(keywords, forKey: "keywords") + try container.encode(locale, forKey: "locale") + try container.encodeIfPresent(marketingUrl, forKey: "marketingUrl") + try container.encodeIfPresent(promotionalText, forKey: "promotionalText") + try container.encodeIfPresent(supportUrl, forKey: "supportUrl") + try container.encodeIfPresent(whatsNew, forKey: "whatsNew") + } } /** @@ -104,6 +130,16 @@ public struct AppStoreVersionLocalizationCreateRequest: Codable, RequestBody { self.appStoreVersion = appStoreVersion } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appStoreVersion = try container.decode(AppStoreVersion.self, forKey: "appStoreVersion") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(appStoreVersion, forKey: "appStoreVersion") + } + /** # AppStoreVersionLocalizationCreateRequest.Data.Relationships.AppStoreVersion The relationships to other resources that you can set with this request. @@ -118,6 +154,16 @@ public struct AppStoreVersionLocalizationCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AppStoreVersionLocalizationCreateRequest.Data.Relationships.AppStoreVersion.Data The type and ID of the resource that you're relating with the resource you're creating. @@ -134,22 +180,17 @@ public struct AppStoreVersionLocalizationCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppStoreVersionLocalizationResponse.swift b/Sources/Bagbutik-Models/AppStore/AppStoreVersionLocalizationResponse.swift index 7944f8ef0..11a5499df 100644 --- a/Sources/Bagbutik-Models/AppStore/AppStoreVersionLocalizationResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppStoreVersionLocalizationResponse.swift @@ -22,6 +22,20 @@ public struct AppStoreVersionLocalizationResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AppStoreVersionLocalization.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getAppPreviewSets() -> [AppPreviewSet] { guard let appPreviewSetIds = data.relationships?.appPreviewSets?.data?.map(\.id), let appPreviewSets = included?.compactMap({ relationship -> AppPreviewSet? in @@ -81,9 +95,5 @@ public struct AppStoreVersionLocalizationResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppStoreVersionLocalizationUpdateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppStoreVersionLocalizationUpdateRequest.swift index 59f744060..dbec3005a 100644 --- a/Sources/Bagbutik-Models/AppStore/AppStoreVersionLocalizationUpdateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppStoreVersionLocalizationUpdateRequest.swift @@ -15,6 +15,16 @@ public struct AppStoreVersionLocalizationUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AppStoreVersionLocalizationUpdateRequest.Data The data element of the request body. @@ -35,25 +45,19 @@ public struct AppStoreVersionLocalizationUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } /** @@ -85,6 +89,26 @@ public struct AppStoreVersionLocalizationUpdateRequest: Codable, RequestBody { self.supportUrl = supportUrl self.whatsNew = whatsNew } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + description = try container.decodeIfPresent(String.self, forKey: "description") + keywords = try container.decodeIfPresent(String.self, forKey: "keywords") + marketingUrl = try container.decodeIfPresent(String.self, forKey: "marketingUrl") + promotionalText = try container.decodeIfPresent(String.self, forKey: "promotionalText") + supportUrl = try container.decodeIfPresent(String.self, forKey: "supportUrl") + whatsNew = try container.decodeIfPresent(String.self, forKey: "whatsNew") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(description, forKey: "description") + try container.encodeIfPresent(keywords, forKey: "keywords") + try container.encodeIfPresent(marketingUrl, forKey: "marketingUrl") + try container.encodeIfPresent(promotionalText, forKey: "promotionalText") + try container.encodeIfPresent(supportUrl, forKey: "supportUrl") + try container.encodeIfPresent(whatsNew, forKey: "whatsNew") + } } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppStoreVersionLocalizationsResponse.swift b/Sources/Bagbutik-Models/AppStore/AppStoreVersionLocalizationsResponse.swift index 67f9f4494..06ca0ccb5 100644 --- a/Sources/Bagbutik-Models/AppStore/AppStoreVersionLocalizationsResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppStoreVersionLocalizationsResponse.swift @@ -27,6 +27,22 @@ public struct AppStoreVersionLocalizationsResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([AppStoreVersionLocalization].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getAppPreviewSets(for appStoreVersionLocalization: AppStoreVersionLocalization) -> [AppPreviewSet] { guard let appPreviewSetIds = appStoreVersionLocalization.relationships?.appPreviewSets?.data?.map(\.id), let appPreviewSets = included?.compactMap({ relationship -> AppPreviewSet? in @@ -86,9 +102,5 @@ public struct AppStoreVersionLocalizationsResponse: Codable, PagedResponse { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppStoreVersionPhasedRelease.swift b/Sources/Bagbutik-Models/AppStore/AppStoreVersionPhasedRelease.swift index 76363b154..ff071379e 100644 --- a/Sources/Bagbutik-Models/AppStore/AppStoreVersionPhasedRelease.swift +++ b/Sources/Bagbutik-Models/AppStore/AppStoreVersionPhasedRelease.swift @@ -24,28 +24,21 @@ public struct AppStoreVersionPhasedRelease: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } /** @@ -71,5 +64,21 @@ public struct AppStoreVersionPhasedRelease: Codable, Identifiable { self.startDate = startDate self.totalPauseDuration = totalPauseDuration } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + currentDayNumber = try container.decodeIfPresent(Int.self, forKey: "currentDayNumber") + phasedReleaseState = try container.decodeIfPresent(PhasedReleaseState.self, forKey: "phasedReleaseState") + startDate = try container.decodeIfPresent(Date.self, forKey: "startDate") + totalPauseDuration = try container.decodeIfPresent(Int.self, forKey: "totalPauseDuration") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(currentDayNumber, forKey: "currentDayNumber") + try container.encodeIfPresent(phasedReleaseState, forKey: "phasedReleaseState") + try container.encodeIfPresent(startDate, forKey: "startDate") + try container.encodeIfPresent(totalPauseDuration, forKey: "totalPauseDuration") + } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppStoreVersionPhasedReleaseCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppStoreVersionPhasedReleaseCreateRequest.swift index b734b765c..eb7ac2d5f 100644 --- a/Sources/Bagbutik-Models/AppStore/AppStoreVersionPhasedReleaseCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppStoreVersionPhasedReleaseCreateRequest.swift @@ -15,6 +15,16 @@ public struct AppStoreVersionPhasedReleaseCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AppStoreVersionPhasedReleaseCreateRequest.Data The data element of the request body. @@ -35,25 +45,19 @@ public struct AppStoreVersionPhasedReleaseCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } /** @@ -69,6 +73,16 @@ public struct AppStoreVersionPhasedReleaseCreateRequest: Codable, RequestBody { public init(phasedReleaseState: PhasedReleaseState? = nil) { self.phasedReleaseState = phasedReleaseState } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + phasedReleaseState = try container.decodeIfPresent(PhasedReleaseState.self, forKey: "phasedReleaseState") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(phasedReleaseState, forKey: "phasedReleaseState") + } } /** @@ -85,6 +99,16 @@ public struct AppStoreVersionPhasedReleaseCreateRequest: Codable, RequestBody { self.appStoreVersion = appStoreVersion } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appStoreVersion = try container.decode(AppStoreVersion.self, forKey: "appStoreVersion") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(appStoreVersion, forKey: "appStoreVersion") + } + /** # AppStoreVersionPhasedReleaseCreateRequest.Data.Relationships.AppStoreVersion The relationships to other resources that you can set with this request. @@ -99,6 +123,16 @@ public struct AppStoreVersionPhasedReleaseCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AppStoreVersionPhasedReleaseCreateRequest.Data.Relationships.AppStoreVersion.Data The type and ID of the resource that you're relating with the resource you're creating. @@ -115,22 +149,17 @@ public struct AppStoreVersionPhasedReleaseCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppStoreVersionPhasedReleaseResponse.swift b/Sources/Bagbutik-Models/AppStore/AppStoreVersionPhasedReleaseResponse.swift index ef097d383..8f554c3c8 100644 --- a/Sources/Bagbutik-Models/AppStore/AppStoreVersionPhasedReleaseResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppStoreVersionPhasedReleaseResponse.swift @@ -18,4 +18,16 @@ public struct AppStoreVersionPhasedReleaseResponse: Codable { self.data = data self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AppStoreVersionPhasedRelease.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/AppStore/AppStoreVersionPhasedReleaseUpdateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppStoreVersionPhasedReleaseUpdateRequest.swift index b60c39875..c10cb9c33 100644 --- a/Sources/Bagbutik-Models/AppStore/AppStoreVersionPhasedReleaseUpdateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppStoreVersionPhasedReleaseUpdateRequest.swift @@ -15,6 +15,16 @@ public struct AppStoreVersionPhasedReleaseUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AppStoreVersionPhasedReleaseUpdateRequest.Data The data element of the request body. @@ -35,25 +45,19 @@ public struct AppStoreVersionPhasedReleaseUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } /** @@ -69,6 +73,16 @@ public struct AppStoreVersionPhasedReleaseUpdateRequest: Codable, RequestBody { public init(phasedReleaseState: PhasedReleaseState? = nil) { self.phasedReleaseState = phasedReleaseState } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + phasedReleaseState = try container.decodeIfPresent(PhasedReleaseState.self, forKey: "phasedReleaseState") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(phasedReleaseState, forKey: "phasedReleaseState") + } } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppStoreVersionPhasedReleaseWithoutIncludesResponse.swift b/Sources/Bagbutik-Models/AppStore/AppStoreVersionPhasedReleaseWithoutIncludesResponse.swift index dc14d8db8..06ee4367d 100644 --- a/Sources/Bagbutik-Models/AppStore/AppStoreVersionPhasedReleaseWithoutIncludesResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppStoreVersionPhasedReleaseWithoutIncludesResponse.swift @@ -11,4 +11,16 @@ public struct AppStoreVersionPhasedReleaseWithoutIncludesResponse: Codable { self.data = data self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AppStoreVersionPhasedRelease.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/AppStore/AppStoreVersionPromotion.swift b/Sources/Bagbutik-Models/AppStore/AppStoreVersionPromotion.swift index b125482cb..fad32a422 100644 --- a/Sources/Bagbutik-Models/AppStore/AppStoreVersionPromotion.swift +++ b/Sources/Bagbutik-Models/AppStore/AppStoreVersionPromotion.swift @@ -14,24 +14,18 @@ public struct AppStoreVersionPromotion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case links - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") } } diff --git a/Sources/Bagbutik-Models/AppStore/AppStoreVersionPromotionCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppStoreVersionPromotionCreateRequest.swift index eae43dce1..028382100 100644 --- a/Sources/Bagbutik-Models/AppStore/AppStoreVersionPromotionCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppStoreVersionPromotionCreateRequest.swift @@ -8,6 +8,16 @@ public struct AppStoreVersionPromotionCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "appStoreVersionPromotions" } public let relationships: Relationships @@ -17,22 +27,17 @@ public struct AppStoreVersionPromotionCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(relationships, forKey: "relationships") } public struct Relationships: Codable { @@ -46,6 +51,18 @@ public struct AppStoreVersionPromotionCreateRequest: Codable, RequestBody { self.appStoreVersionExperimentTreatment = appStoreVersionExperimentTreatment } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appStoreVersion = try container.decode(AppStoreVersion.self, forKey: "appStoreVersion") + appStoreVersionExperimentTreatment = try container.decode(AppStoreVersionExperimentTreatment.self, forKey: "appStoreVersionExperimentTreatment") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(appStoreVersion, forKey: "appStoreVersion") + try container.encode(appStoreVersionExperimentTreatment, forKey: "appStoreVersionExperimentTreatment") + } + public struct AppStoreVersion: Codable { public let data: Data @@ -53,6 +70,16 @@ public struct AppStoreVersionPromotionCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "appStoreVersions" } @@ -62,22 +89,17 @@ public struct AppStoreVersionPromotionCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -89,6 +111,16 @@ public struct AppStoreVersionPromotionCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "appStoreVersionExperimentTreatments" } @@ -98,22 +130,17 @@ public struct AppStoreVersionPromotionCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppStoreVersionPromotionResponse.swift b/Sources/Bagbutik-Models/AppStore/AppStoreVersionPromotionResponse.swift index 3d7442916..8f678c627 100644 --- a/Sources/Bagbutik-Models/AppStore/AppStoreVersionPromotionResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppStoreVersionPromotionResponse.swift @@ -11,4 +11,16 @@ public struct AppStoreVersionPromotionResponse: Codable { self.data = data self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AppStoreVersionPromotion.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/AppStore/AppStoreVersionReleaseRequest.swift b/Sources/Bagbutik-Models/AppStore/AppStoreVersionReleaseRequest.swift index 75916edaa..58087d918 100644 --- a/Sources/Bagbutik-Models/AppStore/AppStoreVersionReleaseRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppStoreVersionReleaseRequest.swift @@ -24,24 +24,18 @@ public struct AppStoreVersionReleaseRequest: Codable, Identifiable, RequestBody } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case links - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") } } diff --git a/Sources/Bagbutik-Models/AppStore/AppStoreVersionReleaseRequestCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppStoreVersionReleaseRequestCreateRequest.swift index 10c4a54db..fb3d49ec8 100644 --- a/Sources/Bagbutik-Models/AppStore/AppStoreVersionReleaseRequestCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppStoreVersionReleaseRequestCreateRequest.swift @@ -16,6 +16,16 @@ public struct AppStoreVersionReleaseRequestCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AppStoreVersionReleaseRequestCreateRequest.Data The data element of the request body. @@ -32,22 +42,17 @@ public struct AppStoreVersionReleaseRequestCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(relationships, forKey: "relationships") } /** @@ -64,6 +69,16 @@ public struct AppStoreVersionReleaseRequestCreateRequest: Codable, RequestBody { self.appStoreVersion = appStoreVersion } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appStoreVersion = try container.decode(AppStoreVersion.self, forKey: "appStoreVersion") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(appStoreVersion, forKey: "appStoreVersion") + } + /** # AppStoreVersionReleaseRequestCreateRequest.Data.Relationships.AppStoreVersion The relationships to other resources that you can set with this request. @@ -78,6 +93,16 @@ public struct AppStoreVersionReleaseRequestCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AppStoreVersionReleaseRequestCreateRequest.Data.Relationships.AppStoreVersion.Data The type and ID of the resource that you're relating with the resource you're creating. @@ -94,22 +119,17 @@ public struct AppStoreVersionReleaseRequestCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppStoreVersionReleaseRequestResponse.swift b/Sources/Bagbutik-Models/AppStore/AppStoreVersionReleaseRequestResponse.swift index c8e6fea6a..e9957ccd2 100644 --- a/Sources/Bagbutik-Models/AppStore/AppStoreVersionReleaseRequestResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppStoreVersionReleaseRequestResponse.swift @@ -20,4 +20,16 @@ public struct AppStoreVersionReleaseRequestResponse: Codable { self.data = data self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AppStoreVersionReleaseRequest.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/AppStore/AppStoreVersionResponse.swift b/Sources/Bagbutik-Models/AppStore/AppStoreVersionResponse.swift index f3756cf77..724f07c3e 100644 --- a/Sources/Bagbutik-Models/AppStore/AppStoreVersionResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppStoreVersionResponse.swift @@ -22,6 +22,20 @@ public struct AppStoreVersionResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AppStoreVersion.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getAlternativeDistributionPackage() -> AlternativeDistributionPackage? { included?.compactMap { relationship -> AlternativeDistributionPackage? in guard case let .alternativeDistributionPackage(alternativeDistributionPackage) = relationship else { return nil } @@ -187,9 +201,5 @@ public struct AppStoreVersionResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppStoreVersionSubmission.swift b/Sources/Bagbutik-Models/AppStore/AppStoreVersionSubmission.swift index 8bf1bb1f2..2523318a6 100644 --- a/Sources/Bagbutik-Models/AppStore/AppStoreVersionSubmission.swift +++ b/Sources/Bagbutik-Models/AppStore/AppStoreVersionSubmission.swift @@ -24,28 +24,21 @@ public struct AppStoreVersionSubmission: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -62,6 +55,16 @@ public struct AppStoreVersionSubmission: Codable, Identifiable { self.appStoreVersion = appStoreVersion } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appStoreVersion = try container.decodeIfPresent(AppStoreVersion.self, forKey: "appStoreVersion") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(appStoreVersion, forKey: "appStoreVersion") + } + /** # AppStoreVersionSubmission.Relationships.AppStoreVersion The data and links that describe the relationship between the resources. @@ -81,20 +84,15 @@ public struct AppStoreVersionSubmission: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -113,22 +111,17 @@ public struct AppStoreVersionSubmission: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -151,20 +144,15 @@ public struct AppStoreVersionSubmission: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppStoreVersionSubmissionCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppStoreVersionSubmissionCreateRequest.swift index f96032114..93f93add0 100644 --- a/Sources/Bagbutik-Models/AppStore/AppStoreVersionSubmissionCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppStoreVersionSubmissionCreateRequest.swift @@ -16,6 +16,16 @@ public struct AppStoreVersionSubmissionCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AppStoreVersionSubmissionCreateRequest.Data The data element of the request body. @@ -34,22 +44,17 @@ public struct AppStoreVersionSubmissionCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(relationships, forKey: "relationships") } /** @@ -66,6 +71,16 @@ public struct AppStoreVersionSubmissionCreateRequest: Codable, RequestBody { self.appStoreVersion = appStoreVersion } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appStoreVersion = try container.decode(AppStoreVersion.self, forKey: "appStoreVersion") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(appStoreVersion, forKey: "appStoreVersion") + } + /** # AppStoreVersionSubmissionCreateRequest.Data.Relationships.AppStoreVersion The relationships to other resources that you can set with this request. @@ -80,6 +95,16 @@ public struct AppStoreVersionSubmissionCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AppStoreVersionSubmissionCreateRequest.Data.Relationships.AppStoreVersion.Data The type and ID of the resource that you're relating with the resource you're creating. @@ -96,22 +121,17 @@ public struct AppStoreVersionSubmissionCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppStoreVersionSubmissionResponse.swift b/Sources/Bagbutik-Models/AppStore/AppStoreVersionSubmissionResponse.swift index bcf2dcb81..2a9a89d10 100644 --- a/Sources/Bagbutik-Models/AppStore/AppStoreVersionSubmissionResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppStoreVersionSubmissionResponse.swift @@ -21,4 +21,18 @@ public struct AppStoreVersionSubmissionResponse: Codable { self.included = included self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AppStoreVersionSubmission.self, forKey: "data") + included = try container.decodeIfPresent([AppStoreVersion].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/AppStore/AppStoreVersionUpdateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppStoreVersionUpdateRequest.swift index 51fbb93df..df92b96ff 100644 --- a/Sources/Bagbutik-Models/AppStore/AppStoreVersionUpdateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppStoreVersionUpdateRequest.swift @@ -15,6 +15,16 @@ public struct AppStoreVersionUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AppStoreVersionUpdateRequest.Data The data element of the request body. @@ -38,28 +48,21 @@ public struct AppStoreVersionUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -92,6 +95,26 @@ public struct AppStoreVersionUpdateRequest: Codable, RequestBody { self.reviewType = reviewType self.versionString = versionString } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + copyright = try container.decodeIfPresent(String.self, forKey: "copyright") + downloadable = try container.decodeIfPresent(Bool.self, forKey: "downloadable") + earliestReleaseDate = try container.decodeIfPresent(Date.self, forKey: "earliestReleaseDate") + releaseType = try container.decodeIfPresent(AppStoreVersion.Attributes.ReleaseType.self, forKey: "releaseType") + reviewType = try container.decodeIfPresent(AppStoreVersion.Attributes.ReviewType.self, forKey: "reviewType") + versionString = try container.decodeIfPresent(String.self, forKey: "versionString") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(copyright, forKey: "copyright") + try container.encodeIfPresent(downloadable, forKey: "downloadable") + try container.encodeIfPresent(earliestReleaseDate, forKey: "earliestReleaseDate") + try container.encodeIfPresent(releaseType, forKey: "releaseType") + try container.encodeIfPresent(reviewType, forKey: "reviewType") + try container.encodeIfPresent(versionString, forKey: "versionString") + } } /** @@ -113,6 +136,18 @@ public struct AppStoreVersionUpdateRequest: Codable, RequestBody { self.build = build } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appClipDefaultExperience = try container.decodeIfPresent(AppClipDefaultExperience.self, forKey: "appClipDefaultExperience") + build = try container.decodeIfPresent(Build.self, forKey: "build") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(appClipDefaultExperience, forKey: "appClipDefaultExperience") + try container.encodeIfPresent(build, forKey: "build") + } + /** # AppStoreVersionUpdateRequest.Data.Relationships.AppClipDefaultExperience The relationship to the Default App Clip Default Experiences resource you set with the request that updates the App Store Versions resource. @@ -129,17 +164,13 @@ public struct AppStoreVersionUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } /** @@ -160,22 +191,17 @@ public struct AppStoreVersionUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -195,17 +221,13 @@ public struct AppStoreVersionUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } /** @@ -224,22 +246,17 @@ public struct AppStoreVersionUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppStoreVersionsResponse.swift b/Sources/Bagbutik-Models/AppStore/AppStoreVersionsResponse.swift index 3cc49ccd6..e6c0d8b87 100644 --- a/Sources/Bagbutik-Models/AppStore/AppStoreVersionsResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppStoreVersionsResponse.swift @@ -27,6 +27,22 @@ public struct AppStoreVersionsResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([AppStoreVersion].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getAlternativeDistributionPackage(for appStoreVersion: AppStoreVersion) -> AlternativeDistributionPackage? { included?.compactMap { relationship -> AlternativeDistributionPackage? in guard case let .alternativeDistributionPackage(alternativeDistributionPackage) = relationship else { return nil } @@ -192,9 +208,5 @@ public struct AppStoreVersionsResponse: Codable, PagedResponse { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppUpdateRequest.swift b/Sources/Bagbutik-Models/AppStore/AppUpdateRequest.swift index 88968c818..96d0aafac 100644 --- a/Sources/Bagbutik-Models/AppStore/AppUpdateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/AppUpdateRequest.swift @@ -19,6 +19,18 @@ public struct AppUpdateRequest: Codable, RequestBody { self.included = included } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + included = try container.decodeIfPresent([AppPriceInlineCreate].self, forKey: "included") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + } + /** # AppUpdateRequest.Data The data element of the request body. @@ -42,28 +54,21 @@ public struct AppUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -120,6 +125,30 @@ public struct AppUpdateRequest: Codable, RequestBody { self.subscriptionStatusUrlVersion = subscriptionStatusUrlVersion self.subscriptionStatusUrlVersionForSandbox = subscriptionStatusUrlVersionForSandbox } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + availableInNewTerritories = try container.decodeIfPresent(Bool.self, forKey: "availableInNewTerritories") + bundleId = try container.decodeIfPresent(String.self, forKey: "bundleId") + contentRightsDeclaration = try container.decodeIfPresent(App.Attributes.ContentRightsDeclaration.self, forKey: "contentRightsDeclaration") + primaryLocale = try container.decodeIfPresent(String.self, forKey: "primaryLocale") + subscriptionStatusUrl = try container.decodeIfPresent(String.self, forKey: "subscriptionStatusUrl") + subscriptionStatusUrlForSandbox = try container.decodeIfPresent(String.self, forKey: "subscriptionStatusUrlForSandbox") + subscriptionStatusUrlVersion = try container.decodeIfPresent(SubscriptionStatusUrlVersion.self, forKey: "subscriptionStatusUrlVersion") + subscriptionStatusUrlVersionForSandbox = try container.decodeIfPresent(SubscriptionStatusUrlVersion.self, forKey: "subscriptionStatusUrlVersionForSandbox") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(availableInNewTerritories, forKey: "availableInNewTerritories") + try container.encodeIfPresent(bundleId, forKey: "bundleId") + try container.encodeIfPresent(contentRightsDeclaration, forKey: "contentRightsDeclaration") + try container.encodeIfPresent(primaryLocale, forKey: "primaryLocale") + try container.encodeIfPresent(subscriptionStatusUrl, forKey: "subscriptionStatusUrl") + try container.encodeIfPresent(subscriptionStatusUrlForSandbox, forKey: "subscriptionStatusUrlForSandbox") + try container.encodeIfPresent(subscriptionStatusUrlVersion, forKey: "subscriptionStatusUrlVersion") + try container.encodeIfPresent(subscriptionStatusUrlVersionForSandbox, forKey: "subscriptionStatusUrlVersionForSandbox") + } } /** @@ -145,6 +174,18 @@ public struct AppUpdateRequest: Codable, RequestBody { public init() {} + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + availableTerritories = try container.decodeIfPresent(AvailableTerritories.self, forKey: "availableTerritories") + prices = try container.decodeIfPresent(Prices.self, forKey: "prices") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(availableTerritories, forKey: "availableTerritories") + try container.encodeIfPresent(prices, forKey: "prices") + } + /** # AppUpdateRequest.Data.Relationships.AvailableTerritories The data and links that describe the relationship between the resources. @@ -160,17 +201,13 @@ public struct AppUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } /** @@ -189,22 +226,17 @@ public struct AppUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -224,17 +256,13 @@ public struct AppUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } /** @@ -253,22 +281,17 @@ public struct AppUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppWithoutIncludesResponse.swift b/Sources/Bagbutik-Models/AppStore/AppWithoutIncludesResponse.swift index 443bcad31..0282ddaca 100644 --- a/Sources/Bagbutik-Models/AppStore/AppWithoutIncludesResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppWithoutIncludesResponse.swift @@ -11,4 +11,16 @@ public struct AppWithoutIncludesResponse: Codable { self.data = data self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(App.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/AppStore/AppsResponse.swift b/Sources/Bagbutik-Models/AppStore/AppsResponse.swift index be30636f5..687b1ae38 100644 --- a/Sources/Bagbutik-Models/AppStore/AppsResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppsResponse.swift @@ -30,6 +30,22 @@ public struct AppsResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([App].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getAppClips(for app: App) -> [AppClip] { guard let appClipIds = app.relationships?.appClips?.data?.map(\.id), let appClips = included?.compactMap({ relationship -> AppClip? in @@ -414,9 +430,5 @@ public struct AppsResponse: Codable, PagedResponse { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/AppsWithoutIncludesResponse.swift b/Sources/Bagbutik-Models/AppStore/AppsWithoutIncludesResponse.swift index 86660555c..1dbb2bb4a 100644 --- a/Sources/Bagbutik-Models/AppStore/AppsWithoutIncludesResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/AppsWithoutIncludesResponse.swift @@ -16,4 +16,18 @@ public struct AppsWithoutIncludesResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([App].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/AppStore/BetaAppClipInvocationsResponse.swift b/Sources/Bagbutik-Models/AppStore/BetaAppClipInvocationsResponse.swift index a907e2209..0ab3ea068 100644 --- a/Sources/Bagbutik-Models/AppStore/BetaAppClipInvocationsResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/BetaAppClipInvocationsResponse.swift @@ -30,4 +30,20 @@ public struct BetaAppClipInvocationsResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([BetaAppClipInvocation].self, forKey: "data") + included = try container.decodeIfPresent([BetaAppClipInvocationLocalization].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/AppStore/BuildBundle.swift b/Sources/Bagbutik-Models/AppStore/BuildBundle.swift index 7a831868b..277b8845a 100644 --- a/Sources/Bagbutik-Models/AppStore/BuildBundle.swift +++ b/Sources/Bagbutik-Models/AppStore/BuildBundle.swift @@ -32,31 +32,23 @@ public struct BuildBundle: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -139,6 +131,48 @@ public struct BuildBundle: Codable, Identifiable { self.usesLocationServices = usesLocationServices } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + bundleId = try container.decodeIfPresent(String.self, forKey: "bundleId") + bundleType = try container.decodeIfPresent(BundleType.self, forKey: "bundleType") + dSYMUrl = try container.decodeIfPresent(String.self, forKey: "dSYMUrl") + deviceProtocols = try container.decodeIfPresent([String].self, forKey: "deviceProtocols") + entitlements = try container.decodeIfPresent([String: [String: String]].self, forKey: "entitlements") + fileName = try container.decodeIfPresent(String.self, forKey: "fileName") + hasOnDemandResources = try container.decodeIfPresent(Bool.self, forKey: "hasOnDemandResources") + hasPrerenderedIcon = try container.decodeIfPresent(Bool.self, forKey: "hasPrerenderedIcon") + hasSirikit = try container.decodeIfPresent(Bool.self, forKey: "hasSirikit") + includesSymbols = try container.decodeIfPresent(Bool.self, forKey: "includesSymbols") + isIosBuildMacAppStoreCompatible = try container.decodeIfPresent(Bool.self, forKey: "isIosBuildMacAppStoreCompatible") + locales = try container.decodeIfPresent([String].self, forKey: "locales") + platformBuild = try container.decodeIfPresent(String.self, forKey: "platformBuild") + requiredCapabilities = try container.decodeIfPresent([String].self, forKey: "requiredCapabilities") + sdkBuild = try container.decodeIfPresent(String.self, forKey: "sdkBuild") + supportedArchitectures = try container.decodeIfPresent([String].self, forKey: "supportedArchitectures") + usesLocationServices = try container.decodeIfPresent(Bool.self, forKey: "usesLocationServices") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(bundleId, forKey: "bundleId") + try container.encodeIfPresent(bundleType, forKey: "bundleType") + try container.encodeIfPresent(dSYMUrl, forKey: "dSYMUrl") + try container.encodeIfPresent(deviceProtocols, forKey: "deviceProtocols") + try container.encodeIfPresent(entitlements, forKey: "entitlements") + try container.encodeIfPresent(fileName, forKey: "fileName") + try container.encodeIfPresent(hasOnDemandResources, forKey: "hasOnDemandResources") + try container.encodeIfPresent(hasPrerenderedIcon, forKey: "hasPrerenderedIcon") + try container.encodeIfPresent(hasSirikit, forKey: "hasSirikit") + try container.encodeIfPresent(includesSymbols, forKey: "includesSymbols") + try container.encodeIfPresent(isIosBuildMacAppStoreCompatible, forKey: "isIosBuildMacAppStoreCompatible") + try container.encodeIfPresent(locales, forKey: "locales") + try container.encodeIfPresent(platformBuild, forKey: "platformBuild") + try container.encodeIfPresent(requiredCapabilities, forKey: "requiredCapabilities") + try container.encodeIfPresent(sdkBuild, forKey: "sdkBuild") + try container.encodeIfPresent(supportedArchitectures, forKey: "supportedArchitectures") + try container.encodeIfPresent(usesLocationServices, forKey: "usesLocationServices") + } + public enum BundleType: String, Codable, CaseIterable { case app = "APP" case appClip = "APP_CLIP" @@ -173,6 +207,22 @@ public struct BuildBundle: Codable, Identifiable { self.buildBundleFileSizes = buildBundleFileSizes } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appClipDomainCacheStatus = try container.decodeIfPresent(AppClipDomainCacheStatus.self, forKey: "appClipDomainCacheStatus") + appClipDomainDebugStatus = try container.decodeIfPresent(AppClipDomainDebugStatus.self, forKey: "appClipDomainDebugStatus") + betaAppClipInvocations = try container.decodeIfPresent(BetaAppClipInvocations.self, forKey: "betaAppClipInvocations") + buildBundleFileSizes = try container.decodeIfPresent(BuildBundleFileSizes.self, forKey: "buildBundleFileSizes") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(appClipDomainCacheStatus, forKey: "appClipDomainCacheStatus") + try container.encodeIfPresent(appClipDomainDebugStatus, forKey: "appClipDomainDebugStatus") + try container.encodeIfPresent(betaAppClipInvocations, forKey: "betaAppClipInvocations") + try container.encodeIfPresent(buildBundleFileSizes, forKey: "buildBundleFileSizes") + } + /** # BuildBundle.Relationships.AppClipDomainCacheStatus The data and links that describe the relationship between the Build Bundles and the App Clip Domain Cache Statuses resources. @@ -194,20 +244,15 @@ public struct BuildBundle: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -228,22 +273,17 @@ public struct BuildBundle: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -268,20 +308,15 @@ public struct BuildBundle: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -307,20 +342,15 @@ public struct BuildBundle: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -341,22 +371,17 @@ public struct BuildBundle: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -381,20 +406,15 @@ public struct BuildBundle: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -424,23 +444,17 @@ public struct BuildBundle: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } /** @@ -461,22 +475,17 @@ public struct BuildBundle: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -501,20 +510,15 @@ public struct BuildBundle: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -544,23 +548,17 @@ public struct BuildBundle: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } /** @@ -581,22 +579,17 @@ public struct BuildBundle: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -621,20 +614,15 @@ public struct BuildBundle: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/BuildBundleFileSize.swift b/Sources/Bagbutik-Models/AppStore/BuildBundleFileSize.swift index b1fa58dc8..6082f7afb 100644 --- a/Sources/Bagbutik-Models/AppStore/BuildBundleFileSize.swift +++ b/Sources/Bagbutik-Models/AppStore/BuildBundleFileSize.swift @@ -28,28 +28,21 @@ public struct BuildBundleFileSize: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } /** @@ -79,5 +72,21 @@ public struct BuildBundleFileSize: Codable, Identifiable { self.installBytes = installBytes self.osVersion = osVersion } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + deviceModel = try container.decodeIfPresent(String.self, forKey: "deviceModel") + downloadBytes = try container.decodeIfPresent(Int.self, forKey: "downloadBytes") + installBytes = try container.decodeIfPresent(Int.self, forKey: "installBytes") + osVersion = try container.decodeIfPresent(String.self, forKey: "osVersion") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(deviceModel, forKey: "deviceModel") + try container.encodeIfPresent(downloadBytes, forKey: "downloadBytes") + try container.encodeIfPresent(installBytes, forKey: "installBytes") + try container.encodeIfPresent(osVersion, forKey: "osVersion") + } } } diff --git a/Sources/Bagbutik-Models/AppStore/BuildBundleFileSizesResponse.swift b/Sources/Bagbutik-Models/AppStore/BuildBundleFileSizesResponse.swift index fe70eb8f0..ded9102b6 100644 --- a/Sources/Bagbutik-Models/AppStore/BuildBundleFileSizesResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/BuildBundleFileSizesResponse.swift @@ -26,4 +26,18 @@ public struct BuildBundleFileSizesResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([BuildBundleFileSize].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/AppStore/BuildIcon.swift b/Sources/Bagbutik-Models/AppStore/BuildIcon.swift index c42e6be2c..47ed8ecb7 100644 --- a/Sources/Bagbutik-Models/AppStore/BuildIcon.swift +++ b/Sources/Bagbutik-Models/AppStore/BuildIcon.swift @@ -24,28 +24,21 @@ public struct BuildIcon: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } /** @@ -68,5 +61,19 @@ public struct BuildIcon: Codable, Identifiable { self.iconType = iconType self.name = name } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + iconAsset = try container.decodeIfPresent(ImageAsset.self, forKey: "iconAsset") + iconType = try container.decodeIfPresent(IconAssetType.self, forKey: "iconType") + name = try container.decodeIfPresent(String.self, forKey: "name") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(iconAsset, forKey: "iconAsset") + try container.encodeIfPresent(iconType, forKey: "iconType") + try container.encodeIfPresent(name, forKey: "name") + } } } diff --git a/Sources/Bagbutik-Models/AppStore/BuildIconsResponse.swift b/Sources/Bagbutik-Models/AppStore/BuildIconsResponse.swift index a1f915713..eb71e9d93 100644 --- a/Sources/Bagbutik-Models/AppStore/BuildIconsResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/BuildIconsResponse.swift @@ -23,4 +23,18 @@ public struct BuildIconsResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([BuildIcon].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/AppStore/BuildIconsWithoutIncludesResponse.swift b/Sources/Bagbutik-Models/AppStore/BuildIconsWithoutIncludesResponse.swift index 592ebeddd..f5149230f 100644 --- a/Sources/Bagbutik-Models/AppStore/BuildIconsWithoutIncludesResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/BuildIconsWithoutIncludesResponse.swift @@ -16,4 +16,18 @@ public struct BuildIconsWithoutIncludesResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([BuildIcon].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/AppStore/Csv.swift b/Sources/Bagbutik-Models/AppStore/Csv.swift index de8929d4e..44691f28b 100644 --- a/Sources/Bagbutik-Models/AppStore/Csv.swift +++ b/Sources/Bagbutik-Models/AppStore/Csv.swift @@ -7,4 +7,13 @@ public struct Csv: PlainTextResponse { public static func from(text: String) -> Csv { return Self(text: text) } + + public init(text: String) { + self.text = text + } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + text = try container.decode(String.self, forKey: "text") + } } diff --git a/Sources/Bagbutik-Models/AppStore/CustomerReview.swift b/Sources/Bagbutik-Models/AppStore/CustomerReview.swift index 5b7e2cc37..247f82d79 100644 --- a/Sources/Bagbutik-Models/AppStore/CustomerReview.swift +++ b/Sources/Bagbutik-Models/AppStore/CustomerReview.swift @@ -32,31 +32,23 @@ public struct CustomerReview: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -94,6 +86,26 @@ public struct CustomerReview: Codable, Identifiable { self.territory = territory self.title = title } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + body = try container.decodeIfPresent(String.self, forKey: "body") + createdDate = try container.decodeIfPresent(Date.self, forKey: "createdDate") + rating = try container.decodeIfPresent(Int.self, forKey: "rating") + reviewerNickname = try container.decodeIfPresent(String.self, forKey: "reviewerNickname") + territory = try container.decodeIfPresent(TerritoryCode.self, forKey: "territory") + title = try container.decodeIfPresent(String.self, forKey: "title") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(body, forKey: "body") + try container.encodeIfPresent(createdDate, forKey: "createdDate") + try container.encodeIfPresent(rating, forKey: "rating") + try container.encodeIfPresent(reviewerNickname, forKey: "reviewerNickname") + try container.encodeIfPresent(territory, forKey: "territory") + try container.encodeIfPresent(title, forKey: "title") + } } /** @@ -111,6 +123,16 @@ public struct CustomerReview: Codable, Identifiable { self.response = response } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + response = try container.decodeIfPresent(Response.self, forKey: "response") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(response, forKey: "response") + } + /** # CustomerReview.Relationships.Response The data and links that describe the relationship between the resources. @@ -132,20 +154,15 @@ public struct CustomerReview: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -166,22 +183,17 @@ public struct CustomerReview: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -206,20 +218,15 @@ public struct CustomerReview: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/CustomerReviewResponse.swift b/Sources/Bagbutik-Models/AppStore/CustomerReviewResponse.swift index 96175f893..7e813eafd 100644 --- a/Sources/Bagbutik-Models/AppStore/CustomerReviewResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/CustomerReviewResponse.swift @@ -24,4 +24,18 @@ public struct CustomerReviewResponse: Codable { self.included = included self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(CustomerReview.self, forKey: "data") + included = try container.decodeIfPresent([CustomerReviewResponseV1].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/AppStore/CustomerReviewResponseV1.swift b/Sources/Bagbutik-Models/AppStore/CustomerReviewResponseV1.swift index 66f590ab8..f1a53d743 100644 --- a/Sources/Bagbutik-Models/AppStore/CustomerReviewResponseV1.swift +++ b/Sources/Bagbutik-Models/AppStore/CustomerReviewResponseV1.swift @@ -32,31 +32,23 @@ public struct CustomerReviewResponseV1: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -83,6 +75,20 @@ public struct CustomerReviewResponseV1: Codable, Identifiable { self.state = state } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + lastModifiedDate = try container.decodeIfPresent(Date.self, forKey: "lastModifiedDate") + responseBody = try container.decodeIfPresent(String.self, forKey: "responseBody") + state = try container.decodeIfPresent(State.self, forKey: "state") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(lastModifiedDate, forKey: "lastModifiedDate") + try container.encodeIfPresent(responseBody, forKey: "responseBody") + try container.encodeIfPresent(state, forKey: "state") + } + public enum State: String, Codable, CaseIterable { case pendingPublish = "PENDING_PUBLISH" case published = "PUBLISHED" @@ -104,6 +110,16 @@ public struct CustomerReviewResponseV1: Codable, Identifiable { self.review = review } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + review = try container.decodeIfPresent(Review.self, forKey: "review") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(review, forKey: "review") + } + /** # CustomerReviewResponseV1.Relationships.Review The data and links that describe the relationship between the resources. @@ -125,20 +141,15 @@ public struct CustomerReviewResponseV1: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -159,22 +170,17 @@ public struct CustomerReviewResponseV1: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -199,20 +205,15 @@ public struct CustomerReviewResponseV1: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/CustomerReviewResponseV1CreateRequest.swift b/Sources/Bagbutik-Models/AppStore/CustomerReviewResponseV1CreateRequest.swift index 2a90e2519..2540533d1 100644 --- a/Sources/Bagbutik-Models/AppStore/CustomerReviewResponseV1CreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/CustomerReviewResponseV1CreateRequest.swift @@ -16,6 +16,16 @@ public struct CustomerReviewResponseV1CreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # CustomerReviewResponseV1CreateRequest.Data The data element of the request body for creating a response to a customer review. @@ -39,25 +49,19 @@ public struct CustomerReviewResponseV1CreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } /** @@ -74,6 +78,16 @@ public struct CustomerReviewResponseV1CreateRequest: Codable, RequestBody { public init(responseBody: String) { self.responseBody = responseBody } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + responseBody = try container.decode(String.self, forKey: "responseBody") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(responseBody, forKey: "responseBody") + } } /** @@ -91,6 +105,16 @@ public struct CustomerReviewResponseV1CreateRequest: Codable, RequestBody { self.review = review } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + review = try container.decode(Review.self, forKey: "review") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(review, forKey: "review") + } + /** # CustomerReviewResponseV1CreateRequest.Data.Relationships.Review The data and links that describe the relationship between the resources. @@ -106,6 +130,16 @@ public struct CustomerReviewResponseV1CreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # CustomerReviewResponseV1CreateRequest.Data.Relationships.Review.Data The type and ID of a resource that you’re relating with the resource you’re updating. @@ -124,22 +158,17 @@ public struct CustomerReviewResponseV1CreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/CustomerReviewResponseV1Response.swift b/Sources/Bagbutik-Models/AppStore/CustomerReviewResponseV1Response.swift index 7ec9389ae..92ae38b4a 100644 --- a/Sources/Bagbutik-Models/AppStore/CustomerReviewResponseV1Response.swift +++ b/Sources/Bagbutik-Models/AppStore/CustomerReviewResponseV1Response.swift @@ -24,4 +24,18 @@ public struct CustomerReviewResponseV1Response: Codable { self.included = included self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(CustomerReviewResponseV1.self, forKey: "data") + included = try container.decodeIfPresent([CustomerReview].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/AppStore/CustomerReviewsResponse.swift b/Sources/Bagbutik-Models/AppStore/CustomerReviewsResponse.swift index cab6e3f1c..1d0b5c267 100644 --- a/Sources/Bagbutik-Models/AppStore/CustomerReviewsResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/CustomerReviewsResponse.swift @@ -30,4 +30,20 @@ public struct CustomerReviewsResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([CustomerReview].self, forKey: "data") + included = try container.decodeIfPresent([CustomerReviewResponseV1].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/AppStore/EndAppAvailabilityPreOrder.swift b/Sources/Bagbutik-Models/AppStore/EndAppAvailabilityPreOrder.swift index 077f9513c..7aae72dce 100644 --- a/Sources/Bagbutik-Models/AppStore/EndAppAvailabilityPreOrder.swift +++ b/Sources/Bagbutik-Models/AppStore/EndAppAvailabilityPreOrder.swift @@ -21,24 +21,18 @@ public struct EndAppAvailabilityPreOrder: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case links - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") } } diff --git a/Sources/Bagbutik-Models/AppStore/EndAppAvailabilityPreOrderCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/EndAppAvailabilityPreOrderCreateRequest.swift index fd90dc034..1b25152f1 100644 --- a/Sources/Bagbutik-Models/AppStore/EndAppAvailabilityPreOrderCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/EndAppAvailabilityPreOrderCreateRequest.swift @@ -15,6 +15,16 @@ public struct EndAppAvailabilityPreOrderCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "endAppAvailabilityPreOrders" } public let relationships: Relationships @@ -24,22 +34,17 @@ public struct EndAppAvailabilityPreOrderCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(relationships, forKey: "relationships") } public struct Relationships: Codable { @@ -49,6 +54,16 @@ public struct EndAppAvailabilityPreOrderCreateRequest: Codable, RequestBody { self.territoryAvailabilities = territoryAvailabilities } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + territoryAvailabilities = try container.decode(TerritoryAvailabilities.self, forKey: "territoryAvailabilities") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(territoryAvailabilities, forKey: "territoryAvailabilities") + } + public struct TerritoryAvailabilities: Codable { public let data: [Data] @@ -56,6 +71,16 @@ public struct EndAppAvailabilityPreOrderCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "territoryAvailabilities" } @@ -65,22 +90,17 @@ public struct EndAppAvailabilityPreOrderCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/EndAppAvailabilityPreOrderResponse.swift b/Sources/Bagbutik-Models/AppStore/EndAppAvailabilityPreOrderResponse.swift index db5847df0..680e13a62 100644 --- a/Sources/Bagbutik-Models/AppStore/EndAppAvailabilityPreOrderResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/EndAppAvailabilityPreOrderResponse.swift @@ -18,4 +18,16 @@ public struct EndAppAvailabilityPreOrderResponse: Codable { self.data = data self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(EndAppAvailabilityPreOrder.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/AppStore/EndUserLicenseAgreement.swift b/Sources/Bagbutik-Models/AppStore/EndUserLicenseAgreement.swift index da8f763de..8673f22db 100644 --- a/Sources/Bagbutik-Models/AppStore/EndUserLicenseAgreement.swift +++ b/Sources/Bagbutik-Models/AppStore/EndUserLicenseAgreement.swift @@ -27,31 +27,23 @@ public struct EndUserLicenseAgreement: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -67,6 +59,16 @@ public struct EndUserLicenseAgreement: Codable, Identifiable { public init(agreementText: String? = nil) { self.agreementText = agreementText } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + agreementText = try container.decodeIfPresent(String.self, forKey: "agreementText") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(agreementText, forKey: "agreementText") + } } /** @@ -87,6 +89,18 @@ public struct EndUserLicenseAgreement: Codable, Identifiable { self.territories = territories } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + app = try container.decodeIfPresent(App.self, forKey: "app") + territories = try container.decodeIfPresent(Territories.self, forKey: "territories") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(app, forKey: "app") + try container.encodeIfPresent(territories, forKey: "territories") + } + /** # EndUserLicenseAgreement.Relationships.App The data and links that describe the relationship between the resources. @@ -106,20 +120,15 @@ public struct EndUserLicenseAgreement: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -138,22 +147,17 @@ public struct EndUserLicenseAgreement: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -176,20 +180,15 @@ public struct EndUserLicenseAgreement: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -216,23 +215,17 @@ public struct EndUserLicenseAgreement: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } /** @@ -251,22 +244,17 @@ public struct EndUserLicenseAgreement: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -289,20 +277,15 @@ public struct EndUserLicenseAgreement: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/EndUserLicenseAgreementCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/EndUserLicenseAgreementCreateRequest.swift index f48652d4c..d235cdb2f 100644 --- a/Sources/Bagbutik-Models/AppStore/EndUserLicenseAgreementCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/EndUserLicenseAgreementCreateRequest.swift @@ -15,6 +15,16 @@ public struct EndUserLicenseAgreementCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # EndUserLicenseAgreementCreateRequest.Data The data element of the request body. @@ -35,25 +45,19 @@ public struct EndUserLicenseAgreementCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } /** @@ -69,6 +73,16 @@ public struct EndUserLicenseAgreementCreateRequest: Codable, RequestBody { public init(agreementText: String) { self.agreementText = agreementText } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + agreementText = try container.decode(String.self, forKey: "agreementText") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(agreementText, forKey: "agreementText") + } } /** @@ -89,6 +103,18 @@ public struct EndUserLicenseAgreementCreateRequest: Codable, RequestBody { self.territories = territories } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + app = try container.decode(App.self, forKey: "app") + territories = try container.decode(Territories.self, forKey: "territories") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(app, forKey: "app") + try container.encode(territories, forKey: "territories") + } + /** # EndUserLicenseAgreementCreateRequest.Data.Relationships.App The relationships to other resources that you can set with this request. @@ -103,6 +129,16 @@ public struct EndUserLicenseAgreementCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # EndUserLicenseAgreementCreateRequest.Data.Relationships.App.Data The type and ID of the resource that you're relating with the resource you're creating. @@ -119,22 +155,17 @@ public struct EndUserLicenseAgreementCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -153,6 +184,16 @@ public struct EndUserLicenseAgreementCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # EndUserLicenseAgreementCreateRequest.Data.Relationships.Territories.Data The type and ID of the resource that you're relating with the resource you're creating. @@ -169,22 +210,17 @@ public struct EndUserLicenseAgreementCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/EndUserLicenseAgreementResponse.swift b/Sources/Bagbutik-Models/AppStore/EndUserLicenseAgreementResponse.swift index 70c0a77b9..ed9a8be2b 100644 --- a/Sources/Bagbutik-Models/AppStore/EndUserLicenseAgreementResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/EndUserLicenseAgreementResponse.swift @@ -22,6 +22,20 @@ public struct EndUserLicenseAgreementResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(EndUserLicenseAgreement.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getApp() -> App? { included?.compactMap { relationship -> App? in guard case let .app(app) = relationship else { return nil } @@ -64,9 +78,5 @@ public struct EndUserLicenseAgreementResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/EndUserLicenseAgreementUpdateRequest.swift b/Sources/Bagbutik-Models/AppStore/EndUserLicenseAgreementUpdateRequest.swift index ddd3af5eb..b887b77a8 100644 --- a/Sources/Bagbutik-Models/AppStore/EndUserLicenseAgreementUpdateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/EndUserLicenseAgreementUpdateRequest.swift @@ -15,6 +15,16 @@ public struct EndUserLicenseAgreementUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # EndUserLicenseAgreementUpdateRequest.Data The data element of the request body. @@ -38,28 +48,21 @@ public struct EndUserLicenseAgreementUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -75,6 +78,16 @@ public struct EndUserLicenseAgreementUpdateRequest: Codable, RequestBody { public init(agreementText: String? = nil) { self.agreementText = agreementText } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + agreementText = try container.decodeIfPresent(String.self, forKey: "agreementText") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(agreementText, forKey: "agreementText") + } } /** @@ -91,6 +104,16 @@ public struct EndUserLicenseAgreementUpdateRequest: Codable, RequestBody { self.territories = territories } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + territories = try container.decodeIfPresent(Territories.self, forKey: "territories") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(territories, forKey: "territories") + } + /** # EndUserLicenseAgreementUpdateRequest.Data.Relationships.Territories The data and links that describe the relationship between the resources. @@ -106,17 +129,13 @@ public struct EndUserLicenseAgreementUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } /** @@ -135,22 +154,17 @@ public struct EndUserLicenseAgreementUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/EndUserLicenseAgreementWithoutIncludesResponse.swift b/Sources/Bagbutik-Models/AppStore/EndUserLicenseAgreementWithoutIncludesResponse.swift index acf246241..312544a21 100644 --- a/Sources/Bagbutik-Models/AppStore/EndUserLicenseAgreementWithoutIncludesResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/EndUserLicenseAgreementWithoutIncludesResponse.swift @@ -11,4 +11,16 @@ public struct EndUserLicenseAgreementWithoutIncludesResponse: Codable { self.data = data self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(EndUserLicenseAgreement.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/AppStore/GameCenterEnabledVersion.swift b/Sources/Bagbutik-Models/AppStore/GameCenterEnabledVersion.swift index 82003053c..69f96372c 100644 --- a/Sources/Bagbutik-Models/AppStore/GameCenterEnabledVersion.swift +++ b/Sources/Bagbutik-Models/AppStore/GameCenterEnabledVersion.swift @@ -27,31 +27,23 @@ public struct GameCenterEnabledVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -74,6 +66,20 @@ public struct GameCenterEnabledVersion: Codable, Identifiable { self.platform = platform self.versionString = versionString } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + iconAsset = try container.decodeIfPresent(ImageAsset.self, forKey: "iconAsset") + platform = try container.decodeIfPresent(Platform.self, forKey: "platform") + versionString = try container.decodeIfPresent(String.self, forKey: "versionString") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(iconAsset, forKey: "iconAsset") + try container.encodeIfPresent(platform, forKey: "platform") + try container.encodeIfPresent(versionString, forKey: "versionString") + } } /** @@ -94,6 +100,18 @@ public struct GameCenterEnabledVersion: Codable, Identifiable { self.compatibleVersions = compatibleVersions } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + app = try container.decodeIfPresent(App.self, forKey: "app") + compatibleVersions = try container.decodeIfPresent(CompatibleVersions.self, forKey: "compatibleVersions") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(app, forKey: "app") + try container.encodeIfPresent(compatibleVersions, forKey: "compatibleVersions") + } + /** # GameCenterEnabledVersion.Relationships.App The data and links that describe the relationship between the resources. @@ -113,20 +131,15 @@ public struct GameCenterEnabledVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -145,22 +158,17 @@ public struct GameCenterEnabledVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -183,20 +191,15 @@ public struct GameCenterEnabledVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -223,23 +226,17 @@ public struct GameCenterEnabledVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } /** @@ -258,22 +255,17 @@ public struct GameCenterEnabledVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -296,20 +288,15 @@ public struct GameCenterEnabledVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/GameCenterEnabledVersionCompatibleVersionsLinkagesRequest.swift b/Sources/Bagbutik-Models/AppStore/GameCenterEnabledVersionCompatibleVersionsLinkagesRequest.swift index 0127996ea..938aa48f5 100644 --- a/Sources/Bagbutik-Models/AppStore/GameCenterEnabledVersionCompatibleVersionsLinkagesRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/GameCenterEnabledVersionCompatibleVersionsLinkagesRequest.swift @@ -15,6 +15,16 @@ public struct GameCenterEnabledVersionCompatibleVersionsLinkagesRequest: Codable self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # GameCenterEnabledVersionCompatibleVersionsLinkagesRequest.Data The data element of the request body. @@ -31,22 +41,17 @@ public struct GameCenterEnabledVersionCompatibleVersionsLinkagesRequest: Codable } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/GameCenterEnabledVersionCompatibleVersionsLinkagesResponse.swift b/Sources/Bagbutik-Models/AppStore/GameCenterEnabledVersionCompatibleVersionsLinkagesResponse.swift index b4d8d4cf5..d2b02d06f 100644 --- a/Sources/Bagbutik-Models/AppStore/GameCenterEnabledVersionCompatibleVersionsLinkagesResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/GameCenterEnabledVersionCompatibleVersionsLinkagesResponse.swift @@ -22,6 +22,20 @@ public struct GameCenterEnabledVersionCompatibleVersionsLinkagesResponse: Codabl self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + /** # GameCenterEnabledVersionCompatibleVersionsLinkagesResponse.Data The data element of the response body. @@ -38,22 +52,17 @@ public struct GameCenterEnabledVersionCompatibleVersionsLinkagesResponse: Codabl } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/GameCenterEnabledVersionsResponse.swift b/Sources/Bagbutik-Models/AppStore/GameCenterEnabledVersionsResponse.swift index 9740d36a3..9bcb9d9a1 100644 --- a/Sources/Bagbutik-Models/AppStore/GameCenterEnabledVersionsResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/GameCenterEnabledVersionsResponse.swift @@ -27,6 +27,22 @@ public struct GameCenterEnabledVersionsResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([GameCenterEnabledVersion].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getApp(for gameCenterEnabledVersion: GameCenterEnabledVersion) -> App? { included?.compactMap { relationship -> App? in guard case let .app(app) = relationship else { return nil } @@ -69,9 +85,5 @@ public struct GameCenterEnabledVersionsResponse: Codable, PagedResponse { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/HttpHeader.swift b/Sources/Bagbutik-Models/AppStore/HttpHeader.swift index 659ae169c..b7a1af630 100644 --- a/Sources/Bagbutik-Models/AppStore/HttpHeader.swift +++ b/Sources/Bagbutik-Models/AppStore/HttpHeader.swift @@ -11,4 +11,16 @@ public struct HttpHeader: Codable { self.name = name self.value = value } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + name = try container.decodeIfPresent(String.self, forKey: "name") + value = try container.decodeIfPresent(String.self, forKey: "value") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(name, forKey: "name") + try container.encodeIfPresent(value, forKey: "value") + } } diff --git a/Sources/Bagbutik-Models/AppStore/InAppPurchase.swift b/Sources/Bagbutik-Models/AppStore/InAppPurchase.swift index 11782daf3..dc755bf45 100644 --- a/Sources/Bagbutik-Models/AppStore/InAppPurchase.swift +++ b/Sources/Bagbutik-Models/AppStore/InAppPurchase.swift @@ -27,31 +27,23 @@ public struct InAppPurchase: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -78,6 +70,22 @@ public struct InAppPurchase: Codable, Identifiable { self.state = state } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + inAppPurchaseType = try container.decodeIfPresent(InAppPurchaseType.self, forKey: "inAppPurchaseType") + productId = try container.decodeIfPresent(String.self, forKey: "productId") + referenceName = try container.decodeIfPresent(String.self, forKey: "referenceName") + state = try container.decodeIfPresent(State.self, forKey: "state") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(inAppPurchaseType, forKey: "inAppPurchaseType") + try container.encodeIfPresent(productId, forKey: "productId") + try container.encodeIfPresent(referenceName, forKey: "referenceName") + try container.encodeIfPresent(state, forKey: "state") + } + public enum InAppPurchaseType: String, Codable, CaseIterable { case automaticallyRenewableSubscription = "AUTOMATICALLY_RENEWABLE_SUBSCRIPTION" case consumable = "CONSUMABLE" @@ -123,6 +131,16 @@ public struct InAppPurchase: Codable, Identifiable { self.apps = apps } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + apps = try container.decodeIfPresent(Apps.self, forKey: "apps") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(apps, forKey: "apps") + } + /** # InAppPurchase.Relationships.Apps The data and links that describe the relationship between the resources. @@ -145,23 +163,17 @@ public struct InAppPurchase: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } /** @@ -180,22 +192,17 @@ public struct InAppPurchase: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -218,20 +225,15 @@ public struct InAppPurchase: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/InAppPurchaseAppStoreReviewScreenshot.swift b/Sources/Bagbutik-Models/AppStore/InAppPurchaseAppStoreReviewScreenshot.swift index d2fe32a34..2fb11fb7d 100644 --- a/Sources/Bagbutik-Models/AppStore/InAppPurchaseAppStoreReviewScreenshot.swift +++ b/Sources/Bagbutik-Models/AppStore/InAppPurchaseAppStoreReviewScreenshot.swift @@ -20,31 +20,23 @@ public struct InAppPurchaseAppStoreReviewScreenshot: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -75,6 +67,30 @@ public struct InAppPurchaseAppStoreReviewScreenshot: Codable, Identifiable { self.sourceFileChecksum = sourceFileChecksum self.uploadOperations = uploadOperations } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + assetDeliveryState = try container.decodeIfPresent(AppMediaAssetState.self, forKey: "assetDeliveryState") + assetToken = try container.decodeIfPresent(String.self, forKey: "assetToken") + assetType = try container.decodeIfPresent(String.self, forKey: "assetType") + fileName = try container.decodeIfPresent(String.self, forKey: "fileName") + fileSize = try container.decodeIfPresent(Int.self, forKey: "fileSize") + imageAsset = try container.decodeIfPresent(ImageAsset.self, forKey: "imageAsset") + sourceFileChecksum = try container.decodeIfPresent(String.self, forKey: "sourceFileChecksum") + uploadOperations = try container.decodeIfPresent([UploadOperation].self, forKey: "uploadOperations") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(assetDeliveryState, forKey: "assetDeliveryState") + try container.encodeIfPresent(assetToken, forKey: "assetToken") + try container.encodeIfPresent(assetType, forKey: "assetType") + try container.encodeIfPresent(fileName, forKey: "fileName") + try container.encodeIfPresent(fileSize, forKey: "fileSize") + try container.encodeIfPresent(imageAsset, forKey: "imageAsset") + try container.encodeIfPresent(sourceFileChecksum, forKey: "sourceFileChecksum") + try container.encodeIfPresent(uploadOperations, forKey: "uploadOperations") + } } public struct Relationships: Codable { @@ -84,6 +100,16 @@ public struct InAppPurchaseAppStoreReviewScreenshot: Codable, Identifiable { self.inAppPurchaseV2 = inAppPurchaseV2 } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + inAppPurchaseV2 = try container.decodeIfPresent(InAppPurchaseV2.self, forKey: "inAppPurchaseV2") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(inAppPurchaseV2, forKey: "inAppPurchaseV2") + } + public struct InAppPurchaseV2: Codable { @NullCodable public var data: Data? public var links: Links? @@ -96,20 +122,15 @@ public struct InAppPurchaseAppStoreReviewScreenshot: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -121,22 +142,17 @@ public struct InAppPurchaseAppStoreReviewScreenshot: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -152,20 +168,15 @@ public struct InAppPurchaseAppStoreReviewScreenshot: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/InAppPurchaseAppStoreReviewScreenshotCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/InAppPurchaseAppStoreReviewScreenshotCreateRequest.swift index a8a9d1ec6..3dd8d4f07 100644 --- a/Sources/Bagbutik-Models/AppStore/InAppPurchaseAppStoreReviewScreenshotCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/InAppPurchaseAppStoreReviewScreenshotCreateRequest.swift @@ -8,6 +8,16 @@ public struct InAppPurchaseAppStoreReviewScreenshotCreateRequest: Codable, Reque self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "inAppPurchaseAppStoreReviewScreenshots" } public let attributes: Attributes @@ -21,25 +31,19 @@ public struct InAppPurchaseAppStoreReviewScreenshotCreateRequest: Codable, Reque } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -52,6 +56,18 @@ public struct InAppPurchaseAppStoreReviewScreenshotCreateRequest: Codable, Reque self.fileName = fileName self.fileSize = fileSize } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + fileName = try container.decode(String.self, forKey: "fileName") + fileSize = try container.decode(Int.self, forKey: "fileSize") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(fileName, forKey: "fileName") + try container.encode(fileSize, forKey: "fileSize") + } } public struct Relationships: Codable { @@ -61,6 +77,16 @@ public struct InAppPurchaseAppStoreReviewScreenshotCreateRequest: Codable, Reque self.inAppPurchaseV2 = inAppPurchaseV2 } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + inAppPurchaseV2 = try container.decode(InAppPurchaseV2.self, forKey: "inAppPurchaseV2") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(inAppPurchaseV2, forKey: "inAppPurchaseV2") + } + public struct InAppPurchaseV2: Codable { public let data: Data @@ -68,6 +94,16 @@ public struct InAppPurchaseAppStoreReviewScreenshotCreateRequest: Codable, Reque self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "inAppPurchases" } @@ -77,22 +113,17 @@ public struct InAppPurchaseAppStoreReviewScreenshotCreateRequest: Codable, Reque } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/InAppPurchaseAppStoreReviewScreenshotResponse.swift b/Sources/Bagbutik-Models/AppStore/InAppPurchaseAppStoreReviewScreenshotResponse.swift index 5f0a8d686..7145990b2 100644 --- a/Sources/Bagbutik-Models/AppStore/InAppPurchaseAppStoreReviewScreenshotResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/InAppPurchaseAppStoreReviewScreenshotResponse.swift @@ -14,4 +14,18 @@ public struct InAppPurchaseAppStoreReviewScreenshotResponse: Codable { self.included = included self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(InAppPurchaseAppStoreReviewScreenshot.self, forKey: "data") + included = try container.decodeIfPresent([InAppPurchaseV2].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/AppStore/InAppPurchaseAppStoreReviewScreenshotUpdateRequest.swift b/Sources/Bagbutik-Models/AppStore/InAppPurchaseAppStoreReviewScreenshotUpdateRequest.swift index 0720f02bb..ea92f2e89 100644 --- a/Sources/Bagbutik-Models/AppStore/InAppPurchaseAppStoreReviewScreenshotUpdateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/InAppPurchaseAppStoreReviewScreenshotUpdateRequest.swift @@ -8,6 +8,16 @@ public struct InAppPurchaseAppStoreReviewScreenshotUpdateRequest: Codable, Reque self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "inAppPurchaseAppStoreReviewScreenshots" } @@ -21,25 +31,19 @@ public struct InAppPurchaseAppStoreReviewScreenshotUpdateRequest: Codable, Reque } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } public struct Attributes: Codable { @@ -52,6 +56,18 @@ public struct InAppPurchaseAppStoreReviewScreenshotUpdateRequest: Codable, Reque self.sourceFileChecksum = sourceFileChecksum self.uploaded = uploaded } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + sourceFileChecksum = try container.decodeIfPresent(String.self, forKey: "sourceFileChecksum") + uploaded = try container.decodeIfPresent(Bool.self, forKey: "uploaded") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(sourceFileChecksum, forKey: "sourceFileChecksum") + try container.encodeIfPresent(uploaded, forKey: "uploaded") + } } } } diff --git a/Sources/Bagbutik-Models/AppStore/InAppPurchaseAvailability.swift b/Sources/Bagbutik-Models/AppStore/InAppPurchaseAvailability.swift index 0036b2673..ebff03a58 100644 --- a/Sources/Bagbutik-Models/AppStore/InAppPurchaseAvailability.swift +++ b/Sources/Bagbutik-Models/AppStore/InAppPurchaseAvailability.swift @@ -20,31 +20,23 @@ public struct InAppPurchaseAvailability: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -53,6 +45,16 @@ public struct InAppPurchaseAvailability: Codable, Identifiable { public init(availableInNewTerritories: Bool? = nil) { self.availableInNewTerritories = availableInNewTerritories } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + availableInNewTerritories = try container.decodeIfPresent(Bool.self, forKey: "availableInNewTerritories") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(availableInNewTerritories, forKey: "availableInNewTerritories") + } } public struct Relationships: Codable { @@ -62,6 +64,16 @@ public struct InAppPurchaseAvailability: Codable, Identifiable { self.availableTerritories = availableTerritories } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + availableTerritories = try container.decodeIfPresent(AvailableTerritories.self, forKey: "availableTerritories") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(availableTerritories, forKey: "availableTerritories") + } + public struct AvailableTerritories: Codable { @NullCodable public var data: [Data]? public var links: Links? @@ -77,23 +89,17 @@ public struct InAppPurchaseAvailability: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -105,22 +111,17 @@ public struct InAppPurchaseAvailability: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -136,20 +137,15 @@ public struct InAppPurchaseAvailability: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/InAppPurchaseAvailabilityCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/InAppPurchaseAvailabilityCreateRequest.swift index f436bd009..49f791c03 100644 --- a/Sources/Bagbutik-Models/AppStore/InAppPurchaseAvailabilityCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/InAppPurchaseAvailabilityCreateRequest.swift @@ -8,6 +8,16 @@ public struct InAppPurchaseAvailabilityCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "inAppPurchaseAvailabilities" } public let attributes: Attributes @@ -21,25 +31,19 @@ public struct InAppPurchaseAvailabilityCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -48,6 +52,16 @@ public struct InAppPurchaseAvailabilityCreateRequest: Codable, RequestBody { public init(availableInNewTerritories: Bool) { self.availableInNewTerritories = availableInNewTerritories } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + availableInNewTerritories = try container.decode(Bool.self, forKey: "availableInNewTerritories") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(availableInNewTerritories, forKey: "availableInNewTerritories") + } } public struct Relationships: Codable { @@ -61,6 +75,18 @@ public struct InAppPurchaseAvailabilityCreateRequest: Codable, RequestBody { self.inAppPurchase = inAppPurchase } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + availableTerritories = try container.decode(AvailableTerritories.self, forKey: "availableTerritories") + inAppPurchase = try container.decode(InAppPurchase.self, forKey: "inAppPurchase") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(availableTerritories, forKey: "availableTerritories") + try container.encode(inAppPurchase, forKey: "inAppPurchase") + } + public struct AvailableTerritories: Codable { public let data: [Data] @@ -68,6 +94,16 @@ public struct InAppPurchaseAvailabilityCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "territories" } @@ -77,22 +113,17 @@ public struct InAppPurchaseAvailabilityCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -104,6 +135,16 @@ public struct InAppPurchaseAvailabilityCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "inAppPurchases" } @@ -113,22 +154,17 @@ public struct InAppPurchaseAvailabilityCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/InAppPurchaseAvailabilityResponse.swift b/Sources/Bagbutik-Models/AppStore/InAppPurchaseAvailabilityResponse.swift index f68d334ae..b83af5d6a 100644 --- a/Sources/Bagbutik-Models/AppStore/InAppPurchaseAvailabilityResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/InAppPurchaseAvailabilityResponse.swift @@ -14,4 +14,18 @@ public struct InAppPurchaseAvailabilityResponse: Codable { self.included = included self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(InAppPurchaseAvailability.self, forKey: "data") + included = try container.decodeIfPresent([Territory].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/AppStore/InAppPurchaseContent.swift b/Sources/Bagbutik-Models/AppStore/InAppPurchaseContent.swift index fb74b0915..8b4e012e3 100644 --- a/Sources/Bagbutik-Models/AppStore/InAppPurchaseContent.swift +++ b/Sources/Bagbutik-Models/AppStore/InAppPurchaseContent.swift @@ -20,31 +20,23 @@ public struct InAppPurchaseContent: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -63,6 +55,22 @@ public struct InAppPurchaseContent: Codable, Identifiable { self.lastModifiedDate = lastModifiedDate self.url = url } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + fileName = try container.decodeIfPresent(String.self, forKey: "fileName") + fileSize = try container.decodeIfPresent(Int.self, forKey: "fileSize") + lastModifiedDate = try container.decodeIfPresent(Date.self, forKey: "lastModifiedDate") + url = try container.decodeIfPresent(String.self, forKey: "url") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(fileName, forKey: "fileName") + try container.encodeIfPresent(fileSize, forKey: "fileSize") + try container.encodeIfPresent(lastModifiedDate, forKey: "lastModifiedDate") + try container.encodeIfPresent(url, forKey: "url") + } } public struct Relationships: Codable { @@ -72,6 +80,16 @@ public struct InAppPurchaseContent: Codable, Identifiable { self.inAppPurchaseV2 = inAppPurchaseV2 } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + inAppPurchaseV2 = try container.decodeIfPresent(InAppPurchaseV2.self, forKey: "inAppPurchaseV2") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(inAppPurchaseV2, forKey: "inAppPurchaseV2") + } + public struct InAppPurchaseV2: Codable { @NullCodable public var data: Data? public var links: Links? @@ -84,20 +102,15 @@ public struct InAppPurchaseContent: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -109,22 +122,17 @@ public struct InAppPurchaseContent: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -140,20 +148,15 @@ public struct InAppPurchaseContent: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/InAppPurchaseContentResponse.swift b/Sources/Bagbutik-Models/AppStore/InAppPurchaseContentResponse.swift index b7872f690..1ed28642a 100644 --- a/Sources/Bagbutik-Models/AppStore/InAppPurchaseContentResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/InAppPurchaseContentResponse.swift @@ -14,4 +14,18 @@ public struct InAppPurchaseContentResponse: Codable { self.included = included self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(InAppPurchaseContent.self, forKey: "data") + included = try container.decodeIfPresent([InAppPurchaseV2].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/AppStore/InAppPurchaseLocalization.swift b/Sources/Bagbutik-Models/AppStore/InAppPurchaseLocalization.swift index a05b538a6..5763c606c 100644 --- a/Sources/Bagbutik-Models/AppStore/InAppPurchaseLocalization.swift +++ b/Sources/Bagbutik-Models/AppStore/InAppPurchaseLocalization.swift @@ -20,31 +20,23 @@ public struct InAppPurchaseLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -64,6 +56,22 @@ public struct InAppPurchaseLocalization: Codable, Identifiable { self.state = state } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + description = try container.decodeIfPresent(String.self, forKey: "description") + locale = try container.decodeIfPresent(String.self, forKey: "locale") + name = try container.decodeIfPresent(String.self, forKey: "name") + state = try container.decodeIfPresent(State.self, forKey: "state") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(description, forKey: "description") + try container.encodeIfPresent(locale, forKey: "locale") + try container.encodeIfPresent(name, forKey: "name") + try container.encodeIfPresent(state, forKey: "state") + } + public enum State: String, Codable, CaseIterable { case approved = "APPROVED" case prepareForSubmission = "PREPARE_FOR_SUBMISSION" @@ -79,6 +87,16 @@ public struct InAppPurchaseLocalization: Codable, Identifiable { self.inAppPurchaseV2 = inAppPurchaseV2 } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + inAppPurchaseV2 = try container.decodeIfPresent(InAppPurchaseV2.self, forKey: "inAppPurchaseV2") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(inAppPurchaseV2, forKey: "inAppPurchaseV2") + } + public struct InAppPurchaseV2: Codable { @NullCodable public var data: Data? public var links: Links? @@ -91,20 +109,15 @@ public struct InAppPurchaseLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -116,22 +129,17 @@ public struct InAppPurchaseLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -147,20 +155,15 @@ public struct InAppPurchaseLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/InAppPurchaseLocalizationCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/InAppPurchaseLocalizationCreateRequest.swift index 5bf9ac362..700b9b187 100644 --- a/Sources/Bagbutik-Models/AppStore/InAppPurchaseLocalizationCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/InAppPurchaseLocalizationCreateRequest.swift @@ -8,6 +8,16 @@ public struct InAppPurchaseLocalizationCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "inAppPurchaseLocalizations" } public let attributes: Attributes @@ -21,25 +31,19 @@ public struct InAppPurchaseLocalizationCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -55,6 +59,20 @@ public struct InAppPurchaseLocalizationCreateRequest: Codable, RequestBody { self.locale = locale self.name = name } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + description = try container.decodeIfPresent(String.self, forKey: "description") + locale = try container.decode(String.self, forKey: "locale") + name = try container.decode(String.self, forKey: "name") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(description, forKey: "description") + try container.encode(locale, forKey: "locale") + try container.encode(name, forKey: "name") + } } public struct Relationships: Codable { @@ -64,6 +82,16 @@ public struct InAppPurchaseLocalizationCreateRequest: Codable, RequestBody { self.inAppPurchaseV2 = inAppPurchaseV2 } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + inAppPurchaseV2 = try container.decode(InAppPurchaseV2.self, forKey: "inAppPurchaseV2") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(inAppPurchaseV2, forKey: "inAppPurchaseV2") + } + public struct InAppPurchaseV2: Codable { public let data: Data @@ -71,6 +99,16 @@ public struct InAppPurchaseLocalizationCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "inAppPurchases" } @@ -80,22 +118,17 @@ public struct InAppPurchaseLocalizationCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/InAppPurchaseLocalizationResponse.swift b/Sources/Bagbutik-Models/AppStore/InAppPurchaseLocalizationResponse.swift index 56b54ab3b..6eb59d171 100644 --- a/Sources/Bagbutik-Models/AppStore/InAppPurchaseLocalizationResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/InAppPurchaseLocalizationResponse.swift @@ -14,4 +14,18 @@ public struct InAppPurchaseLocalizationResponse: Codable { self.included = included self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(InAppPurchaseLocalization.self, forKey: "data") + included = try container.decodeIfPresent([InAppPurchaseV2].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/AppStore/InAppPurchaseLocalizationUpdateRequest.swift b/Sources/Bagbutik-Models/AppStore/InAppPurchaseLocalizationUpdateRequest.swift index 5074a8c5d..e7cf65b12 100644 --- a/Sources/Bagbutik-Models/AppStore/InAppPurchaseLocalizationUpdateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/InAppPurchaseLocalizationUpdateRequest.swift @@ -8,6 +8,16 @@ public struct InAppPurchaseLocalizationUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "inAppPurchaseLocalizations" } @@ -21,25 +31,19 @@ public struct InAppPurchaseLocalizationUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } public struct Attributes: Codable { @@ -52,6 +56,18 @@ public struct InAppPurchaseLocalizationUpdateRequest: Codable, RequestBody { self.description = description self.name = name } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + description = try container.decodeIfPresent(String.self, forKey: "description") + name = try container.decodeIfPresent(String.self, forKey: "name") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(description, forKey: "description") + try container.encodeIfPresent(name, forKey: "name") + } } } } diff --git a/Sources/Bagbutik-Models/AppStore/InAppPurchaseLocalizationsResponse.swift b/Sources/Bagbutik-Models/AppStore/InAppPurchaseLocalizationsResponse.swift index cb9b90130..2ff83e0f6 100644 --- a/Sources/Bagbutik-Models/AppStore/InAppPurchaseLocalizationsResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/InAppPurchaseLocalizationsResponse.swift @@ -19,4 +19,20 @@ public struct InAppPurchaseLocalizationsResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([InAppPurchaseLocalization].self, forKey: "data") + included = try container.decodeIfPresent([InAppPurchaseV2].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/AppStore/InAppPurchasePrice.swift b/Sources/Bagbutik-Models/AppStore/InAppPurchasePrice.swift index 48336919a..260f82d4f 100644 --- a/Sources/Bagbutik-Models/AppStore/InAppPurchasePrice.swift +++ b/Sources/Bagbutik-Models/AppStore/InAppPurchasePrice.swift @@ -20,31 +20,23 @@ public struct InAppPurchasePrice: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -60,6 +52,20 @@ public struct InAppPurchasePrice: Codable, Identifiable { self.manual = manual self.startDate = startDate } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + endDate = try container.decodeIfPresent(String.self, forKey: "endDate") + manual = try container.decodeIfPresent(Bool.self, forKey: "manual") + startDate = try container.decodeIfPresent(String.self, forKey: "startDate") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(endDate, forKey: "endDate") + try container.encodeIfPresent(manual, forKey: "manual") + try container.encodeIfPresent(startDate, forKey: "startDate") + } } public struct Relationships: Codable { @@ -73,6 +79,18 @@ public struct InAppPurchasePrice: Codable, Identifiable { self.territory = territory } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + inAppPurchasePricePoint = try container.decodeIfPresent(InAppPurchasePricePoint.self, forKey: "inAppPurchasePricePoint") + territory = try container.decodeIfPresent(Territory.self, forKey: "territory") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(inAppPurchasePricePoint, forKey: "inAppPurchasePricePoint") + try container.encodeIfPresent(territory, forKey: "territory") + } + public struct InAppPurchasePricePoint: Codable { @NullCodable public var data: Data? public var links: Links? @@ -85,20 +103,15 @@ public struct InAppPurchasePrice: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -110,22 +123,17 @@ public struct InAppPurchasePrice: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -141,20 +149,15 @@ public struct InAppPurchasePrice: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -171,20 +174,15 @@ public struct InAppPurchasePrice: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -196,22 +194,17 @@ public struct InAppPurchasePrice: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -227,20 +220,15 @@ public struct InAppPurchasePrice: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/InAppPurchasePriceInlineCreate.swift b/Sources/Bagbutik-Models/AppStore/InAppPurchasePriceInlineCreate.swift index a574019e8..b61918a42 100644 --- a/Sources/Bagbutik-Models/AppStore/InAppPurchasePriceInlineCreate.swift +++ b/Sources/Bagbutik-Models/AppStore/InAppPurchasePriceInlineCreate.swift @@ -17,28 +17,21 @@ public struct InAppPurchasePriceInlineCreate: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decodeIfPresent(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decodeIfPresent(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -51,6 +44,18 @@ public struct InAppPurchasePriceInlineCreate: Codable, Identifiable { self.endDate = endDate self.startDate = startDate } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + endDate = try container.decodeIfPresent(String.self, forKey: "endDate") + startDate = try container.decodeIfPresent(String.self, forKey: "startDate") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(endDate, forKey: "endDate") + try container.encodeIfPresent(startDate, forKey: "startDate") + } } public struct Relationships: Codable { @@ -64,6 +69,18 @@ public struct InAppPurchasePriceInlineCreate: Codable, Identifiable { self.inAppPurchaseV2 = inAppPurchaseV2 } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + inAppPurchasePricePoint = try container.decodeIfPresent(InAppPurchasePricePoint.self, forKey: "inAppPurchasePricePoint") + inAppPurchaseV2 = try container.decodeIfPresent(InAppPurchaseV2.self, forKey: "inAppPurchaseV2") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(inAppPurchasePricePoint, forKey: "inAppPurchasePricePoint") + try container.encodeIfPresent(inAppPurchaseV2, forKey: "inAppPurchaseV2") + } + public struct InAppPurchasePricePoint: Codable { @NullCodable public var data: Data? @@ -72,17 +89,13 @@ public struct InAppPurchasePriceInlineCreate: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } public struct Data: Codable, Identifiable { @@ -94,22 +107,17 @@ public struct InAppPurchasePriceInlineCreate: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -122,17 +130,13 @@ public struct InAppPurchasePriceInlineCreate: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } public struct Data: Codable, Identifiable { @@ -144,22 +148,17 @@ public struct InAppPurchasePriceInlineCreate: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/InAppPurchasePricePoint.swift b/Sources/Bagbutik-Models/AppStore/InAppPurchasePricePoint.swift index 173b91de9..fa888ea3e 100644 --- a/Sources/Bagbutik-Models/AppStore/InAppPurchasePricePoint.swift +++ b/Sources/Bagbutik-Models/AppStore/InAppPurchasePricePoint.swift @@ -20,31 +20,23 @@ public struct InAppPurchasePricePoint: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -69,6 +61,20 @@ public struct InAppPurchasePricePoint: Codable, Identifiable { self.customerPrice = customerPrice self.proceeds = proceeds } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + customerPrice = try container.decodeIfPresent(String.self, forKey: "customerPrice") + priceTier = try container.decodeIfPresent(String.self, forKey: "priceTier") + proceeds = try container.decodeIfPresent(String.self, forKey: "proceeds") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(customerPrice, forKey: "customerPrice") + try container.encodeIfPresent(priceTier, forKey: "priceTier") + try container.encodeIfPresent(proceeds, forKey: "proceeds") + } } public struct Relationships: Codable { @@ -78,6 +84,16 @@ public struct InAppPurchasePricePoint: Codable, Identifiable { self.territory = territory } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + territory = try container.decodeIfPresent(Territory.self, forKey: "territory") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(territory, forKey: "territory") + } + public struct Territory: Codable { @NullCodable public var data: Data? public var links: Links? @@ -90,20 +106,15 @@ public struct InAppPurchasePricePoint: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -115,22 +126,17 @@ public struct InAppPurchasePricePoint: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -146,20 +152,15 @@ public struct InAppPurchasePricePoint: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/InAppPurchasePricePointsResponse.swift b/Sources/Bagbutik-Models/AppStore/InAppPurchasePricePointsResponse.swift index 39fec0ed2..ba253b665 100644 --- a/Sources/Bagbutik-Models/AppStore/InAppPurchasePricePointsResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/InAppPurchasePricePointsResponse.swift @@ -19,4 +19,20 @@ public struct InAppPurchasePricePointsResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([InAppPurchasePricePoint].self, forKey: "data") + included = try container.decodeIfPresent([Territory].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/AppStore/InAppPurchasePriceSchedule.swift b/Sources/Bagbutik-Models/AppStore/InAppPurchasePriceSchedule.swift index 19692247b..675ff55f6 100644 --- a/Sources/Bagbutik-Models/AppStore/InAppPurchasePriceSchedule.swift +++ b/Sources/Bagbutik-Models/AppStore/InAppPurchasePriceSchedule.swift @@ -17,28 +17,21 @@ public struct InAppPurchasePriceSchedule: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Relationships: Codable { @@ -58,6 +51,22 @@ public struct InAppPurchasePriceSchedule: Codable, Identifiable { self.manualPrices = manualPrices } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + automaticPrices = try container.decodeIfPresent(AutomaticPrices.self, forKey: "automaticPrices") + baseTerritory = try container.decodeIfPresent(BaseTerritory.self, forKey: "baseTerritory") + inAppPurchase = try container.decodeIfPresent(InAppPurchase.self, forKey: "inAppPurchase") + manualPrices = try container.decodeIfPresent(ManualPrices.self, forKey: "manualPrices") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(automaticPrices, forKey: "automaticPrices") + try container.encodeIfPresent(baseTerritory, forKey: "baseTerritory") + try container.encodeIfPresent(inAppPurchase, forKey: "inAppPurchase") + try container.encodeIfPresent(manualPrices, forKey: "manualPrices") + } + public struct AutomaticPrices: Codable { @NullCodable public var data: [Data]? public var links: Links? @@ -73,23 +82,17 @@ public struct InAppPurchasePriceSchedule: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -101,22 +104,17 @@ public struct InAppPurchasePriceSchedule: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -132,20 +130,15 @@ public struct InAppPurchasePriceSchedule: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -162,20 +155,15 @@ public struct InAppPurchasePriceSchedule: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -187,22 +175,17 @@ public struct InAppPurchasePriceSchedule: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -218,20 +201,15 @@ public struct InAppPurchasePriceSchedule: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -248,20 +226,15 @@ public struct InAppPurchasePriceSchedule: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -273,22 +246,17 @@ public struct InAppPurchasePriceSchedule: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -304,20 +272,15 @@ public struct InAppPurchasePriceSchedule: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -337,23 +300,17 @@ public struct InAppPurchasePriceSchedule: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -365,22 +322,17 @@ public struct InAppPurchasePriceSchedule: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -396,20 +348,15 @@ public struct InAppPurchasePriceSchedule: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/InAppPurchasePriceScheduleCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/InAppPurchasePriceScheduleCreateRequest.swift index 1e2934622..56eb32ed9 100644 --- a/Sources/Bagbutik-Models/AppStore/InAppPurchasePriceScheduleCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/InAppPurchasePriceScheduleCreateRequest.swift @@ -12,6 +12,18 @@ public struct InAppPurchasePriceScheduleCreateRequest: Codable, RequestBody { self.included = included } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + } + public struct Data: Codable { public var type: String { "inAppPurchasePriceSchedules" } public let relationships: Relationships @@ -21,22 +33,17 @@ public struct InAppPurchasePriceScheduleCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(relationships, forKey: "relationships") } public struct Relationships: Codable { @@ -53,6 +60,20 @@ public struct InAppPurchasePriceScheduleCreateRequest: Codable, RequestBody { self.manualPrices = manualPrices } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + baseTerritory = try container.decode(BaseTerritory.self, forKey: "baseTerritory") + inAppPurchase = try container.decode(InAppPurchase.self, forKey: "inAppPurchase") + manualPrices = try container.decode(ManualPrices.self, forKey: "manualPrices") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(baseTerritory, forKey: "baseTerritory") + try container.encode(inAppPurchase, forKey: "inAppPurchase") + try container.encode(manualPrices, forKey: "manualPrices") + } + public struct BaseTerritory: Codable { public let data: Data @@ -60,6 +81,16 @@ public struct InAppPurchasePriceScheduleCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "territories" } @@ -69,22 +100,17 @@ public struct InAppPurchasePriceScheduleCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -96,6 +122,16 @@ public struct InAppPurchasePriceScheduleCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "inAppPurchases" } @@ -105,22 +141,17 @@ public struct InAppPurchasePriceScheduleCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -132,6 +163,16 @@ public struct InAppPurchasePriceScheduleCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "inAppPurchasePrices" } @@ -141,22 +182,17 @@ public struct InAppPurchasePriceScheduleCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -186,9 +222,5 @@ public struct InAppPurchasePriceScheduleCreateRequest: Codable, RequestBody { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/InAppPurchasePriceScheduleResponse.swift b/Sources/Bagbutik-Models/AppStore/InAppPurchasePriceScheduleResponse.swift index ab078c24c..8768237d9 100644 --- a/Sources/Bagbutik-Models/AppStore/InAppPurchasePriceScheduleResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/InAppPurchasePriceScheduleResponse.swift @@ -15,6 +15,20 @@ public struct InAppPurchasePriceScheduleResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(InAppPurchasePriceSchedule.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getAutomaticPrices() -> [InAppPurchasePrice] { guard let automaticPriceIds = data.relationships?.automaticPrices?.data?.map(\.id), let automaticPrices = included?.compactMap({ relationship -> InAppPurchasePrice? in @@ -81,9 +95,5 @@ public struct InAppPurchasePriceScheduleResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/InAppPurchasePricesResponse.swift b/Sources/Bagbutik-Models/AppStore/InAppPurchasePricesResponse.swift index 1bbd2847f..080061fac 100644 --- a/Sources/Bagbutik-Models/AppStore/InAppPurchasePricesResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/InAppPurchasePricesResponse.swift @@ -20,6 +20,22 @@ public struct InAppPurchasePricesResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([InAppPurchasePrice].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getInAppPurchasePricePoint(for inAppPurchasePrice: InAppPurchasePrice) -> InAppPurchasePricePoint? { included?.compactMap { relationship -> InAppPurchasePricePoint? in guard case let .inAppPurchasePricePoint(inAppPurchasePricePoint) = relationship else { return nil } @@ -57,9 +73,5 @@ public struct InAppPurchasePricesResponse: Codable, PagedResponse { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/InAppPurchaseResponse.swift b/Sources/Bagbutik-Models/AppStore/InAppPurchaseResponse.swift index f3df5e924..20ac31a5d 100644 --- a/Sources/Bagbutik-Models/AppStore/InAppPurchaseResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/InAppPurchaseResponse.swift @@ -21,4 +21,18 @@ public struct InAppPurchaseResponse: Codable { self.included = included self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(InAppPurchase.self, forKey: "data") + included = try container.decodeIfPresent([App].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/AppStore/InAppPurchaseSubmission.swift b/Sources/Bagbutik-Models/AppStore/InAppPurchaseSubmission.swift index c9f7e0cf5..2bdb659db 100644 --- a/Sources/Bagbutik-Models/AppStore/InAppPurchaseSubmission.swift +++ b/Sources/Bagbutik-Models/AppStore/InAppPurchaseSubmission.swift @@ -17,28 +17,21 @@ public struct InAppPurchaseSubmission: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Relationships: Codable { @@ -48,6 +41,16 @@ public struct InAppPurchaseSubmission: Codable, Identifiable { self.inAppPurchaseV2 = inAppPurchaseV2 } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + inAppPurchaseV2 = try container.decodeIfPresent(InAppPurchaseV2.self, forKey: "inAppPurchaseV2") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(inAppPurchaseV2, forKey: "inAppPurchaseV2") + } + public struct InAppPurchaseV2: Codable { @NullCodable public var data: Data? public var links: Links? @@ -60,20 +63,15 @@ public struct InAppPurchaseSubmission: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -85,22 +83,17 @@ public struct InAppPurchaseSubmission: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -116,20 +109,15 @@ public struct InAppPurchaseSubmission: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/InAppPurchaseSubmissionCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/InAppPurchaseSubmissionCreateRequest.swift index 83a765059..954f8b450 100644 --- a/Sources/Bagbutik-Models/AppStore/InAppPurchaseSubmissionCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/InAppPurchaseSubmissionCreateRequest.swift @@ -8,6 +8,16 @@ public struct InAppPurchaseSubmissionCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "inAppPurchaseSubmissions" } public let relationships: Relationships @@ -17,22 +27,17 @@ public struct InAppPurchaseSubmissionCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(relationships, forKey: "relationships") } public struct Relationships: Codable { @@ -42,6 +47,16 @@ public struct InAppPurchaseSubmissionCreateRequest: Codable, RequestBody { self.inAppPurchaseV2 = inAppPurchaseV2 } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + inAppPurchaseV2 = try container.decode(InAppPurchaseV2.self, forKey: "inAppPurchaseV2") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(inAppPurchaseV2, forKey: "inAppPurchaseV2") + } + public struct InAppPurchaseV2: Codable { public let data: Data @@ -49,6 +64,16 @@ public struct InAppPurchaseSubmissionCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "inAppPurchases" } @@ -58,22 +83,17 @@ public struct InAppPurchaseSubmissionCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/InAppPurchaseSubmissionResponse.swift b/Sources/Bagbutik-Models/AppStore/InAppPurchaseSubmissionResponse.swift index a3e97c8fb..c1f495e53 100644 --- a/Sources/Bagbutik-Models/AppStore/InAppPurchaseSubmissionResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/InAppPurchaseSubmissionResponse.swift @@ -14,4 +14,18 @@ public struct InAppPurchaseSubmissionResponse: Codable { self.included = included self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(InAppPurchaseSubmission.self, forKey: "data") + included = try container.decodeIfPresent([InAppPurchaseV2].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/AppStore/InAppPurchaseV2.swift b/Sources/Bagbutik-Models/AppStore/InAppPurchaseV2.swift index b538385ae..b800efafa 100644 --- a/Sources/Bagbutik-Models/AppStore/InAppPurchaseV2.swift +++ b/Sources/Bagbutik-Models/AppStore/InAppPurchaseV2.swift @@ -20,31 +20,23 @@ public struct InAppPurchaseV2: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -72,6 +64,28 @@ public struct InAppPurchaseV2: Codable, Identifiable { self.reviewNote = reviewNote self.state = state } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + contentHosting = try container.decodeIfPresent(Bool.self, forKey: "contentHosting") + familySharable = try container.decodeIfPresent(Bool.self, forKey: "familySharable") + inAppPurchaseType = try container.decodeIfPresent(InAppPurchaseType.self, forKey: "inAppPurchaseType") + name = try container.decodeIfPresent(String.self, forKey: "name") + productId = try container.decodeIfPresent(String.self, forKey: "productId") + reviewNote = try container.decodeIfPresent(String.self, forKey: "reviewNote") + state = try container.decodeIfPresent(InAppPurchaseState.self, forKey: "state") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(contentHosting, forKey: "contentHosting") + try container.encodeIfPresent(familySharable, forKey: "familySharable") + try container.encodeIfPresent(inAppPurchaseType, forKey: "inAppPurchaseType") + try container.encodeIfPresent(name, forKey: "name") + try container.encodeIfPresent(productId, forKey: "productId") + try container.encodeIfPresent(reviewNote, forKey: "reviewNote") + try container.encodeIfPresent(state, forKey: "state") + } } public struct Relationships: Codable { @@ -100,6 +114,28 @@ public struct InAppPurchaseV2: Codable, Identifiable { self.promotedPurchase = promotedPurchase } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appStoreReviewScreenshot = try container.decodeIfPresent(AppStoreReviewScreenshot.self, forKey: "appStoreReviewScreenshot") + content = try container.decodeIfPresent(Content.self, forKey: "content") + iapPriceSchedule = try container.decodeIfPresent(IapPriceSchedule.self, forKey: "iapPriceSchedule") + inAppPurchaseAvailability = try container.decodeIfPresent(InAppPurchaseAvailability.self, forKey: "inAppPurchaseAvailability") + inAppPurchaseLocalizations = try container.decodeIfPresent(InAppPurchaseLocalizations.self, forKey: "inAppPurchaseLocalizations") + pricePoints = try container.decodeIfPresent(PricePoints.self, forKey: "pricePoints") + promotedPurchase = try container.decodeIfPresent(PromotedPurchase.self, forKey: "promotedPurchase") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(appStoreReviewScreenshot, forKey: "appStoreReviewScreenshot") + try container.encodeIfPresent(content, forKey: "content") + try container.encodeIfPresent(iapPriceSchedule, forKey: "iapPriceSchedule") + try container.encodeIfPresent(inAppPurchaseAvailability, forKey: "inAppPurchaseAvailability") + try container.encodeIfPresent(inAppPurchaseLocalizations, forKey: "inAppPurchaseLocalizations") + try container.encodeIfPresent(pricePoints, forKey: "pricePoints") + try container.encodeIfPresent(promotedPurchase, forKey: "promotedPurchase") + } + public struct AppStoreReviewScreenshot: Codable { @NullCodable public var data: Data? public var links: Links? @@ -112,20 +148,15 @@ public struct InAppPurchaseV2: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -137,22 +168,17 @@ public struct InAppPurchaseV2: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -168,20 +194,15 @@ public struct InAppPurchaseV2: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -198,20 +219,15 @@ public struct InAppPurchaseV2: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -223,22 +239,17 @@ public struct InAppPurchaseV2: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -254,20 +265,15 @@ public struct InAppPurchaseV2: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -284,20 +290,15 @@ public struct InAppPurchaseV2: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -309,22 +310,17 @@ public struct InAppPurchaseV2: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -340,20 +336,15 @@ public struct InAppPurchaseV2: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -370,20 +361,15 @@ public struct InAppPurchaseV2: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -395,22 +381,17 @@ public struct InAppPurchaseV2: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -426,20 +407,15 @@ public struct InAppPurchaseV2: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -459,23 +435,17 @@ public struct InAppPurchaseV2: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -487,22 +457,17 @@ public struct InAppPurchaseV2: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -518,20 +483,15 @@ public struct InAppPurchaseV2: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -551,23 +511,17 @@ public struct InAppPurchaseV2: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -579,22 +533,17 @@ public struct InAppPurchaseV2: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -610,20 +559,15 @@ public struct InAppPurchaseV2: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -640,20 +584,15 @@ public struct InAppPurchaseV2: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -665,22 +604,17 @@ public struct InAppPurchaseV2: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -696,20 +630,15 @@ public struct InAppPurchaseV2: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/InAppPurchaseV2CreateRequest.swift b/Sources/Bagbutik-Models/AppStore/InAppPurchaseV2CreateRequest.swift index 738fa5fbd..55b82e1f7 100644 --- a/Sources/Bagbutik-Models/AppStore/InAppPurchaseV2CreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/InAppPurchaseV2CreateRequest.swift @@ -8,6 +8,16 @@ public struct InAppPurchaseV2CreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "inAppPurchases" } public let attributes: Attributes @@ -21,25 +31,19 @@ public struct InAppPurchaseV2CreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -61,6 +65,24 @@ public struct InAppPurchaseV2CreateRequest: Codable, RequestBody { self.productId = productId self.reviewNote = reviewNote } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + familySharable = try container.decodeIfPresent(Bool.self, forKey: "familySharable") + inAppPurchaseType = try container.decode(InAppPurchaseType.self, forKey: "inAppPurchaseType") + name = try container.decode(String.self, forKey: "name") + productId = try container.decode(String.self, forKey: "productId") + reviewNote = try container.decodeIfPresent(String.self, forKey: "reviewNote") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(familySharable, forKey: "familySharable") + try container.encode(inAppPurchaseType, forKey: "inAppPurchaseType") + try container.encode(name, forKey: "name") + try container.encode(productId, forKey: "productId") + try container.encodeIfPresent(reviewNote, forKey: "reviewNote") + } } public struct Relationships: Codable { @@ -70,6 +92,16 @@ public struct InAppPurchaseV2CreateRequest: Codable, RequestBody { self.app = app } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + app = try container.decode(App.self, forKey: "app") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(app, forKey: "app") + } + public struct App: Codable { public let data: Data @@ -77,6 +109,16 @@ public struct InAppPurchaseV2CreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "apps" } @@ -86,22 +128,17 @@ public struct InAppPurchaseV2CreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/InAppPurchaseV2Response.swift b/Sources/Bagbutik-Models/AppStore/InAppPurchaseV2Response.swift index 1362bfd74..670eb810c 100644 --- a/Sources/Bagbutik-Models/AppStore/InAppPurchaseV2Response.swift +++ b/Sources/Bagbutik-Models/AppStore/InAppPurchaseV2Response.swift @@ -15,6 +15,20 @@ public struct InAppPurchaseV2Response: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(InAppPurchaseV2.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getAppStoreReviewScreenshot() -> InAppPurchaseAppStoreReviewScreenshot? { included?.compactMap { relationship -> InAppPurchaseAppStoreReviewScreenshot? in guard case let .inAppPurchaseAppStoreReviewScreenshot(appStoreReviewScreenshot) = relationship else { return nil } @@ -122,9 +136,5 @@ public struct InAppPurchaseV2Response: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/InAppPurchaseV2UpdateRequest.swift b/Sources/Bagbutik-Models/AppStore/InAppPurchaseV2UpdateRequest.swift index ff0ff59a1..892203d6a 100644 --- a/Sources/Bagbutik-Models/AppStore/InAppPurchaseV2UpdateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/InAppPurchaseV2UpdateRequest.swift @@ -8,6 +8,16 @@ public struct InAppPurchaseV2UpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "inAppPurchases" } @@ -21,25 +31,19 @@ public struct InAppPurchaseV2UpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } public struct Attributes: Codable { @@ -55,6 +59,20 @@ public struct InAppPurchaseV2UpdateRequest: Codable, RequestBody { self.name = name self.reviewNote = reviewNote } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + familySharable = try container.decodeIfPresent(Bool.self, forKey: "familySharable") + name = try container.decodeIfPresent(String.self, forKey: "name") + reviewNote = try container.decodeIfPresent(String.self, forKey: "reviewNote") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(familySharable, forKey: "familySharable") + try container.encodeIfPresent(name, forKey: "name") + try container.encodeIfPresent(reviewNote, forKey: "reviewNote") + } } } } diff --git a/Sources/Bagbutik-Models/AppStore/InAppPurchasesResponse.swift b/Sources/Bagbutik-Models/AppStore/InAppPurchasesResponse.swift index 286b0cdcf..0a39eabd9 100644 --- a/Sources/Bagbutik-Models/AppStore/InAppPurchasesResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/InAppPurchasesResponse.swift @@ -26,4 +26,20 @@ public struct InAppPurchasesResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([InAppPurchase].self, forKey: "data") + included = try container.decodeIfPresent([App].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/AppStore/InAppPurchasesV2Response.swift b/Sources/Bagbutik-Models/AppStore/InAppPurchasesV2Response.swift index fea043321..c02047110 100644 --- a/Sources/Bagbutik-Models/AppStore/InAppPurchasesV2Response.swift +++ b/Sources/Bagbutik-Models/AppStore/InAppPurchasesV2Response.swift @@ -20,6 +20,22 @@ public struct InAppPurchasesV2Response: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([InAppPurchaseV2].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getAppStoreReviewScreenshot(for inAppPurchaseV2: InAppPurchaseV2) -> InAppPurchaseAppStoreReviewScreenshot? { included?.compactMap { relationship -> InAppPurchaseAppStoreReviewScreenshot? in guard case let .inAppPurchaseAppStoreReviewScreenshot(appStoreReviewScreenshot) = relationship else { return nil } @@ -127,9 +143,5 @@ public struct InAppPurchasesV2Response: Codable, PagedResponse { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/PromotedPurchase.swift b/Sources/Bagbutik-Models/AppStore/PromotedPurchase.swift index 138917cec..084ee3a46 100644 --- a/Sources/Bagbutik-Models/AppStore/PromotedPurchase.swift +++ b/Sources/Bagbutik-Models/AppStore/PromotedPurchase.swift @@ -20,31 +20,23 @@ public struct PromotedPurchase: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -61,6 +53,20 @@ public struct PromotedPurchase: Codable, Identifiable { self.visibleForAllUsers = visibleForAllUsers } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + enabled = try container.decodeIfPresent(Bool.self, forKey: "enabled") + state = try container.decodeIfPresent(State.self, forKey: "state") + visibleForAllUsers = try container.decodeIfPresent(Bool.self, forKey: "visibleForAllUsers") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(enabled, forKey: "enabled") + try container.encodeIfPresent(state, forKey: "state") + try container.encodeIfPresent(visibleForAllUsers, forKey: "visibleForAllUsers") + } + public enum State: String, Codable, CaseIterable { case approved = "APPROVED" case inReview = "IN_REVIEW" @@ -83,6 +89,20 @@ public struct PromotedPurchase: Codable, Identifiable { self.subscription = subscription } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + inAppPurchaseV2 = try container.decodeIfPresent(InAppPurchaseV2.self, forKey: "inAppPurchaseV2") + promotionImages = try container.decodeIfPresent(PromotionImages.self, forKey: "promotionImages") + subscription = try container.decodeIfPresent(Subscription.self, forKey: "subscription") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(inAppPurchaseV2, forKey: "inAppPurchaseV2") + try container.encodeIfPresent(promotionImages, forKey: "promotionImages") + try container.encodeIfPresent(subscription, forKey: "subscription") + } + public struct InAppPurchaseV2: Codable { @NullCodable public var data: Data? public var links: Links? @@ -95,20 +115,15 @@ public struct PromotedPurchase: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -120,22 +135,17 @@ public struct PromotedPurchase: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -151,20 +161,15 @@ public struct PromotedPurchase: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -184,23 +189,17 @@ public struct PromotedPurchase: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -212,22 +211,17 @@ public struct PromotedPurchase: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -243,20 +237,15 @@ public struct PromotedPurchase: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -273,20 +262,15 @@ public struct PromotedPurchase: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -298,22 +282,17 @@ public struct PromotedPurchase: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -329,20 +308,15 @@ public struct PromotedPurchase: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/PromotedPurchaseCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/PromotedPurchaseCreateRequest.swift index 5f5c8ff7e..f1cea9987 100644 --- a/Sources/Bagbutik-Models/AppStore/PromotedPurchaseCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/PromotedPurchaseCreateRequest.swift @@ -8,6 +8,16 @@ public struct PromotedPurchaseCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "promotedPurchases" } public let attributes: Attributes @@ -21,25 +31,19 @@ public struct PromotedPurchaseCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -52,6 +56,18 @@ public struct PromotedPurchaseCreateRequest: Codable, RequestBody { self.enabled = enabled self.visibleForAllUsers = visibleForAllUsers } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + enabled = try container.decodeIfPresent(Bool.self, forKey: "enabled") + visibleForAllUsers = try container.decode(Bool.self, forKey: "visibleForAllUsers") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(enabled, forKey: "enabled") + try container.encode(visibleForAllUsers, forKey: "visibleForAllUsers") + } } public struct Relationships: Codable { @@ -68,6 +84,20 @@ public struct PromotedPurchaseCreateRequest: Codable, RequestBody { self.subscription = subscription } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + app = try container.decode(App.self, forKey: "app") + inAppPurchaseV2 = try container.decodeIfPresent(InAppPurchaseV2.self, forKey: "inAppPurchaseV2") + subscription = try container.decodeIfPresent(Subscription.self, forKey: "subscription") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(app, forKey: "app") + try container.encodeIfPresent(inAppPurchaseV2, forKey: "inAppPurchaseV2") + try container.encodeIfPresent(subscription, forKey: "subscription") + } + public struct App: Codable { public let data: Data @@ -75,6 +105,16 @@ public struct PromotedPurchaseCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "apps" } @@ -84,22 +124,17 @@ public struct PromotedPurchaseCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -112,17 +147,13 @@ public struct PromotedPurchaseCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } public struct Data: Codable, Identifiable { @@ -134,22 +165,17 @@ public struct PromotedPurchaseCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -162,17 +188,13 @@ public struct PromotedPurchaseCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } public struct Data: Codable, Identifiable { @@ -184,22 +206,17 @@ public struct PromotedPurchaseCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/PromotedPurchaseImage.swift b/Sources/Bagbutik-Models/AppStore/PromotedPurchaseImage.swift index 615d7defa..99474f9c7 100644 --- a/Sources/Bagbutik-Models/AppStore/PromotedPurchaseImage.swift +++ b/Sources/Bagbutik-Models/AppStore/PromotedPurchaseImage.swift @@ -20,31 +20,23 @@ public struct PromotedPurchaseImage: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -76,6 +68,30 @@ public struct PromotedPurchaseImage: Codable, Identifiable { self.uploadOperations = uploadOperations } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + assetToken = try container.decodeIfPresent(String.self, forKey: "assetToken") + assetType = try container.decodeIfPresent(String.self, forKey: "assetType") + fileName = try container.decodeIfPresent(String.self, forKey: "fileName") + fileSize = try container.decodeIfPresent(Int.self, forKey: "fileSize") + imageAsset = try container.decodeIfPresent(ImageAsset.self, forKey: "imageAsset") + sourceFileChecksum = try container.decodeIfPresent(String.self, forKey: "sourceFileChecksum") + state = try container.decodeIfPresent(State.self, forKey: "state") + uploadOperations = try container.decodeIfPresent([UploadOperation].self, forKey: "uploadOperations") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(assetToken, forKey: "assetToken") + try container.encodeIfPresent(assetType, forKey: "assetType") + try container.encodeIfPresent(fileName, forKey: "fileName") + try container.encodeIfPresent(fileSize, forKey: "fileSize") + try container.encodeIfPresent(imageAsset, forKey: "imageAsset") + try container.encodeIfPresent(sourceFileChecksum, forKey: "sourceFileChecksum") + try container.encodeIfPresent(state, forKey: "state") + try container.encodeIfPresent(uploadOperations, forKey: "uploadOperations") + } + public enum State: String, Codable, CaseIterable { case approved = "APPROVED" case awaitingUpload = "AWAITING_UPLOAD" @@ -94,6 +110,16 @@ public struct PromotedPurchaseImage: Codable, Identifiable { self.promotedPurchase = promotedPurchase } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + promotedPurchase = try container.decodeIfPresent(PromotedPurchase.self, forKey: "promotedPurchase") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(promotedPurchase, forKey: "promotedPurchase") + } + public struct PromotedPurchase: Codable { @NullCodable public var data: Data? public var links: Links? @@ -106,20 +132,15 @@ public struct PromotedPurchaseImage: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -131,22 +152,17 @@ public struct PromotedPurchaseImage: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -162,20 +178,15 @@ public struct PromotedPurchaseImage: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/PromotedPurchaseImageCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/PromotedPurchaseImageCreateRequest.swift index 797e21dbe..43a6430df 100644 --- a/Sources/Bagbutik-Models/AppStore/PromotedPurchaseImageCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/PromotedPurchaseImageCreateRequest.swift @@ -8,6 +8,16 @@ public struct PromotedPurchaseImageCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "promotedPurchaseImages" } public let attributes: Attributes @@ -21,25 +31,19 @@ public struct PromotedPurchaseImageCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -52,6 +56,18 @@ public struct PromotedPurchaseImageCreateRequest: Codable, RequestBody { self.fileName = fileName self.fileSize = fileSize } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + fileName = try container.decode(String.self, forKey: "fileName") + fileSize = try container.decode(Int.self, forKey: "fileSize") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(fileName, forKey: "fileName") + try container.encode(fileSize, forKey: "fileSize") + } } public struct Relationships: Codable { @@ -61,6 +77,16 @@ public struct PromotedPurchaseImageCreateRequest: Codable, RequestBody { self.promotedPurchase = promotedPurchase } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + promotedPurchase = try container.decode(PromotedPurchase.self, forKey: "promotedPurchase") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(promotedPurchase, forKey: "promotedPurchase") + } + public struct PromotedPurchase: Codable { public let data: Data @@ -68,6 +94,16 @@ public struct PromotedPurchaseImageCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "promotedPurchases" } @@ -77,22 +113,17 @@ public struct PromotedPurchaseImageCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/PromotedPurchaseImageResponse.swift b/Sources/Bagbutik-Models/AppStore/PromotedPurchaseImageResponse.swift index 029b336e8..c74f5dad5 100644 --- a/Sources/Bagbutik-Models/AppStore/PromotedPurchaseImageResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/PromotedPurchaseImageResponse.swift @@ -14,4 +14,18 @@ public struct PromotedPurchaseImageResponse: Codable { self.included = included self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(PromotedPurchaseImage.self, forKey: "data") + included = try container.decodeIfPresent([PromotedPurchase].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/AppStore/PromotedPurchaseImageUpdateRequest.swift b/Sources/Bagbutik-Models/AppStore/PromotedPurchaseImageUpdateRequest.swift index b6d3718ea..71f582577 100644 --- a/Sources/Bagbutik-Models/AppStore/PromotedPurchaseImageUpdateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/PromotedPurchaseImageUpdateRequest.swift @@ -8,6 +8,16 @@ public struct PromotedPurchaseImageUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "promotedPurchaseImages" } @@ -21,25 +31,19 @@ public struct PromotedPurchaseImageUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } public struct Attributes: Codable { @@ -52,6 +56,18 @@ public struct PromotedPurchaseImageUpdateRequest: Codable, RequestBody { self.sourceFileChecksum = sourceFileChecksum self.uploaded = uploaded } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + sourceFileChecksum = try container.decodeIfPresent(String.self, forKey: "sourceFileChecksum") + uploaded = try container.decodeIfPresent(Bool.self, forKey: "uploaded") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(sourceFileChecksum, forKey: "sourceFileChecksum") + try container.encodeIfPresent(uploaded, forKey: "uploaded") + } } } } diff --git a/Sources/Bagbutik-Models/AppStore/PromotedPurchaseImagesResponse.swift b/Sources/Bagbutik-Models/AppStore/PromotedPurchaseImagesResponse.swift index 7f0d1e016..3fca4a73b 100644 --- a/Sources/Bagbutik-Models/AppStore/PromotedPurchaseImagesResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/PromotedPurchaseImagesResponse.swift @@ -19,4 +19,20 @@ public struct PromotedPurchaseImagesResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([PromotedPurchaseImage].self, forKey: "data") + included = try container.decodeIfPresent([PromotedPurchase].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/AppStore/PromotedPurchaseResponse.swift b/Sources/Bagbutik-Models/AppStore/PromotedPurchaseResponse.swift index 001bf25a1..56185d3d5 100644 --- a/Sources/Bagbutik-Models/AppStore/PromotedPurchaseResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/PromotedPurchaseResponse.swift @@ -15,6 +15,20 @@ public struct PromotedPurchaseResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(PromotedPurchase.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getInAppPurchaseV2() -> InAppPurchaseV2? { included?.compactMap { relationship -> InAppPurchaseV2? in guard case let .inAppPurchaseV2(inAppPurchaseV2) = relationship else { return nil } @@ -69,9 +83,5 @@ public struct PromotedPurchaseResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/PromotedPurchaseUpdateRequest.swift b/Sources/Bagbutik-Models/AppStore/PromotedPurchaseUpdateRequest.swift index 6508520de..9758f7a96 100644 --- a/Sources/Bagbutik-Models/AppStore/PromotedPurchaseUpdateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/PromotedPurchaseUpdateRequest.swift @@ -8,6 +8,16 @@ public struct PromotedPurchaseUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "promotedPurchases" } @@ -21,25 +31,19 @@ public struct PromotedPurchaseUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } public struct Attributes: Codable { @@ -52,6 +56,18 @@ public struct PromotedPurchaseUpdateRequest: Codable, RequestBody { self.enabled = enabled self.visibleForAllUsers = visibleForAllUsers } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + enabled = try container.decodeIfPresent(Bool.self, forKey: "enabled") + visibleForAllUsers = try container.decodeIfPresent(Bool.self, forKey: "visibleForAllUsers") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(enabled, forKey: "enabled") + try container.encodeIfPresent(visibleForAllUsers, forKey: "visibleForAllUsers") + } } } } diff --git a/Sources/Bagbutik-Models/AppStore/PromotedPurchasesResponse.swift b/Sources/Bagbutik-Models/AppStore/PromotedPurchasesResponse.swift index 35fefafab..606a063b0 100644 --- a/Sources/Bagbutik-Models/AppStore/PromotedPurchasesResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/PromotedPurchasesResponse.swift @@ -20,6 +20,22 @@ public struct PromotedPurchasesResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([PromotedPurchase].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getInAppPurchaseV2(for promotedPurchase: PromotedPurchase) -> InAppPurchaseV2? { included?.compactMap { relationship -> InAppPurchaseV2? in guard case let .inAppPurchaseV2(inAppPurchaseV2) = relationship else { return nil } @@ -74,9 +90,5 @@ public struct PromotedPurchasesResponse: Codable, PagedResponse { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/ReviewSubmission.swift b/Sources/Bagbutik-Models/AppStore/ReviewSubmission.swift index 0c6ef1578..47a247bcd 100644 --- a/Sources/Bagbutik-Models/AppStore/ReviewSubmission.swift +++ b/Sources/Bagbutik-Models/AppStore/ReviewSubmission.swift @@ -20,31 +20,23 @@ public struct ReviewSubmission: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -61,6 +53,20 @@ public struct ReviewSubmission: Codable, Identifiable { self.submittedDate = submittedDate } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + platform = try container.decodeIfPresent(Platform.self, forKey: "platform") + state = try container.decodeIfPresent(State.self, forKey: "state") + submittedDate = try container.decodeIfPresent(Date.self, forKey: "submittedDate") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(platform, forKey: "platform") + try container.encodeIfPresent(state, forKey: "state") + try container.encodeIfPresent(submittedDate, forKey: "submittedDate") + } + public enum State: String, ParameterValue, Codable, CaseIterable { case canceling = "CANCELING" case complete = "COMPLETE" @@ -92,6 +98,24 @@ public struct ReviewSubmission: Codable, Identifiable { self.submittedByActor = submittedByActor } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + app = try container.decodeIfPresent(App.self, forKey: "app") + appStoreVersionForReview = try container.decodeIfPresent(AppStoreVersionForReview.self, forKey: "appStoreVersionForReview") + items = try container.decodeIfPresent(Items.self, forKey: "items") + lastUpdatedByActor = try container.decodeIfPresent(LastUpdatedByActor.self, forKey: "lastUpdatedByActor") + submittedByActor = try container.decodeIfPresent(SubmittedByActor.self, forKey: "submittedByActor") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(app, forKey: "app") + try container.encodeIfPresent(appStoreVersionForReview, forKey: "appStoreVersionForReview") + try container.encodeIfPresent(items, forKey: "items") + try container.encodeIfPresent(lastUpdatedByActor, forKey: "lastUpdatedByActor") + try container.encodeIfPresent(submittedByActor, forKey: "submittedByActor") + } + public struct App: Codable { @NullCodable public var data: Data? public var links: Links? @@ -104,20 +128,15 @@ public struct ReviewSubmission: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -129,22 +148,17 @@ public struct ReviewSubmission: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -160,20 +174,15 @@ public struct ReviewSubmission: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -190,20 +199,15 @@ public struct ReviewSubmission: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -215,22 +219,17 @@ public struct ReviewSubmission: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -246,20 +245,15 @@ public struct ReviewSubmission: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -279,23 +273,17 @@ public struct ReviewSubmission: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Item].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Item].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Item: Codable, Identifiable { @@ -307,22 +295,17 @@ public struct ReviewSubmission: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -338,20 +321,15 @@ public struct ReviewSubmission: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -368,20 +346,15 @@ public struct ReviewSubmission: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -393,22 +366,17 @@ public struct ReviewSubmission: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -424,20 +392,15 @@ public struct ReviewSubmission: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -454,20 +417,15 @@ public struct ReviewSubmission: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -479,22 +437,17 @@ public struct ReviewSubmission: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -510,20 +463,15 @@ public struct ReviewSubmission: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/ReviewSubmissionCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/ReviewSubmissionCreateRequest.swift index 8c005450f..893cdf6b3 100644 --- a/Sources/Bagbutik-Models/AppStore/ReviewSubmissionCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/ReviewSubmissionCreateRequest.swift @@ -8,6 +8,16 @@ public struct ReviewSubmissionCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "reviewSubmissions" } public let attributes: Attributes @@ -21,25 +31,19 @@ public struct ReviewSubmissionCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -48,6 +52,16 @@ public struct ReviewSubmissionCreateRequest: Codable, RequestBody { public init(platform: Platform) { self.platform = platform } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + platform = try container.decode(Platform.self, forKey: "platform") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(platform, forKey: "platform") + } } public struct Relationships: Codable { @@ -57,6 +71,16 @@ public struct ReviewSubmissionCreateRequest: Codable, RequestBody { self.app = app } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + app = try container.decode(App.self, forKey: "app") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(app, forKey: "app") + } + public struct App: Codable { public let data: Data @@ -64,6 +88,16 @@ public struct ReviewSubmissionCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "apps" } @@ -73,22 +107,17 @@ public struct ReviewSubmissionCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/ReviewSubmissionItem.swift b/Sources/Bagbutik-Models/AppStore/ReviewSubmissionItem.swift index 33ea99177..fed65e816 100644 --- a/Sources/Bagbutik-Models/AppStore/ReviewSubmissionItem.swift +++ b/Sources/Bagbutik-Models/AppStore/ReviewSubmissionItem.swift @@ -20,31 +20,23 @@ public struct ReviewSubmissionItem: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -54,6 +46,16 @@ public struct ReviewSubmissionItem: Codable, Identifiable { self.state = state } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + state = try container.decodeIfPresent(State.self, forKey: "state") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(state, forKey: "state") + } + public enum State: String, Codable, CaseIterable { case accepted = "ACCEPTED" case approved = "APPROVED" @@ -83,6 +85,24 @@ public struct ReviewSubmissionItem: Codable, Identifiable { self.appStoreVersionExperimentV2 = appStoreVersionExperimentV2 } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appCustomProductPageVersion = try container.decodeIfPresent(AppCustomProductPageVersion.self, forKey: "appCustomProductPageVersion") + appEvent = try container.decodeIfPresent(AppEvent.self, forKey: "appEvent") + appStoreVersion = try container.decodeIfPresent(AppStoreVersion.self, forKey: "appStoreVersion") + appStoreVersionExperiment = try container.decodeIfPresent(AppStoreVersionExperiment.self, forKey: "appStoreVersionExperiment") + appStoreVersionExperimentV2 = try container.decodeIfPresent(AppStoreVersionExperimentV2.self, forKey: "appStoreVersionExperimentV2") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(appCustomProductPageVersion, forKey: "appCustomProductPageVersion") + try container.encodeIfPresent(appEvent, forKey: "appEvent") + try container.encodeIfPresent(appStoreVersion, forKey: "appStoreVersion") + try container.encodeIfPresent(appStoreVersionExperiment, forKey: "appStoreVersionExperiment") + try container.encodeIfPresent(appStoreVersionExperimentV2, forKey: "appStoreVersionExperimentV2") + } + public struct AppCustomProductPageVersion: Codable { @NullCodable public var data: Data? public var links: Links? @@ -95,20 +115,15 @@ public struct ReviewSubmissionItem: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -120,22 +135,17 @@ public struct ReviewSubmissionItem: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -151,20 +161,15 @@ public struct ReviewSubmissionItem: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -181,20 +186,15 @@ public struct ReviewSubmissionItem: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -206,22 +206,17 @@ public struct ReviewSubmissionItem: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -237,20 +232,15 @@ public struct ReviewSubmissionItem: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -267,20 +257,15 @@ public struct ReviewSubmissionItem: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -292,22 +277,17 @@ public struct ReviewSubmissionItem: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -323,20 +303,15 @@ public struct ReviewSubmissionItem: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -353,20 +328,15 @@ public struct ReviewSubmissionItem: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -378,22 +348,17 @@ public struct ReviewSubmissionItem: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -409,20 +374,15 @@ public struct ReviewSubmissionItem: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -439,20 +399,15 @@ public struct ReviewSubmissionItem: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -464,22 +419,17 @@ public struct ReviewSubmissionItem: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -495,20 +445,15 @@ public struct ReviewSubmissionItem: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/ReviewSubmissionItemCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/ReviewSubmissionItemCreateRequest.swift index aa69c752f..96c519852 100644 --- a/Sources/Bagbutik-Models/AppStore/ReviewSubmissionItemCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/ReviewSubmissionItemCreateRequest.swift @@ -8,6 +8,16 @@ public struct ReviewSubmissionItemCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "reviewSubmissionItems" } public let relationships: Relationships @@ -17,22 +27,17 @@ public struct ReviewSubmissionItemCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(relationships, forKey: "relationships") } public struct Relationships: Codable { @@ -58,6 +63,26 @@ public struct ReviewSubmissionItemCreateRequest: Codable, RequestBody { self.reviewSubmission = reviewSubmission } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appCustomProductPageVersion = try container.decodeIfPresent(AppCustomProductPageVersion.self, forKey: "appCustomProductPageVersion") + appEvent = try container.decodeIfPresent(AppEvent.self, forKey: "appEvent") + appStoreVersion = try container.decodeIfPresent(AppStoreVersion.self, forKey: "appStoreVersion") + appStoreVersionExperiment = try container.decodeIfPresent(AppStoreVersionExperiment.self, forKey: "appStoreVersionExperiment") + appStoreVersionExperimentV2 = try container.decodeIfPresent(AppStoreVersionExperimentV2.self, forKey: "appStoreVersionExperimentV2") + reviewSubmission = try container.decode(ReviewSubmission.self, forKey: "reviewSubmission") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(appCustomProductPageVersion, forKey: "appCustomProductPageVersion") + try container.encodeIfPresent(appEvent, forKey: "appEvent") + try container.encodeIfPresent(appStoreVersion, forKey: "appStoreVersion") + try container.encodeIfPresent(appStoreVersionExperiment, forKey: "appStoreVersionExperiment") + try container.encodeIfPresent(appStoreVersionExperimentV2, forKey: "appStoreVersionExperimentV2") + try container.encode(reviewSubmission, forKey: "reviewSubmission") + } + public struct AppCustomProductPageVersion: Codable { @NullCodable public var data: Data? @@ -66,17 +91,13 @@ public struct ReviewSubmissionItemCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } public struct Data: Codable, Identifiable { @@ -88,22 +109,17 @@ public struct ReviewSubmissionItemCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -116,17 +132,13 @@ public struct ReviewSubmissionItemCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } public struct Data: Codable, Identifiable { @@ -138,22 +150,17 @@ public struct ReviewSubmissionItemCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -166,17 +173,13 @@ public struct ReviewSubmissionItemCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } public struct Data: Codable, Identifiable { @@ -188,22 +191,17 @@ public struct ReviewSubmissionItemCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -216,17 +214,13 @@ public struct ReviewSubmissionItemCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } public struct Data: Codable, Identifiable { @@ -238,22 +232,17 @@ public struct ReviewSubmissionItemCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -266,17 +255,13 @@ public struct ReviewSubmissionItemCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } public struct Data: Codable, Identifiable { @@ -288,22 +273,17 @@ public struct ReviewSubmissionItemCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -315,6 +295,16 @@ public struct ReviewSubmissionItemCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "reviewSubmissions" } @@ -324,22 +314,17 @@ public struct ReviewSubmissionItemCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/ReviewSubmissionItemResponse.swift b/Sources/Bagbutik-Models/AppStore/ReviewSubmissionItemResponse.swift index 7b50cc9de..e496518fa 100644 --- a/Sources/Bagbutik-Models/AppStore/ReviewSubmissionItemResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/ReviewSubmissionItemResponse.swift @@ -15,6 +15,20 @@ public struct ReviewSubmissionItemResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(ReviewSubmissionItem.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getAppCustomProductPageVersion() -> AppCustomProductPageVersion? { included?.compactMap { relationship -> AppCustomProductPageVersion? in guard case let .appCustomProductPageVersion(appCustomProductPageVersion) = relationship else { return nil } @@ -88,9 +102,5 @@ public struct ReviewSubmissionItemResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/ReviewSubmissionItemUpdateRequest.swift b/Sources/Bagbutik-Models/AppStore/ReviewSubmissionItemUpdateRequest.swift index 2058407bd..594c114f0 100644 --- a/Sources/Bagbutik-Models/AppStore/ReviewSubmissionItemUpdateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/ReviewSubmissionItemUpdateRequest.swift @@ -8,6 +8,16 @@ public struct ReviewSubmissionItemUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "reviewSubmissionItems" } @@ -21,25 +31,19 @@ public struct ReviewSubmissionItemUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } public struct Attributes: Codable { @@ -52,6 +56,18 @@ public struct ReviewSubmissionItemUpdateRequest: Codable, RequestBody { self.removed = removed self.resolved = resolved } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + removed = try container.decodeIfPresent(Bool.self, forKey: "removed") + resolved = try container.decodeIfPresent(Bool.self, forKey: "resolved") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(removed, forKey: "removed") + try container.encodeIfPresent(resolved, forKey: "resolved") + } } } } diff --git a/Sources/Bagbutik-Models/AppStore/ReviewSubmissionItemsResponse.swift b/Sources/Bagbutik-Models/AppStore/ReviewSubmissionItemsResponse.swift index 04d513ea9..aa99dce90 100644 --- a/Sources/Bagbutik-Models/AppStore/ReviewSubmissionItemsResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/ReviewSubmissionItemsResponse.swift @@ -20,6 +20,22 @@ public struct ReviewSubmissionItemsResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([ReviewSubmissionItem].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getAppCustomProductPageVersion(for reviewSubmissionItem: ReviewSubmissionItem) -> AppCustomProductPageVersion? { included?.compactMap { relationship -> AppCustomProductPageVersion? in guard case let .appCustomProductPageVersion(appCustomProductPageVersion) = relationship else { return nil } @@ -93,9 +109,5 @@ public struct ReviewSubmissionItemsResponse: Codable, PagedResponse { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/ReviewSubmissionResponse.swift b/Sources/Bagbutik-Models/AppStore/ReviewSubmissionResponse.swift index 9ec154d4e..3f773b0ee 100644 --- a/Sources/Bagbutik-Models/AppStore/ReviewSubmissionResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/ReviewSubmissionResponse.swift @@ -15,6 +15,20 @@ public struct ReviewSubmissionResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(ReviewSubmission.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getApp() -> App? { included?.compactMap { relationship -> App? in guard case let .app(app) = relationship else { return nil } @@ -88,9 +102,5 @@ public struct ReviewSubmissionResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/ReviewSubmissionUpdateRequest.swift b/Sources/Bagbutik-Models/AppStore/ReviewSubmissionUpdateRequest.swift index 6ef79f46b..745289f17 100644 --- a/Sources/Bagbutik-Models/AppStore/ReviewSubmissionUpdateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/ReviewSubmissionUpdateRequest.swift @@ -8,6 +8,16 @@ public struct ReviewSubmissionUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "reviewSubmissions" } @@ -21,25 +31,19 @@ public struct ReviewSubmissionUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } public struct Attributes: Codable { @@ -52,6 +56,18 @@ public struct ReviewSubmissionUpdateRequest: Codable, RequestBody { self.canceled = canceled self.submitted = submitted } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + canceled = try container.decodeIfPresent(Bool.self, forKey: "canceled") + submitted = try container.decodeIfPresent(Bool.self, forKey: "submitted") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(canceled, forKey: "canceled") + try container.encodeIfPresent(submitted, forKey: "submitted") + } } } } diff --git a/Sources/Bagbutik-Models/AppStore/ReviewSubmissionsResponse.swift b/Sources/Bagbutik-Models/AppStore/ReviewSubmissionsResponse.swift index 2d7c66969..fd90fc6be 100644 --- a/Sources/Bagbutik-Models/AppStore/ReviewSubmissionsResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/ReviewSubmissionsResponse.swift @@ -20,6 +20,22 @@ public struct ReviewSubmissionsResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([ReviewSubmission].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getApp(for reviewSubmission: ReviewSubmission) -> App? { included?.compactMap { relationship -> App? in guard case let .app(app) = relationship else { return nil } @@ -93,9 +109,5 @@ public struct ReviewSubmissionsResponse: Codable, PagedResponse { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/RoutingAppCoverage.swift b/Sources/Bagbutik-Models/AppStore/RoutingAppCoverage.swift index a052f3ea1..3028c203d 100644 --- a/Sources/Bagbutik-Models/AppStore/RoutingAppCoverage.swift +++ b/Sources/Bagbutik-Models/AppStore/RoutingAppCoverage.swift @@ -27,31 +27,23 @@ public struct RoutingAppCoverage: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -80,6 +72,24 @@ public struct RoutingAppCoverage: Codable, Identifiable { self.sourceFileChecksum = sourceFileChecksum self.uploadOperations = uploadOperations } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + assetDeliveryState = try container.decodeIfPresent(AppMediaAssetState.self, forKey: "assetDeliveryState") + fileName = try container.decodeIfPresent(String.self, forKey: "fileName") + fileSize = try container.decodeIfPresent(Int.self, forKey: "fileSize") + sourceFileChecksum = try container.decodeIfPresent(String.self, forKey: "sourceFileChecksum") + uploadOperations = try container.decodeIfPresent([UploadOperation].self, forKey: "uploadOperations") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(assetDeliveryState, forKey: "assetDeliveryState") + try container.encodeIfPresent(fileName, forKey: "fileName") + try container.encodeIfPresent(fileSize, forKey: "fileSize") + try container.encodeIfPresent(sourceFileChecksum, forKey: "sourceFileChecksum") + try container.encodeIfPresent(uploadOperations, forKey: "uploadOperations") + } } /** @@ -96,6 +106,16 @@ public struct RoutingAppCoverage: Codable, Identifiable { self.appStoreVersion = appStoreVersion } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appStoreVersion = try container.decodeIfPresent(AppStoreVersion.self, forKey: "appStoreVersion") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(appStoreVersion, forKey: "appStoreVersion") + } + /** # RoutingAppCoverage.Relationships.AppStoreVersion The data and links that describe the relationship between the resources. @@ -115,20 +135,15 @@ public struct RoutingAppCoverage: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -147,22 +162,17 @@ public struct RoutingAppCoverage: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -185,20 +195,15 @@ public struct RoutingAppCoverage: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/RoutingAppCoverageCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/RoutingAppCoverageCreateRequest.swift index 21a062e41..be0d5af4e 100644 --- a/Sources/Bagbutik-Models/AppStore/RoutingAppCoverageCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/RoutingAppCoverageCreateRequest.swift @@ -15,6 +15,16 @@ public struct RoutingAppCoverageCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # RoutingAppCoverageCreateRequest.Data The data element of the request body. @@ -35,25 +45,19 @@ public struct RoutingAppCoverageCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } /** @@ -73,6 +77,18 @@ public struct RoutingAppCoverageCreateRequest: Codable, RequestBody { self.fileName = fileName self.fileSize = fileSize } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + fileName = try container.decode(String.self, forKey: "fileName") + fileSize = try container.decode(Int.self, forKey: "fileSize") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(fileName, forKey: "fileName") + try container.encode(fileSize, forKey: "fileSize") + } } /** @@ -89,6 +105,16 @@ public struct RoutingAppCoverageCreateRequest: Codable, RequestBody { self.appStoreVersion = appStoreVersion } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appStoreVersion = try container.decode(AppStoreVersion.self, forKey: "appStoreVersion") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(appStoreVersion, forKey: "appStoreVersion") + } + /** # RoutingAppCoverageCreateRequest.Data.Relationships.AppStoreVersion The relationships to other resources that you can set with this request. @@ -103,6 +129,16 @@ public struct RoutingAppCoverageCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # RoutingAppCoverageCreateRequest.Data.Relationships.AppStoreVersion.Data The type and ID of the resource that you're relating with the resource you're creating. @@ -119,22 +155,17 @@ public struct RoutingAppCoverageCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/RoutingAppCoverageResponse.swift b/Sources/Bagbutik-Models/AppStore/RoutingAppCoverageResponse.swift index eeac68198..504c3effc 100644 --- a/Sources/Bagbutik-Models/AppStore/RoutingAppCoverageResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/RoutingAppCoverageResponse.swift @@ -21,4 +21,18 @@ public struct RoutingAppCoverageResponse: Codable { self.included = included self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(RoutingAppCoverage.self, forKey: "data") + included = try container.decodeIfPresent([AppStoreVersion].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/AppStore/RoutingAppCoverageUpdateRequest.swift b/Sources/Bagbutik-Models/AppStore/RoutingAppCoverageUpdateRequest.swift index f7a05e71e..a00976dd6 100644 --- a/Sources/Bagbutik-Models/AppStore/RoutingAppCoverageUpdateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/RoutingAppCoverageUpdateRequest.swift @@ -15,6 +15,16 @@ public struct RoutingAppCoverageUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # RoutingAppCoverageUpdateRequest.Data The data element of the request body. @@ -35,25 +45,19 @@ public struct RoutingAppCoverageUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } /** @@ -73,6 +77,18 @@ public struct RoutingAppCoverageUpdateRequest: Codable, RequestBody { self.sourceFileChecksum = sourceFileChecksum self.uploaded = uploaded } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + sourceFileChecksum = try container.decodeIfPresent(String.self, forKey: "sourceFileChecksum") + uploaded = try container.decodeIfPresent(Bool.self, forKey: "uploaded") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(sourceFileChecksum, forKey: "sourceFileChecksum") + try container.encodeIfPresent(uploaded, forKey: "uploaded") + } } } } diff --git a/Sources/Bagbutik-Models/AppStore/RoutingAppCoverageWithoutIncludesResponse.swift b/Sources/Bagbutik-Models/AppStore/RoutingAppCoverageWithoutIncludesResponse.swift index d20419479..c3eabe7d0 100644 --- a/Sources/Bagbutik-Models/AppStore/RoutingAppCoverageWithoutIncludesResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/RoutingAppCoverageWithoutIncludesResponse.swift @@ -11,4 +11,16 @@ public struct RoutingAppCoverageWithoutIncludesResponse: Codable { self.data = data self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(RoutingAppCoverage.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/AppStore/SandboxTesterV2.swift b/Sources/Bagbutik-Models/AppStore/SandboxTesterV2.swift index 54494ed55..8b15144a9 100644 --- a/Sources/Bagbutik-Models/AppStore/SandboxTesterV2.swift +++ b/Sources/Bagbutik-Models/AppStore/SandboxTesterV2.swift @@ -17,28 +17,21 @@ public struct SandboxTesterV2: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } public struct Attributes: Codable { @@ -67,6 +60,28 @@ public struct SandboxTesterV2: Codable, Identifiable { self.territory = territory } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + acAccountName = try container.decodeIfPresent(String.self, forKey: "acAccountName") + applePayCompatible = try container.decodeIfPresent(Bool.self, forKey: "applePayCompatible") + firstName = try container.decodeIfPresent(String.self, forKey: "firstName") + interruptPurchases = try container.decodeIfPresent(Bool.self, forKey: "interruptPurchases") + lastName = try container.decodeIfPresent(String.self, forKey: "lastName") + subscriptionRenewalRate = try container.decodeIfPresent(SubscriptionRenewalRate.self, forKey: "subscriptionRenewalRate") + territory = try container.decodeIfPresent(TerritoryCode.self, forKey: "territory") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(acAccountName, forKey: "acAccountName") + try container.encodeIfPresent(applePayCompatible, forKey: "applePayCompatible") + try container.encodeIfPresent(firstName, forKey: "firstName") + try container.encodeIfPresent(interruptPurchases, forKey: "interruptPurchases") + try container.encodeIfPresent(lastName, forKey: "lastName") + try container.encodeIfPresent(subscriptionRenewalRate, forKey: "subscriptionRenewalRate") + try container.encodeIfPresent(territory, forKey: "territory") + } + public enum SubscriptionRenewalRate: String, Codable, CaseIterable { case monthlyRenewalEveryFifteenMinutes = "MONTHLY_RENEWAL_EVERY_FIFTEEN_MINUTES" case monthlyRenewalEveryFiveMinutes = "MONTHLY_RENEWAL_EVERY_FIVE_MINUTES" diff --git a/Sources/Bagbutik-Models/AppStore/SandboxTesterV2Response.swift b/Sources/Bagbutik-Models/AppStore/SandboxTesterV2Response.swift index 5af483c8b..d2f3b934b 100644 --- a/Sources/Bagbutik-Models/AppStore/SandboxTesterV2Response.swift +++ b/Sources/Bagbutik-Models/AppStore/SandboxTesterV2Response.swift @@ -11,4 +11,16 @@ public struct SandboxTesterV2Response: Codable { self.data = data self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(SandboxTesterV2.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/AppStore/SandboxTesterV2UpdateRequest.swift b/Sources/Bagbutik-Models/AppStore/SandboxTesterV2UpdateRequest.swift index 38aa5c217..408be85c3 100644 --- a/Sources/Bagbutik-Models/AppStore/SandboxTesterV2UpdateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/SandboxTesterV2UpdateRequest.swift @@ -8,6 +8,16 @@ public struct SandboxTesterV2UpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "sandboxTesters" } @@ -21,25 +31,19 @@ public struct SandboxTesterV2UpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } public struct Attributes: Codable { @@ -55,6 +59,20 @@ public struct SandboxTesterV2UpdateRequest: Codable, RequestBody { self.subscriptionRenewalRate = subscriptionRenewalRate self.territory = territory } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + interruptPurchases = try container.decodeIfPresent(Bool.self, forKey: "interruptPurchases") + subscriptionRenewalRate = try container.decodeIfPresent(SandboxTesterV2.Attributes.SubscriptionRenewalRate.self, forKey: "subscriptionRenewalRate") + territory = try container.decodeIfPresent(TerritoryCode.self, forKey: "territory") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(interruptPurchases, forKey: "interruptPurchases") + try container.encodeIfPresent(subscriptionRenewalRate, forKey: "subscriptionRenewalRate") + try container.encodeIfPresent(territory, forKey: "territory") + } } } } diff --git a/Sources/Bagbutik-Models/AppStore/SandboxTestersClearPurchaseHistoryRequestV2.swift b/Sources/Bagbutik-Models/AppStore/SandboxTestersClearPurchaseHistoryRequestV2.swift index 9611bd1cb..270920c44 100644 --- a/Sources/Bagbutik-Models/AppStore/SandboxTestersClearPurchaseHistoryRequestV2.swift +++ b/Sources/Bagbutik-Models/AppStore/SandboxTestersClearPurchaseHistoryRequestV2.swift @@ -14,24 +14,18 @@ public struct SandboxTestersClearPurchaseHistoryRequestV2: Codable, Identifiable } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case links - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") } } diff --git a/Sources/Bagbutik-Models/AppStore/SandboxTestersClearPurchaseHistoryRequestV2CreateRequest.swift b/Sources/Bagbutik-Models/AppStore/SandboxTestersClearPurchaseHistoryRequestV2CreateRequest.swift index f79a63ef3..9f0b72baf 100644 --- a/Sources/Bagbutik-Models/AppStore/SandboxTestersClearPurchaseHistoryRequestV2CreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/SandboxTestersClearPurchaseHistoryRequestV2CreateRequest.swift @@ -8,6 +8,16 @@ public struct SandboxTestersClearPurchaseHistoryRequestV2CreateRequest: Codable, self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "sandboxTestersClearPurchaseHistoryRequest" } public let relationships: Relationships @@ -17,22 +27,17 @@ public struct SandboxTestersClearPurchaseHistoryRequestV2CreateRequest: Codable, } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(relationships, forKey: "relationships") } public struct Relationships: Codable { @@ -42,6 +47,16 @@ public struct SandboxTestersClearPurchaseHistoryRequestV2CreateRequest: Codable, self.sandboxTesters = sandboxTesters } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + sandboxTesters = try container.decode(SandboxTesters.self, forKey: "sandboxTesters") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(sandboxTesters, forKey: "sandboxTesters") + } + public struct SandboxTesters: Codable { public let data: [Data] @@ -49,6 +64,16 @@ public struct SandboxTestersClearPurchaseHistoryRequestV2CreateRequest: Codable, self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "sandboxTesters" } @@ -58,22 +83,17 @@ public struct SandboxTestersClearPurchaseHistoryRequestV2CreateRequest: Codable, } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/SandboxTestersClearPurchaseHistoryRequestV2Response.swift b/Sources/Bagbutik-Models/AppStore/SandboxTestersClearPurchaseHistoryRequestV2Response.swift index a7c1af25c..9baddfde6 100644 --- a/Sources/Bagbutik-Models/AppStore/SandboxTestersClearPurchaseHistoryRequestV2Response.swift +++ b/Sources/Bagbutik-Models/AppStore/SandboxTestersClearPurchaseHistoryRequestV2Response.swift @@ -11,4 +11,16 @@ public struct SandboxTestersClearPurchaseHistoryRequestV2Response: Codable { self.data = data self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(SandboxTestersClearPurchaseHistoryRequestV2.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/AppStore/SandboxTestersV2Response.swift b/Sources/Bagbutik-Models/AppStore/SandboxTestersV2Response.swift index f2babb06d..6a313cc5d 100644 --- a/Sources/Bagbutik-Models/AppStore/SandboxTestersV2Response.swift +++ b/Sources/Bagbutik-Models/AppStore/SandboxTestersV2Response.swift @@ -16,4 +16,18 @@ public struct SandboxTestersV2Response: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([SandboxTesterV2].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/AppStore/Subscription.swift b/Sources/Bagbutik-Models/AppStore/Subscription.swift index dcbfdc93d..8d6c0862e 100644 --- a/Sources/Bagbutik-Models/AppStore/Subscription.swift +++ b/Sources/Bagbutik-Models/AppStore/Subscription.swift @@ -20,31 +20,23 @@ public struct Subscription: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -73,6 +65,28 @@ public struct Subscription: Codable, Identifiable { self.subscriptionPeriod = subscriptionPeriod } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + familySharable = try container.decodeIfPresent(Bool.self, forKey: "familySharable") + groupLevel = try container.decodeIfPresent(Int.self, forKey: "groupLevel") + name = try container.decodeIfPresent(String.self, forKey: "name") + productId = try container.decodeIfPresent(String.self, forKey: "productId") + reviewNote = try container.decodeIfPresent(String.self, forKey: "reviewNote") + state = try container.decodeIfPresent(State.self, forKey: "state") + subscriptionPeriod = try container.decodeIfPresent(SubscriptionPeriod.self, forKey: "subscriptionPeriod") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(familySharable, forKey: "familySharable") + try container.encodeIfPresent(groupLevel, forKey: "groupLevel") + try container.encodeIfPresent(name, forKey: "name") + try container.encodeIfPresent(productId, forKey: "productId") + try container.encodeIfPresent(reviewNote, forKey: "reviewNote") + try container.encodeIfPresent(state, forKey: "state") + try container.encodeIfPresent(subscriptionPeriod, forKey: "subscriptionPeriod") + } + public enum State: String, Codable, CaseIterable { case approved = "APPROVED" case developerActionNeeded = "DEVELOPER_ACTION_NEEDED" @@ -128,6 +142,32 @@ public struct Subscription: Codable, Identifiable { self.subscriptionLocalizations = subscriptionLocalizations } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appStoreReviewScreenshot = try container.decodeIfPresent(AppStoreReviewScreenshot.self, forKey: "appStoreReviewScreenshot") + group = try container.decodeIfPresent(Group.self, forKey: "group") + introductoryOffers = try container.decodeIfPresent(IntroductoryOffers.self, forKey: "introductoryOffers") + offerCodes = try container.decodeIfPresent(OfferCodes.self, forKey: "offerCodes") + prices = try container.decodeIfPresent(Prices.self, forKey: "prices") + promotedPurchase = try container.decodeIfPresent(PromotedPurchase.self, forKey: "promotedPurchase") + promotionalOffers = try container.decodeIfPresent(PromotionalOffers.self, forKey: "promotionalOffers") + subscriptionAvailability = try container.decodeIfPresent(SubscriptionAvailability.self, forKey: "subscriptionAvailability") + subscriptionLocalizations = try container.decodeIfPresent(SubscriptionLocalizations.self, forKey: "subscriptionLocalizations") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(appStoreReviewScreenshot, forKey: "appStoreReviewScreenshot") + try container.encodeIfPresent(group, forKey: "group") + try container.encodeIfPresent(introductoryOffers, forKey: "introductoryOffers") + try container.encodeIfPresent(offerCodes, forKey: "offerCodes") + try container.encodeIfPresent(prices, forKey: "prices") + try container.encodeIfPresent(promotedPurchase, forKey: "promotedPurchase") + try container.encodeIfPresent(promotionalOffers, forKey: "promotionalOffers") + try container.encodeIfPresent(subscriptionAvailability, forKey: "subscriptionAvailability") + try container.encodeIfPresent(subscriptionLocalizations, forKey: "subscriptionLocalizations") + } + public struct AppStoreReviewScreenshot: Codable { @NullCodable public var data: Data? public var links: Links? @@ -140,20 +180,15 @@ public struct Subscription: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -165,22 +200,17 @@ public struct Subscription: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -196,20 +226,15 @@ public struct Subscription: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -226,20 +251,15 @@ public struct Subscription: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -251,22 +271,17 @@ public struct Subscription: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -282,20 +297,15 @@ public struct Subscription: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -315,23 +325,17 @@ public struct Subscription: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -343,22 +347,17 @@ public struct Subscription: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -374,20 +373,15 @@ public struct Subscription: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -407,23 +401,17 @@ public struct Subscription: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -435,22 +423,17 @@ public struct Subscription: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -466,20 +449,15 @@ public struct Subscription: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -499,23 +477,17 @@ public struct Subscription: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -527,22 +499,17 @@ public struct Subscription: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -558,20 +525,15 @@ public struct Subscription: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -588,20 +550,15 @@ public struct Subscription: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -613,22 +570,17 @@ public struct Subscription: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -644,20 +596,15 @@ public struct Subscription: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -677,23 +624,17 @@ public struct Subscription: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -705,22 +646,17 @@ public struct Subscription: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -736,20 +672,15 @@ public struct Subscription: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -766,20 +697,15 @@ public struct Subscription: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -791,22 +717,17 @@ public struct Subscription: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -822,20 +743,15 @@ public struct Subscription: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -855,23 +771,17 @@ public struct Subscription: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -883,22 +793,17 @@ public struct Subscription: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -914,20 +819,15 @@ public struct Subscription: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionAppStoreReviewScreenshot.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionAppStoreReviewScreenshot.swift index cb9e8a260..2c9618a85 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionAppStoreReviewScreenshot.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionAppStoreReviewScreenshot.swift @@ -20,31 +20,23 @@ public struct SubscriptionAppStoreReviewScreenshot: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -75,6 +67,30 @@ public struct SubscriptionAppStoreReviewScreenshot: Codable, Identifiable { self.sourceFileChecksum = sourceFileChecksum self.uploadOperations = uploadOperations } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + assetDeliveryState = try container.decodeIfPresent(AppMediaAssetState.self, forKey: "assetDeliveryState") + assetToken = try container.decodeIfPresent(String.self, forKey: "assetToken") + assetType = try container.decodeIfPresent(String.self, forKey: "assetType") + fileName = try container.decodeIfPresent(String.self, forKey: "fileName") + fileSize = try container.decodeIfPresent(Int.self, forKey: "fileSize") + imageAsset = try container.decodeIfPresent(ImageAsset.self, forKey: "imageAsset") + sourceFileChecksum = try container.decodeIfPresent(String.self, forKey: "sourceFileChecksum") + uploadOperations = try container.decodeIfPresent([UploadOperation].self, forKey: "uploadOperations") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(assetDeliveryState, forKey: "assetDeliveryState") + try container.encodeIfPresent(assetToken, forKey: "assetToken") + try container.encodeIfPresent(assetType, forKey: "assetType") + try container.encodeIfPresent(fileName, forKey: "fileName") + try container.encodeIfPresent(fileSize, forKey: "fileSize") + try container.encodeIfPresent(imageAsset, forKey: "imageAsset") + try container.encodeIfPresent(sourceFileChecksum, forKey: "sourceFileChecksum") + try container.encodeIfPresent(uploadOperations, forKey: "uploadOperations") + } } public struct Relationships: Codable { @@ -84,6 +100,16 @@ public struct SubscriptionAppStoreReviewScreenshot: Codable, Identifiable { self.subscription = subscription } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + subscription = try container.decodeIfPresent(Subscription.self, forKey: "subscription") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(subscription, forKey: "subscription") + } + public struct Subscription: Codable { @NullCodable public var data: Data? public var links: Links? @@ -96,20 +122,15 @@ public struct SubscriptionAppStoreReviewScreenshot: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -121,22 +142,17 @@ public struct SubscriptionAppStoreReviewScreenshot: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -152,20 +168,15 @@ public struct SubscriptionAppStoreReviewScreenshot: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionAppStoreReviewScreenshotCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionAppStoreReviewScreenshotCreateRequest.swift index 1b2134a39..f4c9e722a 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionAppStoreReviewScreenshotCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionAppStoreReviewScreenshotCreateRequest.swift @@ -8,6 +8,16 @@ public struct SubscriptionAppStoreReviewScreenshotCreateRequest: Codable, Reques self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "subscriptionAppStoreReviewScreenshots" } public let attributes: Attributes @@ -21,25 +31,19 @@ public struct SubscriptionAppStoreReviewScreenshotCreateRequest: Codable, Reques } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -52,6 +56,18 @@ public struct SubscriptionAppStoreReviewScreenshotCreateRequest: Codable, Reques self.fileName = fileName self.fileSize = fileSize } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + fileName = try container.decode(String.self, forKey: "fileName") + fileSize = try container.decode(Int.self, forKey: "fileSize") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(fileName, forKey: "fileName") + try container.encode(fileSize, forKey: "fileSize") + } } public struct Relationships: Codable { @@ -61,6 +77,16 @@ public struct SubscriptionAppStoreReviewScreenshotCreateRequest: Codable, Reques self.subscription = subscription } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + subscription = try container.decode(Subscription.self, forKey: "subscription") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(subscription, forKey: "subscription") + } + public struct Subscription: Codable { public let data: Data @@ -68,6 +94,16 @@ public struct SubscriptionAppStoreReviewScreenshotCreateRequest: Codable, Reques self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "subscriptions" } @@ -77,22 +113,17 @@ public struct SubscriptionAppStoreReviewScreenshotCreateRequest: Codable, Reques } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionAppStoreReviewScreenshotResponse.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionAppStoreReviewScreenshotResponse.swift index 096d9d038..ccff0b823 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionAppStoreReviewScreenshotResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionAppStoreReviewScreenshotResponse.swift @@ -14,4 +14,18 @@ public struct SubscriptionAppStoreReviewScreenshotResponse: Codable { self.included = included self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(SubscriptionAppStoreReviewScreenshot.self, forKey: "data") + included = try container.decodeIfPresent([Subscription].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionAppStoreReviewScreenshotUpdateRequest.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionAppStoreReviewScreenshotUpdateRequest.swift index be19b856f..27430b304 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionAppStoreReviewScreenshotUpdateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionAppStoreReviewScreenshotUpdateRequest.swift @@ -8,6 +8,16 @@ public struct SubscriptionAppStoreReviewScreenshotUpdateRequest: Codable, Reques self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "subscriptionAppStoreReviewScreenshots" } @@ -21,25 +31,19 @@ public struct SubscriptionAppStoreReviewScreenshotUpdateRequest: Codable, Reques } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } public struct Attributes: Codable { @@ -52,6 +56,18 @@ public struct SubscriptionAppStoreReviewScreenshotUpdateRequest: Codable, Reques self.sourceFileChecksum = sourceFileChecksum self.uploaded = uploaded } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + sourceFileChecksum = try container.decodeIfPresent(String.self, forKey: "sourceFileChecksum") + uploaded = try container.decodeIfPresent(Bool.self, forKey: "uploaded") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(sourceFileChecksum, forKey: "sourceFileChecksum") + try container.encodeIfPresent(uploaded, forKey: "uploaded") + } } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionAvailability.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionAvailability.swift index 774623836..095a004b8 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionAvailability.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionAvailability.swift @@ -20,31 +20,23 @@ public struct SubscriptionAvailability: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -53,6 +45,16 @@ public struct SubscriptionAvailability: Codable, Identifiable { public init(availableInNewTerritories: Bool? = nil) { self.availableInNewTerritories = availableInNewTerritories } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + availableInNewTerritories = try container.decodeIfPresent(Bool.self, forKey: "availableInNewTerritories") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(availableInNewTerritories, forKey: "availableInNewTerritories") + } } public struct Relationships: Codable { @@ -66,6 +68,18 @@ public struct SubscriptionAvailability: Codable, Identifiable { self.subscription = subscription } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + availableTerritories = try container.decodeIfPresent(AvailableTerritories.self, forKey: "availableTerritories") + subscription = try container.decodeIfPresent(Subscription.self, forKey: "subscription") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(availableTerritories, forKey: "availableTerritories") + try container.encodeIfPresent(subscription, forKey: "subscription") + } + public struct AvailableTerritories: Codable { @NullCodable public var data: [Data]? public var links: Links? @@ -81,23 +95,17 @@ public struct SubscriptionAvailability: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -109,22 +117,17 @@ public struct SubscriptionAvailability: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -140,20 +143,15 @@ public struct SubscriptionAvailability: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -170,20 +168,15 @@ public struct SubscriptionAvailability: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -195,22 +188,17 @@ public struct SubscriptionAvailability: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -226,20 +214,15 @@ public struct SubscriptionAvailability: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionAvailabilityCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionAvailabilityCreateRequest.swift index d1f086c42..aed00452d 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionAvailabilityCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionAvailabilityCreateRequest.swift @@ -8,6 +8,16 @@ public struct SubscriptionAvailabilityCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "subscriptionAvailabilities" } public let attributes: Attributes @@ -21,25 +31,19 @@ public struct SubscriptionAvailabilityCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -48,6 +52,16 @@ public struct SubscriptionAvailabilityCreateRequest: Codable, RequestBody { public init(availableInNewTerritories: Bool) { self.availableInNewTerritories = availableInNewTerritories } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + availableInNewTerritories = try container.decode(Bool.self, forKey: "availableInNewTerritories") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(availableInNewTerritories, forKey: "availableInNewTerritories") + } } public struct Relationships: Codable { @@ -61,6 +75,18 @@ public struct SubscriptionAvailabilityCreateRequest: Codable, RequestBody { self.subscription = subscription } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + availableTerritories = try container.decode(AvailableTerritories.self, forKey: "availableTerritories") + subscription = try container.decode(Subscription.self, forKey: "subscription") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(availableTerritories, forKey: "availableTerritories") + try container.encode(subscription, forKey: "subscription") + } + public struct AvailableTerritories: Codable { public let data: [Data] @@ -68,6 +94,16 @@ public struct SubscriptionAvailabilityCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "territories" } @@ -77,22 +113,17 @@ public struct SubscriptionAvailabilityCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -104,6 +135,16 @@ public struct SubscriptionAvailabilityCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "subscriptions" } @@ -113,22 +154,17 @@ public struct SubscriptionAvailabilityCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionAvailabilityResponse.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionAvailabilityResponse.swift index 1419edef1..26822b4a5 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionAvailabilityResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionAvailabilityResponse.swift @@ -15,6 +15,20 @@ public struct SubscriptionAvailabilityResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(SubscriptionAvailability.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getAvailableTerritories() -> [Territory] { guard let availableTerritoryIds = data.relationships?.availableTerritories?.data?.map(\.id), let availableTerritories = included?.compactMap({ relationship -> Territory? in @@ -57,9 +71,5 @@ public struct SubscriptionAvailabilityResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionCreateRequest.swift index 449476816..e8dabab4a 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionCreateRequest.swift @@ -8,6 +8,16 @@ public struct SubscriptionCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "subscriptions" } public let attributes: Attributes @@ -21,25 +31,19 @@ public struct SubscriptionCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -64,6 +68,26 @@ public struct SubscriptionCreateRequest: Codable, RequestBody { self.reviewNote = reviewNote self.subscriptionPeriod = subscriptionPeriod } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + familySharable = try container.decodeIfPresent(Bool.self, forKey: "familySharable") + groupLevel = try container.decodeIfPresent(Int.self, forKey: "groupLevel") + name = try container.decode(String.self, forKey: "name") + productId = try container.decode(String.self, forKey: "productId") + reviewNote = try container.decodeIfPresent(String.self, forKey: "reviewNote") + subscriptionPeriod = try container.decodeIfPresent(Subscription.Attributes.SubscriptionPeriod.self, forKey: "subscriptionPeriod") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(familySharable, forKey: "familySharable") + try container.encodeIfPresent(groupLevel, forKey: "groupLevel") + try container.encode(name, forKey: "name") + try container.encode(productId, forKey: "productId") + try container.encodeIfPresent(reviewNote, forKey: "reviewNote") + try container.encodeIfPresent(subscriptionPeriod, forKey: "subscriptionPeriod") + } } public struct Relationships: Codable { @@ -73,6 +97,16 @@ public struct SubscriptionCreateRequest: Codable, RequestBody { self.group = group } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + group = try container.decode(Group.self, forKey: "group") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(group, forKey: "group") + } + public struct Group: Codable { public let data: Data @@ -80,6 +114,16 @@ public struct SubscriptionCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "subscriptionGroups" } @@ -89,22 +133,17 @@ public struct SubscriptionCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionGracePeriod.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionGracePeriod.swift index 1317e4f34..e7c7a221e 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionGracePeriod.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionGracePeriod.swift @@ -17,28 +17,21 @@ public struct SubscriptionGracePeriod: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } public struct Attributes: Codable { @@ -58,6 +51,22 @@ public struct SubscriptionGracePeriod: Codable, Identifiable { self.sandboxOptIn = sandboxOptIn } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + duration = try container.decodeIfPresent(SubscriptionGracePeriodDuration.self, forKey: "duration") + optIn = try container.decodeIfPresent(Bool.self, forKey: "optIn") + renewalType = try container.decodeIfPresent(RenewalType.self, forKey: "renewalType") + sandboxOptIn = try container.decodeIfPresent(Bool.self, forKey: "sandboxOptIn") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(duration, forKey: "duration") + try container.encodeIfPresent(optIn, forKey: "optIn") + try container.encodeIfPresent(renewalType, forKey: "renewalType") + try container.encodeIfPresent(sandboxOptIn, forKey: "sandboxOptIn") + } + public enum RenewalType: String, Codable, CaseIterable { case allRenewals = "ALL_RENEWALS" case paidToPaidOnly = "PAID_TO_PAID_ONLY" diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionGracePeriodResponse.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionGracePeriodResponse.swift index c157c4e36..26e45b402 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionGracePeriodResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionGracePeriodResponse.swift @@ -11,4 +11,16 @@ public struct SubscriptionGracePeriodResponse: Codable { self.data = data self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(SubscriptionGracePeriod.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionGracePeriodUpdateRequest.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionGracePeriodUpdateRequest.swift index 860b20725..3c2004c5e 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionGracePeriodUpdateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionGracePeriodUpdateRequest.swift @@ -8,6 +8,16 @@ public struct SubscriptionGracePeriodUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "subscriptionGracePeriods" } @@ -21,25 +31,19 @@ public struct SubscriptionGracePeriodUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } public struct Attributes: Codable { @@ -58,6 +62,22 @@ public struct SubscriptionGracePeriodUpdateRequest: Codable, RequestBody { self.renewalType = renewalType self.sandboxOptIn = sandboxOptIn } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + duration = try container.decodeIfPresent(SubscriptionGracePeriodDuration.self, forKey: "duration") + optIn = try container.decodeIfPresent(Bool.self, forKey: "optIn") + renewalType = try container.decodeIfPresent(SubscriptionGracePeriod.Attributes.RenewalType.self, forKey: "renewalType") + sandboxOptIn = try container.decodeIfPresent(Bool.self, forKey: "sandboxOptIn") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(duration, forKey: "duration") + try container.encodeIfPresent(optIn, forKey: "optIn") + try container.encodeIfPresent(renewalType, forKey: "renewalType") + try container.encodeIfPresent(sandboxOptIn, forKey: "sandboxOptIn") + } } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionGroup.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionGroup.swift index 633695e01..85493a45a 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionGroup.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionGroup.swift @@ -20,31 +20,23 @@ public struct SubscriptionGroup: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -53,6 +45,16 @@ public struct SubscriptionGroup: Codable, Identifiable { public init(referenceName: String? = nil) { self.referenceName = referenceName } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + referenceName = try container.decodeIfPresent(String.self, forKey: "referenceName") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(referenceName, forKey: "referenceName") + } } public struct Relationships: Codable { @@ -66,6 +68,18 @@ public struct SubscriptionGroup: Codable, Identifiable { self.subscriptions = subscriptions } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + subscriptionGroupLocalizations = try container.decodeIfPresent(SubscriptionGroupLocalizations.self, forKey: "subscriptionGroupLocalizations") + subscriptions = try container.decodeIfPresent(Subscriptions.self, forKey: "subscriptions") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(subscriptionGroupLocalizations, forKey: "subscriptionGroupLocalizations") + try container.encodeIfPresent(subscriptions, forKey: "subscriptions") + } + public struct SubscriptionGroupLocalizations: Codable { @NullCodable public var data: [Data]? public var links: Links? @@ -81,23 +95,17 @@ public struct SubscriptionGroup: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -109,22 +117,17 @@ public struct SubscriptionGroup: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -140,20 +143,15 @@ public struct SubscriptionGroup: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -173,23 +171,17 @@ public struct SubscriptionGroup: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -201,22 +193,17 @@ public struct SubscriptionGroup: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -232,20 +219,15 @@ public struct SubscriptionGroup: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionGroupCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionGroupCreateRequest.swift index 103c2ce8d..f6fb5e973 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionGroupCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionGroupCreateRequest.swift @@ -8,6 +8,16 @@ public struct SubscriptionGroupCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "subscriptionGroups" } public let attributes: Attributes @@ -21,25 +31,19 @@ public struct SubscriptionGroupCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -48,6 +52,16 @@ public struct SubscriptionGroupCreateRequest: Codable, RequestBody { public init(referenceName: String) { self.referenceName = referenceName } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + referenceName = try container.decode(String.self, forKey: "referenceName") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(referenceName, forKey: "referenceName") + } } public struct Relationships: Codable { @@ -57,6 +71,16 @@ public struct SubscriptionGroupCreateRequest: Codable, RequestBody { self.app = app } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + app = try container.decode(App.self, forKey: "app") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(app, forKey: "app") + } + public struct App: Codable { public let data: Data @@ -64,6 +88,16 @@ public struct SubscriptionGroupCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "apps" } @@ -73,22 +107,17 @@ public struct SubscriptionGroupCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionGroupLocalization.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionGroupLocalization.swift index c3c0d5456..25a515478 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionGroupLocalization.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionGroupLocalization.swift @@ -20,31 +20,23 @@ public struct SubscriptionGroupLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -64,6 +56,22 @@ public struct SubscriptionGroupLocalization: Codable, Identifiable { self.state = state } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + customAppName = try container.decodeIfPresent(String.self, forKey: "customAppName") + locale = try container.decodeIfPresent(String.self, forKey: "locale") + name = try container.decodeIfPresent(String.self, forKey: "name") + state = try container.decodeIfPresent(State.self, forKey: "state") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(customAppName, forKey: "customAppName") + try container.encodeIfPresent(locale, forKey: "locale") + try container.encodeIfPresent(name, forKey: "name") + try container.encodeIfPresent(state, forKey: "state") + } + public enum State: String, Codable, CaseIterable { case approved = "APPROVED" case prepareForSubmission = "PREPARE_FOR_SUBMISSION" @@ -79,6 +87,16 @@ public struct SubscriptionGroupLocalization: Codable, Identifiable { self.subscriptionGroup = subscriptionGroup } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + subscriptionGroup = try container.decodeIfPresent(SubscriptionGroup.self, forKey: "subscriptionGroup") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(subscriptionGroup, forKey: "subscriptionGroup") + } + public struct SubscriptionGroup: Codable { @NullCodable public var data: Data? public var links: Links? @@ -91,20 +109,15 @@ public struct SubscriptionGroupLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -116,22 +129,17 @@ public struct SubscriptionGroupLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -147,20 +155,15 @@ public struct SubscriptionGroupLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionGroupLocalizationCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionGroupLocalizationCreateRequest.swift index 21677ec1c..f3994e7a2 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionGroupLocalizationCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionGroupLocalizationCreateRequest.swift @@ -8,6 +8,16 @@ public struct SubscriptionGroupLocalizationCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "subscriptionGroupLocalizations" } public let attributes: Attributes @@ -21,25 +31,19 @@ public struct SubscriptionGroupLocalizationCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -55,6 +59,20 @@ public struct SubscriptionGroupLocalizationCreateRequest: Codable, RequestBody { self.locale = locale self.name = name } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + customAppName = try container.decodeIfPresent(String.self, forKey: "customAppName") + locale = try container.decode(String.self, forKey: "locale") + name = try container.decode(String.self, forKey: "name") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(customAppName, forKey: "customAppName") + try container.encode(locale, forKey: "locale") + try container.encode(name, forKey: "name") + } } public struct Relationships: Codable { @@ -64,6 +82,16 @@ public struct SubscriptionGroupLocalizationCreateRequest: Codable, RequestBody { self.subscriptionGroup = subscriptionGroup } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + subscriptionGroup = try container.decode(SubscriptionGroup.self, forKey: "subscriptionGroup") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(subscriptionGroup, forKey: "subscriptionGroup") + } + public struct SubscriptionGroup: Codable { public let data: Data @@ -71,6 +99,16 @@ public struct SubscriptionGroupLocalizationCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "subscriptionGroups" } @@ -80,22 +118,17 @@ public struct SubscriptionGroupLocalizationCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionGroupLocalizationResponse.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionGroupLocalizationResponse.swift index a3f5d6c93..b9b908295 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionGroupLocalizationResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionGroupLocalizationResponse.swift @@ -14,4 +14,18 @@ public struct SubscriptionGroupLocalizationResponse: Codable { self.included = included self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(SubscriptionGroupLocalization.self, forKey: "data") + included = try container.decodeIfPresent([SubscriptionGroup].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionGroupLocalizationUpdateRequest.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionGroupLocalizationUpdateRequest.swift index cbe33dda6..2cf7983c6 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionGroupLocalizationUpdateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionGroupLocalizationUpdateRequest.swift @@ -8,6 +8,16 @@ public struct SubscriptionGroupLocalizationUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "subscriptionGroupLocalizations" } @@ -21,25 +31,19 @@ public struct SubscriptionGroupLocalizationUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } public struct Attributes: Codable { @@ -52,6 +56,18 @@ public struct SubscriptionGroupLocalizationUpdateRequest: Codable, RequestBody { self.customAppName = customAppName self.name = name } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + customAppName = try container.decodeIfPresent(String.self, forKey: "customAppName") + name = try container.decodeIfPresent(String.self, forKey: "name") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(customAppName, forKey: "customAppName") + try container.encodeIfPresent(name, forKey: "name") + } } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionGroupLocalizationsResponse.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionGroupLocalizationsResponse.swift index c337518ab..9e235069d 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionGroupLocalizationsResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionGroupLocalizationsResponse.swift @@ -19,4 +19,20 @@ public struct SubscriptionGroupLocalizationsResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([SubscriptionGroupLocalization].self, forKey: "data") + included = try container.decodeIfPresent([SubscriptionGroup].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionGroupResponse.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionGroupResponse.swift index febfc5503..cd18b83b3 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionGroupResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionGroupResponse.swift @@ -15,6 +15,20 @@ public struct SubscriptionGroupResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(SubscriptionGroup.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getSubscriptionGroupLocalizations() -> [SubscriptionGroupLocalization] { guard let subscriptionGroupLocalizationIds = data.relationships?.subscriptionGroupLocalizations?.data?.map(\.id), let subscriptionGroupLocalizations = included?.compactMap({ relationship -> SubscriptionGroupLocalization? in @@ -62,9 +76,5 @@ public struct SubscriptionGroupResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionGroupSubmission.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionGroupSubmission.swift index 487da943c..69225c6bc 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionGroupSubmission.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionGroupSubmission.swift @@ -14,24 +14,18 @@ public struct SubscriptionGroupSubmission: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case links - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionGroupSubmissionCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionGroupSubmissionCreateRequest.swift index 41461fac6..8df1c1cda 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionGroupSubmissionCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionGroupSubmissionCreateRequest.swift @@ -8,6 +8,16 @@ public struct SubscriptionGroupSubmissionCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "subscriptionGroupSubmissions" } public let relationships: Relationships @@ -17,22 +27,17 @@ public struct SubscriptionGroupSubmissionCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(relationships, forKey: "relationships") } public struct Relationships: Codable { @@ -42,6 +47,16 @@ public struct SubscriptionGroupSubmissionCreateRequest: Codable, RequestBody { self.subscriptionGroup = subscriptionGroup } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + subscriptionGroup = try container.decode(SubscriptionGroup.self, forKey: "subscriptionGroup") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(subscriptionGroup, forKey: "subscriptionGroup") + } + public struct SubscriptionGroup: Codable { public let data: Data @@ -49,6 +64,16 @@ public struct SubscriptionGroupSubmissionCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "subscriptionGroups" } @@ -58,22 +83,17 @@ public struct SubscriptionGroupSubmissionCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionGroupSubmissionResponse.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionGroupSubmissionResponse.swift index 2a0105059..c26100f1e 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionGroupSubmissionResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionGroupSubmissionResponse.swift @@ -11,4 +11,16 @@ public struct SubscriptionGroupSubmissionResponse: Codable { self.data = data self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(SubscriptionGroupSubmission.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionGroupUpdateRequest.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionGroupUpdateRequest.swift index b02414a31..4d32e6c3b 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionGroupUpdateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionGroupUpdateRequest.swift @@ -8,6 +8,16 @@ public struct SubscriptionGroupUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "subscriptionGroups" } @@ -21,25 +31,19 @@ public struct SubscriptionGroupUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } public struct Attributes: Codable { @@ -48,6 +52,16 @@ public struct SubscriptionGroupUpdateRequest: Codable, RequestBody { public init(referenceName: String? = nil) { self.referenceName = referenceName } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + referenceName = try container.decodeIfPresent(String.self, forKey: "referenceName") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(referenceName, forKey: "referenceName") + } } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionGroupsResponse.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionGroupsResponse.swift index f226471f0..d9705df0f 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionGroupsResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionGroupsResponse.swift @@ -20,6 +20,22 @@ public struct SubscriptionGroupsResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([SubscriptionGroup].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getSubscriptionGroupLocalizations(for subscriptionGroup: SubscriptionGroup) -> [SubscriptionGroupLocalization] { guard let subscriptionGroupLocalizationIds = subscriptionGroup.relationships?.subscriptionGroupLocalizations?.data?.map(\.id), let subscriptionGroupLocalizations = included?.compactMap({ relationship -> SubscriptionGroupLocalization? in @@ -67,9 +83,5 @@ public struct SubscriptionGroupsResponse: Codable, PagedResponse { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionIntroductoryOffer.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionIntroductoryOffer.swift index c16af5d3a..9b1e32050 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionIntroductoryOffer.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionIntroductoryOffer.swift @@ -20,31 +20,23 @@ public struct SubscriptionIntroductoryOffer: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -66,6 +58,24 @@ public struct SubscriptionIntroductoryOffer: Codable, Identifiable { self.offerMode = offerMode self.startDate = startDate } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + duration = try container.decodeIfPresent(SubscriptionOfferDuration.self, forKey: "duration") + endDate = try container.decodeIfPresent(String.self, forKey: "endDate") + numberOfPeriods = try container.decodeIfPresent(Int.self, forKey: "numberOfPeriods") + offerMode = try container.decodeIfPresent(SubscriptionOfferMode.self, forKey: "offerMode") + startDate = try container.decodeIfPresent(String.self, forKey: "startDate") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(duration, forKey: "duration") + try container.encodeIfPresent(endDate, forKey: "endDate") + try container.encodeIfPresent(numberOfPeriods, forKey: "numberOfPeriods") + try container.encodeIfPresent(offerMode, forKey: "offerMode") + try container.encodeIfPresent(startDate, forKey: "startDate") + } } public struct Relationships: Codable { @@ -82,6 +92,20 @@ public struct SubscriptionIntroductoryOffer: Codable, Identifiable { self.territory = territory } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + subscription = try container.decodeIfPresent(Subscription.self, forKey: "subscription") + subscriptionPricePoint = try container.decodeIfPresent(SubscriptionPricePoint.self, forKey: "subscriptionPricePoint") + territory = try container.decodeIfPresent(Territory.self, forKey: "territory") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(subscription, forKey: "subscription") + try container.encodeIfPresent(subscriptionPricePoint, forKey: "subscriptionPricePoint") + try container.encodeIfPresent(territory, forKey: "territory") + } + public struct Subscription: Codable { @NullCodable public var data: Data? public var links: Links? @@ -94,20 +118,15 @@ public struct SubscriptionIntroductoryOffer: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -119,22 +138,17 @@ public struct SubscriptionIntroductoryOffer: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -150,20 +164,15 @@ public struct SubscriptionIntroductoryOffer: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -180,20 +189,15 @@ public struct SubscriptionIntroductoryOffer: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -205,22 +209,17 @@ public struct SubscriptionIntroductoryOffer: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -236,20 +235,15 @@ public struct SubscriptionIntroductoryOffer: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -266,20 +260,15 @@ public struct SubscriptionIntroductoryOffer: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -291,22 +280,17 @@ public struct SubscriptionIntroductoryOffer: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -322,20 +306,15 @@ public struct SubscriptionIntroductoryOffer: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionIntroductoryOfferCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionIntroductoryOfferCreateRequest.swift index 348933c30..1dedb4af4 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionIntroductoryOfferCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionIntroductoryOfferCreateRequest.swift @@ -12,6 +12,18 @@ public struct SubscriptionIntroductoryOfferCreateRequest: Codable, RequestBody { self.included = included } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + included = try container.decodeIfPresent([SubscriptionPricePointInlineCreate].self, forKey: "included") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + } + public struct Data: Codable { public var type: String { "subscriptionIntroductoryOffers" } public let attributes: Attributes @@ -25,25 +37,19 @@ public struct SubscriptionIntroductoryOfferCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -65,6 +71,24 @@ public struct SubscriptionIntroductoryOfferCreateRequest: Codable, RequestBody { self.offerMode = offerMode self.startDate = startDate } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + duration = try container.decode(SubscriptionOfferDuration.self, forKey: "duration") + endDate = try container.decodeIfPresent(String.self, forKey: "endDate") + numberOfPeriods = try container.decode(Int.self, forKey: "numberOfPeriods") + offerMode = try container.decode(SubscriptionOfferMode.self, forKey: "offerMode") + startDate = try container.decodeIfPresent(String.self, forKey: "startDate") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(duration, forKey: "duration") + try container.encodeIfPresent(endDate, forKey: "endDate") + try container.encode(numberOfPeriods, forKey: "numberOfPeriods") + try container.encode(offerMode, forKey: "offerMode") + try container.encodeIfPresent(startDate, forKey: "startDate") + } } public struct Relationships: Codable { @@ -81,6 +105,20 @@ public struct SubscriptionIntroductoryOfferCreateRequest: Codable, RequestBody { self.territory = territory } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + subscription = try container.decode(Subscription.self, forKey: "subscription") + subscriptionPricePoint = try container.decodeIfPresent(SubscriptionPricePoint.self, forKey: "subscriptionPricePoint") + territory = try container.decodeIfPresent(Territory.self, forKey: "territory") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(subscription, forKey: "subscription") + try container.encodeIfPresent(subscriptionPricePoint, forKey: "subscriptionPricePoint") + try container.encodeIfPresent(territory, forKey: "territory") + } + public struct Subscription: Codable { public let data: Data @@ -88,6 +126,16 @@ public struct SubscriptionIntroductoryOfferCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "subscriptions" } @@ -97,22 +145,17 @@ public struct SubscriptionIntroductoryOfferCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -125,17 +168,13 @@ public struct SubscriptionIntroductoryOfferCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } public struct Data: Codable, Identifiable { @@ -147,22 +186,17 @@ public struct SubscriptionIntroductoryOfferCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -175,17 +209,13 @@ public struct SubscriptionIntroductoryOfferCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } public struct Data: Codable, Identifiable { @@ -197,22 +227,17 @@ public struct SubscriptionIntroductoryOfferCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionIntroductoryOfferInlineCreate.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionIntroductoryOfferInlineCreate.swift index 5cbc81064..05d96f0ec 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionIntroductoryOfferInlineCreate.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionIntroductoryOfferInlineCreate.swift @@ -17,28 +17,21 @@ public struct SubscriptionIntroductoryOfferInlineCreate: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decodeIfPresent(String.self, forKey: .id) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decodeIfPresent(String.self, forKey: "id") + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -60,6 +53,24 @@ public struct SubscriptionIntroductoryOfferInlineCreate: Codable, Identifiable { self.offerMode = offerMode self.startDate = startDate } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + duration = try container.decode(SubscriptionOfferDuration.self, forKey: "duration") + endDate = try container.decodeIfPresent(String.self, forKey: "endDate") + numberOfPeriods = try container.decode(Int.self, forKey: "numberOfPeriods") + offerMode = try container.decode(SubscriptionOfferMode.self, forKey: "offerMode") + startDate = try container.decodeIfPresent(String.self, forKey: "startDate") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(duration, forKey: "duration") + try container.encodeIfPresent(endDate, forKey: "endDate") + try container.encode(numberOfPeriods, forKey: "numberOfPeriods") + try container.encode(offerMode, forKey: "offerMode") + try container.encodeIfPresent(startDate, forKey: "startDate") + } } public struct Relationships: Codable { @@ -76,6 +87,20 @@ public struct SubscriptionIntroductoryOfferInlineCreate: Codable, Identifiable { self.territory = territory } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + subscription = try container.decodeIfPresent(Subscription.self, forKey: "subscription") + subscriptionPricePoint = try container.decodeIfPresent(SubscriptionPricePoint.self, forKey: "subscriptionPricePoint") + territory = try container.decodeIfPresent(Territory.self, forKey: "territory") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(subscription, forKey: "subscription") + try container.encodeIfPresent(subscriptionPricePoint, forKey: "subscriptionPricePoint") + try container.encodeIfPresent(territory, forKey: "territory") + } + public struct Subscription: Codable { @NullCodable public var data: Data? @@ -84,17 +109,13 @@ public struct SubscriptionIntroductoryOfferInlineCreate: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } public struct Data: Codable, Identifiable { @@ -106,22 +127,17 @@ public struct SubscriptionIntroductoryOfferInlineCreate: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -134,17 +150,13 @@ public struct SubscriptionIntroductoryOfferInlineCreate: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } public struct Data: Codable, Identifiable { @@ -156,22 +168,17 @@ public struct SubscriptionIntroductoryOfferInlineCreate: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -184,17 +191,13 @@ public struct SubscriptionIntroductoryOfferInlineCreate: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } public struct Data: Codable, Identifiable { @@ -206,22 +209,17 @@ public struct SubscriptionIntroductoryOfferInlineCreate: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionIntroductoryOfferResponse.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionIntroductoryOfferResponse.swift index c9b878f5c..6244a7e34 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionIntroductoryOfferResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionIntroductoryOfferResponse.swift @@ -15,6 +15,20 @@ public struct SubscriptionIntroductoryOfferResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(SubscriptionIntroductoryOffer.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getSubscription() -> Subscription? { included?.compactMap { relationship -> Subscription? in guard case let .subscription(subscription) = relationship else { return nil } @@ -64,9 +78,5 @@ public struct SubscriptionIntroductoryOfferResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionIntroductoryOfferUpdateRequest.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionIntroductoryOfferUpdateRequest.swift index b9dd570bf..347ceff4c 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionIntroductoryOfferUpdateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionIntroductoryOfferUpdateRequest.swift @@ -8,6 +8,16 @@ public struct SubscriptionIntroductoryOfferUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "subscriptionIntroductoryOffers" } @@ -21,25 +31,19 @@ public struct SubscriptionIntroductoryOfferUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } public struct Attributes: Codable { @@ -48,6 +52,16 @@ public struct SubscriptionIntroductoryOfferUpdateRequest: Codable, RequestBody { public init(endDate: String? = nil) { self.endDate = endDate } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + endDate = try container.decodeIfPresent(String.self, forKey: "endDate") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(endDate, forKey: "endDate") + } } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionIntroductoryOffersLinkagesRequest.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionIntroductoryOffersLinkagesRequest.swift index 52590c419..b032022ad 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionIntroductoryOffersLinkagesRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionIntroductoryOffersLinkagesRequest.swift @@ -8,6 +8,16 @@ public struct SubscriptionIntroductoryOffersLinkagesRequest: Codable, RequestBod self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "subscriptionIntroductoryOffers" } @@ -17,22 +27,17 @@ public struct SubscriptionIntroductoryOffersLinkagesRequest: Codable, RequestBod } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionIntroductoryOffersLinkagesResponse.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionIntroductoryOffersLinkagesResponse.swift index 96349324f..806741d76 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionIntroductoryOffersLinkagesResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionIntroductoryOffersLinkagesResponse.swift @@ -15,6 +15,20 @@ public struct SubscriptionIntroductoryOffersLinkagesResponse: Codable, PagedResp self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "subscriptionIntroductoryOffers" } @@ -24,22 +38,17 @@ public struct SubscriptionIntroductoryOffersLinkagesResponse: Codable, PagedResp } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionIntroductoryOffersResponse.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionIntroductoryOffersResponse.swift index c1b5b7f59..070d4aec1 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionIntroductoryOffersResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionIntroductoryOffersResponse.swift @@ -20,6 +20,22 @@ public struct SubscriptionIntroductoryOffersResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([SubscriptionIntroductoryOffer].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getSubscription(for subscriptionIntroductoryOffer: SubscriptionIntroductoryOffer) -> Subscription? { included?.compactMap { relationship -> Subscription? in guard case let .subscription(subscription) = relationship else { return nil } @@ -69,9 +85,5 @@ public struct SubscriptionIntroductoryOffersResponse: Codable, PagedResponse { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionLocalization.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionLocalization.swift index ec172cae2..a2a976342 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionLocalization.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionLocalization.swift @@ -20,31 +20,23 @@ public struct SubscriptionLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -64,6 +56,22 @@ public struct SubscriptionLocalization: Codable, Identifiable { self.state = state } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + description = try container.decodeIfPresent(String.self, forKey: "description") + locale = try container.decodeIfPresent(String.self, forKey: "locale") + name = try container.decodeIfPresent(String.self, forKey: "name") + state = try container.decodeIfPresent(State.self, forKey: "state") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(description, forKey: "description") + try container.encodeIfPresent(locale, forKey: "locale") + try container.encodeIfPresent(name, forKey: "name") + try container.encodeIfPresent(state, forKey: "state") + } + public enum State: String, Codable, CaseIterable { case approved = "APPROVED" case prepareForSubmission = "PREPARE_FOR_SUBMISSION" @@ -79,6 +87,16 @@ public struct SubscriptionLocalization: Codable, Identifiable { self.subscription = subscription } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + subscription = try container.decodeIfPresent(Subscription.self, forKey: "subscription") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(subscription, forKey: "subscription") + } + public struct Subscription: Codable { @NullCodable public var data: Data? public var links: Links? @@ -91,20 +109,15 @@ public struct SubscriptionLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -116,22 +129,17 @@ public struct SubscriptionLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -147,20 +155,15 @@ public struct SubscriptionLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionLocalizationCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionLocalizationCreateRequest.swift index a1a4f10ee..91ddf75e7 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionLocalizationCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionLocalizationCreateRequest.swift @@ -8,6 +8,16 @@ public struct SubscriptionLocalizationCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "subscriptionLocalizations" } public let attributes: Attributes @@ -21,25 +31,19 @@ public struct SubscriptionLocalizationCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -55,6 +59,20 @@ public struct SubscriptionLocalizationCreateRequest: Codable, RequestBody { self.locale = locale self.name = name } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + description = try container.decodeIfPresent(String.self, forKey: "description") + locale = try container.decode(String.self, forKey: "locale") + name = try container.decode(String.self, forKey: "name") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(description, forKey: "description") + try container.encode(locale, forKey: "locale") + try container.encode(name, forKey: "name") + } } public struct Relationships: Codable { @@ -64,6 +82,16 @@ public struct SubscriptionLocalizationCreateRequest: Codable, RequestBody { self.subscription = subscription } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + subscription = try container.decode(Subscription.self, forKey: "subscription") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(subscription, forKey: "subscription") + } + public struct Subscription: Codable { public let data: Data @@ -71,6 +99,16 @@ public struct SubscriptionLocalizationCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "subscriptions" } @@ -80,22 +118,17 @@ public struct SubscriptionLocalizationCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionLocalizationResponse.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionLocalizationResponse.swift index aa07a47ea..81ceea01b 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionLocalizationResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionLocalizationResponse.swift @@ -14,4 +14,18 @@ public struct SubscriptionLocalizationResponse: Codable { self.included = included self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(SubscriptionLocalization.self, forKey: "data") + included = try container.decodeIfPresent([Subscription].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionLocalizationUpdateRequest.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionLocalizationUpdateRequest.swift index d29fbab00..9229b1072 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionLocalizationUpdateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionLocalizationUpdateRequest.swift @@ -8,6 +8,16 @@ public struct SubscriptionLocalizationUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "subscriptionLocalizations" } @@ -21,25 +31,19 @@ public struct SubscriptionLocalizationUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } public struct Attributes: Codable { @@ -52,6 +56,18 @@ public struct SubscriptionLocalizationUpdateRequest: Codable, RequestBody { self.description = description self.name = name } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + description = try container.decodeIfPresent(String.self, forKey: "description") + name = try container.decodeIfPresent(String.self, forKey: "name") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(description, forKey: "description") + try container.encodeIfPresent(name, forKey: "name") + } } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionLocalizationsResponse.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionLocalizationsResponse.swift index b5c78e00a..291a604a5 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionLocalizationsResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionLocalizationsResponse.swift @@ -19,4 +19,20 @@ public struct SubscriptionLocalizationsResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([SubscriptionLocalization].self, forKey: "data") + included = try container.decodeIfPresent([Subscription].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCode.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCode.swift index 1abe6f559..42fd0bbad 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCode.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCode.swift @@ -20,31 +20,23 @@ public struct SubscriptionOfferCode: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -75,6 +67,30 @@ public struct SubscriptionOfferCode: Codable, Identifiable { self.offerMode = offerMode self.totalNumberOfCodes = totalNumberOfCodes } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + active = try container.decodeIfPresent(Bool.self, forKey: "active") + customerEligibilities = try container.decodeIfPresent([SubscriptionCustomerEligibility].self, forKey: "customerEligibilities") + duration = try container.decodeIfPresent(SubscriptionOfferDuration.self, forKey: "duration") + name = try container.decodeIfPresent(String.self, forKey: "name") + numberOfPeriods = try container.decodeIfPresent(Int.self, forKey: "numberOfPeriods") + offerEligibility = try container.decodeIfPresent(SubscriptionOfferEligibility.self, forKey: "offerEligibility") + offerMode = try container.decodeIfPresent(SubscriptionOfferMode.self, forKey: "offerMode") + totalNumberOfCodes = try container.decodeIfPresent(Int.self, forKey: "totalNumberOfCodes") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(active, forKey: "active") + try container.encodeIfPresent(customerEligibilities, forKey: "customerEligibilities") + try container.encodeIfPresent(duration, forKey: "duration") + try container.encodeIfPresent(name, forKey: "name") + try container.encodeIfPresent(numberOfPeriods, forKey: "numberOfPeriods") + try container.encodeIfPresent(offerEligibility, forKey: "offerEligibility") + try container.encodeIfPresent(offerMode, forKey: "offerMode") + try container.encodeIfPresent(totalNumberOfCodes, forKey: "totalNumberOfCodes") + } } public struct Relationships: Codable { @@ -94,6 +110,22 @@ public struct SubscriptionOfferCode: Codable, Identifiable { self.subscription = subscription } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + customCodes = try container.decodeIfPresent(CustomCodes.self, forKey: "customCodes") + oneTimeUseCodes = try container.decodeIfPresent(OneTimeUseCodes.self, forKey: "oneTimeUseCodes") + prices = try container.decodeIfPresent(Prices.self, forKey: "prices") + subscription = try container.decodeIfPresent(Subscription.self, forKey: "subscription") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(customCodes, forKey: "customCodes") + try container.encodeIfPresent(oneTimeUseCodes, forKey: "oneTimeUseCodes") + try container.encodeIfPresent(prices, forKey: "prices") + try container.encodeIfPresent(subscription, forKey: "subscription") + } + public struct CustomCodes: Codable { @NullCodable public var data: [Data]? public var links: Links? @@ -109,23 +141,17 @@ public struct SubscriptionOfferCode: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -137,22 +163,17 @@ public struct SubscriptionOfferCode: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -168,20 +189,15 @@ public struct SubscriptionOfferCode: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -201,23 +217,17 @@ public struct SubscriptionOfferCode: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -229,22 +239,17 @@ public struct SubscriptionOfferCode: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -260,20 +265,15 @@ public struct SubscriptionOfferCode: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -293,23 +293,17 @@ public struct SubscriptionOfferCode: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -321,22 +315,17 @@ public struct SubscriptionOfferCode: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -352,20 +341,15 @@ public struct SubscriptionOfferCode: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -382,20 +366,15 @@ public struct SubscriptionOfferCode: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -407,22 +386,17 @@ public struct SubscriptionOfferCode: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -438,20 +412,15 @@ public struct SubscriptionOfferCode: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodeCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodeCreateRequest.swift index 9b755209f..f152b1e3d 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodeCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodeCreateRequest.swift @@ -12,6 +12,18 @@ public struct SubscriptionOfferCodeCreateRequest: Codable, RequestBody { self.included = included } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + included = try container.decodeIfPresent([SubscriptionOfferCodePriceInlineCreate].self, forKey: "included") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + } + public struct Data: Codable { public var type: String { "subscriptionOfferCodes" } public let attributes: Attributes @@ -25,25 +37,19 @@ public struct SubscriptionOfferCodeCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -68,6 +74,26 @@ public struct SubscriptionOfferCodeCreateRequest: Codable, RequestBody { self.offerEligibility = offerEligibility self.offerMode = offerMode } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + customerEligibilities = try container.decode([SubscriptionCustomerEligibility].self, forKey: "customerEligibilities") + duration = try container.decode(SubscriptionOfferDuration.self, forKey: "duration") + name = try container.decode(String.self, forKey: "name") + numberOfPeriods = try container.decode(Int.self, forKey: "numberOfPeriods") + offerEligibility = try container.decode(SubscriptionOfferEligibility.self, forKey: "offerEligibility") + offerMode = try container.decode(SubscriptionOfferMode.self, forKey: "offerMode") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(customerEligibilities, forKey: "customerEligibilities") + try container.encode(duration, forKey: "duration") + try container.encode(name, forKey: "name") + try container.encode(numberOfPeriods, forKey: "numberOfPeriods") + try container.encode(offerEligibility, forKey: "offerEligibility") + try container.encode(offerMode, forKey: "offerMode") + } } public struct Relationships: Codable { @@ -81,6 +107,18 @@ public struct SubscriptionOfferCodeCreateRequest: Codable, RequestBody { self.subscription = subscription } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + prices = try container.decode(Prices.self, forKey: "prices") + subscription = try container.decode(Subscription.self, forKey: "subscription") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(prices, forKey: "prices") + try container.encode(subscription, forKey: "subscription") + } + public struct Prices: Codable { public let data: [Data] @@ -88,6 +126,16 @@ public struct SubscriptionOfferCodeCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "subscriptionOfferCodePrices" } @@ -97,22 +145,17 @@ public struct SubscriptionOfferCodeCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -124,6 +167,16 @@ public struct SubscriptionOfferCodeCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "subscriptions" } @@ -133,22 +186,17 @@ public struct SubscriptionOfferCodeCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodeCustomCode.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodeCustomCode.swift index 9ca149a1a..2d0ccdf0d 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodeCustomCode.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodeCustomCode.swift @@ -20,31 +20,23 @@ public struct SubscriptionOfferCodeCustomCode: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -66,6 +58,24 @@ public struct SubscriptionOfferCodeCustomCode: Codable, Identifiable { self.expirationDate = expirationDate self.numberOfCodes = numberOfCodes } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + active = try container.decodeIfPresent(Bool.self, forKey: "active") + createdDate = try container.decodeIfPresent(Date.self, forKey: "createdDate") + customCode = try container.decodeIfPresent(String.self, forKey: "customCode") + expirationDate = try container.decodeIfPresent(String.self, forKey: "expirationDate") + numberOfCodes = try container.decodeIfPresent(Int.self, forKey: "numberOfCodes") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(active, forKey: "active") + try container.encodeIfPresent(createdDate, forKey: "createdDate") + try container.encodeIfPresent(customCode, forKey: "customCode") + try container.encodeIfPresent(expirationDate, forKey: "expirationDate") + try container.encodeIfPresent(numberOfCodes, forKey: "numberOfCodes") + } } public struct Relationships: Codable { @@ -75,6 +85,16 @@ public struct SubscriptionOfferCodeCustomCode: Codable, Identifiable { self.offerCode = offerCode } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + offerCode = try container.decodeIfPresent(OfferCode.self, forKey: "offerCode") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(offerCode, forKey: "offerCode") + } + public struct OfferCode: Codable { @NullCodable public var data: Data? public var links: Links? @@ -87,20 +107,15 @@ public struct SubscriptionOfferCodeCustomCode: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -112,22 +127,17 @@ public struct SubscriptionOfferCodeCustomCode: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -143,20 +153,15 @@ public struct SubscriptionOfferCodeCustomCode: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodeCustomCodeCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodeCustomCodeCreateRequest.swift index de9951d01..c08708274 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodeCustomCodeCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodeCustomCodeCreateRequest.swift @@ -8,6 +8,16 @@ public struct SubscriptionOfferCodeCustomCodeCreateRequest: Codable, RequestBody self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "subscriptionOfferCodeCustomCodes" } public let attributes: Attributes @@ -21,25 +31,19 @@ public struct SubscriptionOfferCodeCustomCodeCreateRequest: Codable, RequestBody } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -55,6 +59,20 @@ public struct SubscriptionOfferCodeCustomCodeCreateRequest: Codable, RequestBody self.expirationDate = expirationDate self.numberOfCodes = numberOfCodes } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + customCode = try container.decode(String.self, forKey: "customCode") + expirationDate = try container.decodeIfPresent(String.self, forKey: "expirationDate") + numberOfCodes = try container.decode(Int.self, forKey: "numberOfCodes") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(customCode, forKey: "customCode") + try container.encodeIfPresent(expirationDate, forKey: "expirationDate") + try container.encode(numberOfCodes, forKey: "numberOfCodes") + } } public struct Relationships: Codable { @@ -64,6 +82,16 @@ public struct SubscriptionOfferCodeCustomCodeCreateRequest: Codable, RequestBody self.offerCode = offerCode } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + offerCode = try container.decode(OfferCode.self, forKey: "offerCode") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(offerCode, forKey: "offerCode") + } + public struct OfferCode: Codable { public let data: Data @@ -71,6 +99,16 @@ public struct SubscriptionOfferCodeCustomCodeCreateRequest: Codable, RequestBody self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "subscriptionOfferCodes" } @@ -80,22 +118,17 @@ public struct SubscriptionOfferCodeCustomCodeCreateRequest: Codable, RequestBody } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodeCustomCodeResponse.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodeCustomCodeResponse.swift index ad162e427..c8f4be63b 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodeCustomCodeResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodeCustomCodeResponse.swift @@ -14,4 +14,18 @@ public struct SubscriptionOfferCodeCustomCodeResponse: Codable { self.included = included self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(SubscriptionOfferCodeCustomCode.self, forKey: "data") + included = try container.decodeIfPresent([SubscriptionOfferCode].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodeCustomCodeUpdateRequest.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodeCustomCodeUpdateRequest.swift index 280642515..a4098848c 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodeCustomCodeUpdateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodeCustomCodeUpdateRequest.swift @@ -8,6 +8,16 @@ public struct SubscriptionOfferCodeCustomCodeUpdateRequest: Codable, RequestBody self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "subscriptionOfferCodeCustomCodes" } @@ -21,25 +31,19 @@ public struct SubscriptionOfferCodeCustomCodeUpdateRequest: Codable, RequestBody } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } public struct Attributes: Codable { @@ -48,6 +52,16 @@ public struct SubscriptionOfferCodeCustomCodeUpdateRequest: Codable, RequestBody public init(active: Bool? = nil) { self.active = active } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + active = try container.decodeIfPresent(Bool.self, forKey: "active") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(active, forKey: "active") + } } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodeCustomCodesResponse.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodeCustomCodesResponse.swift index c6f1b7aeb..90bd2af08 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodeCustomCodesResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodeCustomCodesResponse.swift @@ -19,4 +19,20 @@ public struct SubscriptionOfferCodeCustomCodesResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([SubscriptionOfferCodeCustomCode].self, forKey: "data") + included = try container.decodeIfPresent([SubscriptionOfferCode].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodeOneTimeUseCode.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodeOneTimeUseCode.swift index 7293b6718..a1cd2ef95 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodeOneTimeUseCode.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodeOneTimeUseCode.swift @@ -20,31 +20,23 @@ public struct SubscriptionOfferCodeOneTimeUseCode: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -63,6 +55,22 @@ public struct SubscriptionOfferCodeOneTimeUseCode: Codable, Identifiable { self.expirationDate = expirationDate self.numberOfCodes = numberOfCodes } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + active = try container.decodeIfPresent(Bool.self, forKey: "active") + createdDate = try container.decodeIfPresent(Date.self, forKey: "createdDate") + expirationDate = try container.decodeIfPresent(String.self, forKey: "expirationDate") + numberOfCodes = try container.decodeIfPresent(Int.self, forKey: "numberOfCodes") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(active, forKey: "active") + try container.encodeIfPresent(createdDate, forKey: "createdDate") + try container.encodeIfPresent(expirationDate, forKey: "expirationDate") + try container.encodeIfPresent(numberOfCodes, forKey: "numberOfCodes") + } } public struct Relationships: Codable { @@ -72,6 +80,16 @@ public struct SubscriptionOfferCodeOneTimeUseCode: Codable, Identifiable { self.offerCode = offerCode } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + offerCode = try container.decodeIfPresent(OfferCode.self, forKey: "offerCode") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(offerCode, forKey: "offerCode") + } + public struct OfferCode: Codable { @NullCodable public var data: Data? public var links: Links? @@ -84,20 +102,15 @@ public struct SubscriptionOfferCodeOneTimeUseCode: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -109,22 +122,17 @@ public struct SubscriptionOfferCodeOneTimeUseCode: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -140,20 +148,15 @@ public struct SubscriptionOfferCodeOneTimeUseCode: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodeOneTimeUseCodeCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodeOneTimeUseCodeCreateRequest.swift index a617b3b36..0d718bbe8 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodeOneTimeUseCodeCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodeOneTimeUseCodeCreateRequest.swift @@ -8,6 +8,16 @@ public struct SubscriptionOfferCodeOneTimeUseCodeCreateRequest: Codable, Request self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "subscriptionOfferCodeOneTimeUseCodes" } public let attributes: Attributes @@ -21,25 +31,19 @@ public struct SubscriptionOfferCodeOneTimeUseCodeCreateRequest: Codable, Request } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -52,6 +56,18 @@ public struct SubscriptionOfferCodeOneTimeUseCodeCreateRequest: Codable, Request self.expirationDate = expirationDate self.numberOfCodes = numberOfCodes } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + expirationDate = try container.decode(String.self, forKey: "expirationDate") + numberOfCodes = try container.decode(Int.self, forKey: "numberOfCodes") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(expirationDate, forKey: "expirationDate") + try container.encode(numberOfCodes, forKey: "numberOfCodes") + } } public struct Relationships: Codable { @@ -61,6 +77,16 @@ public struct SubscriptionOfferCodeOneTimeUseCodeCreateRequest: Codable, Request self.offerCode = offerCode } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + offerCode = try container.decode(OfferCode.self, forKey: "offerCode") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(offerCode, forKey: "offerCode") + } + public struct OfferCode: Codable { public let data: Data @@ -68,6 +94,16 @@ public struct SubscriptionOfferCodeOneTimeUseCodeCreateRequest: Codable, Request self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "subscriptionOfferCodes" } @@ -77,22 +113,17 @@ public struct SubscriptionOfferCodeOneTimeUseCodeCreateRequest: Codable, Request } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodeOneTimeUseCodeResponse.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodeOneTimeUseCodeResponse.swift index 5b71f42c9..bbee781f5 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodeOneTimeUseCodeResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodeOneTimeUseCodeResponse.swift @@ -14,4 +14,18 @@ public struct SubscriptionOfferCodeOneTimeUseCodeResponse: Codable { self.included = included self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(SubscriptionOfferCodeOneTimeUseCode.self, forKey: "data") + included = try container.decodeIfPresent([SubscriptionOfferCode].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodeOneTimeUseCodeUpdateRequest.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodeOneTimeUseCodeUpdateRequest.swift index d6f8e29f9..39cb67bc8 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodeOneTimeUseCodeUpdateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodeOneTimeUseCodeUpdateRequest.swift @@ -8,6 +8,16 @@ public struct SubscriptionOfferCodeOneTimeUseCodeUpdateRequest: Codable, Request self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "subscriptionOfferCodeOneTimeUseCodes" } @@ -21,25 +31,19 @@ public struct SubscriptionOfferCodeOneTimeUseCodeUpdateRequest: Codable, Request } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } public struct Attributes: Codable { @@ -48,6 +52,16 @@ public struct SubscriptionOfferCodeOneTimeUseCodeUpdateRequest: Codable, Request public init(active: Bool? = nil) { self.active = active } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + active = try container.decodeIfPresent(Bool.self, forKey: "active") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(active, forKey: "active") + } } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodeOneTimeUseCodeValue.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodeOneTimeUseCodeValue.swift index fe6867082..0a8d9cc5e 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodeOneTimeUseCodeValue.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodeOneTimeUseCodeValue.swift @@ -14,24 +14,18 @@ public struct SubscriptionOfferCodeOneTimeUseCodeValue: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case links - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodeOneTimeUseCodesResponse.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodeOneTimeUseCodesResponse.swift index 90d06df13..226fd4632 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodeOneTimeUseCodesResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodeOneTimeUseCodesResponse.swift @@ -19,4 +19,20 @@ public struct SubscriptionOfferCodeOneTimeUseCodesResponse: Codable, PagedRespon self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([SubscriptionOfferCodeOneTimeUseCode].self, forKey: "data") + included = try container.decodeIfPresent([SubscriptionOfferCode].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodePrice.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodePrice.swift index fb504a2f7..a02a160f5 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodePrice.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodePrice.swift @@ -17,28 +17,21 @@ public struct SubscriptionOfferCodePrice: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Relationships: Codable { @@ -52,6 +45,18 @@ public struct SubscriptionOfferCodePrice: Codable, Identifiable { self.territory = territory } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + subscriptionPricePoint = try container.decodeIfPresent(SubscriptionPricePoint.self, forKey: "subscriptionPricePoint") + territory = try container.decodeIfPresent(Territory.self, forKey: "territory") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(subscriptionPricePoint, forKey: "subscriptionPricePoint") + try container.encodeIfPresent(territory, forKey: "territory") + } + public struct SubscriptionPricePoint: Codable { @NullCodable public var data: Data? public var links: Links? @@ -64,20 +69,15 @@ public struct SubscriptionOfferCodePrice: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -89,22 +89,17 @@ public struct SubscriptionOfferCodePrice: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -120,20 +115,15 @@ public struct SubscriptionOfferCodePrice: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -150,20 +140,15 @@ public struct SubscriptionOfferCodePrice: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -175,22 +160,17 @@ public struct SubscriptionOfferCodePrice: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -206,20 +186,15 @@ public struct SubscriptionOfferCodePrice: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodePriceInlineCreate.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodePriceInlineCreate.swift index 62a4bd969..605d7ddc8 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodePriceInlineCreate.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodePriceInlineCreate.swift @@ -14,25 +14,19 @@ public struct SubscriptionOfferCodePriceInlineCreate: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decodeIfPresent(String.self, forKey: .id) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decodeIfPresent(String.self, forKey: "id") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case id - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Relationships: Codable { @@ -46,6 +40,18 @@ public struct SubscriptionOfferCodePriceInlineCreate: Codable, Identifiable { self.territory = territory } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + subscriptionPricePoint = try container.decodeIfPresent(SubscriptionPricePoint.self, forKey: "subscriptionPricePoint") + territory = try container.decodeIfPresent(Territory.self, forKey: "territory") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(subscriptionPricePoint, forKey: "subscriptionPricePoint") + try container.encodeIfPresent(territory, forKey: "territory") + } + public struct SubscriptionPricePoint: Codable { @NullCodable public var data: Data? @@ -54,17 +60,13 @@ public struct SubscriptionOfferCodePriceInlineCreate: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } public struct Data: Codable, Identifiable { @@ -76,22 +78,17 @@ public struct SubscriptionOfferCodePriceInlineCreate: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -104,17 +101,13 @@ public struct SubscriptionOfferCodePriceInlineCreate: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } public struct Data: Codable, Identifiable { @@ -126,22 +119,17 @@ public struct SubscriptionOfferCodePriceInlineCreate: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodePricesResponse.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodePricesResponse.swift index 950b97b7e..67be83311 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodePricesResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodePricesResponse.swift @@ -20,6 +20,22 @@ public struct SubscriptionOfferCodePricesResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([SubscriptionOfferCodePrice].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getSubscriptionPricePoint(for subscriptionOfferCodePrice: SubscriptionOfferCodePrice) -> SubscriptionPricePoint? { included?.compactMap { relationship -> SubscriptionPricePoint? in guard case let .subscriptionPricePoint(subscriptionPricePoint) = relationship else { return nil } @@ -57,9 +73,5 @@ public struct SubscriptionOfferCodePricesResponse: Codable, PagedResponse { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodeResponse.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodeResponse.swift index 19f764f9f..0c6d7ae68 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodeResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodeResponse.swift @@ -15,6 +15,20 @@ public struct SubscriptionOfferCodeResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(SubscriptionOfferCode.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getCustomCodes() -> [SubscriptionOfferCodeCustomCode] { guard let customCodeIds = data.relationships?.customCodes?.data?.map(\.id), let customCodes = included?.compactMap({ relationship -> SubscriptionOfferCodeCustomCode? in @@ -91,9 +105,5 @@ public struct SubscriptionOfferCodeResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodeUpdateRequest.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodeUpdateRequest.swift index 2946ea71f..0ce3dda08 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodeUpdateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodeUpdateRequest.swift @@ -8,6 +8,16 @@ public struct SubscriptionOfferCodeUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "subscriptionOfferCodes" } @@ -21,25 +31,19 @@ public struct SubscriptionOfferCodeUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } public struct Attributes: Codable { @@ -48,6 +52,16 @@ public struct SubscriptionOfferCodeUpdateRequest: Codable, RequestBody { public init(active: Bool? = nil) { self.active = active } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + active = try container.decodeIfPresent(Bool.self, forKey: "active") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(active, forKey: "active") + } } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodesResponse.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodesResponse.swift index c74279bf1..eaa071dde 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodesResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionOfferCodesResponse.swift @@ -20,6 +20,22 @@ public struct SubscriptionOfferCodesResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([SubscriptionOfferCode].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getCustomCodes(for subscriptionOfferCode: SubscriptionOfferCode) -> [SubscriptionOfferCodeCustomCode] { guard let customCodeIds = subscriptionOfferCode.relationships?.customCodes?.data?.map(\.id), let customCodes = included?.compactMap({ relationship -> SubscriptionOfferCodeCustomCode? in @@ -96,9 +112,5 @@ public struct SubscriptionOfferCodesResponse: Codable, PagedResponse { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionPrice.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionPrice.swift index 73cc28a5a..7c0d14f8d 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionPrice.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionPrice.swift @@ -20,31 +20,23 @@ public struct SubscriptionPrice: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -57,6 +49,18 @@ public struct SubscriptionPrice: Codable, Identifiable { self.preserved = preserved self.startDate = startDate } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + preserved = try container.decodeIfPresent(Bool.self, forKey: "preserved") + startDate = try container.decodeIfPresent(String.self, forKey: "startDate") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(preserved, forKey: "preserved") + try container.encodeIfPresent(startDate, forKey: "startDate") + } } public struct Relationships: Codable { @@ -70,6 +74,18 @@ public struct SubscriptionPrice: Codable, Identifiable { self.territory = territory } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + subscriptionPricePoint = try container.decodeIfPresent(SubscriptionPricePoint.self, forKey: "subscriptionPricePoint") + territory = try container.decodeIfPresent(Territory.self, forKey: "territory") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(subscriptionPricePoint, forKey: "subscriptionPricePoint") + try container.encodeIfPresent(territory, forKey: "territory") + } + public struct SubscriptionPricePoint: Codable { @NullCodable public var data: Data? public var links: Links? @@ -82,20 +98,15 @@ public struct SubscriptionPrice: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -107,22 +118,17 @@ public struct SubscriptionPrice: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -138,20 +144,15 @@ public struct SubscriptionPrice: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -168,20 +169,15 @@ public struct SubscriptionPrice: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -193,22 +189,17 @@ public struct SubscriptionPrice: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -224,20 +215,15 @@ public struct SubscriptionPrice: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionPriceCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionPriceCreateRequest.swift index 62133bdc6..0d9d6746b 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionPriceCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionPriceCreateRequest.swift @@ -8,6 +8,16 @@ public struct SubscriptionPriceCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "subscriptionPrices" } public var attributes: Attributes? @@ -21,25 +31,19 @@ public struct SubscriptionPriceCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -52,6 +56,18 @@ public struct SubscriptionPriceCreateRequest: Codable, RequestBody { self.preserveCurrentPrice = preserveCurrentPrice self.startDate = startDate } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + preserveCurrentPrice = try container.decodeIfPresent(Bool.self, forKey: "preserveCurrentPrice") + startDate = try container.decodeIfPresent(String.self, forKey: "startDate") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(preserveCurrentPrice, forKey: "preserveCurrentPrice") + try container.encodeIfPresent(startDate, forKey: "startDate") + } } public struct Relationships: Codable { @@ -68,6 +84,20 @@ public struct SubscriptionPriceCreateRequest: Codable, RequestBody { self.territory = territory } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + subscription = try container.decode(Subscription.self, forKey: "subscription") + subscriptionPricePoint = try container.decode(SubscriptionPricePoint.self, forKey: "subscriptionPricePoint") + territory = try container.decodeIfPresent(Territory.self, forKey: "territory") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(subscription, forKey: "subscription") + try container.encode(subscriptionPricePoint, forKey: "subscriptionPricePoint") + try container.encodeIfPresent(territory, forKey: "territory") + } + public struct Subscription: Codable { public let data: Data @@ -75,6 +105,16 @@ public struct SubscriptionPriceCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "subscriptions" } @@ -84,22 +124,17 @@ public struct SubscriptionPriceCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -111,6 +146,16 @@ public struct SubscriptionPriceCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "subscriptionPricePoints" } @@ -120,22 +165,17 @@ public struct SubscriptionPriceCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -148,17 +188,13 @@ public struct SubscriptionPriceCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } public struct Data: Codable, Identifiable { @@ -170,22 +206,17 @@ public struct SubscriptionPriceCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionPriceInlineCreate.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionPriceInlineCreate.swift index f9414128d..b194c20bc 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionPriceInlineCreate.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionPriceInlineCreate.swift @@ -17,28 +17,21 @@ public struct SubscriptionPriceInlineCreate: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decodeIfPresent(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decodeIfPresent(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -51,6 +44,18 @@ public struct SubscriptionPriceInlineCreate: Codable, Identifiable { self.preserveCurrentPrice = preserveCurrentPrice self.startDate = startDate } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + preserveCurrentPrice = try container.decodeIfPresent(Bool.self, forKey: "preserveCurrentPrice") + startDate = try container.decodeIfPresent(String.self, forKey: "startDate") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(preserveCurrentPrice, forKey: "preserveCurrentPrice") + try container.encodeIfPresent(startDate, forKey: "startDate") + } } public struct Relationships: Codable { @@ -67,6 +72,20 @@ public struct SubscriptionPriceInlineCreate: Codable, Identifiable { self.territory = territory } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + subscription = try container.decodeIfPresent(Subscription.self, forKey: "subscription") + subscriptionPricePoint = try container.decodeIfPresent(SubscriptionPricePoint.self, forKey: "subscriptionPricePoint") + territory = try container.decodeIfPresent(Territory.self, forKey: "territory") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(subscription, forKey: "subscription") + try container.encodeIfPresent(subscriptionPricePoint, forKey: "subscriptionPricePoint") + try container.encodeIfPresent(territory, forKey: "territory") + } + public struct Subscription: Codable { @NullCodable public var data: Data? @@ -75,17 +94,13 @@ public struct SubscriptionPriceInlineCreate: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } public struct Data: Codable, Identifiable { @@ -97,22 +112,17 @@ public struct SubscriptionPriceInlineCreate: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -125,17 +135,13 @@ public struct SubscriptionPriceInlineCreate: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } public struct Data: Codable, Identifiable { @@ -147,22 +153,17 @@ public struct SubscriptionPriceInlineCreate: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -175,17 +176,13 @@ public struct SubscriptionPriceInlineCreate: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } public struct Data: Codable, Identifiable { @@ -197,22 +194,17 @@ public struct SubscriptionPriceInlineCreate: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionPricePoint.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionPricePoint.swift index e935b9dcb..ee608d855 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionPricePoint.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionPricePoint.swift @@ -20,31 +20,23 @@ public struct SubscriptionPricePoint: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -60,6 +52,20 @@ public struct SubscriptionPricePoint: Codable, Identifiable { self.proceeds = proceeds self.proceedsYear2 = proceedsYear2 } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + customerPrice = try container.decodeIfPresent(String.self, forKey: "customerPrice") + proceeds = try container.decodeIfPresent(String.self, forKey: "proceeds") + proceedsYear2 = try container.decodeIfPresent(String.self, forKey: "proceedsYear2") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(customerPrice, forKey: "customerPrice") + try container.encodeIfPresent(proceeds, forKey: "proceeds") + try container.encodeIfPresent(proceedsYear2, forKey: "proceedsYear2") + } } public struct Relationships: Codable { @@ -69,6 +75,16 @@ public struct SubscriptionPricePoint: Codable, Identifiable { self.territory = territory } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + territory = try container.decodeIfPresent(Territory.self, forKey: "territory") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(territory, forKey: "territory") + } + public struct Territory: Codable { @NullCodable public var data: Data? public var links: Links? @@ -81,20 +97,15 @@ public struct SubscriptionPricePoint: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -106,22 +117,17 @@ public struct SubscriptionPricePoint: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -137,20 +143,15 @@ public struct SubscriptionPricePoint: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionPricePointInlineCreate.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionPricePointInlineCreate.swift index 4b4cbbcef..c187df15a 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionPricePointInlineCreate.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionPricePointInlineCreate.swift @@ -10,21 +10,16 @@ public struct SubscriptionPricePointInlineCreate: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decodeIfPresent(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decodeIfPresent(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(id, forKey: "id") + try container.encode(type, forKey: "type") } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionPricePointResponse.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionPricePointResponse.swift index 607d973cd..cecb3d001 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionPricePointResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionPricePointResponse.swift @@ -14,4 +14,18 @@ public struct SubscriptionPricePointResponse: Codable { self.included = included self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(SubscriptionPricePoint.self, forKey: "data") + included = try container.decodeIfPresent([Territory].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionPricePointsResponse.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionPricePointsResponse.swift index 71f8dd1f2..7567bb54a 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionPricePointsResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionPricePointsResponse.swift @@ -19,4 +19,20 @@ public struct SubscriptionPricePointsResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([SubscriptionPricePoint].self, forKey: "data") + included = try container.decodeIfPresent([Territory].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionPriceResponse.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionPriceResponse.swift index 340e67f7e..4d9458598 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionPriceResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionPriceResponse.swift @@ -15,6 +15,20 @@ public struct SubscriptionPriceResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(SubscriptionPrice.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getSubscriptionPricePoint() -> SubscriptionPricePoint? { included?.compactMap { relationship -> SubscriptionPricePoint? in guard case let .subscriptionPricePoint(subscriptionPricePoint) = relationship else { return nil } @@ -52,9 +66,5 @@ public struct SubscriptionPriceResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionPricesLinkagesRequest.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionPricesLinkagesRequest.swift index 2bbdab0b7..f62fd6e5a 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionPricesLinkagesRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionPricesLinkagesRequest.swift @@ -8,6 +8,16 @@ public struct SubscriptionPricesLinkagesRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "subscriptionPrices" } @@ -17,22 +27,17 @@ public struct SubscriptionPricesLinkagesRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionPricesLinkagesResponse.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionPricesLinkagesResponse.swift index e17af12d3..bb5163eda 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionPricesLinkagesResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionPricesLinkagesResponse.swift @@ -15,6 +15,20 @@ public struct SubscriptionPricesLinkagesResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "subscriptionPrices" } @@ -24,22 +38,17 @@ public struct SubscriptionPricesLinkagesResponse: Codable, PagedResponse { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionPricesResponse.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionPricesResponse.swift index 0238d94ef..b84b886fb 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionPricesResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionPricesResponse.swift @@ -20,6 +20,22 @@ public struct SubscriptionPricesResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([SubscriptionPrice].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getSubscriptionPricePoint(for subscriptionPrice: SubscriptionPrice) -> SubscriptionPricePoint? { included?.compactMap { relationship -> SubscriptionPricePoint? in guard case let .subscriptionPricePoint(subscriptionPricePoint) = relationship else { return nil } @@ -57,9 +73,5 @@ public struct SubscriptionPricesResponse: Codable, PagedResponse { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionPromotionalOffer.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionPromotionalOffer.swift index 864416884..ba12095c1 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionPromotionalOffer.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionPromotionalOffer.swift @@ -20,31 +20,23 @@ public struct SubscriptionPromotionalOffer: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -66,6 +58,24 @@ public struct SubscriptionPromotionalOffer: Codable, Identifiable { self.offerCode = offerCode self.offerMode = offerMode } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + duration = try container.decodeIfPresent(SubscriptionOfferDuration.self, forKey: "duration") + name = try container.decodeIfPresent(String.self, forKey: "name") + numberOfPeriods = try container.decodeIfPresent(Int.self, forKey: "numberOfPeriods") + offerCode = try container.decodeIfPresent(String.self, forKey: "offerCode") + offerMode = try container.decodeIfPresent(SubscriptionOfferMode.self, forKey: "offerMode") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(duration, forKey: "duration") + try container.encodeIfPresent(name, forKey: "name") + try container.encodeIfPresent(numberOfPeriods, forKey: "numberOfPeriods") + try container.encodeIfPresent(offerCode, forKey: "offerCode") + try container.encodeIfPresent(offerMode, forKey: "offerMode") + } } public struct Relationships: Codable { @@ -79,6 +89,18 @@ public struct SubscriptionPromotionalOffer: Codable, Identifiable { self.subscription = subscription } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + prices = try container.decodeIfPresent(Prices.self, forKey: "prices") + subscription = try container.decodeIfPresent(Subscription.self, forKey: "subscription") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(prices, forKey: "prices") + try container.encodeIfPresent(subscription, forKey: "subscription") + } + public struct Prices: Codable { @NullCodable public var data: [Data]? public var links: Links? @@ -94,23 +116,17 @@ public struct SubscriptionPromotionalOffer: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -122,22 +138,17 @@ public struct SubscriptionPromotionalOffer: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -153,20 +164,15 @@ public struct SubscriptionPromotionalOffer: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -183,20 +189,15 @@ public struct SubscriptionPromotionalOffer: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -208,22 +209,17 @@ public struct SubscriptionPromotionalOffer: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -239,20 +235,15 @@ public struct SubscriptionPromotionalOffer: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionPromotionalOfferCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionPromotionalOfferCreateRequest.swift index 1b4ad38d4..8f64839b8 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionPromotionalOfferCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionPromotionalOfferCreateRequest.swift @@ -12,6 +12,18 @@ public struct SubscriptionPromotionalOfferCreateRequest: Codable, RequestBody { self.included = included } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + included = try container.decodeIfPresent([SubscriptionPromotionalOfferPriceInlineCreate].self, forKey: "included") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + } + public struct Data: Codable { public var type: String { "subscriptionPromotionalOffers" } public let attributes: Attributes @@ -25,25 +37,19 @@ public struct SubscriptionPromotionalOfferCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -65,6 +71,24 @@ public struct SubscriptionPromotionalOfferCreateRequest: Codable, RequestBody { self.offerCode = offerCode self.offerMode = offerMode } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + duration = try container.decode(SubscriptionOfferDuration.self, forKey: "duration") + name = try container.decode(String.self, forKey: "name") + numberOfPeriods = try container.decode(Int.self, forKey: "numberOfPeriods") + offerCode = try container.decode(String.self, forKey: "offerCode") + offerMode = try container.decode(SubscriptionOfferMode.self, forKey: "offerMode") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(duration, forKey: "duration") + try container.encode(name, forKey: "name") + try container.encode(numberOfPeriods, forKey: "numberOfPeriods") + try container.encode(offerCode, forKey: "offerCode") + try container.encode(offerMode, forKey: "offerMode") + } } public struct Relationships: Codable { @@ -78,6 +102,18 @@ public struct SubscriptionPromotionalOfferCreateRequest: Codable, RequestBody { self.subscription = subscription } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + prices = try container.decode(Prices.self, forKey: "prices") + subscription = try container.decode(Subscription.self, forKey: "subscription") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(prices, forKey: "prices") + try container.encode(subscription, forKey: "subscription") + } + public struct Prices: Codable { public let data: [Data] @@ -85,6 +121,16 @@ public struct SubscriptionPromotionalOfferCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "subscriptionPromotionalOfferPrices" } @@ -94,22 +140,17 @@ public struct SubscriptionPromotionalOfferCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -121,6 +162,16 @@ public struct SubscriptionPromotionalOfferCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "subscriptions" } @@ -130,22 +181,17 @@ public struct SubscriptionPromotionalOfferCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionPromotionalOfferInlineCreate.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionPromotionalOfferInlineCreate.swift index ab78b1c81..52c1277ab 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionPromotionalOfferInlineCreate.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionPromotionalOfferInlineCreate.swift @@ -17,28 +17,21 @@ public struct SubscriptionPromotionalOfferInlineCreate: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decodeIfPresent(String.self, forKey: .id) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decodeIfPresent(String.self, forKey: "id") + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -60,6 +53,24 @@ public struct SubscriptionPromotionalOfferInlineCreate: Codable, Identifiable { self.offerCode = offerCode self.offerMode = offerMode } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + duration = try container.decode(SubscriptionOfferDuration.self, forKey: "duration") + name = try container.decode(String.self, forKey: "name") + numberOfPeriods = try container.decode(Int.self, forKey: "numberOfPeriods") + offerCode = try container.decode(String.self, forKey: "offerCode") + offerMode = try container.decode(SubscriptionOfferMode.self, forKey: "offerMode") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(duration, forKey: "duration") + try container.encode(name, forKey: "name") + try container.encode(numberOfPeriods, forKey: "numberOfPeriods") + try container.encode(offerCode, forKey: "offerCode") + try container.encode(offerMode, forKey: "offerMode") + } } public struct Relationships: Codable { @@ -73,6 +84,18 @@ public struct SubscriptionPromotionalOfferInlineCreate: Codable, Identifiable { self.subscription = subscription } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + prices = try container.decodeIfPresent(Prices.self, forKey: "prices") + subscription = try container.decodeIfPresent(Subscription.self, forKey: "subscription") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(prices, forKey: "prices") + try container.encodeIfPresent(subscription, forKey: "subscription") + } + public struct Prices: Codable { @NullCodable public var data: [Data]? @@ -81,17 +104,13 @@ public struct SubscriptionPromotionalOfferInlineCreate: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } public struct Data: Codable, Identifiable { @@ -103,22 +122,17 @@ public struct SubscriptionPromotionalOfferInlineCreate: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -131,17 +145,13 @@ public struct SubscriptionPromotionalOfferInlineCreate: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } public struct Data: Codable, Identifiable { @@ -153,22 +163,17 @@ public struct SubscriptionPromotionalOfferInlineCreate: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionPromotionalOfferPrice.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionPromotionalOfferPrice.swift index 122925c07..2c4643524 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionPromotionalOfferPrice.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionPromotionalOfferPrice.swift @@ -17,28 +17,21 @@ public struct SubscriptionPromotionalOfferPrice: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Relationships: Codable { @@ -52,6 +45,18 @@ public struct SubscriptionPromotionalOfferPrice: Codable, Identifiable { self.territory = territory } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + subscriptionPricePoint = try container.decodeIfPresent(SubscriptionPricePoint.self, forKey: "subscriptionPricePoint") + territory = try container.decodeIfPresent(Territory.self, forKey: "territory") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(subscriptionPricePoint, forKey: "subscriptionPricePoint") + try container.encodeIfPresent(territory, forKey: "territory") + } + public struct SubscriptionPricePoint: Codable { @NullCodable public var data: Data? public var links: Links? @@ -64,20 +69,15 @@ public struct SubscriptionPromotionalOfferPrice: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -89,22 +89,17 @@ public struct SubscriptionPromotionalOfferPrice: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -120,20 +115,15 @@ public struct SubscriptionPromotionalOfferPrice: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -150,20 +140,15 @@ public struct SubscriptionPromotionalOfferPrice: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -175,22 +160,17 @@ public struct SubscriptionPromotionalOfferPrice: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -206,20 +186,15 @@ public struct SubscriptionPromotionalOfferPrice: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionPromotionalOfferPriceInlineCreate.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionPromotionalOfferPriceInlineCreate.swift index f342e9361..27684d374 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionPromotionalOfferPriceInlineCreate.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionPromotionalOfferPriceInlineCreate.swift @@ -14,25 +14,19 @@ public struct SubscriptionPromotionalOfferPriceInlineCreate: Codable, Identifiab } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decodeIfPresent(String.self, forKey: .id) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decodeIfPresent(String.self, forKey: "id") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case id - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Relationships: Codable { @@ -46,6 +40,18 @@ public struct SubscriptionPromotionalOfferPriceInlineCreate: Codable, Identifiab self.territory = territory } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + subscriptionPricePoint = try container.decodeIfPresent(SubscriptionPricePoint.self, forKey: "subscriptionPricePoint") + territory = try container.decodeIfPresent(Territory.self, forKey: "territory") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(subscriptionPricePoint, forKey: "subscriptionPricePoint") + try container.encodeIfPresent(territory, forKey: "territory") + } + public struct SubscriptionPricePoint: Codable { @NullCodable public var data: Data? @@ -54,17 +60,13 @@ public struct SubscriptionPromotionalOfferPriceInlineCreate: Codable, Identifiab } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } public struct Data: Codable, Identifiable { @@ -76,22 +78,17 @@ public struct SubscriptionPromotionalOfferPriceInlineCreate: Codable, Identifiab } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -104,17 +101,13 @@ public struct SubscriptionPromotionalOfferPriceInlineCreate: Codable, Identifiab } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } public struct Data: Codable, Identifiable { @@ -126,22 +119,17 @@ public struct SubscriptionPromotionalOfferPriceInlineCreate: Codable, Identifiab } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionPromotionalOfferPricesResponse.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionPromotionalOfferPricesResponse.swift index 565475dc1..e5c993508 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionPromotionalOfferPricesResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionPromotionalOfferPricesResponse.swift @@ -20,6 +20,22 @@ public struct SubscriptionPromotionalOfferPricesResponse: Codable, PagedResponse self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([SubscriptionPromotionalOfferPrice].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getSubscriptionPricePoint(for subscriptionPromotionalOfferPrice: SubscriptionPromotionalOfferPrice) -> SubscriptionPricePoint? { included?.compactMap { relationship -> SubscriptionPricePoint? in guard case let .subscriptionPricePoint(subscriptionPricePoint) = relationship else { return nil } @@ -57,9 +73,5 @@ public struct SubscriptionPromotionalOfferPricesResponse: Codable, PagedResponse try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionPromotionalOfferResponse.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionPromotionalOfferResponse.swift index 3ff90e9f7..fb9ab22b6 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionPromotionalOfferResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionPromotionalOfferResponse.swift @@ -15,6 +15,20 @@ public struct SubscriptionPromotionalOfferResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(SubscriptionPromotionalOffer.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getPrices() -> [SubscriptionPromotionalOfferPrice] { guard let priceIds = data.relationships?.prices?.data?.map(\.id), let prices = included?.compactMap({ relationship -> SubscriptionPromotionalOfferPrice? in @@ -57,9 +71,5 @@ public struct SubscriptionPromotionalOfferResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionPromotionalOfferUpdateRequest.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionPromotionalOfferUpdateRequest.swift index bd0d48317..fa5d36ee7 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionPromotionalOfferUpdateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionPromotionalOfferUpdateRequest.swift @@ -12,6 +12,18 @@ public struct SubscriptionPromotionalOfferUpdateRequest: Codable, RequestBody { self.included = included } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + included = try container.decodeIfPresent([SubscriptionPromotionalOfferPriceInlineCreate].self, forKey: "included") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "subscriptionPromotionalOffers" } @@ -25,25 +37,19 @@ public struct SubscriptionPromotionalOfferUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case id - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Relationships: Codable { @@ -53,6 +59,16 @@ public struct SubscriptionPromotionalOfferUpdateRequest: Codable, RequestBody { self.prices = prices } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + prices = try container.decodeIfPresent(Prices.self, forKey: "prices") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(prices, forKey: "prices") + } + public struct Prices: Codable { @NullCodable public var data: [Data]? @@ -61,17 +77,13 @@ public struct SubscriptionPromotionalOfferUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } public struct Data: Codable, Identifiable { @@ -83,22 +95,17 @@ public struct SubscriptionPromotionalOfferUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionPromotionalOffersResponse.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionPromotionalOffersResponse.swift index 33b68865f..b72657295 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionPromotionalOffersResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionPromotionalOffersResponse.swift @@ -20,6 +20,22 @@ public struct SubscriptionPromotionalOffersResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([SubscriptionPromotionalOffer].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getPrices(for subscriptionPromotionalOffer: SubscriptionPromotionalOffer) -> [SubscriptionPromotionalOfferPrice] { guard let priceIds = subscriptionPromotionalOffer.relationships?.prices?.data?.map(\.id), let prices = included?.compactMap({ relationship -> SubscriptionPromotionalOfferPrice? in @@ -62,9 +78,5 @@ public struct SubscriptionPromotionalOffersResponse: Codable, PagedResponse { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionResponse.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionResponse.swift index 8bfbe1760..df9a4c21f 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionResponse.swift @@ -15,6 +15,20 @@ public struct SubscriptionResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Subscription.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getAppStoreReviewScreenshot() -> SubscriptionAppStoreReviewScreenshot? { included?.compactMap { relationship -> SubscriptionAppStoreReviewScreenshot? in guard case let .subscriptionAppStoreReviewScreenshot(appStoreReviewScreenshot) = relationship else { return nil } @@ -161,9 +175,5 @@ public struct SubscriptionResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionSubmission.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionSubmission.swift index eb24acd14..5a367de52 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionSubmission.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionSubmission.swift @@ -17,28 +17,21 @@ public struct SubscriptionSubmission: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Relationships: Codable { @@ -48,6 +41,16 @@ public struct SubscriptionSubmission: Codable, Identifiable { self.subscription = subscription } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + subscription = try container.decodeIfPresent(Subscription.self, forKey: "subscription") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(subscription, forKey: "subscription") + } + public struct Subscription: Codable { @NullCodable public var data: Data? public var links: Links? @@ -60,20 +63,15 @@ public struct SubscriptionSubmission: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -85,22 +83,17 @@ public struct SubscriptionSubmission: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -116,20 +109,15 @@ public struct SubscriptionSubmission: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionSubmissionCreateRequest.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionSubmissionCreateRequest.swift index f74771264..c6baae78e 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionSubmissionCreateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionSubmissionCreateRequest.swift @@ -8,6 +8,16 @@ public struct SubscriptionSubmissionCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "subscriptionSubmissions" } public let relationships: Relationships @@ -17,22 +27,17 @@ public struct SubscriptionSubmissionCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(relationships, forKey: "relationships") } public struct Relationships: Codable { @@ -42,6 +47,16 @@ public struct SubscriptionSubmissionCreateRequest: Codable, RequestBody { self.subscription = subscription } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + subscription = try container.decode(Subscription.self, forKey: "subscription") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(subscription, forKey: "subscription") + } + public struct Subscription: Codable { public let data: Data @@ -49,6 +64,16 @@ public struct SubscriptionSubmissionCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "subscriptions" } @@ -58,22 +83,17 @@ public struct SubscriptionSubmissionCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionSubmissionResponse.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionSubmissionResponse.swift index 913db51bc..c71024eb3 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionSubmissionResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionSubmissionResponse.swift @@ -14,4 +14,18 @@ public struct SubscriptionSubmissionResponse: Codable { self.included = included self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(SubscriptionSubmission.self, forKey: "data") + included = try container.decodeIfPresent([Subscription].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionUpdateRequest.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionUpdateRequest.swift index c23df10dd..9667c50c4 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionUpdateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionUpdateRequest.swift @@ -12,6 +12,18 @@ public struct SubscriptionUpdateRequest: Codable, RequestBody { self.included = included } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "subscriptions" } @@ -28,28 +40,21 @@ public struct SubscriptionUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -71,6 +76,24 @@ public struct SubscriptionUpdateRequest: Codable, RequestBody { self.reviewNote = reviewNote self.subscriptionPeriod = subscriptionPeriod } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + familySharable = try container.decodeIfPresent(Bool.self, forKey: "familySharable") + groupLevel = try container.decodeIfPresent(Int.self, forKey: "groupLevel") + name = try container.decodeIfPresent(String.self, forKey: "name") + reviewNote = try container.decodeIfPresent(String.self, forKey: "reviewNote") + subscriptionPeriod = try container.decodeIfPresent(Subscription.Attributes.SubscriptionPeriod.self, forKey: "subscriptionPeriod") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(familySharable, forKey: "familySharable") + try container.encodeIfPresent(groupLevel, forKey: "groupLevel") + try container.encodeIfPresent(name, forKey: "name") + try container.encodeIfPresent(reviewNote, forKey: "reviewNote") + try container.encodeIfPresent(subscriptionPeriod, forKey: "subscriptionPeriod") + } } public struct Relationships: Codable { @@ -87,6 +110,20 @@ public struct SubscriptionUpdateRequest: Codable, RequestBody { self.promotionalOffers = promotionalOffers } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + introductoryOffers = try container.decodeIfPresent(IntroductoryOffers.self, forKey: "introductoryOffers") + prices = try container.decodeIfPresent(Prices.self, forKey: "prices") + promotionalOffers = try container.decodeIfPresent(PromotionalOffers.self, forKey: "promotionalOffers") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(introductoryOffers, forKey: "introductoryOffers") + try container.encodeIfPresent(prices, forKey: "prices") + try container.encodeIfPresent(promotionalOffers, forKey: "promotionalOffers") + } + public struct IntroductoryOffers: Codable { @NullCodable public var data: [Data]? @@ -95,17 +132,13 @@ public struct SubscriptionUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } public struct Data: Codable, Identifiable { @@ -117,22 +150,17 @@ public struct SubscriptionUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -145,17 +173,13 @@ public struct SubscriptionUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } public struct Data: Codable, Identifiable { @@ -167,22 +191,17 @@ public struct SubscriptionUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -195,17 +214,13 @@ public struct SubscriptionUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } public struct Data: Codable, Identifiable { @@ -217,22 +232,17 @@ public struct SubscriptionUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -267,9 +277,5 @@ public struct SubscriptionUpdateRequest: Codable, RequestBody { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/SubscriptionsResponse.swift b/Sources/Bagbutik-Models/AppStore/SubscriptionsResponse.swift index 75c456f49..cda7a33e5 100644 --- a/Sources/Bagbutik-Models/AppStore/SubscriptionsResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/SubscriptionsResponse.swift @@ -20,6 +20,22 @@ public struct SubscriptionsResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Subscription].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getAppStoreReviewScreenshot(for subscription: Subscription) -> SubscriptionAppStoreReviewScreenshot? { included?.compactMap { relationship -> SubscriptionAppStoreReviewScreenshot? in guard case let .subscriptionAppStoreReviewScreenshot(appStoreReviewScreenshot) = relationship else { return nil } @@ -166,9 +182,5 @@ public struct SubscriptionsResponse: Codable, PagedResponse { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/AppStore/TerritoriesResponse.swift b/Sources/Bagbutik-Models/AppStore/TerritoriesResponse.swift index 4b180e14a..01a8f2bf5 100644 --- a/Sources/Bagbutik-Models/AppStore/TerritoriesResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/TerritoriesResponse.swift @@ -23,4 +23,18 @@ public struct TerritoriesResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Territory].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/AppStore/TerritoriesWithoutIncludesResponse.swift b/Sources/Bagbutik-Models/AppStore/TerritoriesWithoutIncludesResponse.swift index dbd9b3e4d..e2f14ced3 100644 --- a/Sources/Bagbutik-Models/AppStore/TerritoriesWithoutIncludesResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/TerritoriesWithoutIncludesResponse.swift @@ -16,4 +16,18 @@ public struct TerritoriesWithoutIncludesResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Territory].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/AppStore/Territory.swift b/Sources/Bagbutik-Models/AppStore/Territory.swift index da819c8c4..217d01d22 100644 --- a/Sources/Bagbutik-Models/AppStore/Territory.swift +++ b/Sources/Bagbutik-Models/AppStore/Territory.swift @@ -24,28 +24,21 @@ public struct Territory: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } /** @@ -61,5 +54,15 @@ public struct Territory: Codable, Identifiable { public init(currency: String? = nil) { self.currency = currency } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + currency = try container.decodeIfPresent(String.self, forKey: "currency") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(currency, forKey: "currency") + } } } diff --git a/Sources/Bagbutik-Models/AppStore/TerritoryAvailabilitiesResponse.swift b/Sources/Bagbutik-Models/AppStore/TerritoryAvailabilitiesResponse.swift index e67cccb5f..4c3cf0b9c 100644 --- a/Sources/Bagbutik-Models/AppStore/TerritoryAvailabilitiesResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/TerritoryAvailabilitiesResponse.swift @@ -26,4 +26,20 @@ public struct TerritoryAvailabilitiesResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([TerritoryAvailability].self, forKey: "data") + included = try container.decodeIfPresent([Territory].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/AppStore/TerritoryAvailability.swift b/Sources/Bagbutik-Models/AppStore/TerritoryAvailability.swift index 125e53610..68240e32e 100644 --- a/Sources/Bagbutik-Models/AppStore/TerritoryAvailability.swift +++ b/Sources/Bagbutik-Models/AppStore/TerritoryAvailability.swift @@ -27,31 +27,23 @@ public struct TerritoryAvailability: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -74,6 +66,24 @@ public struct TerritoryAvailability: Codable, Identifiable { self.releaseDate = releaseDate } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + available = try container.decodeIfPresent(Bool.self, forKey: "available") + contentStatuses = try container.decodeIfPresent(Items.self, forKey: "contentStatuses") + preOrderEnabled = try container.decodeIfPresent(Bool.self, forKey: "preOrderEnabled") + preOrderPublishDate = try container.decodeIfPresent(String.self, forKey: "preOrderPublishDate") + releaseDate = try container.decodeIfPresent(String.self, forKey: "releaseDate") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(available, forKey: "available") + try container.encodeIfPresent(contentStatuses, forKey: "contentStatuses") + try container.encodeIfPresent(preOrderEnabled, forKey: "preOrderEnabled") + try container.encodeIfPresent(preOrderPublishDate, forKey: "preOrderPublishDate") + try container.encodeIfPresent(releaseDate, forKey: "releaseDate") + } + public enum Items: String, Codable, CaseIterable { case available = "AVAILABLE" case availableForPreorder = "AVAILABLE_FOR_PREORDER" @@ -118,6 +128,16 @@ public struct TerritoryAvailability: Codable, Identifiable { self.territory = territory } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + territory = try container.decodeIfPresent(Territory.self, forKey: "territory") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(territory, forKey: "territory") + } + public struct Territory: Codable { @NullCodable public var data: Data? public var links: Links? @@ -130,20 +150,15 @@ public struct TerritoryAvailability: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -155,22 +170,17 @@ public struct TerritoryAvailability: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -186,20 +196,15 @@ public struct TerritoryAvailability: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/AppStore/TerritoryAvailabilityInlineCreate.swift b/Sources/Bagbutik-Models/AppStore/TerritoryAvailabilityInlineCreate.swift index 9073e0f0f..14b80842c 100644 --- a/Sources/Bagbutik-Models/AppStore/TerritoryAvailabilityInlineCreate.swift +++ b/Sources/Bagbutik-Models/AppStore/TerritoryAvailabilityInlineCreate.swift @@ -17,21 +17,16 @@ public struct TerritoryAvailabilityInlineCreate: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decodeIfPresent(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decodeIfPresent(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(id, forKey: "id") + try container.encode(type, forKey: "type") } } diff --git a/Sources/Bagbutik-Models/AppStore/TerritoryAvailabilityResponse.swift b/Sources/Bagbutik-Models/AppStore/TerritoryAvailabilityResponse.swift index 947bb08f9..ee145e722 100644 --- a/Sources/Bagbutik-Models/AppStore/TerritoryAvailabilityResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/TerritoryAvailabilityResponse.swift @@ -21,4 +21,18 @@ public struct TerritoryAvailabilityResponse: Codable { self.included = included self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(TerritoryAvailability.self, forKey: "data") + included = try container.decodeIfPresent([Territory].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/AppStore/TerritoryAvailabilityUpdateRequest.swift b/Sources/Bagbutik-Models/AppStore/TerritoryAvailabilityUpdateRequest.swift index 60a43c383..3aea45d8f 100644 --- a/Sources/Bagbutik-Models/AppStore/TerritoryAvailabilityUpdateRequest.swift +++ b/Sources/Bagbutik-Models/AppStore/TerritoryAvailabilityUpdateRequest.swift @@ -15,6 +15,16 @@ public struct TerritoryAvailabilityUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "territoryAvailabilities" } @@ -28,25 +38,19 @@ public struct TerritoryAvailabilityUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } public struct Attributes: Codable { @@ -62,6 +66,20 @@ public struct TerritoryAvailabilityUpdateRequest: Codable, RequestBody { self.preOrderEnabled = preOrderEnabled self.releaseDate = releaseDate } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + available = try container.decodeIfPresent(Bool.self, forKey: "available") + preOrderEnabled = try container.decodeIfPresent(Bool.self, forKey: "preOrderEnabled") + releaseDate = try container.decodeIfPresent(String.self, forKey: "releaseDate") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(available, forKey: "available") + try container.encodeIfPresent(preOrderEnabled, forKey: "preOrderEnabled") + try container.encodeIfPresent(releaseDate, forKey: "releaseDate") + } } } } diff --git a/Sources/Bagbutik-Models/AppStore/TerritoryInlineCreate.swift b/Sources/Bagbutik-Models/AppStore/TerritoryInlineCreate.swift index f86047046..b23235b21 100644 --- a/Sources/Bagbutik-Models/AppStore/TerritoryInlineCreate.swift +++ b/Sources/Bagbutik-Models/AppStore/TerritoryInlineCreate.swift @@ -10,21 +10,16 @@ public struct TerritoryInlineCreate: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decodeIfPresent(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decodeIfPresent(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(id, forKey: "id") + try container.encode(type, forKey: "type") } } diff --git a/Sources/Bagbutik-Models/AppStore/TerritoryResponse.swift b/Sources/Bagbutik-Models/AppStore/TerritoryResponse.swift index 83312a900..cbe3c731d 100644 --- a/Sources/Bagbutik-Models/AppStore/TerritoryResponse.swift +++ b/Sources/Bagbutik-Models/AppStore/TerritoryResponse.swift @@ -18,4 +18,16 @@ public struct TerritoryResponse: Codable { self.data = data self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Territory.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/AppStore/UploadOperation.swift b/Sources/Bagbutik-Models/AppStore/UploadOperation.swift index ebae49b99..70e5f5a3c 100644 --- a/Sources/Bagbutik-Models/AppStore/UploadOperation.swift +++ b/Sources/Bagbutik-Models/AppStore/UploadOperation.swift @@ -27,4 +27,22 @@ public struct UploadOperation: Codable { self.requestHeaders = requestHeaders self.url = url } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + length = try container.decodeIfPresent(Int.self, forKey: "length") + method = try container.decodeIfPresent(String.self, forKey: "method") + offset = try container.decodeIfPresent(Int.self, forKey: "offset") + requestHeaders = try container.decodeIfPresent([HttpHeader].self, forKey: "requestHeaders") + url = try container.decodeIfPresent(String.self, forKey: "url") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(length, forKey: "length") + try container.encodeIfPresent(method, forKey: "method") + try container.encodeIfPresent(offset, forKey: "offset") + try container.encodeIfPresent(requestHeaders, forKey: "requestHeaders") + try container.encodeIfPresent(url, forKey: "url") + } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterAchievement.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterAchievement.swift index 39130b64e..08f0ea624 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterAchievement.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterAchievement.swift @@ -27,31 +27,23 @@ public struct GameCenterAchievement: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -76,6 +68,26 @@ public struct GameCenterAchievement: Codable, Identifiable { self.showBeforeEarned = showBeforeEarned self.vendorIdentifier = vendorIdentifier } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + archived = try container.decodeIfPresent(Bool.self, forKey: "archived") + points = try container.decodeIfPresent(Int.self, forKey: "points") + referenceName = try container.decodeIfPresent(String.self, forKey: "referenceName") + repeatable = try container.decodeIfPresent(Bool.self, forKey: "repeatable") + showBeforeEarned = try container.decodeIfPresent(Bool.self, forKey: "showBeforeEarned") + vendorIdentifier = try container.decodeIfPresent(String.self, forKey: "vendorIdentifier") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(archived, forKey: "archived") + try container.encodeIfPresent(points, forKey: "points") + try container.encodeIfPresent(referenceName, forKey: "referenceName") + try container.encodeIfPresent(repeatable, forKey: "repeatable") + try container.encodeIfPresent(showBeforeEarned, forKey: "showBeforeEarned") + try container.encodeIfPresent(vendorIdentifier, forKey: "vendorIdentifier") + } } public struct Relationships: Codable { @@ -98,6 +110,24 @@ public struct GameCenterAchievement: Codable, Identifiable { self.releases = releases } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + gameCenterDetail = try container.decodeIfPresent(GameCenterDetail.self, forKey: "gameCenterDetail") + gameCenterGroup = try container.decodeIfPresent(GameCenterGroup.self, forKey: "gameCenterGroup") + groupAchievement = try container.decodeIfPresent(GroupAchievement.self, forKey: "groupAchievement") + localizations = try container.decodeIfPresent(Localizations.self, forKey: "localizations") + releases = try container.decodeIfPresent(Releases.self, forKey: "releases") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(gameCenterDetail, forKey: "gameCenterDetail") + try container.encodeIfPresent(gameCenterGroup, forKey: "gameCenterGroup") + try container.encodeIfPresent(groupAchievement, forKey: "groupAchievement") + try container.encodeIfPresent(localizations, forKey: "localizations") + try container.encodeIfPresent(releases, forKey: "releases") + } + public struct GameCenterDetail: Codable { @NullCodable public var data: Data? public var links: Links? @@ -110,20 +140,15 @@ public struct GameCenterAchievement: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -135,22 +160,17 @@ public struct GameCenterAchievement: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -166,20 +186,15 @@ public struct GameCenterAchievement: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -196,20 +211,15 @@ public struct GameCenterAchievement: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -221,22 +231,17 @@ public struct GameCenterAchievement: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -252,20 +257,15 @@ public struct GameCenterAchievement: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -282,20 +282,15 @@ public struct GameCenterAchievement: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -307,22 +302,17 @@ public struct GameCenterAchievement: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -338,20 +328,15 @@ public struct GameCenterAchievement: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -371,23 +356,17 @@ public struct GameCenterAchievement: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -399,22 +378,17 @@ public struct GameCenterAchievement: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -430,20 +404,15 @@ public struct GameCenterAchievement: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -463,23 +432,17 @@ public struct GameCenterAchievement: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -491,22 +454,17 @@ public struct GameCenterAchievement: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -522,20 +480,15 @@ public struct GameCenterAchievement: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementCreateRequest.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementCreateRequest.swift index bd7af46a4..75f079b95 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementCreateRequest.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementCreateRequest.swift @@ -15,6 +15,16 @@ public struct GameCenterAchievementCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "gameCenterAchievements" } public let attributes: Attributes @@ -28,25 +38,19 @@ public struct GameCenterAchievementCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -68,6 +72,24 @@ public struct GameCenterAchievementCreateRequest: Codable, RequestBody { self.showBeforeEarned = showBeforeEarned self.vendorIdentifier = vendorIdentifier } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + points = try container.decode(Int.self, forKey: "points") + referenceName = try container.decode(String.self, forKey: "referenceName") + repeatable = try container.decode(Bool.self, forKey: "repeatable") + showBeforeEarned = try container.decode(Bool.self, forKey: "showBeforeEarned") + vendorIdentifier = try container.decode(String.self, forKey: "vendorIdentifier") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(points, forKey: "points") + try container.encode(referenceName, forKey: "referenceName") + try container.encode(repeatable, forKey: "repeatable") + try container.encode(showBeforeEarned, forKey: "showBeforeEarned") + try container.encode(vendorIdentifier, forKey: "vendorIdentifier") + } } public struct Relationships: Codable { @@ -81,6 +103,18 @@ public struct GameCenterAchievementCreateRequest: Codable, RequestBody { self.gameCenterGroup = gameCenterGroup } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + gameCenterDetail = try container.decodeIfPresent(GameCenterDetail.self, forKey: "gameCenterDetail") + gameCenterGroup = try container.decodeIfPresent(GameCenterGroup.self, forKey: "gameCenterGroup") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(gameCenterDetail, forKey: "gameCenterDetail") + try container.encodeIfPresent(gameCenterGroup, forKey: "gameCenterGroup") + } + public struct GameCenterDetail: Codable { @NullCodable public var data: Data? @@ -89,17 +123,13 @@ public struct GameCenterAchievementCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } public struct Data: Codable, Identifiable { @@ -111,22 +141,17 @@ public struct GameCenterAchievementCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -139,17 +164,13 @@ public struct GameCenterAchievementCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } public struct Data: Codable, Identifiable { @@ -161,22 +182,17 @@ public struct GameCenterAchievementCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementGroupAchievementLinkageRequest.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementGroupAchievementLinkageRequest.swift index 6cd875372..5ec244035 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementGroupAchievementLinkageRequest.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementGroupAchievementLinkageRequest.swift @@ -16,17 +16,13 @@ public struct GameCenterAchievementGroupAchievementLinkageRequest: Codable, Requ } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } public struct Data: Codable, Identifiable { @@ -38,22 +34,17 @@ public struct GameCenterAchievementGroupAchievementLinkageRequest: Codable, Requ } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementGroupAchievementLinkageResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementGroupAchievementLinkageResponse.swift index fb88e9a78..84693501e 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementGroupAchievementLinkageResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementGroupAchievementLinkageResponse.swift @@ -19,6 +19,18 @@ public struct GameCenterAchievementGroupAchievementLinkageResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "gameCenterAchievements" } @@ -28,22 +40,17 @@ public struct GameCenterAchievementGroupAchievementLinkageResponse: Codable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementImage.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementImage.swift index dfd5e2613..1d1e1d1b5 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementImage.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementImage.swift @@ -27,31 +27,23 @@ public struct GameCenterAchievementImage: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -73,6 +65,24 @@ public struct GameCenterAchievementImage: Codable, Identifiable { self.imageAsset = imageAsset self.uploadOperations = uploadOperations } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + assetDeliveryState = try container.decodeIfPresent(AppMediaAssetState.self, forKey: "assetDeliveryState") + fileName = try container.decodeIfPresent(String.self, forKey: "fileName") + fileSize = try container.decodeIfPresent(Int.self, forKey: "fileSize") + imageAsset = try container.decodeIfPresent(ImageAsset.self, forKey: "imageAsset") + uploadOperations = try container.decodeIfPresent([UploadOperation].self, forKey: "uploadOperations") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(assetDeliveryState, forKey: "assetDeliveryState") + try container.encodeIfPresent(fileName, forKey: "fileName") + try container.encodeIfPresent(fileSize, forKey: "fileSize") + try container.encodeIfPresent(imageAsset, forKey: "imageAsset") + try container.encodeIfPresent(uploadOperations, forKey: "uploadOperations") + } } public struct Relationships: Codable { @@ -82,6 +92,16 @@ public struct GameCenterAchievementImage: Codable, Identifiable { self.gameCenterAchievementLocalization = gameCenterAchievementLocalization } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + gameCenterAchievementLocalization = try container.decodeIfPresent(GameCenterAchievementLocalization.self, forKey: "gameCenterAchievementLocalization") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(gameCenterAchievementLocalization, forKey: "gameCenterAchievementLocalization") + } + public struct GameCenterAchievementLocalization: Codable { @NullCodable public var data: Data? public var links: Links? @@ -94,20 +114,15 @@ public struct GameCenterAchievementImage: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -119,22 +134,17 @@ public struct GameCenterAchievementImage: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -150,20 +160,15 @@ public struct GameCenterAchievementImage: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementImageCreateRequest.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementImageCreateRequest.swift index 6756989f8..d70e89924 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementImageCreateRequest.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementImageCreateRequest.swift @@ -15,6 +15,16 @@ public struct GameCenterAchievementImageCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "gameCenterAchievementImages" } public let attributes: Attributes @@ -28,25 +38,19 @@ public struct GameCenterAchievementImageCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -59,6 +63,18 @@ public struct GameCenterAchievementImageCreateRequest: Codable, RequestBody { self.fileName = fileName self.fileSize = fileSize } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + fileName = try container.decode(String.self, forKey: "fileName") + fileSize = try container.decode(Int.self, forKey: "fileSize") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(fileName, forKey: "fileName") + try container.encode(fileSize, forKey: "fileSize") + } } public struct Relationships: Codable { @@ -68,6 +84,16 @@ public struct GameCenterAchievementImageCreateRequest: Codable, RequestBody { self.gameCenterAchievementLocalization = gameCenterAchievementLocalization } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + gameCenterAchievementLocalization = try container.decode(GameCenterAchievementLocalization.self, forKey: "gameCenterAchievementLocalization") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(gameCenterAchievementLocalization, forKey: "gameCenterAchievementLocalization") + } + public struct GameCenterAchievementLocalization: Codable { public let data: Data @@ -75,6 +101,16 @@ public struct GameCenterAchievementImageCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "gameCenterAchievementLocalizations" } @@ -84,22 +120,17 @@ public struct GameCenterAchievementImageCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementImageResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementImageResponse.swift index cd80f7a47..49709b585 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementImageResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementImageResponse.swift @@ -21,4 +21,18 @@ public struct GameCenterAchievementImageResponse: Codable { self.included = included self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(GameCenterAchievementImage.self, forKey: "data") + included = try container.decodeIfPresent([GameCenterAchievementLocalization].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementImageUpdateRequest.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementImageUpdateRequest.swift index da4a3af03..ace259d61 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementImageUpdateRequest.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementImageUpdateRequest.swift @@ -15,6 +15,16 @@ public struct GameCenterAchievementImageUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "gameCenterAchievementImages" } @@ -28,25 +38,19 @@ public struct GameCenterAchievementImageUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } public struct Attributes: Codable { @@ -55,6 +59,16 @@ public struct GameCenterAchievementImageUpdateRequest: Codable, RequestBody { public init(uploaded: Bool? = nil) { self.uploaded = uploaded } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + uploaded = try container.decodeIfPresent(Bool.self, forKey: "uploaded") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(uploaded, forKey: "uploaded") + } } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementLocalization.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementLocalization.swift index b413808c9..fc0260909 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementLocalization.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementLocalization.swift @@ -20,31 +20,23 @@ public struct GameCenterAchievementLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -63,6 +55,22 @@ public struct GameCenterAchievementLocalization: Codable, Identifiable { self.locale = locale self.name = name } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + afterEarnedDescription = try container.decodeIfPresent(String.self, forKey: "afterEarnedDescription") + beforeEarnedDescription = try container.decodeIfPresent(String.self, forKey: "beforeEarnedDescription") + locale = try container.decodeIfPresent(String.self, forKey: "locale") + name = try container.decodeIfPresent(String.self, forKey: "name") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(afterEarnedDescription, forKey: "afterEarnedDescription") + try container.encodeIfPresent(beforeEarnedDescription, forKey: "beforeEarnedDescription") + try container.encodeIfPresent(locale, forKey: "locale") + try container.encodeIfPresent(name, forKey: "name") + } } public struct Relationships: Codable { @@ -76,6 +84,18 @@ public struct GameCenterAchievementLocalization: Codable, Identifiable { self.gameCenterAchievementImage = gameCenterAchievementImage } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + gameCenterAchievement = try container.decodeIfPresent(GameCenterAchievement.self, forKey: "gameCenterAchievement") + gameCenterAchievementImage = try container.decodeIfPresent(GameCenterAchievementImage.self, forKey: "gameCenterAchievementImage") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(gameCenterAchievement, forKey: "gameCenterAchievement") + try container.encodeIfPresent(gameCenterAchievementImage, forKey: "gameCenterAchievementImage") + } + public struct GameCenterAchievement: Codable { @NullCodable public var data: Data? public var links: Links? @@ -88,20 +108,15 @@ public struct GameCenterAchievementLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -113,22 +128,17 @@ public struct GameCenterAchievementLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -144,20 +154,15 @@ public struct GameCenterAchievementLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -174,20 +179,15 @@ public struct GameCenterAchievementLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -199,22 +199,17 @@ public struct GameCenterAchievementLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -230,20 +225,15 @@ public struct GameCenterAchievementLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementLocalizationCreateRequest.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementLocalizationCreateRequest.swift index b6337774f..ebe3d1750 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementLocalizationCreateRequest.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementLocalizationCreateRequest.swift @@ -8,6 +8,16 @@ public struct GameCenterAchievementLocalizationCreateRequest: Codable, RequestBo self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "gameCenterAchievementLocalizations" } public let attributes: Attributes @@ -21,25 +31,19 @@ public struct GameCenterAchievementLocalizationCreateRequest: Codable, RequestBo } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -58,6 +62,22 @@ public struct GameCenterAchievementLocalizationCreateRequest: Codable, RequestBo self.locale = locale self.name = name } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + afterEarnedDescription = try container.decode(String.self, forKey: "afterEarnedDescription") + beforeEarnedDescription = try container.decode(String.self, forKey: "beforeEarnedDescription") + locale = try container.decode(String.self, forKey: "locale") + name = try container.decode(String.self, forKey: "name") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(afterEarnedDescription, forKey: "afterEarnedDescription") + try container.encode(beforeEarnedDescription, forKey: "beforeEarnedDescription") + try container.encode(locale, forKey: "locale") + try container.encode(name, forKey: "name") + } } public struct Relationships: Codable { @@ -67,6 +87,16 @@ public struct GameCenterAchievementLocalizationCreateRequest: Codable, RequestBo self.gameCenterAchievement = gameCenterAchievement } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + gameCenterAchievement = try container.decode(GameCenterAchievement.self, forKey: "gameCenterAchievement") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(gameCenterAchievement, forKey: "gameCenterAchievement") + } + public struct GameCenterAchievement: Codable { public let data: Data @@ -74,6 +104,16 @@ public struct GameCenterAchievementLocalizationCreateRequest: Codable, RequestBo self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "gameCenterAchievements" } @@ -83,22 +123,17 @@ public struct GameCenterAchievementLocalizationCreateRequest: Codable, RequestBo } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementLocalizationResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementLocalizationResponse.swift index 3c75e806b..7a1f45622 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementLocalizationResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementLocalizationResponse.swift @@ -15,6 +15,20 @@ public struct GameCenterAchievementLocalizationResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(GameCenterAchievementLocalization.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getGameCenterAchievement() -> GameCenterAchievement? { included?.compactMap { relationship -> GameCenterAchievement? in guard case let .gameCenterAchievement(gameCenterAchievement) = relationship else { return nil } @@ -52,9 +66,5 @@ public struct GameCenterAchievementLocalizationResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementLocalizationUpdateRequest.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementLocalizationUpdateRequest.swift index 1ff6412a4..cb560f437 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementLocalizationUpdateRequest.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementLocalizationUpdateRequest.swift @@ -8,6 +8,16 @@ public struct GameCenterAchievementLocalizationUpdateRequest: Codable, RequestBo self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "gameCenterAchievementLocalizations" } @@ -21,25 +31,19 @@ public struct GameCenterAchievementLocalizationUpdateRequest: Codable, RequestBo } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } public struct Attributes: Codable { @@ -55,6 +59,20 @@ public struct GameCenterAchievementLocalizationUpdateRequest: Codable, RequestBo self.beforeEarnedDescription = beforeEarnedDescription self.name = name } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + afterEarnedDescription = try container.decodeIfPresent(String.self, forKey: "afterEarnedDescription") + beforeEarnedDescription = try container.decodeIfPresent(String.self, forKey: "beforeEarnedDescription") + name = try container.decodeIfPresent(String.self, forKey: "name") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(afterEarnedDescription, forKey: "afterEarnedDescription") + try container.encodeIfPresent(beforeEarnedDescription, forKey: "beforeEarnedDescription") + try container.encodeIfPresent(name, forKey: "name") + } } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementLocalizationsResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementLocalizationsResponse.swift index 1ad751c9a..f15d93918 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementLocalizationsResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementLocalizationsResponse.swift @@ -20,6 +20,22 @@ public struct GameCenterAchievementLocalizationsResponse: Codable, PagedResponse self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([GameCenterAchievementLocalization].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getGameCenterAchievement(for gameCenterAchievementLocalization: GameCenterAchievementLocalization) -> GameCenterAchievement? { included?.compactMap { relationship -> GameCenterAchievement? in guard case let .gameCenterAchievement(gameCenterAchievement) = relationship else { return nil } @@ -57,9 +73,5 @@ public struct GameCenterAchievementLocalizationsResponse: Codable, PagedResponse try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementRelease.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementRelease.swift index abb620693..0afb131d5 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementRelease.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementRelease.swift @@ -27,31 +27,23 @@ public struct GameCenterAchievementRelease: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -60,6 +52,16 @@ public struct GameCenterAchievementRelease: Codable, Identifiable { public init(live: Bool? = nil) { self.live = live } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + live = try container.decodeIfPresent(Bool.self, forKey: "live") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(live, forKey: "live") + } } public struct Relationships: Codable { @@ -73,6 +75,18 @@ public struct GameCenterAchievementRelease: Codable, Identifiable { self.gameCenterDetail = gameCenterDetail } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + gameCenterAchievement = try container.decodeIfPresent(GameCenterAchievement.self, forKey: "gameCenterAchievement") + gameCenterDetail = try container.decodeIfPresent(GameCenterDetail.self, forKey: "gameCenterDetail") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(gameCenterAchievement, forKey: "gameCenterAchievement") + try container.encodeIfPresent(gameCenterDetail, forKey: "gameCenterDetail") + } + public struct GameCenterAchievement: Codable { @NullCodable public var data: Data? public var links: Links? @@ -85,20 +99,15 @@ public struct GameCenterAchievementRelease: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -110,22 +119,17 @@ public struct GameCenterAchievementRelease: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -141,20 +145,15 @@ public struct GameCenterAchievementRelease: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -171,20 +170,15 @@ public struct GameCenterAchievementRelease: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -196,22 +190,17 @@ public struct GameCenterAchievementRelease: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -227,20 +216,15 @@ public struct GameCenterAchievementRelease: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementReleaseCreateRequest.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementReleaseCreateRequest.swift index 59acd0a3d..78669d0ce 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementReleaseCreateRequest.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementReleaseCreateRequest.swift @@ -15,6 +15,16 @@ public struct GameCenterAchievementReleaseCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "gameCenterAchievementReleases" } public let relationships: Relationships @@ -24,22 +34,17 @@ public struct GameCenterAchievementReleaseCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(relationships, forKey: "relationships") } public struct Relationships: Codable { @@ -53,6 +58,18 @@ public struct GameCenterAchievementReleaseCreateRequest: Codable, RequestBody { self.gameCenterDetail = gameCenterDetail } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + gameCenterAchievement = try container.decode(GameCenterAchievement.self, forKey: "gameCenterAchievement") + gameCenterDetail = try container.decode(GameCenterDetail.self, forKey: "gameCenterDetail") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(gameCenterAchievement, forKey: "gameCenterAchievement") + try container.encode(gameCenterDetail, forKey: "gameCenterDetail") + } + public struct GameCenterAchievement: Codable { public let data: Data @@ -60,6 +77,16 @@ public struct GameCenterAchievementReleaseCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "gameCenterAchievements" } @@ -69,22 +96,17 @@ public struct GameCenterAchievementReleaseCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -96,6 +118,16 @@ public struct GameCenterAchievementReleaseCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "gameCenterDetails" } @@ -105,22 +137,17 @@ public struct GameCenterAchievementReleaseCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementReleaseResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementReleaseResponse.swift index 68aa79234..aed3f8309 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementReleaseResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementReleaseResponse.swift @@ -22,6 +22,20 @@ public struct GameCenterAchievementReleaseResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(GameCenterAchievementRelease.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getGameCenterAchievement() -> GameCenterAchievement? { included?.compactMap { relationship -> GameCenterAchievement? in guard case let .gameCenterAchievement(gameCenterAchievement) = relationship else { return nil } @@ -59,9 +73,5 @@ public struct GameCenterAchievementReleaseResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementReleasesResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementReleasesResponse.swift index 54e2150c3..08efd72ec 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementReleasesResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementReleasesResponse.swift @@ -27,6 +27,22 @@ public struct GameCenterAchievementReleasesResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([GameCenterAchievementRelease].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getGameCenterAchievement(for gameCenterAchievementRelease: GameCenterAchievementRelease) -> GameCenterAchievement? { included?.compactMap { relationship -> GameCenterAchievement? in guard case let .gameCenterAchievement(gameCenterAchievement) = relationship else { return nil } @@ -64,9 +80,5 @@ public struct GameCenterAchievementReleasesResponse: Codable, PagedResponse { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementResponse.swift index 8ba1bb275..6f7178bb0 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementResponse.swift @@ -22,6 +22,20 @@ public struct GameCenterAchievementResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(GameCenterAchievement.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getGameCenterDetail() -> GameCenterDetail? { included?.compactMap { relationship -> GameCenterDetail? in guard case let .gameCenterDetail(gameCenterDetail) = relationship else { return nil } @@ -105,9 +119,5 @@ public struct GameCenterAchievementResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementUpdateRequest.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementUpdateRequest.swift index 3ef17a26f..2c842f777 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementUpdateRequest.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementUpdateRequest.swift @@ -15,6 +15,16 @@ public struct GameCenterAchievementUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "gameCenterAchievements" } @@ -28,25 +38,19 @@ public struct GameCenterAchievementUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } public struct Attributes: Codable { @@ -68,6 +72,24 @@ public struct GameCenterAchievementUpdateRequest: Codable, RequestBody { self.repeatable = repeatable self.showBeforeEarned = showBeforeEarned } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + archived = try container.decodeIfPresent(Bool.self, forKey: "archived") + points = try container.decodeIfPresent(Int.self, forKey: "points") + referenceName = try container.decodeIfPresent(String.self, forKey: "referenceName") + repeatable = try container.decodeIfPresent(Bool.self, forKey: "repeatable") + showBeforeEarned = try container.decodeIfPresent(Bool.self, forKey: "showBeforeEarned") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(archived, forKey: "archived") + try container.encodeIfPresent(points, forKey: "points") + try container.encodeIfPresent(referenceName, forKey: "referenceName") + try container.encodeIfPresent(repeatable, forKey: "repeatable") + try container.encodeIfPresent(showBeforeEarned, forKey: "showBeforeEarned") + } } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementsResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementsResponse.swift index 2519ed6cc..723328553 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementsResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterAchievementsResponse.swift @@ -27,6 +27,22 @@ public struct GameCenterAchievementsResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([GameCenterAchievement].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getGameCenterDetail(for gameCenterAchievement: GameCenterAchievement) -> GameCenterDetail? { included?.compactMap { relationship -> GameCenterDetail? in guard case let .gameCenterDetail(gameCenterDetail) = relationship else { return nil } @@ -110,9 +126,5 @@ public struct GameCenterAchievementsResponse: Codable, PagedResponse { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterAppVersion.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterAppVersion.swift index 67876625d..0a41bb05a 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterAppVersion.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterAppVersion.swift @@ -27,31 +27,23 @@ public struct GameCenterAppVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -60,6 +52,16 @@ public struct GameCenterAppVersion: Codable, Identifiable { public init(enabled: Bool? = nil) { self.enabled = enabled } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + enabled = try container.decodeIfPresent(Bool.self, forKey: "enabled") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(enabled, forKey: "enabled") + } } public struct Relationships: Codable { @@ -73,6 +75,18 @@ public struct GameCenterAppVersion: Codable, Identifiable { self.compatibilityVersions = compatibilityVersions } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appStoreVersion = try container.decodeIfPresent(AppStoreVersion.self, forKey: "appStoreVersion") + compatibilityVersions = try container.decodeIfPresent(CompatibilityVersions.self, forKey: "compatibilityVersions") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(appStoreVersion, forKey: "appStoreVersion") + try container.encodeIfPresent(compatibilityVersions, forKey: "compatibilityVersions") + } + public struct AppStoreVersion: Codable { @NullCodable public var data: Data? public var links: Links? @@ -85,20 +99,15 @@ public struct GameCenterAppVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -110,22 +119,17 @@ public struct GameCenterAppVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -141,20 +145,15 @@ public struct GameCenterAppVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -174,23 +173,17 @@ public struct GameCenterAppVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -202,22 +195,17 @@ public struct GameCenterAppVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -233,20 +221,15 @@ public struct GameCenterAppVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterAppVersionCompatibilityVersionsLinkagesRequest.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterAppVersionCompatibilityVersionsLinkagesRequest.swift index 3442d9841..0ca6d4394 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterAppVersionCompatibilityVersionsLinkagesRequest.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterAppVersionCompatibilityVersionsLinkagesRequest.swift @@ -15,6 +15,16 @@ public struct GameCenterAppVersionCompatibilityVersionsLinkagesRequest: Codable, self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "gameCenterAppVersions" } @@ -24,22 +34,17 @@ public struct GameCenterAppVersionCompatibilityVersionsLinkagesRequest: Codable, } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterAppVersionCompatibilityVersionsLinkagesResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterAppVersionCompatibilityVersionsLinkagesResponse.swift index 2b05199e5..438527353 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterAppVersionCompatibilityVersionsLinkagesResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterAppVersionCompatibilityVersionsLinkagesResponse.swift @@ -22,6 +22,20 @@ public struct GameCenterAppVersionCompatibilityVersionsLinkagesResponse: Codable self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "gameCenterAppVersions" } @@ -31,22 +45,17 @@ public struct GameCenterAppVersionCompatibilityVersionsLinkagesResponse: Codable } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterAppVersionCreateRequest.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterAppVersionCreateRequest.swift index 3d3dc7985..caa38c314 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterAppVersionCreateRequest.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterAppVersionCreateRequest.swift @@ -15,6 +15,16 @@ public struct GameCenterAppVersionCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "gameCenterAppVersions" } public let relationships: Relationships @@ -24,22 +34,17 @@ public struct GameCenterAppVersionCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(relationships, forKey: "relationships") } public struct Relationships: Codable { @@ -49,6 +54,16 @@ public struct GameCenterAppVersionCreateRequest: Codable, RequestBody { self.appStoreVersion = appStoreVersion } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appStoreVersion = try container.decode(AppStoreVersion.self, forKey: "appStoreVersion") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(appStoreVersion, forKey: "appStoreVersion") + } + public struct AppStoreVersion: Codable { public let data: Data @@ -56,6 +71,16 @@ public struct GameCenterAppVersionCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "appStoreVersions" } @@ -65,22 +90,17 @@ public struct GameCenterAppVersionCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterAppVersionResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterAppVersionResponse.swift index a1a4b4a51..9ccc1d284 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterAppVersionResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterAppVersionResponse.swift @@ -22,6 +22,20 @@ public struct GameCenterAppVersionResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(GameCenterAppVersion.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getAppStoreVersion() -> AppStoreVersion? { included?.compactMap { relationship -> AppStoreVersion? in guard case let .appStoreVersion(appStoreVersion) = relationship else { return nil } @@ -64,9 +78,5 @@ public struct GameCenterAppVersionResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterAppVersionUpdateRequest.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterAppVersionUpdateRequest.swift index 14bfbe83c..2ffac085c 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterAppVersionUpdateRequest.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterAppVersionUpdateRequest.swift @@ -15,6 +15,16 @@ public struct GameCenterAppVersionUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "gameCenterAppVersions" } @@ -28,25 +38,19 @@ public struct GameCenterAppVersionUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } public struct Attributes: Codable { @@ -55,6 +59,16 @@ public struct GameCenterAppVersionUpdateRequest: Codable, RequestBody { public init(enabled: Bool? = nil) { self.enabled = enabled } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + enabled = try container.decodeIfPresent(Bool.self, forKey: "enabled") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(enabled, forKey: "enabled") + } } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterAppVersionsResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterAppVersionsResponse.swift index 200c1ba48..c7cfaeb88 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterAppVersionsResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterAppVersionsResponse.swift @@ -27,6 +27,22 @@ public struct GameCenterAppVersionsResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([GameCenterAppVersion].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getAppStoreVersion(for gameCenterAppVersion: GameCenterAppVersion) -> AppStoreVersion? { included?.compactMap { relationship -> AppStoreVersion? in guard case let .appStoreVersion(appStoreVersion) = relationship else { return nil } @@ -69,9 +85,5 @@ public struct GameCenterAppVersionsResponse: Codable, PagedResponse { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterDetail.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterDetail.swift index 4599cc55d..ea12b7fce 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterDetail.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterDetail.swift @@ -27,31 +27,23 @@ public struct GameCenterDetail: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -64,6 +56,18 @@ public struct GameCenterDetail: Codable, Identifiable { self.arcadeEnabled = arcadeEnabled self.challengeEnabled = challengeEnabled } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + arcadeEnabled = try container.decodeIfPresent(Bool.self, forKey: "arcadeEnabled") + challengeEnabled = try container.decodeIfPresent(Bool.self, forKey: "challengeEnabled") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(arcadeEnabled, forKey: "arcadeEnabled") + try container.encodeIfPresent(challengeEnabled, forKey: "challengeEnabled") + } } public struct Relationships: Codable { @@ -104,6 +108,36 @@ public struct GameCenterDetail: Codable, Identifiable { self.leaderboardSetReleases = leaderboardSetReleases } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + achievementReleases = try container.decodeIfPresent(AchievementReleases.self, forKey: "achievementReleases") + app = try container.decodeIfPresent(App.self, forKey: "app") + defaultGroupLeaderboard = try container.decodeIfPresent(DefaultGroupLeaderboard.self, forKey: "defaultGroupLeaderboard") + defaultLeaderboard = try container.decodeIfPresent(DefaultLeaderboard.self, forKey: "defaultLeaderboard") + gameCenterAchievements = try container.decodeIfPresent(GameCenterAchievements.self, forKey: "gameCenterAchievements") + gameCenterAppVersions = try container.decodeIfPresent(GameCenterAppVersions.self, forKey: "gameCenterAppVersions") + gameCenterGroup = try container.decodeIfPresent(GameCenterGroup.self, forKey: "gameCenterGroup") + gameCenterLeaderboardSets = try container.decodeIfPresent(GameCenterLeaderboardSets.self, forKey: "gameCenterLeaderboardSets") + gameCenterLeaderboards = try container.decodeIfPresent(GameCenterLeaderboards.self, forKey: "gameCenterLeaderboards") + leaderboardReleases = try container.decodeIfPresent(LeaderboardReleases.self, forKey: "leaderboardReleases") + leaderboardSetReleases = try container.decodeIfPresent(LeaderboardSetReleases.self, forKey: "leaderboardSetReleases") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(achievementReleases, forKey: "achievementReleases") + try container.encodeIfPresent(app, forKey: "app") + try container.encodeIfPresent(defaultGroupLeaderboard, forKey: "defaultGroupLeaderboard") + try container.encodeIfPresent(defaultLeaderboard, forKey: "defaultLeaderboard") + try container.encodeIfPresent(gameCenterAchievements, forKey: "gameCenterAchievements") + try container.encodeIfPresent(gameCenterAppVersions, forKey: "gameCenterAppVersions") + try container.encodeIfPresent(gameCenterGroup, forKey: "gameCenterGroup") + try container.encodeIfPresent(gameCenterLeaderboardSets, forKey: "gameCenterLeaderboardSets") + try container.encodeIfPresent(gameCenterLeaderboards, forKey: "gameCenterLeaderboards") + try container.encodeIfPresent(leaderboardReleases, forKey: "leaderboardReleases") + try container.encodeIfPresent(leaderboardSetReleases, forKey: "leaderboardSetReleases") + } + public struct AchievementReleases: Codable { @NullCodable public var data: [Data]? public var links: Links? @@ -119,23 +153,17 @@ public struct GameCenterDetail: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -147,22 +175,17 @@ public struct GameCenterDetail: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -178,20 +201,15 @@ public struct GameCenterDetail: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -208,20 +226,15 @@ public struct GameCenterDetail: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -233,22 +246,17 @@ public struct GameCenterDetail: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -264,20 +272,15 @@ public struct GameCenterDetail: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -294,20 +297,15 @@ public struct GameCenterDetail: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -319,22 +317,17 @@ public struct GameCenterDetail: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -350,20 +343,15 @@ public struct GameCenterDetail: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -380,20 +368,15 @@ public struct GameCenterDetail: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -405,22 +388,17 @@ public struct GameCenterDetail: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -436,20 +414,15 @@ public struct GameCenterDetail: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -469,23 +442,17 @@ public struct GameCenterDetail: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -497,22 +464,17 @@ public struct GameCenterDetail: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -528,20 +490,15 @@ public struct GameCenterDetail: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -561,23 +518,17 @@ public struct GameCenterDetail: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -589,22 +540,17 @@ public struct GameCenterDetail: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -620,20 +566,15 @@ public struct GameCenterDetail: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -650,20 +591,15 @@ public struct GameCenterDetail: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -675,22 +611,17 @@ public struct GameCenterDetail: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -706,20 +637,15 @@ public struct GameCenterDetail: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -739,23 +665,17 @@ public struct GameCenterDetail: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -767,22 +687,17 @@ public struct GameCenterDetail: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -798,20 +713,15 @@ public struct GameCenterDetail: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -831,23 +741,17 @@ public struct GameCenterDetail: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -859,22 +763,17 @@ public struct GameCenterDetail: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -890,20 +789,15 @@ public struct GameCenterDetail: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -923,23 +817,17 @@ public struct GameCenterDetail: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -951,22 +839,17 @@ public struct GameCenterDetail: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -982,20 +865,15 @@ public struct GameCenterDetail: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -1015,23 +893,17 @@ public struct GameCenterDetail: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -1043,22 +915,17 @@ public struct GameCenterDetail: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -1074,20 +941,15 @@ public struct GameCenterDetail: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterDetailCreateRequest.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterDetailCreateRequest.swift index b87dc4a0b..57b5a33ed 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterDetailCreateRequest.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterDetailCreateRequest.swift @@ -15,6 +15,16 @@ public struct GameCenterDetailCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "gameCenterDetails" } public var attributes: Attributes? @@ -28,25 +38,19 @@ public struct GameCenterDetailCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -55,6 +59,16 @@ public struct GameCenterDetailCreateRequest: Codable, RequestBody { public init(challengeEnabled: Bool? = nil) { self.challengeEnabled = challengeEnabled } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + challengeEnabled = try container.decodeIfPresent(Bool.self, forKey: "challengeEnabled") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(challengeEnabled, forKey: "challengeEnabled") + } } public struct Relationships: Codable { @@ -64,6 +78,16 @@ public struct GameCenterDetailCreateRequest: Codable, RequestBody { self.app = app } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + app = try container.decode(App.self, forKey: "app") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(app, forKey: "app") + } + public struct App: Codable { public let data: Data @@ -71,6 +95,16 @@ public struct GameCenterDetailCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "apps" } @@ -80,22 +114,17 @@ public struct GameCenterDetailCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterDetailGameCenterAchievementsLinkagesRequest.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterDetailGameCenterAchievementsLinkagesRequest.swift index 1ce33f84d..8b6aa2951 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterDetailGameCenterAchievementsLinkagesRequest.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterDetailGameCenterAchievementsLinkagesRequest.swift @@ -15,6 +15,16 @@ public struct GameCenterDetailGameCenterAchievementsLinkagesRequest: Codable, Re self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "gameCenterAchievements" } @@ -24,22 +34,17 @@ public struct GameCenterDetailGameCenterAchievementsLinkagesRequest: Codable, Re } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterDetailGameCenterAchievementsLinkagesResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterDetailGameCenterAchievementsLinkagesResponse.swift index b5157b403..725d47434 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterDetailGameCenterAchievementsLinkagesResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterDetailGameCenterAchievementsLinkagesResponse.swift @@ -22,6 +22,20 @@ public struct GameCenterDetailGameCenterAchievementsLinkagesResponse: Codable, P self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "gameCenterAchievements" } @@ -31,22 +45,17 @@ public struct GameCenterDetailGameCenterAchievementsLinkagesResponse: Codable, P } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterDetailGameCenterLeaderboardSetsLinkagesRequest.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterDetailGameCenterLeaderboardSetsLinkagesRequest.swift index c7e5a0ea4..6ba212540 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterDetailGameCenterLeaderboardSetsLinkagesRequest.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterDetailGameCenterLeaderboardSetsLinkagesRequest.swift @@ -15,6 +15,16 @@ public struct GameCenterDetailGameCenterLeaderboardSetsLinkagesRequest: Codable, self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "gameCenterLeaderboardSets" } @@ -24,22 +34,17 @@ public struct GameCenterDetailGameCenterLeaderboardSetsLinkagesRequest: Codable, } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterDetailGameCenterLeaderboardSetsLinkagesResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterDetailGameCenterLeaderboardSetsLinkagesResponse.swift index a9adf43f2..2ec2873aa 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterDetailGameCenterLeaderboardSetsLinkagesResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterDetailGameCenterLeaderboardSetsLinkagesResponse.swift @@ -22,6 +22,20 @@ public struct GameCenterDetailGameCenterLeaderboardSetsLinkagesResponse: Codable self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "gameCenterLeaderboardSets" } @@ -31,22 +45,17 @@ public struct GameCenterDetailGameCenterLeaderboardSetsLinkagesResponse: Codable } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterDetailGameCenterLeaderboardsLinkagesRequest.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterDetailGameCenterLeaderboardsLinkagesRequest.swift index 54b67c1aa..cfd146acc 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterDetailGameCenterLeaderboardsLinkagesRequest.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterDetailGameCenterLeaderboardsLinkagesRequest.swift @@ -15,6 +15,16 @@ public struct GameCenterDetailGameCenterLeaderboardsLinkagesRequest: Codable, Re self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "gameCenterLeaderboards" } @@ -24,22 +34,17 @@ public struct GameCenterDetailGameCenterLeaderboardsLinkagesRequest: Codable, Re } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterDetailGameCenterLeaderboardsLinkagesResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterDetailGameCenterLeaderboardsLinkagesResponse.swift index a2f2a8afa..fd2b5f4ff 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterDetailGameCenterLeaderboardsLinkagesResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterDetailGameCenterLeaderboardsLinkagesResponse.swift @@ -22,6 +22,20 @@ public struct GameCenterDetailGameCenterLeaderboardsLinkagesResponse: Codable, P self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "gameCenterLeaderboards" } @@ -31,22 +45,17 @@ public struct GameCenterDetailGameCenterLeaderboardsLinkagesResponse: Codable, P } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterDetailResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterDetailResponse.swift index eddf34167..caf457941 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterDetailResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterDetailResponse.swift @@ -22,6 +22,20 @@ public struct GameCenterDetailResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(GameCenterDetail.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getAchievementReleases() -> [GameCenterAchievementRelease] { guard let achievementReleaseIds = data.relationships?.achievementReleases?.data?.map(\.id), let achievementReleases = included?.compactMap({ relationship -> GameCenterAchievementRelease? in @@ -192,9 +206,5 @@ public struct GameCenterDetailResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterDetailUpdateRequest.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterDetailUpdateRequest.swift index d5b562d1a..767928d40 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterDetailUpdateRequest.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterDetailUpdateRequest.swift @@ -15,6 +15,16 @@ public struct GameCenterDetailUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "gameCenterDetails" } @@ -31,28 +41,21 @@ public struct GameCenterDetailUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -61,6 +64,16 @@ public struct GameCenterDetailUpdateRequest: Codable, RequestBody { public init(challengeEnabled: Bool? = nil) { self.challengeEnabled = challengeEnabled } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + challengeEnabled = try container.decodeIfPresent(Bool.self, forKey: "challengeEnabled") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(challengeEnabled, forKey: "challengeEnabled") + } } public struct Relationships: Codable { @@ -77,6 +90,20 @@ public struct GameCenterDetailUpdateRequest: Codable, RequestBody { self.gameCenterGroup = gameCenterGroup } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + defaultGroupLeaderboard = try container.decodeIfPresent(DefaultGroupLeaderboard.self, forKey: "defaultGroupLeaderboard") + defaultLeaderboard = try container.decodeIfPresent(DefaultLeaderboard.self, forKey: "defaultLeaderboard") + gameCenterGroup = try container.decodeIfPresent(GameCenterGroup.self, forKey: "gameCenterGroup") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(defaultGroupLeaderboard, forKey: "defaultGroupLeaderboard") + try container.encodeIfPresent(defaultLeaderboard, forKey: "defaultLeaderboard") + try container.encodeIfPresent(gameCenterGroup, forKey: "gameCenterGroup") + } + public struct DefaultGroupLeaderboard: Codable { @NullCodable public var data: Data? @@ -85,17 +112,13 @@ public struct GameCenterDetailUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } public struct Data: Codable, Identifiable { @@ -107,22 +130,17 @@ public struct GameCenterDetailUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -135,17 +153,13 @@ public struct GameCenterDetailUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } public struct Data: Codable, Identifiable { @@ -157,22 +171,17 @@ public struct GameCenterDetailUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -185,17 +194,13 @@ public struct GameCenterDetailUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } public struct Data: Codable, Identifiable { @@ -207,22 +212,17 @@ public struct GameCenterDetailUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterDetailsResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterDetailsResponse.swift index 3b8aa8669..395c6406b 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterDetailsResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterDetailsResponse.swift @@ -27,6 +27,22 @@ public struct GameCenterDetailsResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([GameCenterDetail].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getAchievementReleases(for gameCenterDetail: GameCenterDetail) -> [GameCenterAchievementRelease] { guard let achievementReleaseIds = gameCenterDetail.relationships?.achievementReleases?.data?.map(\.id), let achievementReleases = included?.compactMap({ relationship -> GameCenterAchievementRelease? in @@ -197,9 +213,5 @@ public struct GameCenterDetailsResponse: Codable, PagedResponse { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterGroup.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterGroup.swift index ee47b17e6..dcba94475 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterGroup.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterGroup.swift @@ -27,31 +27,23 @@ public struct GameCenterGroup: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -60,6 +52,16 @@ public struct GameCenterGroup: Codable, Identifiable { public init(referenceName: String? = nil) { self.referenceName = referenceName } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + referenceName = try container.decodeIfPresent(String.self, forKey: "referenceName") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(referenceName, forKey: "referenceName") + } } public struct Relationships: Codable { @@ -79,6 +81,22 @@ public struct GameCenterGroup: Codable, Identifiable { self.gameCenterLeaderboards = gameCenterLeaderboards } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + gameCenterAchievements = try container.decodeIfPresent(GameCenterAchievements.self, forKey: "gameCenterAchievements") + gameCenterDetails = try container.decodeIfPresent(GameCenterDetails.self, forKey: "gameCenterDetails") + gameCenterLeaderboardSets = try container.decodeIfPresent(GameCenterLeaderboardSets.self, forKey: "gameCenterLeaderboardSets") + gameCenterLeaderboards = try container.decodeIfPresent(GameCenterLeaderboards.self, forKey: "gameCenterLeaderboards") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(gameCenterAchievements, forKey: "gameCenterAchievements") + try container.encodeIfPresent(gameCenterDetails, forKey: "gameCenterDetails") + try container.encodeIfPresent(gameCenterLeaderboardSets, forKey: "gameCenterLeaderboardSets") + try container.encodeIfPresent(gameCenterLeaderboards, forKey: "gameCenterLeaderboards") + } + public struct GameCenterAchievements: Codable { @NullCodable public var data: [Data]? public var links: Links? @@ -94,23 +112,17 @@ public struct GameCenterGroup: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -122,22 +134,17 @@ public struct GameCenterGroup: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -153,20 +160,15 @@ public struct GameCenterGroup: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -186,23 +188,17 @@ public struct GameCenterGroup: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -214,22 +210,17 @@ public struct GameCenterGroup: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -245,20 +236,15 @@ public struct GameCenterGroup: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -278,23 +264,17 @@ public struct GameCenterGroup: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -306,22 +286,17 @@ public struct GameCenterGroup: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -337,20 +312,15 @@ public struct GameCenterGroup: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -370,23 +340,17 @@ public struct GameCenterGroup: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -398,22 +362,17 @@ public struct GameCenterGroup: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -429,20 +388,15 @@ public struct GameCenterGroup: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterGroupCreateRequest.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterGroupCreateRequest.swift index 38ffa23fe..898718806 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterGroupCreateRequest.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterGroupCreateRequest.swift @@ -15,6 +15,16 @@ public struct GameCenterGroupCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "gameCenterGroups" } public var attributes: Attributes? @@ -24,22 +34,17 @@ public struct GameCenterGroupCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } public struct Attributes: Codable { @@ -48,6 +53,16 @@ public struct GameCenterGroupCreateRequest: Codable, RequestBody { public init(referenceName: String? = nil) { self.referenceName = referenceName } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + referenceName = try container.decodeIfPresent(String.self, forKey: "referenceName") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(referenceName, forKey: "referenceName") + } } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterGroupGameCenterAchievementsLinkagesRequest.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterGroupGameCenterAchievementsLinkagesRequest.swift index 85f276d23..6909b1fe4 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterGroupGameCenterAchievementsLinkagesRequest.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterGroupGameCenterAchievementsLinkagesRequest.swift @@ -15,6 +15,16 @@ public struct GameCenterGroupGameCenterAchievementsLinkagesRequest: Codable, Req self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "gameCenterAchievements" } @@ -24,22 +34,17 @@ public struct GameCenterGroupGameCenterAchievementsLinkagesRequest: Codable, Req } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterGroupGameCenterAchievementsLinkagesResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterGroupGameCenterAchievementsLinkagesResponse.swift index 6b4fe87f9..0f35c8f1e 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterGroupGameCenterAchievementsLinkagesResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterGroupGameCenterAchievementsLinkagesResponse.swift @@ -22,6 +22,20 @@ public struct GameCenterGroupGameCenterAchievementsLinkagesResponse: Codable, Pa self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "gameCenterAchievements" } @@ -31,22 +45,17 @@ public struct GameCenterGroupGameCenterAchievementsLinkagesResponse: Codable, Pa } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterGroupGameCenterLeaderboardSetsLinkagesRequest.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterGroupGameCenterLeaderboardSetsLinkagesRequest.swift index c2e57d973..ed4473d5c 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterGroupGameCenterLeaderboardSetsLinkagesRequest.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterGroupGameCenterLeaderboardSetsLinkagesRequest.swift @@ -15,6 +15,16 @@ public struct GameCenterGroupGameCenterLeaderboardSetsLinkagesRequest: Codable, self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "gameCenterLeaderboardSets" } @@ -24,22 +34,17 @@ public struct GameCenterGroupGameCenterLeaderboardSetsLinkagesRequest: Codable, } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterGroupGameCenterLeaderboardSetsLinkagesResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterGroupGameCenterLeaderboardSetsLinkagesResponse.swift index f314cb0e1..e5fb4a494 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterGroupGameCenterLeaderboardSetsLinkagesResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterGroupGameCenterLeaderboardSetsLinkagesResponse.swift @@ -22,6 +22,20 @@ public struct GameCenterGroupGameCenterLeaderboardSetsLinkagesResponse: Codable, self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "gameCenterLeaderboardSets" } @@ -31,22 +45,17 @@ public struct GameCenterGroupGameCenterLeaderboardSetsLinkagesResponse: Codable, } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterGroupGameCenterLeaderboardsLinkagesRequest.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterGroupGameCenterLeaderboardsLinkagesRequest.swift index 396f523f5..da7d6140a 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterGroupGameCenterLeaderboardsLinkagesRequest.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterGroupGameCenterLeaderboardsLinkagesRequest.swift @@ -15,6 +15,16 @@ public struct GameCenterGroupGameCenterLeaderboardsLinkagesRequest: Codable, Req self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "gameCenterLeaderboards" } @@ -24,22 +34,17 @@ public struct GameCenterGroupGameCenterLeaderboardsLinkagesRequest: Codable, Req } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterGroupGameCenterLeaderboardsLinkagesResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterGroupGameCenterLeaderboardsLinkagesResponse.swift index 41611b138..2095fd7d2 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterGroupGameCenterLeaderboardsLinkagesResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterGroupGameCenterLeaderboardsLinkagesResponse.swift @@ -22,6 +22,20 @@ public struct GameCenterGroupGameCenterLeaderboardsLinkagesResponse: Codable, Pa self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "gameCenterLeaderboards" } @@ -31,22 +45,17 @@ public struct GameCenterGroupGameCenterLeaderboardsLinkagesResponse: Codable, Pa } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterGroupResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterGroupResponse.swift index 15b44e97e..2f5d67546 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterGroupResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterGroupResponse.swift @@ -22,6 +22,20 @@ public struct GameCenterGroupResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(GameCenterGroup.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getGameCenterAchievements() -> [GameCenterAchievement] { guard let gameCenterAchievementIds = data.relationships?.gameCenterAchievements?.data?.map(\.id), let gameCenterAchievements = included?.compactMap({ relationship -> GameCenterAchievement? in @@ -103,9 +117,5 @@ public struct GameCenterGroupResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterGroupUpdateRequest.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterGroupUpdateRequest.swift index 9d308a4b6..9fadd807d 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterGroupUpdateRequest.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterGroupUpdateRequest.swift @@ -15,6 +15,16 @@ public struct GameCenterGroupUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "gameCenterGroups" } @@ -28,25 +38,19 @@ public struct GameCenterGroupUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } public struct Attributes: Codable { @@ -55,6 +59,16 @@ public struct GameCenterGroupUpdateRequest: Codable, RequestBody { public init(referenceName: String? = nil) { self.referenceName = referenceName } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + referenceName = try container.decodeIfPresent(String.self, forKey: "referenceName") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(referenceName, forKey: "referenceName") + } } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterGroupsResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterGroupsResponse.swift index 655d79706..5f18e8264 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterGroupsResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterGroupsResponse.swift @@ -27,6 +27,22 @@ public struct GameCenterGroupsResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([GameCenterGroup].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getGameCenterAchievements(for gameCenterGroup: GameCenterGroup) -> [GameCenterAchievement] { guard let gameCenterAchievementIds = gameCenterGroup.relationships?.gameCenterAchievements?.data?.map(\.id), let gameCenterAchievements = included?.compactMap({ relationship -> GameCenterAchievement? in @@ -108,9 +124,5 @@ public struct GameCenterGroupsResponse: Codable, PagedResponse { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboard.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboard.swift index f3b13642a..31905b01b 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboard.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboard.swift @@ -27,31 +27,23 @@ public struct GameCenterLeaderboard: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -92,6 +84,36 @@ public struct GameCenterLeaderboard: Codable, Identifiable { self.vendorIdentifier = vendorIdentifier } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + archived = try container.decodeIfPresent(Bool.self, forKey: "archived") + defaultFormatter = try container.decodeIfPresent(GameCenterLeaderboardFormatter.self, forKey: "defaultFormatter") + recurrenceDuration = try container.decodeIfPresent(String.self, forKey: "recurrenceDuration") + recurrenceRule = try container.decodeIfPresent(String.self, forKey: "recurrenceRule") + recurrenceStartDate = try container.decodeIfPresent(Date.self, forKey: "recurrenceStartDate") + referenceName = try container.decodeIfPresent(String.self, forKey: "referenceName") + scoreRangeEnd = try container.decodeIfPresent(String.self, forKey: "scoreRangeEnd") + scoreRangeStart = try container.decodeIfPresent(String.self, forKey: "scoreRangeStart") + scoreSortType = try container.decodeIfPresent(ScoreSortType.self, forKey: "scoreSortType") + submissionType = try container.decodeIfPresent(SubmissionType.self, forKey: "submissionType") + vendorIdentifier = try container.decodeIfPresent(String.self, forKey: "vendorIdentifier") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(archived, forKey: "archived") + try container.encodeIfPresent(defaultFormatter, forKey: "defaultFormatter") + try container.encodeIfPresent(recurrenceDuration, forKey: "recurrenceDuration") + try container.encodeIfPresent(recurrenceRule, forKey: "recurrenceRule") + try container.encodeIfPresent(recurrenceStartDate, forKey: "recurrenceStartDate") + try container.encodeIfPresent(referenceName, forKey: "referenceName") + try container.encodeIfPresent(scoreRangeEnd, forKey: "scoreRangeEnd") + try container.encodeIfPresent(scoreRangeStart, forKey: "scoreRangeStart") + try container.encodeIfPresent(scoreSortType, forKey: "scoreSortType") + try container.encodeIfPresent(submissionType, forKey: "submissionType") + try container.encodeIfPresent(vendorIdentifier, forKey: "vendorIdentifier") + } + public enum ScoreSortType: String, Codable, CaseIterable { case asc = "ASC" case desc = "DESC" @@ -126,6 +148,26 @@ public struct GameCenterLeaderboard: Codable, Identifiable { self.releases = releases } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + gameCenterDetail = try container.decodeIfPresent(GameCenterDetail.self, forKey: "gameCenterDetail") + gameCenterGroup = try container.decodeIfPresent(GameCenterGroup.self, forKey: "gameCenterGroup") + gameCenterLeaderboardSets = try container.decodeIfPresent(GameCenterLeaderboardSets.self, forKey: "gameCenterLeaderboardSets") + groupLeaderboard = try container.decodeIfPresent(GroupLeaderboard.self, forKey: "groupLeaderboard") + localizations = try container.decodeIfPresent(Localizations.self, forKey: "localizations") + releases = try container.decodeIfPresent(Releases.self, forKey: "releases") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(gameCenterDetail, forKey: "gameCenterDetail") + try container.encodeIfPresent(gameCenterGroup, forKey: "gameCenterGroup") + try container.encodeIfPresent(gameCenterLeaderboardSets, forKey: "gameCenterLeaderboardSets") + try container.encodeIfPresent(groupLeaderboard, forKey: "groupLeaderboard") + try container.encodeIfPresent(localizations, forKey: "localizations") + try container.encodeIfPresent(releases, forKey: "releases") + } + public struct GameCenterDetail: Codable { @NullCodable public var data: Data? public var links: Links? @@ -138,20 +180,15 @@ public struct GameCenterLeaderboard: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -163,22 +200,17 @@ public struct GameCenterLeaderboard: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -194,20 +226,15 @@ public struct GameCenterLeaderboard: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -224,20 +251,15 @@ public struct GameCenterLeaderboard: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -249,22 +271,17 @@ public struct GameCenterLeaderboard: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -280,20 +297,15 @@ public struct GameCenterLeaderboard: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -313,23 +325,17 @@ public struct GameCenterLeaderboard: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -341,22 +347,17 @@ public struct GameCenterLeaderboard: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -372,20 +373,15 @@ public struct GameCenterLeaderboard: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -402,20 +398,15 @@ public struct GameCenterLeaderboard: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -427,22 +418,17 @@ public struct GameCenterLeaderboard: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -458,20 +444,15 @@ public struct GameCenterLeaderboard: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -491,23 +472,17 @@ public struct GameCenterLeaderboard: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -519,22 +494,17 @@ public struct GameCenterLeaderboard: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -550,20 +520,15 @@ public struct GameCenterLeaderboard: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -583,23 +548,17 @@ public struct GameCenterLeaderboard: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -611,22 +570,17 @@ public struct GameCenterLeaderboard: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -642,20 +596,15 @@ public struct GameCenterLeaderboard: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardCreateRequest.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardCreateRequest.swift index ab5070964..5b25089a3 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardCreateRequest.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardCreateRequest.swift @@ -15,6 +15,16 @@ public struct GameCenterLeaderboardCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "gameCenterLeaderboards" } public let attributes: Attributes @@ -28,25 +38,19 @@ public struct GameCenterLeaderboardCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -83,6 +87,34 @@ public struct GameCenterLeaderboardCreateRequest: Codable, RequestBody { self.submissionType = submissionType self.vendorIdentifier = vendorIdentifier } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + defaultFormatter = try container.decode(GameCenterLeaderboardFormatter.self, forKey: "defaultFormatter") + recurrenceDuration = try container.decodeIfPresent(String.self, forKey: "recurrenceDuration") + recurrenceRule = try container.decodeIfPresent(String.self, forKey: "recurrenceRule") + recurrenceStartDate = try container.decodeIfPresent(Date.self, forKey: "recurrenceStartDate") + referenceName = try container.decode(String.self, forKey: "referenceName") + scoreRangeEnd = try container.decodeIfPresent(String.self, forKey: "scoreRangeEnd") + scoreRangeStart = try container.decodeIfPresent(String.self, forKey: "scoreRangeStart") + scoreSortType = try container.decode(GameCenterLeaderboard.Attributes.ScoreSortType.self, forKey: "scoreSortType") + submissionType = try container.decode(GameCenterLeaderboard.Attributes.SubmissionType.self, forKey: "submissionType") + vendorIdentifier = try container.decode(String.self, forKey: "vendorIdentifier") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(defaultFormatter, forKey: "defaultFormatter") + try container.encodeIfPresent(recurrenceDuration, forKey: "recurrenceDuration") + try container.encodeIfPresent(recurrenceRule, forKey: "recurrenceRule") + try container.encodeIfPresent(recurrenceStartDate, forKey: "recurrenceStartDate") + try container.encode(referenceName, forKey: "referenceName") + try container.encodeIfPresent(scoreRangeEnd, forKey: "scoreRangeEnd") + try container.encodeIfPresent(scoreRangeStart, forKey: "scoreRangeStart") + try container.encode(scoreSortType, forKey: "scoreSortType") + try container.encode(submissionType, forKey: "submissionType") + try container.encode(vendorIdentifier, forKey: "vendorIdentifier") + } } public struct Relationships: Codable { @@ -99,6 +131,20 @@ public struct GameCenterLeaderboardCreateRequest: Codable, RequestBody { self.gameCenterLeaderboardSets = gameCenterLeaderboardSets } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + gameCenterDetail = try container.decodeIfPresent(GameCenterDetail.self, forKey: "gameCenterDetail") + gameCenterGroup = try container.decodeIfPresent(GameCenterGroup.self, forKey: "gameCenterGroup") + gameCenterLeaderboardSets = try container.decodeIfPresent(GameCenterLeaderboardSets.self, forKey: "gameCenterLeaderboardSets") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(gameCenterDetail, forKey: "gameCenterDetail") + try container.encodeIfPresent(gameCenterGroup, forKey: "gameCenterGroup") + try container.encodeIfPresent(gameCenterLeaderboardSets, forKey: "gameCenterLeaderboardSets") + } + public struct GameCenterDetail: Codable { @NullCodable public var data: Data? @@ -107,17 +153,13 @@ public struct GameCenterLeaderboardCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } public struct Data: Codable, Identifiable { @@ -129,22 +171,17 @@ public struct GameCenterLeaderboardCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -157,17 +194,13 @@ public struct GameCenterLeaderboardCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } public struct Data: Codable, Identifiable { @@ -179,22 +212,17 @@ public struct GameCenterLeaderboardCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -207,17 +235,13 @@ public struct GameCenterLeaderboardCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } public struct Data: Codable, Identifiable { @@ -229,22 +253,17 @@ public struct GameCenterLeaderboardCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardEntrySubmission.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardEntrySubmission.swift index 4fbb63e84..b43551464 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardEntrySubmission.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardEntrySubmission.swift @@ -24,28 +24,21 @@ public struct GameCenterLeaderboardEntrySubmission: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } public struct Attributes: Codable { @@ -73,5 +66,27 @@ public struct GameCenterLeaderboardEntrySubmission: Codable, Identifiable { self.submittedDate = submittedDate self.vendorIdentifier = vendorIdentifier } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + bundleId = try container.decodeIfPresent(String.self, forKey: "bundleId") + challengeIds = try container.decodeIfPresent([String].self, forKey: "challengeIds") + context = try container.decodeIfPresent(String.self, forKey: "context") + scopedPlayerId = try container.decodeIfPresent(String.self, forKey: "scopedPlayerId") + score = try container.decodeIfPresent(String.self, forKey: "score") + submittedDate = try container.decodeIfPresent(Date.self, forKey: "submittedDate") + vendorIdentifier = try container.decodeIfPresent(String.self, forKey: "vendorIdentifier") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(bundleId, forKey: "bundleId") + try container.encodeIfPresent(challengeIds, forKey: "challengeIds") + try container.encodeIfPresent(context, forKey: "context") + try container.encodeIfPresent(scopedPlayerId, forKey: "scopedPlayerId") + try container.encodeIfPresent(score, forKey: "score") + try container.encodeIfPresent(submittedDate, forKey: "submittedDate") + try container.encodeIfPresent(vendorIdentifier, forKey: "vendorIdentifier") + } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardEntrySubmissionCreateRequest.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardEntrySubmissionCreateRequest.swift index 6304d4f8b..30487b3fe 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardEntrySubmissionCreateRequest.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardEntrySubmissionCreateRequest.swift @@ -15,6 +15,16 @@ public struct GameCenterLeaderboardEntrySubmissionCreateRequest: Codable, Reques self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # GameCenterLeaderboardEntrySubmissionCreateRequest.Data The data element of the request body. @@ -31,22 +41,17 @@ public struct GameCenterLeaderboardEntrySubmissionCreateRequest: Codable, Reques } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") } /** @@ -81,6 +86,28 @@ public struct GameCenterLeaderboardEntrySubmissionCreateRequest: Codable, Reques self.submittedDate = submittedDate self.vendorIdentifier = vendorIdentifier } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + bundleId = try container.decode(String.self, forKey: "bundleId") + challengeIds = try container.decodeIfPresent([String].self, forKey: "challengeIds") + context = try container.decodeIfPresent(String.self, forKey: "context") + scopedPlayerId = try container.decode(String.self, forKey: "scopedPlayerId") + score = try container.decode(String.self, forKey: "score") + submittedDate = try container.decodeIfPresent(Date.self, forKey: "submittedDate") + vendorIdentifier = try container.decode(String.self, forKey: "vendorIdentifier") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(bundleId, forKey: "bundleId") + try container.encodeIfPresent(challengeIds, forKey: "challengeIds") + try container.encodeIfPresent(context, forKey: "context") + try container.encode(scopedPlayerId, forKey: "scopedPlayerId") + try container.encode(score, forKey: "score") + try container.encodeIfPresent(submittedDate, forKey: "submittedDate") + try container.encode(vendorIdentifier, forKey: "vendorIdentifier") + } } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardEntrySubmissionResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardEntrySubmissionResponse.swift index 7dcd84fff..e18ff88e1 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardEntrySubmissionResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardEntrySubmissionResponse.swift @@ -18,4 +18,16 @@ public struct GameCenterLeaderboardEntrySubmissionResponse: Codable { self.data = data self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(GameCenterLeaderboardEntrySubmission.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardGroupLeaderboardLinkageRequest.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardGroupLeaderboardLinkageRequest.swift index 75e02cf7d..9ba89b493 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardGroupLeaderboardLinkageRequest.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardGroupLeaderboardLinkageRequest.swift @@ -16,17 +16,13 @@ public struct GameCenterLeaderboardGroupLeaderboardLinkageRequest: Codable, Requ } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } public struct Data: Codable, Identifiable { @@ -38,22 +34,17 @@ public struct GameCenterLeaderboardGroupLeaderboardLinkageRequest: Codable, Requ } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardGroupLeaderboardLinkageResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardGroupLeaderboardLinkageResponse.swift index f7ce31992..73a71cb64 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardGroupLeaderboardLinkageResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardGroupLeaderboardLinkageResponse.swift @@ -19,6 +19,18 @@ public struct GameCenterLeaderboardGroupLeaderboardLinkageResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "gameCenterLeaderboards" } @@ -28,22 +40,17 @@ public struct GameCenterLeaderboardGroupLeaderboardLinkageResponse: Codable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardImage.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardImage.swift index 9a7084b26..9d571b7c5 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardImage.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardImage.swift @@ -27,31 +27,23 @@ public struct GameCenterLeaderboardImage: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -73,6 +65,24 @@ public struct GameCenterLeaderboardImage: Codable, Identifiable { self.imageAsset = imageAsset self.uploadOperations = uploadOperations } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + assetDeliveryState = try container.decodeIfPresent(AppMediaAssetState.self, forKey: "assetDeliveryState") + fileName = try container.decodeIfPresent(String.self, forKey: "fileName") + fileSize = try container.decodeIfPresent(Int.self, forKey: "fileSize") + imageAsset = try container.decodeIfPresent(ImageAsset.self, forKey: "imageAsset") + uploadOperations = try container.decodeIfPresent([UploadOperation].self, forKey: "uploadOperations") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(assetDeliveryState, forKey: "assetDeliveryState") + try container.encodeIfPresent(fileName, forKey: "fileName") + try container.encodeIfPresent(fileSize, forKey: "fileSize") + try container.encodeIfPresent(imageAsset, forKey: "imageAsset") + try container.encodeIfPresent(uploadOperations, forKey: "uploadOperations") + } } public struct Relationships: Codable { @@ -82,6 +92,16 @@ public struct GameCenterLeaderboardImage: Codable, Identifiable { self.gameCenterLeaderboardLocalization = gameCenterLeaderboardLocalization } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + gameCenterLeaderboardLocalization = try container.decodeIfPresent(GameCenterLeaderboardLocalization.self, forKey: "gameCenterLeaderboardLocalization") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(gameCenterLeaderboardLocalization, forKey: "gameCenterLeaderboardLocalization") + } + public struct GameCenterLeaderboardLocalization: Codable { @NullCodable public var data: Data? public var links: Links? @@ -94,20 +114,15 @@ public struct GameCenterLeaderboardImage: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -119,22 +134,17 @@ public struct GameCenterLeaderboardImage: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -150,20 +160,15 @@ public struct GameCenterLeaderboardImage: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardImageCreateRequest.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardImageCreateRequest.swift index 8c064fac1..c60e6e7ce 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardImageCreateRequest.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardImageCreateRequest.swift @@ -15,6 +15,16 @@ public struct GameCenterLeaderboardImageCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "gameCenterLeaderboardImages" } public let attributes: Attributes @@ -28,25 +38,19 @@ public struct GameCenterLeaderboardImageCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -59,6 +63,18 @@ public struct GameCenterLeaderboardImageCreateRequest: Codable, RequestBody { self.fileName = fileName self.fileSize = fileSize } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + fileName = try container.decode(String.self, forKey: "fileName") + fileSize = try container.decode(Int.self, forKey: "fileSize") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(fileName, forKey: "fileName") + try container.encode(fileSize, forKey: "fileSize") + } } public struct Relationships: Codable { @@ -68,6 +84,16 @@ public struct GameCenterLeaderboardImageCreateRequest: Codable, RequestBody { self.gameCenterLeaderboardLocalization = gameCenterLeaderboardLocalization } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + gameCenterLeaderboardLocalization = try container.decode(GameCenterLeaderboardLocalization.self, forKey: "gameCenterLeaderboardLocalization") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(gameCenterLeaderboardLocalization, forKey: "gameCenterLeaderboardLocalization") + } + public struct GameCenterLeaderboardLocalization: Codable { public let data: Data @@ -75,6 +101,16 @@ public struct GameCenterLeaderboardImageCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "gameCenterLeaderboardLocalizations" } @@ -84,22 +120,17 @@ public struct GameCenterLeaderboardImageCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardImageResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardImageResponse.swift index 74fec4d84..d131a40ea 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardImageResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardImageResponse.swift @@ -21,4 +21,18 @@ public struct GameCenterLeaderboardImageResponse: Codable { self.included = included self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(GameCenterLeaderboardImage.self, forKey: "data") + included = try container.decodeIfPresent([GameCenterLeaderboardLocalization].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardImageUpdateRequest.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardImageUpdateRequest.swift index af3b031e9..a029a78ae 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardImageUpdateRequest.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardImageUpdateRequest.swift @@ -15,6 +15,16 @@ public struct GameCenterLeaderboardImageUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "gameCenterLeaderboardImages" } @@ -28,25 +38,19 @@ public struct GameCenterLeaderboardImageUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } public struct Attributes: Codable { @@ -55,6 +59,16 @@ public struct GameCenterLeaderboardImageUpdateRequest: Codable, RequestBody { public init(uploaded: Bool? = nil) { self.uploaded = uploaded } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + uploaded = try container.decodeIfPresent(Bool.self, forKey: "uploaded") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(uploaded, forKey: "uploaded") + } } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardLocalization.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardLocalization.swift index 6d107eeec..ac26ac96c 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardLocalization.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardLocalization.swift @@ -27,31 +27,23 @@ public struct GameCenterLeaderboardLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -73,6 +65,24 @@ public struct GameCenterLeaderboardLocalization: Codable, Identifiable { self.locale = locale self.name = name } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + formatterOverride = try container.decodeIfPresent(GameCenterLeaderboardFormatter.self, forKey: "formatterOverride") + formatterSuffix = try container.decodeIfPresent(String.self, forKey: "formatterSuffix") + formatterSuffixSingular = try container.decodeIfPresent(String.self, forKey: "formatterSuffixSingular") + locale = try container.decodeIfPresent(String.self, forKey: "locale") + name = try container.decodeIfPresent(String.self, forKey: "name") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(formatterOverride, forKey: "formatterOverride") + try container.encodeIfPresent(formatterSuffix, forKey: "formatterSuffix") + try container.encodeIfPresent(formatterSuffixSingular, forKey: "formatterSuffixSingular") + try container.encodeIfPresent(locale, forKey: "locale") + try container.encodeIfPresent(name, forKey: "name") + } } public struct Relationships: Codable { @@ -86,6 +96,18 @@ public struct GameCenterLeaderboardLocalization: Codable, Identifiable { self.gameCenterLeaderboardImage = gameCenterLeaderboardImage } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + gameCenterLeaderboard = try container.decodeIfPresent(GameCenterLeaderboard.self, forKey: "gameCenterLeaderboard") + gameCenterLeaderboardImage = try container.decodeIfPresent(GameCenterLeaderboardImage.self, forKey: "gameCenterLeaderboardImage") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(gameCenterLeaderboard, forKey: "gameCenterLeaderboard") + try container.encodeIfPresent(gameCenterLeaderboardImage, forKey: "gameCenterLeaderboardImage") + } + public struct GameCenterLeaderboard: Codable { @NullCodable public var data: Data? public var links: Links? @@ -98,20 +120,15 @@ public struct GameCenterLeaderboardLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -123,22 +140,17 @@ public struct GameCenterLeaderboardLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -154,20 +166,15 @@ public struct GameCenterLeaderboardLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -184,20 +191,15 @@ public struct GameCenterLeaderboardLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -209,22 +211,17 @@ public struct GameCenterLeaderboardLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -240,20 +237,15 @@ public struct GameCenterLeaderboardLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardLocalizationCreateRequest.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardLocalizationCreateRequest.swift index e213320c1..d5087f430 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardLocalizationCreateRequest.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardLocalizationCreateRequest.swift @@ -15,6 +15,16 @@ public struct GameCenterLeaderboardLocalizationCreateRequest: Codable, RequestBo self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "gameCenterLeaderboardLocalizations" } public let attributes: Attributes @@ -28,25 +38,19 @@ public struct GameCenterLeaderboardLocalizationCreateRequest: Codable, RequestBo } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -68,6 +72,24 @@ public struct GameCenterLeaderboardLocalizationCreateRequest: Codable, RequestBo self.locale = locale self.name = name } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + formatterOverride = try container.decodeIfPresent(GameCenterLeaderboardFormatter.self, forKey: "formatterOverride") + formatterSuffix = try container.decodeIfPresent(String.self, forKey: "formatterSuffix") + formatterSuffixSingular = try container.decodeIfPresent(String.self, forKey: "formatterSuffixSingular") + locale = try container.decode(String.self, forKey: "locale") + name = try container.decode(String.self, forKey: "name") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(formatterOverride, forKey: "formatterOverride") + try container.encodeIfPresent(formatterSuffix, forKey: "formatterSuffix") + try container.encodeIfPresent(formatterSuffixSingular, forKey: "formatterSuffixSingular") + try container.encode(locale, forKey: "locale") + try container.encode(name, forKey: "name") + } } public struct Relationships: Codable { @@ -77,6 +99,16 @@ public struct GameCenterLeaderboardLocalizationCreateRequest: Codable, RequestBo self.gameCenterLeaderboard = gameCenterLeaderboard } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + gameCenterLeaderboard = try container.decode(GameCenterLeaderboard.self, forKey: "gameCenterLeaderboard") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(gameCenterLeaderboard, forKey: "gameCenterLeaderboard") + } + public struct GameCenterLeaderboard: Codable { public let data: Data @@ -84,6 +116,16 @@ public struct GameCenterLeaderboardLocalizationCreateRequest: Codable, RequestBo self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "gameCenterLeaderboards" } @@ -93,22 +135,17 @@ public struct GameCenterLeaderboardLocalizationCreateRequest: Codable, RequestBo } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardLocalizationResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardLocalizationResponse.swift index 6dbd8bd0a..2fb3b61a3 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardLocalizationResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardLocalizationResponse.swift @@ -22,6 +22,20 @@ public struct GameCenterLeaderboardLocalizationResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(GameCenterLeaderboardLocalization.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getGameCenterLeaderboard() -> GameCenterLeaderboard? { included?.compactMap { relationship -> GameCenterLeaderboard? in guard case let .gameCenterLeaderboard(gameCenterLeaderboard) = relationship else { return nil } @@ -59,9 +73,5 @@ public struct GameCenterLeaderboardLocalizationResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardLocalizationUpdateRequest.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardLocalizationUpdateRequest.swift index f77f2b6e7..154a3dda7 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardLocalizationUpdateRequest.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardLocalizationUpdateRequest.swift @@ -15,6 +15,16 @@ public struct GameCenterLeaderboardLocalizationUpdateRequest: Codable, RequestBo self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "gameCenterLeaderboardLocalizations" } @@ -28,25 +38,19 @@ public struct GameCenterLeaderboardLocalizationUpdateRequest: Codable, RequestBo } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } public struct Attributes: Codable { @@ -65,6 +69,22 @@ public struct GameCenterLeaderboardLocalizationUpdateRequest: Codable, RequestBo self.formatterSuffixSingular = formatterSuffixSingular self.name = name } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + formatterOverride = try container.decodeIfPresent(GameCenterLeaderboardFormatter.self, forKey: "formatterOverride") + formatterSuffix = try container.decodeIfPresent(String.self, forKey: "formatterSuffix") + formatterSuffixSingular = try container.decodeIfPresent(String.self, forKey: "formatterSuffixSingular") + name = try container.decodeIfPresent(String.self, forKey: "name") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(formatterOverride, forKey: "formatterOverride") + try container.encodeIfPresent(formatterSuffix, forKey: "formatterSuffix") + try container.encodeIfPresent(formatterSuffixSingular, forKey: "formatterSuffixSingular") + try container.encodeIfPresent(name, forKey: "name") + } } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardLocalizationsResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardLocalizationsResponse.swift index d5f29cd4a..a1378e322 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardLocalizationsResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardLocalizationsResponse.swift @@ -27,6 +27,22 @@ public struct GameCenterLeaderboardLocalizationsResponse: Codable, PagedResponse self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([GameCenterLeaderboardLocalization].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getGameCenterLeaderboard(for gameCenterLeaderboardLocalization: GameCenterLeaderboardLocalization) -> GameCenterLeaderboard? { included?.compactMap { relationship -> GameCenterLeaderboard? in guard case let .gameCenterLeaderboard(gameCenterLeaderboard) = relationship else { return nil } @@ -64,9 +80,5 @@ public struct GameCenterLeaderboardLocalizationsResponse: Codable, PagedResponse try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardRelease.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardRelease.swift index 8fee6eb81..cb3396032 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardRelease.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardRelease.swift @@ -27,31 +27,23 @@ public struct GameCenterLeaderboardRelease: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -60,6 +52,16 @@ public struct GameCenterLeaderboardRelease: Codable, Identifiable { public init(live: Bool? = nil) { self.live = live } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + live = try container.decodeIfPresent(Bool.self, forKey: "live") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(live, forKey: "live") + } } public struct Relationships: Codable { @@ -73,6 +75,18 @@ public struct GameCenterLeaderboardRelease: Codable, Identifiable { self.gameCenterLeaderboard = gameCenterLeaderboard } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + gameCenterDetail = try container.decodeIfPresent(GameCenterDetail.self, forKey: "gameCenterDetail") + gameCenterLeaderboard = try container.decodeIfPresent(GameCenterLeaderboard.self, forKey: "gameCenterLeaderboard") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(gameCenterDetail, forKey: "gameCenterDetail") + try container.encodeIfPresent(gameCenterLeaderboard, forKey: "gameCenterLeaderboard") + } + public struct GameCenterDetail: Codable { @NullCodable public var data: Data? public var links: Links? @@ -85,20 +99,15 @@ public struct GameCenterLeaderboardRelease: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -110,22 +119,17 @@ public struct GameCenterLeaderboardRelease: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -141,20 +145,15 @@ public struct GameCenterLeaderboardRelease: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -171,20 +170,15 @@ public struct GameCenterLeaderboardRelease: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -196,22 +190,17 @@ public struct GameCenterLeaderboardRelease: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -227,20 +216,15 @@ public struct GameCenterLeaderboardRelease: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardReleaseCreateRequest.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardReleaseCreateRequest.swift index 2c57d987b..f5857e243 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardReleaseCreateRequest.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardReleaseCreateRequest.swift @@ -15,6 +15,16 @@ public struct GameCenterLeaderboardReleaseCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "gameCenterLeaderboardReleases" } public let relationships: Relationships @@ -24,22 +34,17 @@ public struct GameCenterLeaderboardReleaseCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(relationships, forKey: "relationships") } public struct Relationships: Codable { @@ -53,6 +58,18 @@ public struct GameCenterLeaderboardReleaseCreateRequest: Codable, RequestBody { self.gameCenterLeaderboard = gameCenterLeaderboard } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + gameCenterDetail = try container.decode(GameCenterDetail.self, forKey: "gameCenterDetail") + gameCenterLeaderboard = try container.decode(GameCenterLeaderboard.self, forKey: "gameCenterLeaderboard") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(gameCenterDetail, forKey: "gameCenterDetail") + try container.encode(gameCenterLeaderboard, forKey: "gameCenterLeaderboard") + } + public struct GameCenterDetail: Codable { public let data: Data @@ -60,6 +77,16 @@ public struct GameCenterLeaderboardReleaseCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "gameCenterDetails" } @@ -69,22 +96,17 @@ public struct GameCenterLeaderboardReleaseCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -96,6 +118,16 @@ public struct GameCenterLeaderboardReleaseCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "gameCenterLeaderboards" } @@ -105,22 +137,17 @@ public struct GameCenterLeaderboardReleaseCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardReleaseResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardReleaseResponse.swift index b9c5c5342..b42676784 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardReleaseResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardReleaseResponse.swift @@ -22,6 +22,20 @@ public struct GameCenterLeaderboardReleaseResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(GameCenterLeaderboardRelease.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getGameCenterDetail() -> GameCenterDetail? { included?.compactMap { relationship -> GameCenterDetail? in guard case let .gameCenterDetail(gameCenterDetail) = relationship else { return nil } @@ -59,9 +73,5 @@ public struct GameCenterLeaderboardReleaseResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardReleasesResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardReleasesResponse.swift index fbd1030b9..a215a177b 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardReleasesResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardReleasesResponse.swift @@ -27,6 +27,22 @@ public struct GameCenterLeaderboardReleasesResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([GameCenterLeaderboardRelease].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getGameCenterDetail(for gameCenterLeaderboardRelease: GameCenterLeaderboardRelease) -> GameCenterDetail? { included?.compactMap { relationship -> GameCenterDetail? in guard case let .gameCenterDetail(gameCenterDetail) = relationship else { return nil } @@ -64,9 +80,5 @@ public struct GameCenterLeaderboardReleasesResponse: Codable, PagedResponse { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardResponse.swift index 2360a8587..bc4cd43e2 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardResponse.swift @@ -22,6 +22,20 @@ public struct GameCenterLeaderboardResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(GameCenterLeaderboard.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getGameCenterDetail() -> GameCenterDetail? { included?.compactMap { relationship -> GameCenterDetail? in guard case let .gameCenterDetail(gameCenterDetail) = relationship else { return nil } @@ -122,9 +136,5 @@ public struct GameCenterLeaderboardResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSet.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSet.swift index efd27180f..59d850606 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSet.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSet.swift @@ -27,31 +27,23 @@ public struct GameCenterLeaderboardSet: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -64,6 +56,18 @@ public struct GameCenterLeaderboardSet: Codable, Identifiable { self.referenceName = referenceName self.vendorIdentifier = vendorIdentifier } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + referenceName = try container.decodeIfPresent(String.self, forKey: "referenceName") + vendorIdentifier = try container.decodeIfPresent(String.self, forKey: "vendorIdentifier") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(referenceName, forKey: "referenceName") + try container.encodeIfPresent(vendorIdentifier, forKey: "vendorIdentifier") + } } public struct Relationships: Codable { @@ -89,6 +93,26 @@ public struct GameCenterLeaderboardSet: Codable, Identifiable { self.releases = releases } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + gameCenterDetail = try container.decodeIfPresent(GameCenterDetail.self, forKey: "gameCenterDetail") + gameCenterGroup = try container.decodeIfPresent(GameCenterGroup.self, forKey: "gameCenterGroup") + gameCenterLeaderboards = try container.decodeIfPresent(GameCenterLeaderboards.self, forKey: "gameCenterLeaderboards") + groupLeaderboardSet = try container.decodeIfPresent(GroupLeaderboardSet.self, forKey: "groupLeaderboardSet") + localizations = try container.decodeIfPresent(Localizations.self, forKey: "localizations") + releases = try container.decodeIfPresent(Releases.self, forKey: "releases") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(gameCenterDetail, forKey: "gameCenterDetail") + try container.encodeIfPresent(gameCenterGroup, forKey: "gameCenterGroup") + try container.encodeIfPresent(gameCenterLeaderboards, forKey: "gameCenterLeaderboards") + try container.encodeIfPresent(groupLeaderboardSet, forKey: "groupLeaderboardSet") + try container.encodeIfPresent(localizations, forKey: "localizations") + try container.encodeIfPresent(releases, forKey: "releases") + } + public struct GameCenterDetail: Codable { @NullCodable public var data: Data? public var links: Links? @@ -101,20 +125,15 @@ public struct GameCenterLeaderboardSet: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -126,22 +145,17 @@ public struct GameCenterLeaderboardSet: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -157,20 +171,15 @@ public struct GameCenterLeaderboardSet: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -187,20 +196,15 @@ public struct GameCenterLeaderboardSet: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -212,22 +216,17 @@ public struct GameCenterLeaderboardSet: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -243,20 +242,15 @@ public struct GameCenterLeaderboardSet: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -276,23 +270,17 @@ public struct GameCenterLeaderboardSet: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -304,22 +292,17 @@ public struct GameCenterLeaderboardSet: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -335,20 +318,15 @@ public struct GameCenterLeaderboardSet: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -365,20 +343,15 @@ public struct GameCenterLeaderboardSet: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -390,22 +363,17 @@ public struct GameCenterLeaderboardSet: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -421,20 +389,15 @@ public struct GameCenterLeaderboardSet: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -454,23 +417,17 @@ public struct GameCenterLeaderboardSet: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -482,22 +439,17 @@ public struct GameCenterLeaderboardSet: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -513,20 +465,15 @@ public struct GameCenterLeaderboardSet: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -546,23 +493,17 @@ public struct GameCenterLeaderboardSet: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -574,22 +515,17 @@ public struct GameCenterLeaderboardSet: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -605,20 +541,15 @@ public struct GameCenterLeaderboardSet: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetCreateRequest.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetCreateRequest.swift index cb90819bd..fbfd6ed91 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetCreateRequest.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetCreateRequest.swift @@ -15,6 +15,16 @@ public struct GameCenterLeaderboardSetCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "gameCenterLeaderboardSets" } public let attributes: Attributes @@ -28,25 +38,19 @@ public struct GameCenterLeaderboardSetCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -59,6 +63,18 @@ public struct GameCenterLeaderboardSetCreateRequest: Codable, RequestBody { self.referenceName = referenceName self.vendorIdentifier = vendorIdentifier } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + referenceName = try container.decode(String.self, forKey: "referenceName") + vendorIdentifier = try container.decode(String.self, forKey: "vendorIdentifier") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(referenceName, forKey: "referenceName") + try container.encode(vendorIdentifier, forKey: "vendorIdentifier") + } } public struct Relationships: Codable { @@ -75,6 +91,20 @@ public struct GameCenterLeaderboardSetCreateRequest: Codable, RequestBody { self.gameCenterLeaderboards = gameCenterLeaderboards } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + gameCenterDetail = try container.decodeIfPresent(GameCenterDetail.self, forKey: "gameCenterDetail") + gameCenterGroup = try container.decodeIfPresent(GameCenterGroup.self, forKey: "gameCenterGroup") + gameCenterLeaderboards = try container.decodeIfPresent(GameCenterLeaderboards.self, forKey: "gameCenterLeaderboards") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(gameCenterDetail, forKey: "gameCenterDetail") + try container.encodeIfPresent(gameCenterGroup, forKey: "gameCenterGroup") + try container.encodeIfPresent(gameCenterLeaderboards, forKey: "gameCenterLeaderboards") + } + public struct GameCenterDetail: Codable { @NullCodable public var data: Data? @@ -83,17 +113,13 @@ public struct GameCenterLeaderboardSetCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } public struct Data: Codable, Identifiable { @@ -105,22 +131,17 @@ public struct GameCenterLeaderboardSetCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -133,17 +154,13 @@ public struct GameCenterLeaderboardSetCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } public struct Data: Codable, Identifiable { @@ -155,22 +172,17 @@ public struct GameCenterLeaderboardSetCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -183,17 +195,13 @@ public struct GameCenterLeaderboardSetCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } public struct Data: Codable, Identifiable { @@ -205,22 +213,17 @@ public struct GameCenterLeaderboardSetCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetGameCenterLeaderboardsLinkagesRequest.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetGameCenterLeaderboardsLinkagesRequest.swift index d037dced2..72e15067a 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetGameCenterLeaderboardsLinkagesRequest.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetGameCenterLeaderboardsLinkagesRequest.swift @@ -15,6 +15,16 @@ public struct GameCenterLeaderboardSetGameCenterLeaderboardsLinkagesRequest: Cod self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "gameCenterLeaderboards" } @@ -24,22 +34,17 @@ public struct GameCenterLeaderboardSetGameCenterLeaderboardsLinkagesRequest: Cod } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetGameCenterLeaderboardsLinkagesResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetGameCenterLeaderboardsLinkagesResponse.swift index b78c7bb41..7d5dfdb39 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetGameCenterLeaderboardsLinkagesResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetGameCenterLeaderboardsLinkagesResponse.swift @@ -22,6 +22,20 @@ public struct GameCenterLeaderboardSetGameCenterLeaderboardsLinkagesResponse: Co self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "gameCenterLeaderboards" } @@ -31,22 +45,17 @@ public struct GameCenterLeaderboardSetGameCenterLeaderboardsLinkagesResponse: Co } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetGroupLeaderboardSetLinkageRequest.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetGroupLeaderboardSetLinkageRequest.swift index bb0d078fe..b271db5ad 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetGroupLeaderboardSetLinkageRequest.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetGroupLeaderboardSetLinkageRequest.swift @@ -16,17 +16,13 @@ public struct GameCenterLeaderboardSetGroupLeaderboardSetLinkageRequest: Codable } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } public struct Data: Codable, Identifiable { @@ -38,22 +34,17 @@ public struct GameCenterLeaderboardSetGroupLeaderboardSetLinkageRequest: Codable } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetGroupLeaderboardSetLinkageResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetGroupLeaderboardSetLinkageResponse.swift index c987f9f6a..60aa3b392 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetGroupLeaderboardSetLinkageResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetGroupLeaderboardSetLinkageResponse.swift @@ -19,6 +19,18 @@ public struct GameCenterLeaderboardSetGroupLeaderboardSetLinkageResponse: Codabl self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "gameCenterLeaderboardSets" } @@ -28,22 +40,17 @@ public struct GameCenterLeaderboardSetGroupLeaderboardSetLinkageResponse: Codabl } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetImage.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetImage.swift index 127ebacfb..14235fac4 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetImage.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetImage.swift @@ -27,31 +27,23 @@ public struct GameCenterLeaderboardSetImage: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -73,6 +65,24 @@ public struct GameCenterLeaderboardSetImage: Codable, Identifiable { self.imageAsset = imageAsset self.uploadOperations = uploadOperations } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + assetDeliveryState = try container.decodeIfPresent(AppMediaAssetState.self, forKey: "assetDeliveryState") + fileName = try container.decodeIfPresent(String.self, forKey: "fileName") + fileSize = try container.decodeIfPresent(Int.self, forKey: "fileSize") + imageAsset = try container.decodeIfPresent(ImageAsset.self, forKey: "imageAsset") + uploadOperations = try container.decodeIfPresent([UploadOperation].self, forKey: "uploadOperations") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(assetDeliveryState, forKey: "assetDeliveryState") + try container.encodeIfPresent(fileName, forKey: "fileName") + try container.encodeIfPresent(fileSize, forKey: "fileSize") + try container.encodeIfPresent(imageAsset, forKey: "imageAsset") + try container.encodeIfPresent(uploadOperations, forKey: "uploadOperations") + } } public struct Relationships: Codable { @@ -82,6 +92,16 @@ public struct GameCenterLeaderboardSetImage: Codable, Identifiable { self.gameCenterLeaderboardSetLocalization = gameCenterLeaderboardSetLocalization } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + gameCenterLeaderboardSetLocalization = try container.decodeIfPresent(GameCenterLeaderboardSetLocalization.self, forKey: "gameCenterLeaderboardSetLocalization") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(gameCenterLeaderboardSetLocalization, forKey: "gameCenterLeaderboardSetLocalization") + } + public struct GameCenterLeaderboardSetLocalization: Codable { @NullCodable public var data: Data? public var links: Links? @@ -94,20 +114,15 @@ public struct GameCenterLeaderboardSetImage: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -119,22 +134,17 @@ public struct GameCenterLeaderboardSetImage: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -150,20 +160,15 @@ public struct GameCenterLeaderboardSetImage: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetImageCreateRequest.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetImageCreateRequest.swift index ae20aab67..8cf4b3a14 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetImageCreateRequest.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetImageCreateRequest.swift @@ -15,6 +15,16 @@ public struct GameCenterLeaderboardSetImageCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "gameCenterLeaderboardSetImages" } public let attributes: Attributes @@ -28,25 +38,19 @@ public struct GameCenterLeaderboardSetImageCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -59,6 +63,18 @@ public struct GameCenterLeaderboardSetImageCreateRequest: Codable, RequestBody { self.fileName = fileName self.fileSize = fileSize } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + fileName = try container.decode(String.self, forKey: "fileName") + fileSize = try container.decode(Int.self, forKey: "fileSize") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(fileName, forKey: "fileName") + try container.encode(fileSize, forKey: "fileSize") + } } public struct Relationships: Codable { @@ -68,6 +84,16 @@ public struct GameCenterLeaderboardSetImageCreateRequest: Codable, RequestBody { self.gameCenterLeaderboardSetLocalization = gameCenterLeaderboardSetLocalization } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + gameCenterLeaderboardSetLocalization = try container.decode(GameCenterLeaderboardSetLocalization.self, forKey: "gameCenterLeaderboardSetLocalization") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(gameCenterLeaderboardSetLocalization, forKey: "gameCenterLeaderboardSetLocalization") + } + public struct GameCenterLeaderboardSetLocalization: Codable { public let data: Data @@ -75,6 +101,16 @@ public struct GameCenterLeaderboardSetImageCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "gameCenterLeaderboardSetLocalizations" } @@ -84,22 +120,17 @@ public struct GameCenterLeaderboardSetImageCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetImageResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetImageResponse.swift index 52a6dc31d..71e0bd288 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetImageResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetImageResponse.swift @@ -21,4 +21,18 @@ public struct GameCenterLeaderboardSetImageResponse: Codable { self.included = included self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(GameCenterLeaderboardSetImage.self, forKey: "data") + included = try container.decodeIfPresent([GameCenterLeaderboardSetLocalization].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetImageUpdateRequest.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetImageUpdateRequest.swift index b5db84d06..14c103dfc 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetImageUpdateRequest.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetImageUpdateRequest.swift @@ -15,6 +15,16 @@ public struct GameCenterLeaderboardSetImageUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "gameCenterLeaderboardSetImages" } @@ -28,25 +38,19 @@ public struct GameCenterLeaderboardSetImageUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } public struct Attributes: Codable { @@ -55,6 +59,16 @@ public struct GameCenterLeaderboardSetImageUpdateRequest: Codable, RequestBody { public init(uploaded: Bool? = nil) { self.uploaded = uploaded } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + uploaded = try container.decodeIfPresent(Bool.self, forKey: "uploaded") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(uploaded, forKey: "uploaded") + } } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetLocalization.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetLocalization.swift index d6db16c58..27bc20f4c 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetLocalization.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetLocalization.swift @@ -27,31 +27,23 @@ public struct GameCenterLeaderboardSetLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -64,6 +56,18 @@ public struct GameCenterLeaderboardSetLocalization: Codable, Identifiable { self.locale = locale self.name = name } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + locale = try container.decodeIfPresent(String.self, forKey: "locale") + name = try container.decodeIfPresent(String.self, forKey: "name") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(locale, forKey: "locale") + try container.encodeIfPresent(name, forKey: "name") + } } public struct Relationships: Codable { @@ -77,6 +81,18 @@ public struct GameCenterLeaderboardSetLocalization: Codable, Identifiable { self.gameCenterLeaderboardSetImage = gameCenterLeaderboardSetImage } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + gameCenterLeaderboardSet = try container.decodeIfPresent(GameCenterLeaderboardSet.self, forKey: "gameCenterLeaderboardSet") + gameCenterLeaderboardSetImage = try container.decodeIfPresent(GameCenterLeaderboardSetImage.self, forKey: "gameCenterLeaderboardSetImage") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(gameCenterLeaderboardSet, forKey: "gameCenterLeaderboardSet") + try container.encodeIfPresent(gameCenterLeaderboardSetImage, forKey: "gameCenterLeaderboardSetImage") + } + public struct GameCenterLeaderboardSet: Codable { @NullCodable public var data: Data? public var links: Links? @@ -89,20 +105,15 @@ public struct GameCenterLeaderboardSetLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -114,22 +125,17 @@ public struct GameCenterLeaderboardSetLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -145,20 +151,15 @@ public struct GameCenterLeaderboardSetLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -175,20 +176,15 @@ public struct GameCenterLeaderboardSetLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -200,22 +196,17 @@ public struct GameCenterLeaderboardSetLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -231,20 +222,15 @@ public struct GameCenterLeaderboardSetLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetLocalizationCreateRequest.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetLocalizationCreateRequest.swift index a7d15167e..6a923363b 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetLocalizationCreateRequest.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetLocalizationCreateRequest.swift @@ -15,6 +15,16 @@ public struct GameCenterLeaderboardSetLocalizationCreateRequest: Codable, Reques self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "gameCenterLeaderboardSetLocalizations" } public let attributes: Attributes @@ -28,25 +38,19 @@ public struct GameCenterLeaderboardSetLocalizationCreateRequest: Codable, Reques } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -59,6 +63,18 @@ public struct GameCenterLeaderboardSetLocalizationCreateRequest: Codable, Reques self.locale = locale self.name = name } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + locale = try container.decode(String.self, forKey: "locale") + name = try container.decode(String.self, forKey: "name") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(locale, forKey: "locale") + try container.encode(name, forKey: "name") + } } public struct Relationships: Codable { @@ -68,6 +84,16 @@ public struct GameCenterLeaderboardSetLocalizationCreateRequest: Codable, Reques self.gameCenterLeaderboardSet = gameCenterLeaderboardSet } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + gameCenterLeaderboardSet = try container.decode(GameCenterLeaderboardSet.self, forKey: "gameCenterLeaderboardSet") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(gameCenterLeaderboardSet, forKey: "gameCenterLeaderboardSet") + } + public struct GameCenterLeaderboardSet: Codable { public let data: Data @@ -75,6 +101,16 @@ public struct GameCenterLeaderboardSetLocalizationCreateRequest: Codable, Reques self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "gameCenterLeaderboardSets" } @@ -84,22 +120,17 @@ public struct GameCenterLeaderboardSetLocalizationCreateRequest: Codable, Reques } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetLocalizationResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetLocalizationResponse.swift index c7fe983d8..efc099b40 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetLocalizationResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetLocalizationResponse.swift @@ -22,6 +22,20 @@ public struct GameCenterLeaderboardSetLocalizationResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(GameCenterLeaderboardSetLocalization.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getGameCenterLeaderboardSet() -> GameCenterLeaderboardSet? { included?.compactMap { relationship -> GameCenterLeaderboardSet? in guard case let .gameCenterLeaderboardSet(gameCenterLeaderboardSet) = relationship else { return nil } @@ -59,9 +73,5 @@ public struct GameCenterLeaderboardSetLocalizationResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetLocalizationUpdateRequest.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetLocalizationUpdateRequest.swift index 308b9de3d..0704ddaa8 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetLocalizationUpdateRequest.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetLocalizationUpdateRequest.swift @@ -15,6 +15,16 @@ public struct GameCenterLeaderboardSetLocalizationUpdateRequest: Codable, Reques self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "gameCenterLeaderboardSetLocalizations" } @@ -28,25 +38,19 @@ public struct GameCenterLeaderboardSetLocalizationUpdateRequest: Codable, Reques } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } public struct Attributes: Codable { @@ -55,6 +59,16 @@ public struct GameCenterLeaderboardSetLocalizationUpdateRequest: Codable, Reques public init(name: String? = nil) { self.name = name } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + name = try container.decodeIfPresent(String.self, forKey: "name") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(name, forKey: "name") + } } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetLocalizationsResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetLocalizationsResponse.swift index 1bbc56178..123a9fc15 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetLocalizationsResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetLocalizationsResponse.swift @@ -27,6 +27,22 @@ public struct GameCenterLeaderboardSetLocalizationsResponse: Codable, PagedRespo self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([GameCenterLeaderboardSetLocalization].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getGameCenterLeaderboardSet(for gameCenterLeaderboardSetLocalization: GameCenterLeaderboardSetLocalization) -> GameCenterLeaderboardSet? { included?.compactMap { relationship -> GameCenterLeaderboardSet? in guard case let .gameCenterLeaderboardSet(gameCenterLeaderboardSet) = relationship else { return nil } @@ -64,9 +80,5 @@ public struct GameCenterLeaderboardSetLocalizationsResponse: Codable, PagedRespo try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetMemberLocalization.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetMemberLocalization.swift index 774957cd9..328260808 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetMemberLocalization.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetMemberLocalization.swift @@ -27,31 +27,23 @@ public struct GameCenterLeaderboardSetMemberLocalization: Codable, Identifiable } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -64,6 +56,18 @@ public struct GameCenterLeaderboardSetMemberLocalization: Codable, Identifiable self.locale = locale self.name = name } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + locale = try container.decodeIfPresent(String.self, forKey: "locale") + name = try container.decodeIfPresent(String.self, forKey: "name") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(locale, forKey: "locale") + try container.encodeIfPresent(name, forKey: "name") + } } public struct Relationships: Codable { @@ -77,6 +81,18 @@ public struct GameCenterLeaderboardSetMemberLocalization: Codable, Identifiable self.gameCenterLeaderboardSet = gameCenterLeaderboardSet } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + gameCenterLeaderboard = try container.decodeIfPresent(GameCenterLeaderboard.self, forKey: "gameCenterLeaderboard") + gameCenterLeaderboardSet = try container.decodeIfPresent(GameCenterLeaderboardSet.self, forKey: "gameCenterLeaderboardSet") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(gameCenterLeaderboard, forKey: "gameCenterLeaderboard") + try container.encodeIfPresent(gameCenterLeaderboardSet, forKey: "gameCenterLeaderboardSet") + } + public struct GameCenterLeaderboard: Codable { @NullCodable public var data: Data? public var links: Links? @@ -89,20 +105,15 @@ public struct GameCenterLeaderboardSetMemberLocalization: Codable, Identifiable } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -114,22 +125,17 @@ public struct GameCenterLeaderboardSetMemberLocalization: Codable, Identifiable } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -145,20 +151,15 @@ public struct GameCenterLeaderboardSetMemberLocalization: Codable, Identifiable } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -175,20 +176,15 @@ public struct GameCenterLeaderboardSetMemberLocalization: Codable, Identifiable } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -200,22 +196,17 @@ public struct GameCenterLeaderboardSetMemberLocalization: Codable, Identifiable } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -231,20 +222,15 @@ public struct GameCenterLeaderboardSetMemberLocalization: Codable, Identifiable } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetMemberLocalizationCreateRequest.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetMemberLocalizationCreateRequest.swift index 1b90529fd..2dfacc565 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetMemberLocalizationCreateRequest.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetMemberLocalizationCreateRequest.swift @@ -15,6 +15,16 @@ public struct GameCenterLeaderboardSetMemberLocalizationCreateRequest: Codable, self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "gameCenterLeaderboardSetMemberLocalizations" } public var attributes: Attributes? @@ -28,25 +38,19 @@ public struct GameCenterLeaderboardSetMemberLocalizationCreateRequest: Codable, } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -59,6 +63,18 @@ public struct GameCenterLeaderboardSetMemberLocalizationCreateRequest: Codable, self.locale = locale self.name = name } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + locale = try container.decodeIfPresent(String.self, forKey: "locale") + name = try container.decodeIfPresent(String.self, forKey: "name") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(locale, forKey: "locale") + try container.encodeIfPresent(name, forKey: "name") + } } public struct Relationships: Codable { @@ -72,6 +88,18 @@ public struct GameCenterLeaderboardSetMemberLocalizationCreateRequest: Codable, self.gameCenterLeaderboardSet = gameCenterLeaderboardSet } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + gameCenterLeaderboard = try container.decode(GameCenterLeaderboard.self, forKey: "gameCenterLeaderboard") + gameCenterLeaderboardSet = try container.decode(GameCenterLeaderboardSet.self, forKey: "gameCenterLeaderboardSet") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(gameCenterLeaderboard, forKey: "gameCenterLeaderboard") + try container.encode(gameCenterLeaderboardSet, forKey: "gameCenterLeaderboardSet") + } + public struct GameCenterLeaderboard: Codable { public let data: Data @@ -79,6 +107,16 @@ public struct GameCenterLeaderboardSetMemberLocalizationCreateRequest: Codable, self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "gameCenterLeaderboards" } @@ -88,22 +126,17 @@ public struct GameCenterLeaderboardSetMemberLocalizationCreateRequest: Codable, } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -115,6 +148,16 @@ public struct GameCenterLeaderboardSetMemberLocalizationCreateRequest: Codable, self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "gameCenterLeaderboardSets" } @@ -124,22 +167,17 @@ public struct GameCenterLeaderboardSetMemberLocalizationCreateRequest: Codable, } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetMemberLocalizationResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetMemberLocalizationResponse.swift index 7b34077b5..397e08f0e 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetMemberLocalizationResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetMemberLocalizationResponse.swift @@ -22,6 +22,20 @@ public struct GameCenterLeaderboardSetMemberLocalizationResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(GameCenterLeaderboardSetMemberLocalization.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getGameCenterLeaderboard() -> GameCenterLeaderboard? { included?.compactMap { relationship -> GameCenterLeaderboard? in guard case let .gameCenterLeaderboard(gameCenterLeaderboard) = relationship else { return nil } @@ -59,9 +73,5 @@ public struct GameCenterLeaderboardSetMemberLocalizationResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetMemberLocalizationUpdateRequest.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetMemberLocalizationUpdateRequest.swift index 1b2ff15ad..21cd0721a 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetMemberLocalizationUpdateRequest.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetMemberLocalizationUpdateRequest.swift @@ -15,6 +15,16 @@ public struct GameCenterLeaderboardSetMemberLocalizationUpdateRequest: Codable, self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "gameCenterLeaderboardSetMemberLocalizations" } @@ -28,25 +38,19 @@ public struct GameCenterLeaderboardSetMemberLocalizationUpdateRequest: Codable, } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } public struct Attributes: Codable { @@ -55,6 +59,16 @@ public struct GameCenterLeaderboardSetMemberLocalizationUpdateRequest: Codable, public init(name: String? = nil) { self.name = name } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + name = try container.decodeIfPresent(String.self, forKey: "name") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(name, forKey: "name") + } } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetMemberLocalizationsResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetMemberLocalizationsResponse.swift index 36e9aa126..4829453bf 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetMemberLocalizationsResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetMemberLocalizationsResponse.swift @@ -27,6 +27,22 @@ public struct GameCenterLeaderboardSetMemberLocalizationsResponse: Codable, Page self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([GameCenterLeaderboardSetMemberLocalization].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getGameCenterLeaderboard(for gameCenterLeaderboardSetMemberLocalization: GameCenterLeaderboardSetMemberLocalization) -> GameCenterLeaderboard? { included?.compactMap { relationship -> GameCenterLeaderboard? in guard case let .gameCenterLeaderboard(gameCenterLeaderboard) = relationship else { return nil } @@ -64,9 +80,5 @@ public struct GameCenterLeaderboardSetMemberLocalizationsResponse: Codable, Page try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetRelease.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetRelease.swift index d056c33e3..12725d25f 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetRelease.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetRelease.swift @@ -27,31 +27,23 @@ public struct GameCenterLeaderboardSetRelease: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -60,6 +52,16 @@ public struct GameCenterLeaderboardSetRelease: Codable, Identifiable { public init(live: Bool? = nil) { self.live = live } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + live = try container.decodeIfPresent(Bool.self, forKey: "live") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(live, forKey: "live") + } } public struct Relationships: Codable { @@ -73,6 +75,18 @@ public struct GameCenterLeaderboardSetRelease: Codable, Identifiable { self.gameCenterLeaderboardSet = gameCenterLeaderboardSet } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + gameCenterDetail = try container.decodeIfPresent(GameCenterDetail.self, forKey: "gameCenterDetail") + gameCenterLeaderboardSet = try container.decodeIfPresent(GameCenterLeaderboardSet.self, forKey: "gameCenterLeaderboardSet") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(gameCenterDetail, forKey: "gameCenterDetail") + try container.encodeIfPresent(gameCenterLeaderboardSet, forKey: "gameCenterLeaderboardSet") + } + public struct GameCenterDetail: Codable { @NullCodable public var data: Data? public var links: Links? @@ -85,20 +99,15 @@ public struct GameCenterLeaderboardSetRelease: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -110,22 +119,17 @@ public struct GameCenterLeaderboardSetRelease: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -141,20 +145,15 @@ public struct GameCenterLeaderboardSetRelease: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -171,20 +170,15 @@ public struct GameCenterLeaderboardSetRelease: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -196,22 +190,17 @@ public struct GameCenterLeaderboardSetRelease: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -227,20 +216,15 @@ public struct GameCenterLeaderboardSetRelease: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetReleaseCreateRequest.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetReleaseCreateRequest.swift index 1a95b77e8..109fe70d7 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetReleaseCreateRequest.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetReleaseCreateRequest.swift @@ -15,6 +15,16 @@ public struct GameCenterLeaderboardSetReleaseCreateRequest: Codable, RequestBody self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "gameCenterLeaderboardSetReleases" } public let relationships: Relationships @@ -24,22 +34,17 @@ public struct GameCenterLeaderboardSetReleaseCreateRequest: Codable, RequestBody } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(relationships, forKey: "relationships") } public struct Relationships: Codable { @@ -53,6 +58,18 @@ public struct GameCenterLeaderboardSetReleaseCreateRequest: Codable, RequestBody self.gameCenterLeaderboardSet = gameCenterLeaderboardSet } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + gameCenterDetail = try container.decode(GameCenterDetail.self, forKey: "gameCenterDetail") + gameCenterLeaderboardSet = try container.decode(GameCenterLeaderboardSet.self, forKey: "gameCenterLeaderboardSet") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(gameCenterDetail, forKey: "gameCenterDetail") + try container.encode(gameCenterLeaderboardSet, forKey: "gameCenterLeaderboardSet") + } + public struct GameCenterDetail: Codable { public let data: Data @@ -60,6 +77,16 @@ public struct GameCenterLeaderboardSetReleaseCreateRequest: Codable, RequestBody self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "gameCenterDetails" } @@ -69,22 +96,17 @@ public struct GameCenterLeaderboardSetReleaseCreateRequest: Codable, RequestBody } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -96,6 +118,16 @@ public struct GameCenterLeaderboardSetReleaseCreateRequest: Codable, RequestBody self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "gameCenterLeaderboardSets" } @@ -105,22 +137,17 @@ public struct GameCenterLeaderboardSetReleaseCreateRequest: Codable, RequestBody } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetReleaseResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetReleaseResponse.swift index 3cb18d6c5..98af61d65 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetReleaseResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetReleaseResponse.swift @@ -22,6 +22,20 @@ public struct GameCenterLeaderboardSetReleaseResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(GameCenterLeaderboardSetRelease.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getGameCenterDetail() -> GameCenterDetail? { included?.compactMap { relationship -> GameCenterDetail? in guard case let .gameCenterDetail(gameCenterDetail) = relationship else { return nil } @@ -59,9 +73,5 @@ public struct GameCenterLeaderboardSetReleaseResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetReleasesResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetReleasesResponse.swift index 96aa8d48b..549b736dd 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetReleasesResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetReleasesResponse.swift @@ -27,6 +27,22 @@ public struct GameCenterLeaderboardSetReleasesResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([GameCenterLeaderboardSetRelease].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getGameCenterDetail(for gameCenterLeaderboardSetRelease: GameCenterLeaderboardSetRelease) -> GameCenterDetail? { included?.compactMap { relationship -> GameCenterDetail? in guard case let .gameCenterDetail(gameCenterDetail) = relationship else { return nil } @@ -64,9 +80,5 @@ public struct GameCenterLeaderboardSetReleasesResponse: Codable, PagedResponse { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetResponse.swift index 147dfa3b1..b2b8ba125 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetResponse.swift @@ -22,6 +22,20 @@ public struct GameCenterLeaderboardSetResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(GameCenterLeaderboardSet.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getGameCenterDetail() -> GameCenterDetail? { included?.compactMap { relationship -> GameCenterDetail? in guard case let .gameCenterDetail(gameCenterDetail) = relationship else { return nil } @@ -122,9 +136,5 @@ public struct GameCenterLeaderboardSetResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetUpdateRequest.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetUpdateRequest.swift index d71ed885b..5be36eec5 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetUpdateRequest.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetUpdateRequest.swift @@ -15,6 +15,16 @@ public struct GameCenterLeaderboardSetUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "gameCenterLeaderboardSets" } @@ -28,25 +38,19 @@ public struct GameCenterLeaderboardSetUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } public struct Attributes: Codable { @@ -55,6 +59,16 @@ public struct GameCenterLeaderboardSetUpdateRequest: Codable, RequestBody { public init(referenceName: String? = nil) { self.referenceName = referenceName } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + referenceName = try container.decodeIfPresent(String.self, forKey: "referenceName") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(referenceName, forKey: "referenceName") + } } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetsResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetsResponse.swift index 1e7030765..31672005f 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetsResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardSetsResponse.swift @@ -27,6 +27,22 @@ public struct GameCenterLeaderboardSetsResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([GameCenterLeaderboardSet].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getGameCenterDetail(for gameCenterLeaderboardSet: GameCenterLeaderboardSet) -> GameCenterDetail? { included?.compactMap { relationship -> GameCenterDetail? in guard case let .gameCenterDetail(gameCenterDetail) = relationship else { return nil } @@ -127,9 +143,5 @@ public struct GameCenterLeaderboardSetsResponse: Codable, PagedResponse { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardUpdateRequest.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardUpdateRequest.swift index 76d22fff9..5164b2690 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardUpdateRequest.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardUpdateRequest.swift @@ -15,6 +15,16 @@ public struct GameCenterLeaderboardUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "gameCenterLeaderboards" } @@ -28,25 +38,19 @@ public struct GameCenterLeaderboardUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } public struct Attributes: Codable { @@ -83,6 +87,34 @@ public struct GameCenterLeaderboardUpdateRequest: Codable, RequestBody { self.scoreSortType = scoreSortType self.submissionType = submissionType } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + archived = try container.decodeIfPresent(Bool.self, forKey: "archived") + defaultFormatter = try container.decodeIfPresent(GameCenterLeaderboardFormatter.self, forKey: "defaultFormatter") + recurrenceDuration = try container.decodeIfPresent(String.self, forKey: "recurrenceDuration") + recurrenceRule = try container.decodeIfPresent(String.self, forKey: "recurrenceRule") + recurrenceStartDate = try container.decodeIfPresent(Date.self, forKey: "recurrenceStartDate") + referenceName = try container.decodeIfPresent(String.self, forKey: "referenceName") + scoreRangeEnd = try container.decodeIfPresent(String.self, forKey: "scoreRangeEnd") + scoreRangeStart = try container.decodeIfPresent(String.self, forKey: "scoreRangeStart") + scoreSortType = try container.decodeIfPresent(GameCenterLeaderboard.Attributes.ScoreSortType.self, forKey: "scoreSortType") + submissionType = try container.decodeIfPresent(GameCenterLeaderboard.Attributes.SubmissionType.self, forKey: "submissionType") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(archived, forKey: "archived") + try container.encodeIfPresent(defaultFormatter, forKey: "defaultFormatter") + try container.encodeIfPresent(recurrenceDuration, forKey: "recurrenceDuration") + try container.encodeIfPresent(recurrenceRule, forKey: "recurrenceRule") + try container.encodeIfPresent(recurrenceStartDate, forKey: "recurrenceStartDate") + try container.encodeIfPresent(referenceName, forKey: "referenceName") + try container.encodeIfPresent(scoreRangeEnd, forKey: "scoreRangeEnd") + try container.encodeIfPresent(scoreRangeStart, forKey: "scoreRangeStart") + try container.encodeIfPresent(scoreSortType, forKey: "scoreSortType") + try container.encodeIfPresent(submissionType, forKey: "submissionType") + } } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardsResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardsResponse.swift index 0d4ec255b..befbbfd98 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardsResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterLeaderboardsResponse.swift @@ -27,6 +27,22 @@ public struct GameCenterLeaderboardsResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([GameCenterLeaderboard].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getGameCenterDetail(for gameCenterLeaderboard: GameCenterLeaderboard) -> GameCenterDetail? { included?.compactMap { relationship -> GameCenterDetail? in guard case let .gameCenterDetail(gameCenterDetail) = relationship else { return nil } @@ -127,9 +143,5 @@ public struct GameCenterLeaderboardsResponse: Codable, PagedResponse { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingAppRequestsV1MetricResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingAppRequestsV1MetricResponse.swift index 726dace96..48a1105d8 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingAppRequestsV1MetricResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingAppRequestsV1MetricResponse.swift @@ -22,6 +22,20 @@ public struct GameCenterMatchmakingAppRequestsV1MetricResponse: Codable, PagedRe self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + /** # GameCenterMatchmakingAppRequestsV1MetricResponse.Data The data structure in a response body for a match request. @@ -44,6 +58,20 @@ public struct GameCenterMatchmakingAppRequestsV1MetricResponse: Codable, PagedRe self.granularity = granularity } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + dataPoints = try container.decodeIfPresent(DataPoints.self, forKey: "dataPoints") + dimensions = try container.decodeIfPresent(Dimensions.self, forKey: "dimensions") + granularity = try container.decodeIfPresent(Granularity.self, forKey: "granularity") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(dataPoints, forKey: "dataPoints") + try container.encodeIfPresent(dimensions, forKey: "dimensions") + try container.encodeIfPresent(granularity, forKey: "granularity") + } + /** # GameCenterMatchmakingAppRequestsV1MetricResponse.Data.DataPoints The data properties in the response. @@ -67,6 +95,20 @@ public struct GameCenterMatchmakingAppRequestsV1MetricResponse: Codable, PagedRe self.values = values } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + end = try container.decodeIfPresent(Date.self, forKey: "end") + start = try container.decodeIfPresent(Date.self, forKey: "start") + values = try container.decodeIfPresent(Values.self, forKey: "values") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(end, forKey: "end") + try container.encodeIfPresent(start, forKey: "start") + try container.encodeIfPresent(values, forKey: "values") + } + /** # GameCenterMatchmakingAppRequestsV1MetricResponse.Data.DataPoints.Values The values of the data points. @@ -94,6 +136,22 @@ public struct GameCenterMatchmakingAppRequestsV1MetricResponse: Codable, PagedRe self.p50SecondsInQueue = p50SecondsInQueue self.p95SecondsInQueue = p95SecondsInQueue } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + averageSecondsInQueue = try container.decodeIfPresent(Double.self, forKey: "averageSecondsInQueue") + count = try container.decodeIfPresent(Int.self, forKey: "count") + p50SecondsInQueue = try container.decodeIfPresent(Double.self, forKey: "p50SecondsInQueue") + p95SecondsInQueue = try container.decodeIfPresent(Double.self, forKey: "p95SecondsInQueue") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(averageSecondsInQueue, forKey: "averageSecondsInQueue") + try container.encodeIfPresent(count, forKey: "count") + try container.encodeIfPresent(p50SecondsInQueue, forKey: "p50SecondsInQueue") + try container.encodeIfPresent(p95SecondsInQueue, forKey: "p95SecondsInQueue") + } } } @@ -111,6 +169,16 @@ public struct GameCenterMatchmakingAppRequestsV1MetricResponse: Codable, PagedRe self.result = result } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + result = try container.decodeIfPresent(Result.self, forKey: "result") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(result, forKey: "result") + } + /** # GameCenterMatchmakingAppRequestsV1MetricResponse.Data.Dimensions.Result The links to the details of the data. @@ -125,6 +193,16 @@ public struct GameCenterMatchmakingAppRequestsV1MetricResponse: Codable, PagedRe self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + links = try container.decodeIfPresent(Links.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(links, forKey: "links") + } + /** # GameCenterMatchmakingAppRequestsV1MetricResponse.Data.Dimensions.Result.Links The link representation of the results. @@ -139,6 +217,16 @@ public struct GameCenterMatchmakingAppRequestsV1MetricResponse: Codable, PagedRe public init(groupBy: String? = nil) { self.groupBy = groupBy } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + groupBy = try container.decodeIfPresent(String.self, forKey: "groupBy") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(groupBy, forKey: "groupBy") + } } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingBooleanRuleResultsV1MetricResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingBooleanRuleResultsV1MetricResponse.swift index 613e68dc0..5142cf8e5 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingBooleanRuleResultsV1MetricResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingBooleanRuleResultsV1MetricResponse.swift @@ -22,6 +22,20 @@ public struct GameCenterMatchmakingBooleanRuleResultsV1MetricResponse: Codable, self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + /** # GameCenterMatchmakingBooleanRuleResultsV1MetricResponse.Data The data structure in a response body for Boolean match request results. @@ -44,6 +58,20 @@ public struct GameCenterMatchmakingBooleanRuleResultsV1MetricResponse: Codable, self.granularity = granularity } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + dataPoints = try container.decodeIfPresent(DataPoints.self, forKey: "dataPoints") + dimensions = try container.decodeIfPresent(Dimensions.self, forKey: "dimensions") + granularity = try container.decodeIfPresent(Granularity.self, forKey: "granularity") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(dataPoints, forKey: "dataPoints") + try container.encodeIfPresent(dimensions, forKey: "dimensions") + try container.encodeIfPresent(granularity, forKey: "granularity") + } + /** # GameCenterMatchmakingBooleanRuleResultsV1MetricResponse.Data.DataPoints The key properties of the data in the response. @@ -67,6 +95,20 @@ public struct GameCenterMatchmakingBooleanRuleResultsV1MetricResponse: Codable, self.values = values } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + end = try container.decodeIfPresent(Date.self, forKey: "end") + start = try container.decodeIfPresent(Date.self, forKey: "start") + values = try container.decodeIfPresent(Values.self, forKey: "values") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(end, forKey: "end") + try container.encodeIfPresent(start, forKey: "start") + try container.encodeIfPresent(values, forKey: "values") + } + /** # GameCenterMatchmakingBooleanRuleResultsV1MetricResponse.Data.DataPoints.Values The values of the data points. @@ -81,6 +123,16 @@ public struct GameCenterMatchmakingBooleanRuleResultsV1MetricResponse: Codable, public init(count: Int? = nil) { self.count = count } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + count = try container.decodeIfPresent(Int.self, forKey: "count") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(count, forKey: "count") + } } } @@ -102,6 +154,18 @@ public struct GameCenterMatchmakingBooleanRuleResultsV1MetricResponse: Codable, self.result = result } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + gameCenterMatchmakingQueue = try container.decodeIfPresent(GameCenterMatchmakingQueue.self, forKey: "gameCenterMatchmakingQueue") + result = try container.decodeIfPresent(Result.self, forKey: "result") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(gameCenterMatchmakingQueue, forKey: "gameCenterMatchmakingQueue") + try container.encodeIfPresent(result, forKey: "result") + } + /** # GameCenterMatchmakingBooleanRuleResultsV1MetricResponse.Data.Dimensions.GameCenterMatchmakingQueue The details of the data about the queue. @@ -116,6 +180,16 @@ public struct GameCenterMatchmakingBooleanRuleResultsV1MetricResponse: Codable, self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + links = try container.decodeIfPresent(Links.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(links, forKey: "links") + } + /** # GameCenterMatchmakingBooleanRuleResultsV1MetricResponse.Data.Dimensions.GameCenterMatchmakingQueue.Links The link representations of the queue results. @@ -135,6 +209,18 @@ public struct GameCenterMatchmakingBooleanRuleResultsV1MetricResponse: Codable, self.groupBy = groupBy self.related = related } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + groupBy = try container.decodeIfPresent(String.self, forKey: "groupBy") + related = try container.decodeIfPresent(String.self, forKey: "related") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(groupBy, forKey: "groupBy") + try container.encodeIfPresent(related, forKey: "related") + } } } @@ -152,6 +238,16 @@ public struct GameCenterMatchmakingBooleanRuleResultsV1MetricResponse: Codable, self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + links = try container.decodeIfPresent(Links.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(links, forKey: "links") + } + /** # GameCenterMatchmakingBooleanRuleResultsV1MetricResponse.Data.Dimensions.Result.Links The link representation of the results. @@ -166,6 +262,16 @@ public struct GameCenterMatchmakingBooleanRuleResultsV1MetricResponse: Codable, public init(groupBy: String? = nil) { self.groupBy = groupBy } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + groupBy = try container.decodeIfPresent(String.self, forKey: "groupBy") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(groupBy, forKey: "groupBy") + } } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingNumberRuleResultsV1MetricResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingNumberRuleResultsV1MetricResponse.swift index 42e7aaa1b..6558f5fac 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingNumberRuleResultsV1MetricResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingNumberRuleResultsV1MetricResponse.swift @@ -22,6 +22,20 @@ public struct GameCenterMatchmakingNumberRuleResultsV1MetricResponse: Codable, P self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + /** # GameCenterMatchmakingNumberRuleResultsV1MetricResponse.Data The data structure in a response body for numeric rule results. @@ -44,6 +58,20 @@ public struct GameCenterMatchmakingNumberRuleResultsV1MetricResponse: Codable, P self.granularity = granularity } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + dataPoints = try container.decodeIfPresent(DataPoints.self, forKey: "dataPoints") + dimensions = try container.decodeIfPresent(Dimensions.self, forKey: "dimensions") + granularity = try container.decodeIfPresent(Granularity.self, forKey: "granularity") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(dataPoints, forKey: "dataPoints") + try container.encodeIfPresent(dimensions, forKey: "dimensions") + try container.encodeIfPresent(granularity, forKey: "granularity") + } + /** # GameCenterMatchmakingNumberRuleResultsV1MetricResponse.Data.DataPoints The key properties of the data in the response. @@ -67,6 +95,20 @@ public struct GameCenterMatchmakingNumberRuleResultsV1MetricResponse: Codable, P self.values = values } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + end = try container.decodeIfPresent(Date.self, forKey: "end") + start = try container.decodeIfPresent(Date.self, forKey: "start") + values = try container.decodeIfPresent(Values.self, forKey: "values") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(end, forKey: "end") + try container.encodeIfPresent(start, forKey: "start") + try container.encodeIfPresent(values, forKey: "values") + } + /** # GameCenterMatchmakingNumberRuleResultsV1MetricResponse.Data.DataPoints.Values The values of the data points. @@ -94,6 +136,22 @@ public struct GameCenterMatchmakingNumberRuleResultsV1MetricResponse: Codable, P self.p50Result = p50Result self.p95Result = p95Result } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + averageResult = try container.decodeIfPresent(Double.self, forKey: "averageResult") + count = try container.decodeIfPresent(Int.self, forKey: "count") + p50Result = try container.decodeIfPresent(Double.self, forKey: "p50Result") + p95Result = try container.decodeIfPresent(Double.self, forKey: "p95Result") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(averageResult, forKey: "averageResult") + try container.encodeIfPresent(count, forKey: "count") + try container.encodeIfPresent(p50Result, forKey: "p50Result") + try container.encodeIfPresent(p95Result, forKey: "p95Result") + } } } @@ -111,6 +169,16 @@ public struct GameCenterMatchmakingNumberRuleResultsV1MetricResponse: Codable, P self.gameCenterMatchmakingQueue = gameCenterMatchmakingQueue } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + gameCenterMatchmakingQueue = try container.decodeIfPresent(GameCenterMatchmakingQueue.self, forKey: "gameCenterMatchmakingQueue") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(gameCenterMatchmakingQueue, forKey: "gameCenterMatchmakingQueue") + } + /** # GameCenterMatchmakingNumberRuleResultsV1MetricResponse.Data.Dimensions.GameCenterMatchmakingQueue The details of the data about the queue. @@ -125,6 +193,16 @@ public struct GameCenterMatchmakingNumberRuleResultsV1MetricResponse: Codable, P self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + links = try container.decodeIfPresent(Links.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(links, forKey: "links") + } + /** # GameCenterMatchmakingNumberRuleResultsV1MetricResponse.Data.Dimensions.GameCenterMatchmakingQueue.Links The link representations of the queue results. @@ -144,6 +222,18 @@ public struct GameCenterMatchmakingNumberRuleResultsV1MetricResponse: Codable, P self.groupBy = groupBy self.related = related } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + groupBy = try container.decodeIfPresent(String.self, forKey: "groupBy") + related = try container.decodeIfPresent(String.self, forKey: "related") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(groupBy, forKey: "groupBy") + try container.encodeIfPresent(related, forKey: "related") + } } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingQueue.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingQueue.swift index b8c8d3b5b..e3d18b709 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingQueue.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingQueue.swift @@ -32,31 +32,23 @@ public struct GameCenterMatchmakingQueue: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -77,6 +69,18 @@ public struct GameCenterMatchmakingQueue: Codable, Identifiable { self.classicMatchmakingBundleIds = classicMatchmakingBundleIds self.referenceName = referenceName } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + classicMatchmakingBundleIds = try container.decodeIfPresent([String].self, forKey: "classicMatchmakingBundleIds") + referenceName = try container.decodeIfPresent(String.self, forKey: "referenceName") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(classicMatchmakingBundleIds, forKey: "classicMatchmakingBundleIds") + try container.encodeIfPresent(referenceName, forKey: "referenceName") + } } /** @@ -97,6 +101,18 @@ public struct GameCenterMatchmakingQueue: Codable, Identifiable { self.ruleSet = ruleSet } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + experimentRuleSet = try container.decodeIfPresent(ExperimentRuleSet.self, forKey: "experimentRuleSet") + ruleSet = try container.decodeIfPresent(RuleSet.self, forKey: "ruleSet") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(experimentRuleSet, forKey: "experimentRuleSet") + try container.encodeIfPresent(ruleSet, forKey: "ruleSet") + } + /** # GameCenterMatchmakingQueue.Relationships.ExperimentRuleSet An experimental rule set for testing this queue. @@ -116,20 +132,15 @@ public struct GameCenterMatchmakingQueue: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -150,22 +161,17 @@ public struct GameCenterMatchmakingQueue: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -190,20 +196,15 @@ public struct GameCenterMatchmakingQueue: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -227,20 +228,15 @@ public struct GameCenterMatchmakingQueue: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -261,22 +257,17 @@ public struct GameCenterMatchmakingQueue: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -301,20 +292,15 @@ public struct GameCenterMatchmakingQueue: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingQueueCreateRequest.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingQueueCreateRequest.swift index 231e4659d..d850bc8c2 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingQueueCreateRequest.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingQueueCreateRequest.swift @@ -16,6 +16,16 @@ public struct GameCenterMatchmakingQueueCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # GameCenterMatchmakingQueueCreateRequest.Data The data structure of the request body you use to create a queue. @@ -36,25 +46,19 @@ public struct GameCenterMatchmakingQueueCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } /** @@ -75,6 +79,18 @@ public struct GameCenterMatchmakingQueueCreateRequest: Codable, RequestBody { self.classicMatchmakingBundleIds = classicMatchmakingBundleIds self.referenceName = referenceName } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + classicMatchmakingBundleIds = try container.decodeIfPresent([String].self, forKey: "classicMatchmakingBundleIds") + referenceName = try container.decode(String.self, forKey: "referenceName") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(classicMatchmakingBundleIds, forKey: "classicMatchmakingBundleIds") + try container.encode(referenceName, forKey: "referenceName") + } } /** @@ -97,6 +113,18 @@ public struct GameCenterMatchmakingQueueCreateRequest: Codable, RequestBody { self.ruleSet = ruleSet } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + experimentRuleSet = try container.decodeIfPresent(ExperimentRuleSet.self, forKey: "experimentRuleSet") + ruleSet = try container.decode(RuleSet.self, forKey: "ruleSet") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(experimentRuleSet, forKey: "experimentRuleSet") + try container.encode(ruleSet, forKey: "ruleSet") + } + /** # GameCenterMatchmakingQueueCreateRequest.Data.Relationships.ExperimentRuleSet An experimental rule set for testing this queue. @@ -113,17 +141,13 @@ public struct GameCenterMatchmakingQueueCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } /** @@ -144,22 +168,17 @@ public struct GameCenterMatchmakingQueueCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -179,6 +198,16 @@ public struct GameCenterMatchmakingQueueCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # GameCenterMatchmakingQueueCreateRequest.Data.Relationships.RuleSet.Data The data structure of the request body for the rule set. @@ -197,22 +226,17 @@ public struct GameCenterMatchmakingQueueCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingQueueRequestsV1MetricResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingQueueRequestsV1MetricResponse.swift index 795c1cf9b..492388c7b 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingQueueRequestsV1MetricResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingQueueRequestsV1MetricResponse.swift @@ -22,6 +22,20 @@ public struct GameCenterMatchmakingQueueRequestsV1MetricResponse: Codable, Paged self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + /** # GameCenterMatchmakingQueueRequestsV1MetricResponse.Data The data structure in a response body for the match requests in a queue. @@ -44,6 +58,20 @@ public struct GameCenterMatchmakingQueueRequestsV1MetricResponse: Codable, Paged self.granularity = granularity } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + dataPoints = try container.decodeIfPresent(DataPoints.self, forKey: "dataPoints") + dimensions = try container.decodeIfPresent(Dimensions.self, forKey: "dimensions") + granularity = try container.decodeIfPresent(Granularity.self, forKey: "granularity") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(dataPoints, forKey: "dataPoints") + try container.encodeIfPresent(dimensions, forKey: "dimensions") + try container.encodeIfPresent(granularity, forKey: "granularity") + } + /** # GameCenterMatchmakingQueueRequestsV1MetricResponse.Data.DataPoints The key properties of the data in the response. @@ -67,6 +95,20 @@ public struct GameCenterMatchmakingQueueRequestsV1MetricResponse: Codable, Paged self.values = values } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + end = try container.decodeIfPresent(Date.self, forKey: "end") + start = try container.decodeIfPresent(Date.self, forKey: "start") + values = try container.decodeIfPresent(Values.self, forKey: "values") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(end, forKey: "end") + try container.encodeIfPresent(start, forKey: "start") + try container.encodeIfPresent(values, forKey: "values") + } + /** # GameCenterMatchmakingQueueRequestsV1MetricResponse.Data.DataPoints.Values The values of the data points. @@ -94,6 +136,22 @@ public struct GameCenterMatchmakingQueueRequestsV1MetricResponse: Codable, Paged self.p50SecondsInQueue = p50SecondsInQueue self.p95SecondsInQueue = p95SecondsInQueue } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + averageSecondsInQueue = try container.decodeIfPresent(Double.self, forKey: "averageSecondsInQueue") + count = try container.decodeIfPresent(Int.self, forKey: "count") + p50SecondsInQueue = try container.decodeIfPresent(Double.self, forKey: "p50SecondsInQueue") + p95SecondsInQueue = try container.decodeIfPresent(Double.self, forKey: "p95SecondsInQueue") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(averageSecondsInQueue, forKey: "averageSecondsInQueue") + try container.encodeIfPresent(count, forKey: "count") + try container.encodeIfPresent(p50SecondsInQueue, forKey: "p50SecondsInQueue") + try container.encodeIfPresent(p95SecondsInQueue, forKey: "p95SecondsInQueue") + } } } @@ -115,6 +173,18 @@ public struct GameCenterMatchmakingQueueRequestsV1MetricResponse: Codable, Paged self.result = result } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + gameCenterDetail = try container.decodeIfPresent(GameCenterDetail.self, forKey: "gameCenterDetail") + result = try container.decodeIfPresent(Result.self, forKey: "result") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(gameCenterDetail, forKey: "gameCenterDetail") + try container.encodeIfPresent(result, forKey: "result") + } + /** # GameCenterMatchmakingQueueRequestsV1MetricResponse.Data.Dimensions.GameCenterDetail The links to the details of the Game Center data. @@ -129,6 +199,16 @@ public struct GameCenterMatchmakingQueueRequestsV1MetricResponse: Codable, Paged self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + links = try container.decodeIfPresent(Links.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(links, forKey: "links") + } + /** # GameCenterMatchmakingQueueRequestsV1MetricResponse.Data.Dimensions.GameCenterDetail.Links The link representation of the results. @@ -148,6 +228,18 @@ public struct GameCenterMatchmakingQueueRequestsV1MetricResponse: Codable, Paged self.groupBy = groupBy self.related = related } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + groupBy = try container.decodeIfPresent(String.self, forKey: "groupBy") + related = try container.decodeIfPresent(String.self, forKey: "related") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(groupBy, forKey: "groupBy") + try container.encodeIfPresent(related, forKey: "related") + } } } @@ -165,6 +257,16 @@ public struct GameCenterMatchmakingQueueRequestsV1MetricResponse: Codable, Paged self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + links = try container.decodeIfPresent(Links.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(links, forKey: "links") + } + /** # GameCenterMatchmakingQueueRequestsV1MetricResponse.Data.Dimensions.Result.Links The link representation of the results. @@ -179,6 +281,16 @@ public struct GameCenterMatchmakingQueueRequestsV1MetricResponse: Codable, Paged public init(groupBy: String? = nil) { self.groupBy = groupBy } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + groupBy = try container.decodeIfPresent(String.self, forKey: "groupBy") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(groupBy, forKey: "groupBy") + } } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingQueueResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingQueueResponse.swift index 7404c94d5..98fc0bfe6 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingQueueResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingQueueResponse.swift @@ -24,4 +24,18 @@ public struct GameCenterMatchmakingQueueResponse: Codable { self.included = included self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(GameCenterMatchmakingQueue.self, forKey: "data") + included = try container.decodeIfPresent([GameCenterMatchmakingRuleSet].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingQueueSizesV1MetricResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingQueueSizesV1MetricResponse.swift index a0cb05180..9b6933641 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingQueueSizesV1MetricResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingQueueSizesV1MetricResponse.swift @@ -22,6 +22,20 @@ public struct GameCenterMatchmakingQueueSizesV1MetricResponse: Codable, PagedRes self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + /** # GameCenterMatchmakingQueueSizesV1MetricResponse.Data The data structure in a response body for queue sizes. @@ -41,6 +55,18 @@ public struct GameCenterMatchmakingQueueSizesV1MetricResponse: Codable, PagedRes self.granularity = granularity } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + dataPoints = try container.decodeIfPresent(DataPoints.self, forKey: "dataPoints") + granularity = try container.decodeIfPresent(Granularity.self, forKey: "granularity") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(dataPoints, forKey: "dataPoints") + try container.encodeIfPresent(granularity, forKey: "granularity") + } + /** # GameCenterMatchmakingQueueSizesV1MetricResponse.Data.DataPoints The key properties of the data in the response. @@ -64,6 +90,20 @@ public struct GameCenterMatchmakingQueueSizesV1MetricResponse: Codable, PagedRes self.values = values } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + end = try container.decodeIfPresent(Date.self, forKey: "end") + start = try container.decodeIfPresent(Date.self, forKey: "start") + values = try container.decodeIfPresent(Values.self, forKey: "values") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(end, forKey: "end") + try container.encodeIfPresent(start, forKey: "start") + try container.encodeIfPresent(values, forKey: "values") + } + /** # GameCenterMatchmakingQueueSizesV1MetricResponse.Data.DataPoints.Values The values of the data points. @@ -91,6 +131,22 @@ public struct GameCenterMatchmakingQueueSizesV1MetricResponse: Codable, PagedRes self.p50NumberOfRequests = p50NumberOfRequests self.p95NumberOfRequests = p95NumberOfRequests } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + averageNumberOfRequests = try container.decodeIfPresent(Double.self, forKey: "averageNumberOfRequests") + count = try container.decodeIfPresent(Int.self, forKey: "count") + p50NumberOfRequests = try container.decodeIfPresent(Double.self, forKey: "p50NumberOfRequests") + p95NumberOfRequests = try container.decodeIfPresent(Double.self, forKey: "p95NumberOfRequests") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(averageNumberOfRequests, forKey: "averageNumberOfRequests") + try container.encodeIfPresent(count, forKey: "count") + try container.encodeIfPresent(p50NumberOfRequests, forKey: "p50NumberOfRequests") + try container.encodeIfPresent(p95NumberOfRequests, forKey: "p95NumberOfRequests") + } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingQueueUpdateRequest.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingQueueUpdateRequest.swift index 13a9d7cf5..4a9b546aa 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingQueueUpdateRequest.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingQueueUpdateRequest.swift @@ -16,6 +16,16 @@ public struct GameCenterMatchmakingQueueUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # GameCenterMatchmakingQueueUpdateRequest.Data The data structure of the request body you use to modify a queue. @@ -41,28 +51,21 @@ public struct GameCenterMatchmakingQueueUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -78,6 +81,16 @@ public struct GameCenterMatchmakingQueueUpdateRequest: Codable, RequestBody { public init(classicMatchmakingBundleIds: [String]? = nil) { self.classicMatchmakingBundleIds = classicMatchmakingBundleIds } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + classicMatchmakingBundleIds = try container.decodeIfPresent([String].self, forKey: "classicMatchmakingBundleIds") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(classicMatchmakingBundleIds, forKey: "classicMatchmakingBundleIds") + } } /** @@ -100,6 +113,18 @@ public struct GameCenterMatchmakingQueueUpdateRequest: Codable, RequestBody { self.ruleSet = ruleSet } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + experimentRuleSet = try container.decodeIfPresent(ExperimentRuleSet.self, forKey: "experimentRuleSet") + ruleSet = try container.decodeIfPresent(RuleSet.self, forKey: "ruleSet") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(experimentRuleSet, forKey: "experimentRuleSet") + try container.encodeIfPresent(ruleSet, forKey: "ruleSet") + } + /** # GameCenterMatchmakingQueueUpdateRequest.Data.Relationships.ExperimentRuleSet The rule set for testing the queue. @@ -115,17 +140,13 @@ public struct GameCenterMatchmakingQueueUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } /** @@ -146,22 +167,17 @@ public struct GameCenterMatchmakingQueueUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -181,17 +197,13 @@ public struct GameCenterMatchmakingQueueUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } /** @@ -212,22 +224,17 @@ public struct GameCenterMatchmakingQueueUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingQueuesResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingQueuesResponse.swift index b7279033d..7b6e4a53a 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingQueuesResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingQueuesResponse.swift @@ -29,4 +29,20 @@ public struct GameCenterMatchmakingQueuesResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([GameCenterMatchmakingQueue].self, forKey: "data") + included = try container.decodeIfPresent([GameCenterMatchmakingRuleSet].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingRule.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingRule.swift index e0f0dd54e..27fe3917f 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingRule.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingRule.swift @@ -26,28 +26,21 @@ public struct GameCenterMatchmakingRule: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } /** @@ -82,6 +75,24 @@ public struct GameCenterMatchmakingRule: Codable, Identifiable { self.weight = weight } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + description = try container.decodeIfPresent(String.self, forKey: "description") + expression = try container.decodeIfPresent(String.self, forKey: "expression") + referenceName = try container.decodeIfPresent(String.self, forKey: "referenceName") + type = try container.decode(AttributesType.self, forKey: "type") + weight = try container.decodeIfPresent(Double.self, forKey: "weight") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(description, forKey: "description") + try container.encodeIfPresent(expression, forKey: "expression") + try container.encodeIfPresent(referenceName, forKey: "referenceName") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(weight, forKey: "weight") + } + public enum AttributesType: String, Codable, CaseIterable { case compatible = "COMPATIBLE" case distance = "DISTANCE" diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingRuleCreateRequest.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingRuleCreateRequest.swift index 3dce04743..e71b3cb16 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingRuleCreateRequest.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingRuleCreateRequest.swift @@ -16,6 +16,16 @@ public struct GameCenterMatchmakingRuleCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # GameCenterMatchmakingRuleCreateRequest.Data The data structure of the request body you use to create a rule. @@ -36,25 +46,19 @@ public struct GameCenterMatchmakingRuleCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } /** @@ -90,6 +94,24 @@ public struct GameCenterMatchmakingRuleCreateRequest: Codable, RequestBody { self.type = type self.weight = weight } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + description = try container.decode(String.self, forKey: "description") + expression = try container.decode(String.self, forKey: "expression") + referenceName = try container.decode(String.self, forKey: "referenceName") + type = try container.decode(GameCenterMatchmakingRule.Attributes.AttributesType.self, forKey: "type") + weight = try container.decodeIfPresent(Double.self, forKey: "weight") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(description, forKey: "description") + try container.encode(expression, forKey: "expression") + try container.encode(referenceName, forKey: "referenceName") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(weight, forKey: "weight") + } } /** @@ -106,6 +128,16 @@ public struct GameCenterMatchmakingRuleCreateRequest: Codable, RequestBody { self.ruleSet = ruleSet } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + ruleSet = try container.decode(RuleSet.self, forKey: "ruleSet") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(ruleSet, forKey: "ruleSet") + } + /** # GameCenterMatchmakingRuleCreateRequest.Data.Relationships.RuleSet The relationship to the rule set that you provide when you create a rule. @@ -120,6 +152,16 @@ public struct GameCenterMatchmakingRuleCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # GameCenterMatchmakingRuleCreateRequest.Data.Relationships.RuleSet.Data The type and ID for the rule set that you’re adding the rule to. @@ -138,22 +180,17 @@ public struct GameCenterMatchmakingRuleCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingRuleErrorsV1MetricResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingRuleErrorsV1MetricResponse.swift index 2e6e6f292..47b600b6b 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingRuleErrorsV1MetricResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingRuleErrorsV1MetricResponse.swift @@ -22,6 +22,20 @@ public struct GameCenterMatchmakingRuleErrorsV1MetricResponse: Codable, PagedRes self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + /** # GameCenterMatchmakingRuleErrorsV1MetricResponse.Data The data structure in a response body for the rule errors. @@ -44,6 +58,20 @@ public struct GameCenterMatchmakingRuleErrorsV1MetricResponse: Codable, PagedRes self.granularity = granularity } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + dataPoints = try container.decodeIfPresent(DataPoints.self, forKey: "dataPoints") + dimensions = try container.decodeIfPresent(Dimensions.self, forKey: "dimensions") + granularity = try container.decodeIfPresent(Granularity.self, forKey: "granularity") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(dataPoints, forKey: "dataPoints") + try container.encodeIfPresent(dimensions, forKey: "dimensions") + try container.encodeIfPresent(granularity, forKey: "granularity") + } + /** # GameCenterMatchmakingRuleErrorsV1MetricResponse.Data.DataPoints The key properties of the data in the response. @@ -67,6 +95,20 @@ public struct GameCenterMatchmakingRuleErrorsV1MetricResponse: Codable, PagedRes self.values = values } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + end = try container.decodeIfPresent(Date.self, forKey: "end") + start = try container.decodeIfPresent(Date.self, forKey: "start") + values = try container.decodeIfPresent(Values.self, forKey: "values") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(end, forKey: "end") + try container.encodeIfPresent(start, forKey: "start") + try container.encodeIfPresent(values, forKey: "values") + } + /** # GameCenterMatchmakingRuleErrorsV1MetricResponse.Data.DataPoints.Values The values of the data points. @@ -81,6 +123,16 @@ public struct GameCenterMatchmakingRuleErrorsV1MetricResponse: Codable, PagedRes public init(count: Int? = nil) { self.count = count } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + count = try container.decodeIfPresent(Int.self, forKey: "count") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(count, forKey: "count") + } } } @@ -98,6 +150,16 @@ public struct GameCenterMatchmakingRuleErrorsV1MetricResponse: Codable, PagedRes self.gameCenterMatchmakingQueue = gameCenterMatchmakingQueue } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + gameCenterMatchmakingQueue = try container.decodeIfPresent(GameCenterMatchmakingQueue.self, forKey: "gameCenterMatchmakingQueue") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(gameCenterMatchmakingQueue, forKey: "gameCenterMatchmakingQueue") + } + /** # GameCenterMatchmakingRuleErrorsV1MetricResponse.Data.Dimensions.GameCenterMatchmakingQueue The links to the details of the rule errors. @@ -112,6 +174,16 @@ public struct GameCenterMatchmakingRuleErrorsV1MetricResponse: Codable, PagedRes self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + links = try container.decodeIfPresent(Links.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(links, forKey: "links") + } + /** # GameCenterMatchmakingRuleErrorsV1MetricResponse.Data.Dimensions.GameCenterMatchmakingQueue.Links The link representation of the results. @@ -131,6 +203,18 @@ public struct GameCenterMatchmakingRuleErrorsV1MetricResponse: Codable, PagedRes self.groupBy = groupBy self.related = related } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + groupBy = try container.decodeIfPresent(String.self, forKey: "groupBy") + related = try container.decodeIfPresent(String.self, forKey: "related") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(groupBy, forKey: "groupBy") + try container.encodeIfPresent(related, forKey: "related") + } } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingRuleResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingRuleResponse.swift index 90349007c..81ee19180 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingRuleResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingRuleResponse.swift @@ -19,4 +19,16 @@ public struct GameCenterMatchmakingRuleResponse: Codable { self.data = data self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(GameCenterMatchmakingRule.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingRuleSet.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingRuleSet.swift index a5e859054..9f1ae3fcf 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingRuleSet.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingRuleSet.swift @@ -31,31 +31,23 @@ public struct GameCenterMatchmakingRuleSet: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -85,6 +77,22 @@ public struct GameCenterMatchmakingRuleSet: Codable, Identifiable { self.referenceName = referenceName self.ruleLanguageVersion = ruleLanguageVersion } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + maxPlayers = try container.decodeIfPresent(Int.self, forKey: "maxPlayers") + minPlayers = try container.decodeIfPresent(Int.self, forKey: "minPlayers") + referenceName = try container.decodeIfPresent(String.self, forKey: "referenceName") + ruleLanguageVersion = try container.decodeIfPresent(Int.self, forKey: "ruleLanguageVersion") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(maxPlayers, forKey: "maxPlayers") + try container.encodeIfPresent(minPlayers, forKey: "minPlayers") + try container.encodeIfPresent(referenceName, forKey: "referenceName") + try container.encodeIfPresent(ruleLanguageVersion, forKey: "ruleLanguageVersion") + } } /** @@ -111,6 +119,20 @@ public struct GameCenterMatchmakingRuleSet: Codable, Identifiable { self.teams = teams } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + matchmakingQueues = try container.decodeIfPresent(MatchmakingQueues.self, forKey: "matchmakingQueues") + rules = try container.decodeIfPresent(Rules.self, forKey: "rules") + teams = try container.decodeIfPresent(Teams.self, forKey: "teams") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(matchmakingQueues, forKey: "matchmakingQueues") + try container.encodeIfPresent(rules, forKey: "rules") + try container.encodeIfPresent(teams, forKey: "teams") + } + /** # GameCenterMatchmakingRuleSet.Relationships.MatchmakingQueues The queues related to the rule set. @@ -133,23 +155,17 @@ public struct GameCenterMatchmakingRuleSet: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } /** @@ -170,22 +186,17 @@ public struct GameCenterMatchmakingRuleSet: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -210,20 +221,15 @@ public struct GameCenterMatchmakingRuleSet: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -250,23 +256,17 @@ public struct GameCenterMatchmakingRuleSet: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } /** @@ -287,22 +287,17 @@ public struct GameCenterMatchmakingRuleSet: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -327,20 +322,15 @@ public struct GameCenterMatchmakingRuleSet: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -367,23 +357,17 @@ public struct GameCenterMatchmakingRuleSet: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } /** @@ -404,22 +388,17 @@ public struct GameCenterMatchmakingRuleSet: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -435,20 +414,15 @@ public struct GameCenterMatchmakingRuleSet: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingRuleSetCreateRequest.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingRuleSetCreateRequest.swift index ad9079b69..d52a9d073 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingRuleSetCreateRequest.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingRuleSetCreateRequest.swift @@ -16,6 +16,16 @@ public struct GameCenterMatchmakingRuleSetCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # GameCenterMatchmakingRuleSetCreateRequest.Data The data structure of the request body you use to create a rule set. @@ -32,22 +42,17 @@ public struct GameCenterMatchmakingRuleSetCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") } /** @@ -80,6 +85,22 @@ public struct GameCenterMatchmakingRuleSetCreateRequest: Codable, RequestBody { self.referenceName = referenceName self.ruleLanguageVersion = ruleLanguageVersion } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + maxPlayers = try container.decode(Int.self, forKey: "maxPlayers") + minPlayers = try container.decode(Int.self, forKey: "minPlayers") + referenceName = try container.decode(String.self, forKey: "referenceName") + ruleLanguageVersion = try container.decode(Int.self, forKey: "ruleLanguageVersion") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(maxPlayers, forKey: "maxPlayers") + try container.encode(minPlayers, forKey: "minPlayers") + try container.encode(referenceName, forKey: "referenceName") + try container.encode(ruleLanguageVersion, forKey: "ruleLanguageVersion") + } } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingRuleSetResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingRuleSetResponse.swift index 33e62465c..c6d918262 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingRuleSetResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingRuleSetResponse.swift @@ -24,6 +24,20 @@ public struct GameCenterMatchmakingRuleSetResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(GameCenterMatchmakingRuleSet.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getMatchmakingQueues() -> [GameCenterMatchmakingQueue] { guard let matchmakingQueueIds = data.relationships?.matchmakingQueues?.data?.map(\.id), let matchmakingQueues = included?.compactMap({ relationship -> GameCenterMatchmakingQueue? in @@ -88,9 +102,5 @@ public struct GameCenterMatchmakingRuleSetResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingRuleSetTest.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingRuleSetTest.swift index 89f9874ae..5a3dc5e9a 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingRuleSetTest.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingRuleSetTest.swift @@ -28,28 +28,21 @@ public struct GameCenterMatchmakingRuleSetTest: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } /** @@ -66,6 +59,16 @@ public struct GameCenterMatchmakingRuleSetTest: Codable, Identifiable { self.matchmakingResults = matchmakingResults } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + matchmakingResults = try container.decodeIfPresent([MatchmakingResults].self, forKey: "matchmakingResults") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(matchmakingResults, forKey: "matchmakingResults") + } + /** # GameCenterMatchmakingRuleSetTest.Attributes.MatchmakingResults The data structure representing the results of a match request. @@ -85,6 +88,18 @@ public struct GameCenterMatchmakingRuleSetTest: Codable, Identifiable { self.requestName = requestName self.teamAssignments = teamAssignments } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + requestName = try container.decodeIfPresent(String.self, forKey: "requestName") + teamAssignments = try container.decodeIfPresent([GameCenterMatchmakingTeamAssignment].self, forKey: "teamAssignments") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(requestName, forKey: "requestName") + try container.encodeIfPresent(teamAssignments, forKey: "teamAssignments") + } } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingRuleSetTestCreateRequest.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingRuleSetTestCreateRequest.swift index a29bb6fa7..b0f71e98a 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingRuleSetTestCreateRequest.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingRuleSetTestCreateRequest.swift @@ -21,6 +21,18 @@ public struct GameCenterMatchmakingRuleSetTestCreateRequest: Codable, RequestBod self.included = included } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + } + /** # GameCenterMatchmakingRuleSetTestCreateRequest.Data The data structure of the request body for testing a rule set. @@ -37,22 +49,17 @@ public struct GameCenterMatchmakingRuleSetTestCreateRequest: Codable, RequestBod } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(relationships, forKey: "relationships") } /** @@ -73,6 +80,18 @@ public struct GameCenterMatchmakingRuleSetTestCreateRequest: Codable, RequestBod self.matchmakingRuleSet = matchmakingRuleSet } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + matchmakingRequests = try container.decode(MatchmakingRequests.self, forKey: "matchmakingRequests") + matchmakingRuleSet = try container.decode(MatchmakingRuleSet.self, forKey: "matchmakingRuleSet") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(matchmakingRequests, forKey: "matchmakingRequests") + try container.encode(matchmakingRuleSet, forKey: "matchmakingRuleSet") + } + /** # GameCenterMatchmakingRuleSetTestCreateRequest.Data.Relationships.MatchmakingRequests The data structure representing the sample match requests. @@ -87,6 +106,16 @@ public struct GameCenterMatchmakingRuleSetTestCreateRequest: Codable, RequestBod self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # GameCenterMatchmakingRuleSetTestCreateRequest.Data.Relationships.MatchmakingRequests.Data The resource object for a match request. @@ -105,22 +134,17 @@ public struct GameCenterMatchmakingRuleSetTestCreateRequest: Codable, RequestBod } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -139,6 +163,16 @@ public struct GameCenterMatchmakingRuleSetTestCreateRequest: Codable, RequestBod self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # GameCenterMatchmakingRuleSetTestCreateRequest.Data.Relationships.MatchmakingRuleSet.Data A resource object for a rule set. @@ -157,22 +191,17 @@ public struct GameCenterMatchmakingRuleSetTestCreateRequest: Codable, RequestBod } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -202,9 +231,5 @@ public struct GameCenterMatchmakingRuleSetTestCreateRequest: Codable, RequestBod try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingRuleSetTestResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingRuleSetTestResponse.swift index 823784fd1..091e82429 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingRuleSetTestResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingRuleSetTestResponse.swift @@ -18,4 +18,16 @@ public struct GameCenterMatchmakingRuleSetTestResponse: Codable { self.data = data self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(GameCenterMatchmakingRuleSetTest.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingRuleSetUpdateRequest.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingRuleSetUpdateRequest.swift index 2cd0db19a..4cb26eb13 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingRuleSetUpdateRequest.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingRuleSetUpdateRequest.swift @@ -16,6 +16,16 @@ public struct GameCenterMatchmakingRuleSetUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # GameCenterMatchmakingRuleSetUpdateRequest.Data The data structure of the request body you use to modify a rule set. @@ -38,25 +48,19 @@ public struct GameCenterMatchmakingRuleSetUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } /** @@ -78,6 +82,18 @@ public struct GameCenterMatchmakingRuleSetUpdateRequest: Codable, RequestBody { self.maxPlayers = maxPlayers self.minPlayers = minPlayers } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + maxPlayers = try container.decodeIfPresent(Int.self, forKey: "maxPlayers") + minPlayers = try container.decodeIfPresent(Int.self, forKey: "minPlayers") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(maxPlayers, forKey: "maxPlayers") + try container.encodeIfPresent(minPlayers, forKey: "minPlayers") + } } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingRuleSetsResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingRuleSetsResponse.swift index e554517df..0a9c6f629 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingRuleSetsResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingRuleSetsResponse.swift @@ -29,6 +29,22 @@ public struct GameCenterMatchmakingRuleSetsResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([GameCenterMatchmakingRuleSet].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getMatchmakingQueues(for gameCenterMatchmakingRuleSet: GameCenterMatchmakingRuleSet) -> [GameCenterMatchmakingQueue] { guard let matchmakingQueueIds = gameCenterMatchmakingRuleSet.relationships?.matchmakingQueues?.data?.map(\.id), let matchmakingQueues = included?.compactMap({ relationship -> GameCenterMatchmakingQueue? in @@ -93,9 +109,5 @@ public struct GameCenterMatchmakingRuleSetsResponse: Codable, PagedResponse { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingRuleUpdateRequest.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingRuleUpdateRequest.swift index 5e60b932c..be171f40c 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingRuleUpdateRequest.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingRuleUpdateRequest.swift @@ -16,6 +16,16 @@ public struct GameCenterMatchmakingRuleUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # GameCenterMatchmakingRuleUpdateRequest.Data The data structure of the request body you use to modify a rule. @@ -37,25 +47,19 @@ public struct GameCenterMatchmakingRuleUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } /** @@ -81,6 +85,20 @@ public struct GameCenterMatchmakingRuleUpdateRequest: Codable, RequestBody { self.expression = expression self.weight = weight } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + description = try container.decodeIfPresent(String.self, forKey: "description") + expression = try container.decodeIfPresent(String.self, forKey: "expression") + weight = try container.decodeIfPresent(Double.self, forKey: "weight") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(description, forKey: "description") + try container.encodeIfPresent(expression, forKey: "expression") + try container.encodeIfPresent(weight, forKey: "weight") + } } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingRulesResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingRulesResponse.swift index 86323a062..8efd3ed1b 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingRulesResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingRulesResponse.swift @@ -24,4 +24,18 @@ public struct GameCenterMatchmakingRulesResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([GameCenterMatchmakingRule].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingSessionsV1MetricResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingSessionsV1MetricResponse.swift index a8ce2d1dc..380bb00ea 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingSessionsV1MetricResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingSessionsV1MetricResponse.swift @@ -23,6 +23,20 @@ public struct GameCenterMatchmakingSessionsV1MetricResponse: Codable, PagedRespo self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + /** # GameCenterMatchmakingSessionsV1MetricResponse.Data The data structure for the results of a successful matchmaking session. @@ -42,6 +56,18 @@ public struct GameCenterMatchmakingSessionsV1MetricResponse: Codable, PagedRespo self.granularity = granularity } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + dataPoints = try container.decodeIfPresent(DataPoints.self, forKey: "dataPoints") + granularity = try container.decodeIfPresent(Granularity.self, forKey: "granularity") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(dataPoints, forKey: "dataPoints") + try container.encodeIfPresent(granularity, forKey: "granularity") + } + public struct DataPoints: Codable { public var end: Date? public var start: Date? @@ -56,6 +82,20 @@ public struct GameCenterMatchmakingSessionsV1MetricResponse: Codable, PagedRespo self.values = values } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + end = try container.decodeIfPresent(Date.self, forKey: "end") + start = try container.decodeIfPresent(Date.self, forKey: "start") + values = try container.decodeIfPresent(Values.self, forKey: "values") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(end, forKey: "end") + try container.encodeIfPresent(start, forKey: "start") + try container.encodeIfPresent(values, forKey: "values") + } + /** # GameCenterMatchmakingSessionsV1MetricResponse.Data.DataPoints.Values The data values in the response per session. @@ -83,6 +123,22 @@ public struct GameCenterMatchmakingSessionsV1MetricResponse: Codable, PagedRespo self.p50PlayerCount = p50PlayerCount self.p95PlayerCount = p95PlayerCount } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + averagePlayerCount = try container.decodeIfPresent(Double.self, forKey: "averagePlayerCount") + count = try container.decodeIfPresent(Int.self, forKey: "count") + p50PlayerCount = try container.decodeIfPresent(Double.self, forKey: "p50PlayerCount") + p95PlayerCount = try container.decodeIfPresent(Double.self, forKey: "p95PlayerCount") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(averagePlayerCount, forKey: "averagePlayerCount") + try container.encodeIfPresent(count, forKey: "count") + try container.encodeIfPresent(p50PlayerCount, forKey: "p50PlayerCount") + try container.encodeIfPresent(p95PlayerCount, forKey: "p95PlayerCount") + } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingTeam.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingTeam.swift index a0a5a11ed..a0a4d76f0 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingTeam.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingTeam.swift @@ -28,28 +28,21 @@ public struct GameCenterMatchmakingTeam: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } /** @@ -75,5 +68,19 @@ public struct GameCenterMatchmakingTeam: Codable, Identifiable { self.minPlayers = minPlayers self.referenceName = referenceName } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + maxPlayers = try container.decodeIfPresent(Int.self, forKey: "maxPlayers") + minPlayers = try container.decodeIfPresent(Int.self, forKey: "minPlayers") + referenceName = try container.decodeIfPresent(String.self, forKey: "referenceName") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(maxPlayers, forKey: "maxPlayers") + try container.encodeIfPresent(minPlayers, forKey: "minPlayers") + try container.encodeIfPresent(referenceName, forKey: "referenceName") + } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingTeamAssignment.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingTeamAssignment.swift index db5f3c366..5fec1453f 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingTeamAssignment.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingTeamAssignment.swift @@ -20,4 +20,16 @@ public struct GameCenterMatchmakingTeamAssignment: Codable { self.playerId = playerId self.team = team } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + playerId = try container.decodeIfPresent(String.self, forKey: "playerId") + team = try container.decodeIfPresent(String.self, forKey: "team") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(playerId, forKey: "playerId") + try container.encodeIfPresent(team, forKey: "team") + } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingTeamCreateRequest.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingTeamCreateRequest.swift index d2a6acc93..aa40cadb6 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingTeamCreateRequest.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingTeamCreateRequest.swift @@ -15,6 +15,16 @@ public struct GameCenterMatchmakingTeamCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # GameCenterMatchmakingTeamCreateRequest.Data The data structure of the request body you use to create a team. @@ -35,25 +45,19 @@ public struct GameCenterMatchmakingTeamCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } /** @@ -79,6 +83,20 @@ public struct GameCenterMatchmakingTeamCreateRequest: Codable, RequestBody { self.minPlayers = minPlayers self.referenceName = referenceName } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + maxPlayers = try container.decode(Int.self, forKey: "maxPlayers") + minPlayers = try container.decode(Int.self, forKey: "minPlayers") + referenceName = try container.decode(String.self, forKey: "referenceName") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(maxPlayers, forKey: "maxPlayers") + try container.encode(minPlayers, forKey: "minPlayers") + try container.encode(referenceName, forKey: "referenceName") + } } /** @@ -95,6 +113,16 @@ public struct GameCenterMatchmakingTeamCreateRequest: Codable, RequestBody { self.ruleSet = ruleSet } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + ruleSet = try container.decode(RuleSet.self, forKey: "ruleSet") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(ruleSet, forKey: "ruleSet") + } + /** # GameCenterMatchmakingTeamCreateRequest.Data.Relationships.RuleSet The relationship to the rule set that you provide when you create a team. @@ -109,6 +137,16 @@ public struct GameCenterMatchmakingTeamCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # GameCenterMatchmakingTeamCreateRequest.Data.Relationships.RuleSet.Data The type and ID for the rule set that you’re adding the team to. @@ -127,22 +165,17 @@ public struct GameCenterMatchmakingTeamCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingTeamResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingTeamResponse.swift index 296d3875d..312c232af 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingTeamResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingTeamResponse.swift @@ -20,4 +20,16 @@ public struct GameCenterMatchmakingTeamResponse: Codable { self.data = data self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(GameCenterMatchmakingTeam.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingTeamUpdateRequest.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingTeamUpdateRequest.swift index f461a3eff..3ec9ff044 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingTeamUpdateRequest.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingTeamUpdateRequest.swift @@ -16,6 +16,16 @@ public struct GameCenterMatchmakingTeamUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # GameCenterMatchmakingTeamUpdateRequest.Data The data structure of the request body you use to modify a team. @@ -38,25 +48,19 @@ public struct GameCenterMatchmakingTeamUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } /** @@ -78,6 +82,18 @@ public struct GameCenterMatchmakingTeamUpdateRequest: Codable, RequestBody { self.maxPlayers = maxPlayers self.minPlayers = minPlayers } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + maxPlayers = try container.decodeIfPresent(Int.self, forKey: "maxPlayers") + minPlayers = try container.decodeIfPresent(Int.self, forKey: "minPlayers") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(maxPlayers, forKey: "maxPlayers") + try container.encodeIfPresent(minPlayers, forKey: "minPlayers") + } } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingTeamsResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingTeamsResponse.swift index 276cfc704..10e801eac 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingTeamsResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingTeamsResponse.swift @@ -25,4 +25,18 @@ public struct GameCenterMatchmakingTeamsResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([GameCenterMatchmakingTeam].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingTestPlayerPropertyInlineCreate.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingTestPlayerPropertyInlineCreate.swift index 36a029c47..03f3e7dc9 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingTestPlayerPropertyInlineCreate.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingTestPlayerPropertyInlineCreate.swift @@ -24,25 +24,19 @@ public struct GameCenterMatchmakingTestPlayerPropertyInlineCreate: Codable, Iden } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decodeIfPresent(String.self, forKey: .id) - attributes = try container.decode(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decodeIfPresent(String.self, forKey: "id") + attributes = try container.decode(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") } /** @@ -64,5 +58,17 @@ public struct GameCenterMatchmakingTestPlayerPropertyInlineCreate: Codable, Iden self.playerId = playerId self.properties = properties } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + playerId = try container.decode(String.self, forKey: "playerId") + properties = try container.decodeIfPresent([Property].self, forKey: "properties") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(playerId, forKey: "playerId") + try container.encodeIfPresent(properties, forKey: "properties") + } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingTestRequestInlineCreate.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingTestRequestInlineCreate.swift index e3cecf599..b2c9e0d03 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingTestRequestInlineCreate.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterMatchmakingTestRequestInlineCreate.swift @@ -28,28 +28,21 @@ public struct GameCenterMatchmakingTestRequestInlineCreate: Codable, Identifiabl } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decodeIfPresent(String.self, forKey: .id) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decodeIfPresent(String.self, forKey: "id") + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -104,6 +97,34 @@ public struct GameCenterMatchmakingTestRequestInlineCreate: Codable, Identifiabl self.secondsInQueue = secondsInQueue } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appVersion = try container.decode(String.self, forKey: "appVersion") + bundleId = try container.decode(String.self, forKey: "bundleId") + locale = try container.decodeIfPresent(Locale.self, forKey: "locale") + location = try container.decodeIfPresent(Location.self, forKey: "location") + maxPlayers = try container.decodeIfPresent(Int.self, forKey: "maxPlayers") + minPlayers = try container.decodeIfPresent(Int.self, forKey: "minPlayers") + platform = try container.decode(Platform.self, forKey: "platform") + playerCount = try container.decodeIfPresent(Int.self, forKey: "playerCount") + requestName = try container.decode(String.self, forKey: "requestName") + secondsInQueue = try container.decode(Int.self, forKey: "secondsInQueue") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(appVersion, forKey: "appVersion") + try container.encode(bundleId, forKey: "bundleId") + try container.encodeIfPresent(locale, forKey: "locale") + try container.encodeIfPresent(location, forKey: "location") + try container.encodeIfPresent(maxPlayers, forKey: "maxPlayers") + try container.encodeIfPresent(minPlayers, forKey: "minPlayers") + try container.encode(platform, forKey: "platform") + try container.encodeIfPresent(playerCount, forKey: "playerCount") + try container.encode(requestName, forKey: "requestName") + try container.encode(secondsInQueue, forKey: "secondsInQueue") + } + public enum Locale: String, Codable, CaseIterable { case AR_SA = "AR-SA" case CA_ES = "CA-ES" @@ -161,6 +182,16 @@ public struct GameCenterMatchmakingTestRequestInlineCreate: Codable, Identifiabl self.matchmakingPlayerProperties = matchmakingPlayerProperties } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + matchmakingPlayerProperties = try container.decodeIfPresent(MatchmakingPlayerProperties.self, forKey: "matchmakingPlayerProperties") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(matchmakingPlayerProperties, forKey: "matchmakingPlayerProperties") + } + /** # GameCenterMatchmakingTestRequestInlineCreate.Relationships.MatchmakingPlayerProperties A resource object for the game-specific properties for a match request. @@ -176,17 +207,13 @@ public struct GameCenterMatchmakingTestRequestInlineCreate: Codable, Identifiabl } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } /** @@ -207,22 +234,17 @@ public struct GameCenterMatchmakingTestRequestInlineCreate: Codable, Identifiabl } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterPlayerAchievementSubmission.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterPlayerAchievementSubmission.swift index f2fa902ff..ace30f105 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterPlayerAchievementSubmission.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterPlayerAchievementSubmission.swift @@ -17,28 +17,21 @@ public struct GameCenterPlayerAchievementSubmission: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } public struct Attributes: Codable { @@ -63,5 +56,25 @@ public struct GameCenterPlayerAchievementSubmission: Codable, Identifiable { self.submittedDate = submittedDate self.vendorIdentifier = vendorIdentifier } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + bundleId = try container.decodeIfPresent(String.self, forKey: "bundleId") + challengeIds = try container.decodeIfPresent([String].self, forKey: "challengeIds") + percentageAchieved = try container.decodeIfPresent(Int.self, forKey: "percentageAchieved") + scopedPlayerId = try container.decodeIfPresent(String.self, forKey: "scopedPlayerId") + submittedDate = try container.decodeIfPresent(Date.self, forKey: "submittedDate") + vendorIdentifier = try container.decodeIfPresent(String.self, forKey: "vendorIdentifier") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(bundleId, forKey: "bundleId") + try container.encodeIfPresent(challengeIds, forKey: "challengeIds") + try container.encodeIfPresent(percentageAchieved, forKey: "percentageAchieved") + try container.encodeIfPresent(scopedPlayerId, forKey: "scopedPlayerId") + try container.encodeIfPresent(submittedDate, forKey: "submittedDate") + try container.encodeIfPresent(vendorIdentifier, forKey: "vendorIdentifier") + } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterPlayerAchievementSubmissionCreateRequest.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterPlayerAchievementSubmissionCreateRequest.swift index 36eb97851..6af999466 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterPlayerAchievementSubmissionCreateRequest.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterPlayerAchievementSubmissionCreateRequest.swift @@ -15,6 +15,16 @@ public struct GameCenterPlayerAchievementSubmissionCreateRequest: Codable, Reque self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "gameCenterPlayerAchievementSubmissions" } public let attributes: Attributes @@ -24,22 +34,17 @@ public struct GameCenterPlayerAchievementSubmissionCreateRequest: Codable, Reque } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") } public struct Attributes: Codable { @@ -64,6 +69,26 @@ public struct GameCenterPlayerAchievementSubmissionCreateRequest: Codable, Reque self.submittedDate = submittedDate self.vendorIdentifier = vendorIdentifier } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + bundleId = try container.decode(String.self, forKey: "bundleId") + challengeIds = try container.decodeIfPresent([String].self, forKey: "challengeIds") + percentageAchieved = try container.decode(Int.self, forKey: "percentageAchieved") + scopedPlayerId = try container.decode(String.self, forKey: "scopedPlayerId") + submittedDate = try container.decodeIfPresent(Date.self, forKey: "submittedDate") + vendorIdentifier = try container.decode(String.self, forKey: "vendorIdentifier") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(bundleId, forKey: "bundleId") + try container.encodeIfPresent(challengeIds, forKey: "challengeIds") + try container.encode(percentageAchieved, forKey: "percentageAchieved") + try container.encode(scopedPlayerId, forKey: "scopedPlayerId") + try container.encodeIfPresent(submittedDate, forKey: "submittedDate") + try container.encode(vendorIdentifier, forKey: "vendorIdentifier") + } } } } diff --git a/Sources/Bagbutik-Models/GameCenter/GameCenterPlayerAchievementSubmissionResponse.swift b/Sources/Bagbutik-Models/GameCenter/GameCenterPlayerAchievementSubmissionResponse.swift index e60171717..d814bd369 100644 --- a/Sources/Bagbutik-Models/GameCenter/GameCenterPlayerAchievementSubmissionResponse.swift +++ b/Sources/Bagbutik-Models/GameCenter/GameCenterPlayerAchievementSubmissionResponse.swift @@ -18,4 +18,16 @@ public struct GameCenterPlayerAchievementSubmissionResponse: Codable { self.data = data self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(GameCenterPlayerAchievementSubmission.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/GameCenter/Location.swift b/Sources/Bagbutik-Models/GameCenter/Location.swift index 36b169335..cc78f969e 100644 --- a/Sources/Bagbutik-Models/GameCenter/Location.swift +++ b/Sources/Bagbutik-Models/GameCenter/Location.swift @@ -20,4 +20,16 @@ public struct Location: Codable { self.latitude = latitude self.longitude = longitude } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + latitude = try container.decodeIfPresent(Double.self, forKey: "latitude") + longitude = try container.decodeIfPresent(Double.self, forKey: "longitude") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(latitude, forKey: "latitude") + try container.encodeIfPresent(longitude, forKey: "longitude") + } } diff --git a/Sources/Bagbutik-Models/GameCenter/Property.swift b/Sources/Bagbutik-Models/GameCenter/Property.swift index 85c60feec..49c5adb31 100644 --- a/Sources/Bagbutik-Models/GameCenter/Property.swift +++ b/Sources/Bagbutik-Models/GameCenter/Property.swift @@ -20,4 +20,16 @@ public struct Property: Codable { self.key = key self.value = value } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + key = try container.decodeIfPresent(String.self, forKey: "key") + value = try container.decodeIfPresent(String.self, forKey: "value") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(key, forKey: "key") + try container.encodeIfPresent(value, forKey: "value") + } } diff --git a/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionDomain.swift b/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionDomain.swift index f459b5582..a7ef47a58 100644 --- a/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionDomain.swift +++ b/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionDomain.swift @@ -24,28 +24,21 @@ public struct AlternativeDistributionDomain: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } /** @@ -68,5 +61,19 @@ public struct AlternativeDistributionDomain: Codable, Identifiable { self.domain = domain self.referenceName = referenceName } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + createdDate = try container.decodeIfPresent(Date.self, forKey: "createdDate") + domain = try container.decodeIfPresent(String.self, forKey: "domain") + referenceName = try container.decodeIfPresent(String.self, forKey: "referenceName") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(createdDate, forKey: "createdDate") + try container.encodeIfPresent(domain, forKey: "domain") + try container.encodeIfPresent(referenceName, forKey: "referenceName") + } } } diff --git a/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionDomainCreateRequest.swift b/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionDomainCreateRequest.swift index 4ac871484..30d2db5ba 100644 --- a/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionDomainCreateRequest.swift +++ b/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionDomainCreateRequest.swift @@ -15,6 +15,16 @@ public struct AlternativeDistributionDomainCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "alternativeDistributionDomains" } public let attributes: Attributes @@ -24,22 +34,17 @@ public struct AlternativeDistributionDomainCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") } /** @@ -59,6 +64,18 @@ public struct AlternativeDistributionDomainCreateRequest: Codable, RequestBody { self.domain = domain self.referenceName = referenceName } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + domain = try container.decode(String.self, forKey: "domain") + referenceName = try container.decode(String.self, forKey: "referenceName") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(domain, forKey: "domain") + try container.encode(referenceName, forKey: "referenceName") + } } } } diff --git a/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionDomainResponse.swift b/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionDomainResponse.swift index a8c56c467..467876ff7 100644 --- a/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionDomainResponse.swift +++ b/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionDomainResponse.swift @@ -18,4 +18,16 @@ public struct AlternativeDistributionDomainResponse: Codable { self.data = data self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AlternativeDistributionDomain.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionDomainsResponse.swift b/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionDomainsResponse.swift index b11868926..6eee37646 100644 --- a/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionDomainsResponse.swift +++ b/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionDomainsResponse.swift @@ -23,4 +23,18 @@ public struct AlternativeDistributionDomainsResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([AlternativeDistributionDomain].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionKey.swift b/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionKey.swift index 701eb373c..edc61dd0b 100644 --- a/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionKey.swift +++ b/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionKey.swift @@ -27,28 +27,21 @@ public struct AlternativeDistributionKey: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } /** @@ -67,5 +60,15 @@ public struct AlternativeDistributionKey: Codable, Identifiable { public init(publicKey: String? = nil) { self.publicKey = publicKey } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + publicKey = try container.decodeIfPresent(String.self, forKey: "publicKey") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(publicKey, forKey: "publicKey") + } } } diff --git a/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionKeyCreateRequest.swift b/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionKeyCreateRequest.swift index 5c3b3bc60..8b9a8163e 100644 --- a/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionKeyCreateRequest.swift +++ b/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionKeyCreateRequest.swift @@ -17,6 +17,16 @@ public struct AlternativeDistributionKeyCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "alternativeDistributionKeys" } public let attributes: Attributes @@ -30,25 +40,19 @@ public struct AlternativeDistributionKeyCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -65,6 +69,16 @@ public struct AlternativeDistributionKeyCreateRequest: Codable, RequestBody { public init(publicKey: String) { self.publicKey = publicKey } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + publicKey = try container.decode(String.self, forKey: "publicKey") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(publicKey, forKey: "publicKey") + } } public struct Relationships: Codable { @@ -74,6 +88,16 @@ public struct AlternativeDistributionKeyCreateRequest: Codable, RequestBody { self.app = app } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + app = try container.decodeIfPresent(App.self, forKey: "app") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(app, forKey: "app") + } + /** # AlternativeDistributionKeyCreateRequest.Data.Relationships.App The relationships you included in the request and those on which you can operate. @@ -89,17 +113,13 @@ public struct AlternativeDistributionKeyCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } /** @@ -119,22 +139,17 @@ public struct AlternativeDistributionKeyCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionKeyResponse.swift b/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionKeyResponse.swift index 078868f83..adb8739e0 100644 --- a/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionKeyResponse.swift +++ b/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionKeyResponse.swift @@ -23,4 +23,16 @@ public struct AlternativeDistributionKeyResponse: Codable { self.data = data self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AlternativeDistributionKey.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionKeysResponse.swift b/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionKeysResponse.swift index ae5995c3b..4661aa06c 100644 --- a/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionKeysResponse.swift +++ b/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionKeysResponse.swift @@ -25,4 +25,18 @@ public struct AlternativeDistributionKeysResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([AlternativeDistributionKey].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionPackage.swift b/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionPackage.swift index c97de767e..6d1ff997f 100644 --- a/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionPackage.swift +++ b/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionPackage.swift @@ -27,28 +27,21 @@ public struct AlternativeDistributionPackage: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -67,6 +60,16 @@ public struct AlternativeDistributionPackage: Codable, Identifiable { self.versions = versions } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + versions = try container.decodeIfPresent(Versions.self, forKey: "versions") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(versions, forKey: "versions") + } + /** # AlternativeDistributionPackage.Relationships.Versions The data structure that represents the versions for the relationships of an alternative distribution package resource. @@ -91,23 +94,17 @@ public struct AlternativeDistributionPackage: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } /** @@ -129,22 +126,17 @@ public struct AlternativeDistributionPackage: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -169,20 +161,15 @@ public struct AlternativeDistributionPackage: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionPackageCreateRequest.swift b/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionPackageCreateRequest.swift index db2c332f6..83e03d9eb 100644 --- a/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionPackageCreateRequest.swift +++ b/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionPackageCreateRequest.swift @@ -17,6 +17,16 @@ public struct AlternativeDistributionPackageCreateRequest: Codable, RequestBody self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "alternativeDistributionPackages" } public let relationships: Relationships @@ -26,22 +36,17 @@ public struct AlternativeDistributionPackageCreateRequest: Codable, RequestBody } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(relationships, forKey: "relationships") } public struct Relationships: Codable { @@ -51,6 +56,16 @@ public struct AlternativeDistributionPackageCreateRequest: Codable, RequestBody self.appStoreVersion = appStoreVersion } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appStoreVersion = try container.decode(AppStoreVersion.self, forKey: "appStoreVersion") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(appStoreVersion, forKey: "appStoreVersion") + } + public struct AppStoreVersion: Codable { public let data: Data @@ -58,6 +73,16 @@ public struct AlternativeDistributionPackageCreateRequest: Codable, RequestBody self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "appStoreVersions" } @@ -67,22 +92,17 @@ public struct AlternativeDistributionPackageCreateRequest: Codable, RequestBody } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionPackageDelta.swift b/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionPackageDelta.swift index 355a02113..760fd9c0d 100644 --- a/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionPackageDelta.swift +++ b/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionPackageDelta.swift @@ -27,28 +27,21 @@ public struct AlternativeDistributionPackageDelta: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } public struct Attributes: Codable { @@ -67,5 +60,21 @@ public struct AlternativeDistributionPackageDelta: Codable, Identifiable { self.url = url self.urlExpirationDate = urlExpirationDate } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + alternativeDistributionKeyBlob = try container.decodeIfPresent(String.self, forKey: "alternativeDistributionKeyBlob") + fileChecksum = try container.decodeIfPresent(String.self, forKey: "fileChecksum") + url = try container.decodeIfPresent(String.self, forKey: "url") + urlExpirationDate = try container.decodeIfPresent(Date.self, forKey: "urlExpirationDate") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(alternativeDistributionKeyBlob, forKey: "alternativeDistributionKeyBlob") + try container.encodeIfPresent(fileChecksum, forKey: "fileChecksum") + try container.encodeIfPresent(url, forKey: "url") + try container.encodeIfPresent(urlExpirationDate, forKey: "urlExpirationDate") + } } } diff --git a/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionPackageDeltaResponse.swift b/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionPackageDeltaResponse.swift index 5877f7544..78359c9a9 100644 --- a/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionPackageDeltaResponse.swift +++ b/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionPackageDeltaResponse.swift @@ -23,4 +23,16 @@ public struct AlternativeDistributionPackageDeltaResponse: Codable { self.data = data self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AlternativeDistributionPackageDelta.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionPackageDeltasResponse.swift b/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionPackageDeltasResponse.swift index 202f49a4d..cf925bfe6 100644 --- a/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionPackageDeltasResponse.swift +++ b/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionPackageDeltasResponse.swift @@ -28,4 +28,18 @@ public struct AlternativeDistributionPackageDeltasResponse: Codable, PagedRespon self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([AlternativeDistributionPackageDelta].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionPackageResponse.swift b/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionPackageResponse.swift index 05ba86b90..b6a0f3502 100644 --- a/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionPackageResponse.swift +++ b/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionPackageResponse.swift @@ -26,4 +26,18 @@ public struct AlternativeDistributionPackageResponse: Codable { self.included = included self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AlternativeDistributionPackage.self, forKey: "data") + included = try container.decodeIfPresent([AlternativeDistributionPackageVersion].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionPackageVariant.swift b/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionPackageVariant.swift index 8a1089595..b03d7766c 100644 --- a/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionPackageVariant.swift +++ b/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionPackageVariant.swift @@ -27,28 +27,21 @@ public struct AlternativeDistributionPackageVariant: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } public struct Attributes: Codable { @@ -67,5 +60,21 @@ public struct AlternativeDistributionPackageVariant: Codable, Identifiable { self.url = url self.urlExpirationDate = urlExpirationDate } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + alternativeDistributionKeyBlob = try container.decodeIfPresent(String.self, forKey: "alternativeDistributionKeyBlob") + fileChecksum = try container.decodeIfPresent(String.self, forKey: "fileChecksum") + url = try container.decodeIfPresent(String.self, forKey: "url") + urlExpirationDate = try container.decodeIfPresent(Date.self, forKey: "urlExpirationDate") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(alternativeDistributionKeyBlob, forKey: "alternativeDistributionKeyBlob") + try container.encodeIfPresent(fileChecksum, forKey: "fileChecksum") + try container.encodeIfPresent(url, forKey: "url") + try container.encodeIfPresent(urlExpirationDate, forKey: "urlExpirationDate") + } } } diff --git a/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionPackageVariantResponse.swift b/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionPackageVariantResponse.swift index dacb8b309..9ba44b6db 100644 --- a/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionPackageVariantResponse.swift +++ b/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionPackageVariantResponse.swift @@ -23,4 +23,16 @@ public struct AlternativeDistributionPackageVariantResponse: Codable { self.data = data self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AlternativeDistributionPackageVariant.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionPackageVariantsResponse.swift b/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionPackageVariantsResponse.swift index effd1e39c..1a0061880 100644 --- a/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionPackageVariantsResponse.swift +++ b/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionPackageVariantsResponse.swift @@ -28,4 +28,18 @@ public struct AlternativeDistributionPackageVariantsResponse: Codable, PagedResp self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([AlternativeDistributionPackageVariant].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionPackageVersion.swift b/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionPackageVersion.swift index 2548032f0..bddc46fb1 100644 --- a/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionPackageVersion.swift +++ b/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionPackageVersion.swift @@ -30,31 +30,23 @@ public struct AlternativeDistributionPackageVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -77,6 +69,24 @@ public struct AlternativeDistributionPackageVersion: Codable, Identifiable { self.version = version } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + fileChecksum = try container.decodeIfPresent(String.self, forKey: "fileChecksum") + state = try container.decodeIfPresent(State.self, forKey: "state") + url = try container.decodeIfPresent(String.self, forKey: "url") + urlExpirationDate = try container.decodeIfPresent(Date.self, forKey: "urlExpirationDate") + version = try container.decodeIfPresent(String.self, forKey: "version") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(fileChecksum, forKey: "fileChecksum") + try container.encodeIfPresent(state, forKey: "state") + try container.encodeIfPresent(url, forKey: "url") + try container.encodeIfPresent(urlExpirationDate, forKey: "urlExpirationDate") + try container.encodeIfPresent(version, forKey: "version") + } + public enum State: String, Codable, CaseIterable { case completed = "COMPLETED" case replaced = "REPLACED" @@ -97,6 +107,20 @@ public struct AlternativeDistributionPackageVersion: Codable, Identifiable { self.variants = variants } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + alternativeDistributionPackage = try container.decodeIfPresent(AlternativeDistributionPackage.self, forKey: "alternativeDistributionPackage") + deltas = try container.decodeIfPresent(Deltas.self, forKey: "deltas") + variants = try container.decodeIfPresent(Variants.self, forKey: "variants") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(alternativeDistributionPackage, forKey: "alternativeDistributionPackage") + try container.encodeIfPresent(deltas, forKey: "deltas") + try container.encodeIfPresent(variants, forKey: "variants") + } + public struct AlternativeDistributionPackage: Codable { @NullCodable public var data: Data? public var links: Links? @@ -109,20 +133,15 @@ public struct AlternativeDistributionPackageVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } public struct Data: Codable, Identifiable { @@ -134,22 +153,17 @@ public struct AlternativeDistributionPackageVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -165,20 +179,15 @@ public struct AlternativeDistributionPackageVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -198,23 +207,17 @@ public struct AlternativeDistributionPackageVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -226,22 +229,17 @@ public struct AlternativeDistributionPackageVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -257,20 +255,15 @@ public struct AlternativeDistributionPackageVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -290,23 +283,17 @@ public struct AlternativeDistributionPackageVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -318,22 +305,17 @@ public struct AlternativeDistributionPackageVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -349,20 +331,15 @@ public struct AlternativeDistributionPackageVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionPackageVersionResponse.swift b/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionPackageVersionResponse.swift index 49ede5a40..3ee931163 100644 --- a/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionPackageVersionResponse.swift +++ b/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionPackageVersionResponse.swift @@ -27,6 +27,20 @@ public struct AlternativeDistributionPackageVersionResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AlternativeDistributionPackageVersion.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getAlternativeDistributionPackage() -> AlternativeDistributionPackage? { included?.compactMap { relationship -> AlternativeDistributionPackage? in guard case let .alternativeDistributionPackage(alternativeDistributionPackage) = relationship else { return nil } @@ -86,9 +100,5 @@ public struct AlternativeDistributionPackageVersionResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionPackageVersionsResponse.swift b/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionPackageVersionsResponse.swift index 90b5fd721..85d156e77 100644 --- a/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionPackageVersionsResponse.swift +++ b/Sources/Bagbutik-Models/Marketplaces/AlternativeDistributionPackageVersionsResponse.swift @@ -32,6 +32,22 @@ public struct AlternativeDistributionPackageVersionsResponse: Codable, PagedResp self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([AlternativeDistributionPackageVersion].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getAlternativeDistributionPackage(for alternativeDistributionPackageVersion: AlternativeDistributionPackageVersion) -> AlternativeDistributionPackage? { included?.compactMap { relationship -> AlternativeDistributionPackage? in guard case let .alternativeDistributionPackage(alternativeDistributionPackage) = relationship else { return nil } @@ -91,9 +107,5 @@ public struct AlternativeDistributionPackageVersionsResponse: Codable, PagedResp try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/Marketplaces/MarketplaceDomain.swift b/Sources/Bagbutik-Models/Marketplaces/MarketplaceDomain.swift index f5515d4ff..de46fe7c9 100644 --- a/Sources/Bagbutik-Models/Marketplaces/MarketplaceDomain.swift +++ b/Sources/Bagbutik-Models/Marketplaces/MarketplaceDomain.swift @@ -24,28 +24,21 @@ public struct MarketplaceDomain: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } public struct Attributes: Codable { @@ -61,5 +54,19 @@ public struct MarketplaceDomain: Codable, Identifiable { self.domain = domain self.referenceName = referenceName } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + createdDate = try container.decodeIfPresent(Date.self, forKey: "createdDate") + domain = try container.decodeIfPresent(String.self, forKey: "domain") + referenceName = try container.decodeIfPresent(String.self, forKey: "referenceName") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(createdDate, forKey: "createdDate") + try container.encodeIfPresent(domain, forKey: "domain") + try container.encodeIfPresent(referenceName, forKey: "referenceName") + } } } diff --git a/Sources/Bagbutik-Models/Marketplaces/MarketplaceDomainCreateRequest.swift b/Sources/Bagbutik-Models/Marketplaces/MarketplaceDomainCreateRequest.swift index a0dd30c9c..3568c3ee4 100644 --- a/Sources/Bagbutik-Models/Marketplaces/MarketplaceDomainCreateRequest.swift +++ b/Sources/Bagbutik-Models/Marketplaces/MarketplaceDomainCreateRequest.swift @@ -15,6 +15,16 @@ public struct MarketplaceDomainCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "marketplaceDomains" } public let attributes: Attributes @@ -24,22 +34,17 @@ public struct MarketplaceDomainCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") } public struct Attributes: Codable { @@ -52,6 +57,18 @@ public struct MarketplaceDomainCreateRequest: Codable, RequestBody { self.domain = domain self.referenceName = referenceName } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + domain = try container.decode(String.self, forKey: "domain") + referenceName = try container.decode(String.self, forKey: "referenceName") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(domain, forKey: "domain") + try container.encode(referenceName, forKey: "referenceName") + } } } } diff --git a/Sources/Bagbutik-Models/Marketplaces/MarketplaceDomainResponse.swift b/Sources/Bagbutik-Models/Marketplaces/MarketplaceDomainResponse.swift index 5524220cc..6ba597e3f 100644 --- a/Sources/Bagbutik-Models/Marketplaces/MarketplaceDomainResponse.swift +++ b/Sources/Bagbutik-Models/Marketplaces/MarketplaceDomainResponse.swift @@ -18,4 +18,16 @@ public struct MarketplaceDomainResponse: Codable { self.data = data self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(MarketplaceDomain.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/Marketplaces/MarketplaceDomainsResponse.swift b/Sources/Bagbutik-Models/Marketplaces/MarketplaceDomainsResponse.swift index c8eeb9455..ddb18d580 100644 --- a/Sources/Bagbutik-Models/Marketplaces/MarketplaceDomainsResponse.swift +++ b/Sources/Bagbutik-Models/Marketplaces/MarketplaceDomainsResponse.swift @@ -23,4 +23,18 @@ public struct MarketplaceDomainsResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([MarketplaceDomain].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/Marketplaces/MarketplaceSearchDetail.swift b/Sources/Bagbutik-Models/Marketplaces/MarketplaceSearchDetail.swift index 654b2c074..9b367e5e3 100644 --- a/Sources/Bagbutik-Models/Marketplaces/MarketplaceSearchDetail.swift +++ b/Sources/Bagbutik-Models/Marketplaces/MarketplaceSearchDetail.swift @@ -24,28 +24,21 @@ public struct MarketplaceSearchDetail: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } public struct Attributes: Codable { @@ -54,5 +47,15 @@ public struct MarketplaceSearchDetail: Codable, Identifiable { public init(catalogUrl: String? = nil) { self.catalogUrl = catalogUrl } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + catalogUrl = try container.decodeIfPresent(String.self, forKey: "catalogUrl") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(catalogUrl, forKey: "catalogUrl") + } } } diff --git a/Sources/Bagbutik-Models/Marketplaces/MarketplaceSearchDetailCreateRequest.swift b/Sources/Bagbutik-Models/Marketplaces/MarketplaceSearchDetailCreateRequest.swift index 079da83cf..95d9468f9 100644 --- a/Sources/Bagbutik-Models/Marketplaces/MarketplaceSearchDetailCreateRequest.swift +++ b/Sources/Bagbutik-Models/Marketplaces/MarketplaceSearchDetailCreateRequest.swift @@ -15,6 +15,16 @@ public struct MarketplaceSearchDetailCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "marketplaceSearchDetails" } public let attributes: Attributes @@ -28,25 +38,19 @@ public struct MarketplaceSearchDetailCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } public struct Attributes: Codable { @@ -55,6 +59,16 @@ public struct MarketplaceSearchDetailCreateRequest: Codable, RequestBody { public init(catalogUrl: String) { self.catalogUrl = catalogUrl } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + catalogUrl = try container.decode(String.self, forKey: "catalogUrl") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(catalogUrl, forKey: "catalogUrl") + } } public struct Relationships: Codable { @@ -64,6 +78,16 @@ public struct MarketplaceSearchDetailCreateRequest: Codable, RequestBody { self.app = app } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + app = try container.decode(App.self, forKey: "app") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(app, forKey: "app") + } + public struct App: Codable { public let data: Data @@ -71,6 +95,16 @@ public struct MarketplaceSearchDetailCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "apps" } @@ -80,22 +114,17 @@ public struct MarketplaceSearchDetailCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/Marketplaces/MarketplaceSearchDetailResponse.swift b/Sources/Bagbutik-Models/Marketplaces/MarketplaceSearchDetailResponse.swift index 7a566daa2..be172a28c 100644 --- a/Sources/Bagbutik-Models/Marketplaces/MarketplaceSearchDetailResponse.swift +++ b/Sources/Bagbutik-Models/Marketplaces/MarketplaceSearchDetailResponse.swift @@ -18,4 +18,16 @@ public struct MarketplaceSearchDetailResponse: Codable { self.data = data self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(MarketplaceSearchDetail.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/Marketplaces/MarketplaceSearchDetailUpdateRequest.swift b/Sources/Bagbutik-Models/Marketplaces/MarketplaceSearchDetailUpdateRequest.swift index 4b244f01e..b48387a16 100644 --- a/Sources/Bagbutik-Models/Marketplaces/MarketplaceSearchDetailUpdateRequest.swift +++ b/Sources/Bagbutik-Models/Marketplaces/MarketplaceSearchDetailUpdateRequest.swift @@ -15,6 +15,16 @@ public struct MarketplaceSearchDetailUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable, Identifiable { public let id: String public var type: String { "marketplaceSearchDetails" } @@ -28,25 +38,19 @@ public struct MarketplaceSearchDetailUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } public struct Attributes: Codable { @@ -55,6 +59,16 @@ public struct MarketplaceSearchDetailUpdateRequest: Codable, RequestBody { public init(catalogUrl: String? = nil) { self.catalogUrl = catalogUrl } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + catalogUrl = try container.decodeIfPresent(String.self, forKey: "catalogUrl") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(catalogUrl, forKey: "catalogUrl") + } } } } diff --git a/Sources/Bagbutik-Models/Marketplaces/MarketplaceWebhook.swift b/Sources/Bagbutik-Models/Marketplaces/MarketplaceWebhook.swift index 960a6047b..27a6034dd 100644 --- a/Sources/Bagbutik-Models/Marketplaces/MarketplaceWebhook.swift +++ b/Sources/Bagbutik-Models/Marketplaces/MarketplaceWebhook.swift @@ -24,28 +24,21 @@ public struct MarketplaceWebhook: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } /** @@ -61,5 +54,15 @@ public struct MarketplaceWebhook: Codable, Identifiable { public init(endpointUrl: String? = nil) { self.endpointUrl = endpointUrl } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + endpointUrl = try container.decodeIfPresent(String.self, forKey: "endpointUrl") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(endpointUrl, forKey: "endpointUrl") + } } } diff --git a/Sources/Bagbutik-Models/Marketplaces/MarketplaceWebhookCreateRequest.swift b/Sources/Bagbutik-Models/Marketplaces/MarketplaceWebhookCreateRequest.swift index 4351886e9..6ce2a3764 100644 --- a/Sources/Bagbutik-Models/Marketplaces/MarketplaceWebhookCreateRequest.swift +++ b/Sources/Bagbutik-Models/Marketplaces/MarketplaceWebhookCreateRequest.swift @@ -15,6 +15,16 @@ public struct MarketplaceWebhookCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + public struct Data: Codable { public var type: String { "marketplaceWebhooks" } public let attributes: Attributes @@ -24,22 +34,17 @@ public struct MarketplaceWebhookCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") } /** @@ -60,6 +65,18 @@ public struct MarketplaceWebhookCreateRequest: Codable, RequestBody { self.endpointUrl = endpointUrl self.secret = secret } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + endpointUrl = try container.decode(String.self, forKey: "endpointUrl") + secret = try container.decode(String.self, forKey: "secret") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(endpointUrl, forKey: "endpointUrl") + try container.encode(secret, forKey: "secret") + } } } } diff --git a/Sources/Bagbutik-Models/Marketplaces/MarketplaceWebhookResponse.swift b/Sources/Bagbutik-Models/Marketplaces/MarketplaceWebhookResponse.swift index 809d1e533..e3d14b14e 100644 --- a/Sources/Bagbutik-Models/Marketplaces/MarketplaceWebhookResponse.swift +++ b/Sources/Bagbutik-Models/Marketplaces/MarketplaceWebhookResponse.swift @@ -20,4 +20,16 @@ public struct MarketplaceWebhookResponse: Codable { self.data = data self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(MarketplaceWebhook.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/Marketplaces/MarketplaceWebhookUpdateRequest.swift b/Sources/Bagbutik-Models/Marketplaces/MarketplaceWebhookUpdateRequest.swift index 7562f579b..5f3c2927a 100644 --- a/Sources/Bagbutik-Models/Marketplaces/MarketplaceWebhookUpdateRequest.swift +++ b/Sources/Bagbutik-Models/Marketplaces/MarketplaceWebhookUpdateRequest.swift @@ -15,6 +15,16 @@ public struct MarketplaceWebhookUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # MarketplaceWebhookUpdateRequest.Data The data structure that represent a marketplace webhook resource. @@ -35,25 +45,19 @@ public struct MarketplaceWebhookUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } /** @@ -74,6 +78,18 @@ public struct MarketplaceWebhookUpdateRequest: Codable, RequestBody { self.endpointUrl = endpointUrl self.secret = secret } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + endpointUrl = try container.decodeIfPresent(String.self, forKey: "endpointUrl") + secret = try container.decodeIfPresent(String.self, forKey: "secret") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(endpointUrl, forKey: "endpointUrl") + try container.encodeIfPresent(secret, forKey: "secret") + } } } } diff --git a/Sources/Bagbutik-Models/Marketplaces/MarketplaceWebhooksResponse.swift b/Sources/Bagbutik-Models/Marketplaces/MarketplaceWebhooksResponse.swift index 602a599d4..b00d1beb0 100644 --- a/Sources/Bagbutik-Models/Marketplaces/MarketplaceWebhooksResponse.swift +++ b/Sources/Bagbutik-Models/Marketplaces/MarketplaceWebhooksResponse.swift @@ -25,4 +25,18 @@ public struct MarketplaceWebhooksResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([MarketplaceWebhook].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/Provisioning/BundleId.swift b/Sources/Bagbutik-Models/Provisioning/BundleId.swift index 93e31c3e8..0ee256311 100644 --- a/Sources/Bagbutik-Models/Provisioning/BundleId.swift +++ b/Sources/Bagbutik-Models/Provisioning/BundleId.swift @@ -32,31 +32,23 @@ public struct BundleId: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -82,6 +74,22 @@ public struct BundleId: Codable, Identifiable { self.platform = platform self.seedId = seedId } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + identifier = try container.decodeIfPresent(String.self, forKey: "identifier") + name = try container.decodeIfPresent(String.self, forKey: "name") + platform = try container.decodeIfPresent(BundleIdPlatform.self, forKey: "platform") + seedId = try container.decodeIfPresent(String.self, forKey: "seedId") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(identifier, forKey: "identifier") + try container.encodeIfPresent(name, forKey: "name") + try container.encodeIfPresent(platform, forKey: "platform") + try container.encodeIfPresent(seedId, forKey: "seedId") + } } /** @@ -105,6 +113,20 @@ public struct BundleId: Codable, Identifiable { self.profiles = profiles } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + app = try container.decodeIfPresent(App.self, forKey: "app") + bundleIdCapabilities = try container.decodeIfPresent(BundleIdCapabilities.self, forKey: "bundleIdCapabilities") + profiles = try container.decodeIfPresent(Profiles.self, forKey: "profiles") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(app, forKey: "app") + try container.encodeIfPresent(bundleIdCapabilities, forKey: "bundleIdCapabilities") + try container.encodeIfPresent(profiles, forKey: "profiles") + } + /** # BundleId.Relationships.App The data and links that describe the relationship between the resources. @@ -124,20 +146,15 @@ public struct BundleId: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -156,22 +173,17 @@ public struct BundleId: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -194,20 +206,15 @@ public struct BundleId: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -234,23 +241,17 @@ public struct BundleId: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } /** @@ -269,22 +270,17 @@ public struct BundleId: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -307,20 +303,15 @@ public struct BundleId: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -347,23 +338,17 @@ public struct BundleId: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } /** @@ -382,22 +367,17 @@ public struct BundleId: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -420,20 +400,15 @@ public struct BundleId: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/Provisioning/BundleIdCapabilitiesResponse.swift b/Sources/Bagbutik-Models/Provisioning/BundleIdCapabilitiesResponse.swift index 8df0ec1a7..9087a0377 100644 --- a/Sources/Bagbutik-Models/Provisioning/BundleIdCapabilitiesResponse.swift +++ b/Sources/Bagbutik-Models/Provisioning/BundleIdCapabilitiesResponse.swift @@ -26,4 +26,18 @@ public struct BundleIdCapabilitiesResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([BundleIdCapability].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/Provisioning/BundleIdCapabilitiesWithoutIncludesResponse.swift b/Sources/Bagbutik-Models/Provisioning/BundleIdCapabilitiesWithoutIncludesResponse.swift index 1aa611034..2108fcb4d 100644 --- a/Sources/Bagbutik-Models/Provisioning/BundleIdCapabilitiesWithoutIncludesResponse.swift +++ b/Sources/Bagbutik-Models/Provisioning/BundleIdCapabilitiesWithoutIncludesResponse.swift @@ -16,4 +16,18 @@ public struct BundleIdCapabilitiesWithoutIncludesResponse: Codable, PagedRespons self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([BundleIdCapability].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/Provisioning/BundleIdCapability.swift b/Sources/Bagbutik-Models/Provisioning/BundleIdCapability.swift index 4e88f020d..cf867dfd4 100644 --- a/Sources/Bagbutik-Models/Provisioning/BundleIdCapability.swift +++ b/Sources/Bagbutik-Models/Provisioning/BundleIdCapability.swift @@ -28,28 +28,21 @@ public struct BundleIdCapability: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } /** @@ -69,5 +62,17 @@ public struct BundleIdCapability: Codable, Identifiable { self.capabilityType = capabilityType self.settings = settings } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + capabilityType = try container.decodeIfPresent(CapabilityType.self, forKey: "capabilityType") + settings = try container.decodeIfPresent([CapabilitySetting].self, forKey: "settings") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(capabilityType, forKey: "capabilityType") + try container.encodeIfPresent(settings, forKey: "settings") + } } } diff --git a/Sources/Bagbutik-Models/Provisioning/BundleIdCapabilityCreateRequest.swift b/Sources/Bagbutik-Models/Provisioning/BundleIdCapabilityCreateRequest.swift index 1bbbf5914..9a6075116 100644 --- a/Sources/Bagbutik-Models/Provisioning/BundleIdCapabilityCreateRequest.swift +++ b/Sources/Bagbutik-Models/Provisioning/BundleIdCapabilityCreateRequest.swift @@ -16,6 +16,16 @@ public struct BundleIdCapabilityCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # BundleIdCapabilityCreateRequest.Data The data element of the request body. @@ -36,25 +46,19 @@ public struct BundleIdCapabilityCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } /** @@ -74,6 +78,18 @@ public struct BundleIdCapabilityCreateRequest: Codable, RequestBody { self.capabilityType = capabilityType self.settings = settings } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + capabilityType = try container.decode(CapabilityType.self, forKey: "capabilityType") + settings = try container.decodeIfPresent([CapabilitySetting].self, forKey: "settings") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(capabilityType, forKey: "capabilityType") + try container.encodeIfPresent(settings, forKey: "settings") + } } /** @@ -90,6 +106,16 @@ public struct BundleIdCapabilityCreateRequest: Codable, RequestBody { self.bundleId = bundleId } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + bundleId = try container.decode(BundleId.self, forKey: "bundleId") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(bundleId, forKey: "bundleId") + } + /** # BundleIdCapabilityCreateRequest.Data.Relationships.BundleId The relationships to other resources that you can set with this request. @@ -104,6 +130,16 @@ public struct BundleIdCapabilityCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # BundleIdCapabilityCreateRequest.Data.Relationships.BundleId.Data The type and ID of the resource that you're relating with the resource you're creating. @@ -120,22 +156,17 @@ public struct BundleIdCapabilityCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/Provisioning/BundleIdCapabilityResponse.swift b/Sources/Bagbutik-Models/Provisioning/BundleIdCapabilityResponse.swift index 837c2d7e2..b58091fdd 100644 --- a/Sources/Bagbutik-Models/Provisioning/BundleIdCapabilityResponse.swift +++ b/Sources/Bagbutik-Models/Provisioning/BundleIdCapabilityResponse.swift @@ -20,4 +20,16 @@ public struct BundleIdCapabilityResponse: Codable { self.data = data self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(BundleIdCapability.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/Provisioning/BundleIdCapabilityUpdateRequest.swift b/Sources/Bagbutik-Models/Provisioning/BundleIdCapabilityUpdateRequest.swift index 84779339f..b0020c53d 100644 --- a/Sources/Bagbutik-Models/Provisioning/BundleIdCapabilityUpdateRequest.swift +++ b/Sources/Bagbutik-Models/Provisioning/BundleIdCapabilityUpdateRequest.swift @@ -16,6 +16,16 @@ public struct BundleIdCapabilityUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # BundleIdCapabilityUpdateRequest.Data The data element of the request body. @@ -36,25 +46,19 @@ public struct BundleIdCapabilityUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } /** @@ -74,6 +78,18 @@ public struct BundleIdCapabilityUpdateRequest: Codable, RequestBody { self.capabilityType = capabilityType self.settings = settings } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + capabilityType = try container.decodeIfPresent(CapabilityType.self, forKey: "capabilityType") + settings = try container.decodeIfPresent([CapabilitySetting].self, forKey: "settings") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(capabilityType, forKey: "capabilityType") + try container.encodeIfPresent(settings, forKey: "settings") + } } } } diff --git a/Sources/Bagbutik-Models/Provisioning/BundleIdCreateRequest.swift b/Sources/Bagbutik-Models/Provisioning/BundleIdCreateRequest.swift index 2bdd7c8d5..d0cbde3b7 100644 --- a/Sources/Bagbutik-Models/Provisioning/BundleIdCreateRequest.swift +++ b/Sources/Bagbutik-Models/Provisioning/BundleIdCreateRequest.swift @@ -16,6 +16,16 @@ public struct BundleIdCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # BundleIdCreateRequest.Data The data element of the request body. @@ -32,22 +42,17 @@ public struct BundleIdCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") } /** @@ -73,6 +78,22 @@ public struct BundleIdCreateRequest: Codable, RequestBody { self.platform = platform self.seedId = seedId } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + identifier = try container.decode(String.self, forKey: "identifier") + name = try container.decode(String.self, forKey: "name") + platform = try container.decode(BundleIdPlatform.self, forKey: "platform") + seedId = try container.decodeIfPresent(String.self, forKey: "seedId") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(identifier, forKey: "identifier") + try container.encode(name, forKey: "name") + try container.encode(platform, forKey: "platform") + try container.encodeIfPresent(seedId, forKey: "seedId") + } } } } diff --git a/Sources/Bagbutik-Models/Provisioning/BundleIdResponse.swift b/Sources/Bagbutik-Models/Provisioning/BundleIdResponse.swift index 8ef3ddd9b..a93757080 100644 --- a/Sources/Bagbutik-Models/Provisioning/BundleIdResponse.swift +++ b/Sources/Bagbutik-Models/Provisioning/BundleIdResponse.swift @@ -25,6 +25,20 @@ public struct BundleIdResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(BundleId.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getApp() -> App? { included?.compactMap { relationship -> App? in guard case let .app(app) = relationship else { return nil } @@ -84,9 +98,5 @@ public struct BundleIdResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/Provisioning/BundleIdUpdateRequest.swift b/Sources/Bagbutik-Models/Provisioning/BundleIdUpdateRequest.swift index 17ef37003..e2c873eaa 100644 --- a/Sources/Bagbutik-Models/Provisioning/BundleIdUpdateRequest.swift +++ b/Sources/Bagbutik-Models/Provisioning/BundleIdUpdateRequest.swift @@ -16,6 +16,16 @@ public struct BundleIdUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # BundleIdUpdateRequest.Data The data element of the request body. @@ -36,25 +46,19 @@ public struct BundleIdUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } /** @@ -70,6 +74,16 @@ public struct BundleIdUpdateRequest: Codable, RequestBody { public init(name: String? = nil) { self.name = name } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + name = try container.decodeIfPresent(String.self, forKey: "name") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(name, forKey: "name") + } } } } diff --git a/Sources/Bagbutik-Models/Provisioning/BundleIdWithoutIncludesResponse.swift b/Sources/Bagbutik-Models/Provisioning/BundleIdWithoutIncludesResponse.swift index 7bb248016..3f348958d 100644 --- a/Sources/Bagbutik-Models/Provisioning/BundleIdWithoutIncludesResponse.swift +++ b/Sources/Bagbutik-Models/Provisioning/BundleIdWithoutIncludesResponse.swift @@ -11,4 +11,16 @@ public struct BundleIdWithoutIncludesResponse: Codable { self.data = data self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(BundleId.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/Provisioning/BundleIdsResponse.swift b/Sources/Bagbutik-Models/Provisioning/BundleIdsResponse.swift index 0ba114dec..45a90f0ed 100644 --- a/Sources/Bagbutik-Models/Provisioning/BundleIdsResponse.swift +++ b/Sources/Bagbutik-Models/Provisioning/BundleIdsResponse.swift @@ -31,6 +31,22 @@ public struct BundleIdsResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([BundleId].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getApp(for bundleId: BundleId) -> App? { included?.compactMap { relationship -> App? in guard case let .app(app) = relationship else { return nil } @@ -90,9 +106,5 @@ public struct BundleIdsResponse: Codable, PagedResponse { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/Provisioning/CapabilityOption.swift b/Sources/Bagbutik-Models/Provisioning/CapabilityOption.swift index 0bcb8eb9f..e2359d115 100644 --- a/Sources/Bagbutik-Models/Provisioning/CapabilityOption.swift +++ b/Sources/Bagbutik-Models/Provisioning/CapabilityOption.swift @@ -31,6 +31,26 @@ public struct CapabilityOption: Codable { self.supportsWildcard = supportsWildcard } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + description = try container.decodeIfPresent(String.self, forKey: "description") + enabled = try container.decodeIfPresent(Bool.self, forKey: "enabled") + enabledByDefault = try container.decodeIfPresent(Bool.self, forKey: "enabledByDefault") + key = try container.decodeIfPresent(Key.self, forKey: "key") + name = try container.decodeIfPresent(String.self, forKey: "name") + supportsWildcard = try container.decodeIfPresent(Bool.self, forKey: "supportsWildcard") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(description, forKey: "description") + try container.encodeIfPresent(enabled, forKey: "enabled") + try container.encodeIfPresent(enabledByDefault, forKey: "enabledByDefault") + try container.encodeIfPresent(key, forKey: "key") + try container.encodeIfPresent(name, forKey: "name") + try container.encodeIfPresent(supportsWildcard, forKey: "supportsWildcard") + } + public enum Key: String, Codable, CaseIterable { case completeProtection = "COMPLETE_PROTECTION" case primaryAppConsent = "PRIMARY_APP_CONSENT" diff --git a/Sources/Bagbutik-Models/Provisioning/CapabilitySetting.swift b/Sources/Bagbutik-Models/Provisioning/CapabilitySetting.swift index 466ce11f2..6bc78b035 100644 --- a/Sources/Bagbutik-Models/Provisioning/CapabilitySetting.swift +++ b/Sources/Bagbutik-Models/Provisioning/CapabilitySetting.swift @@ -37,6 +37,30 @@ public struct CapabilitySetting: Codable { self.visible = visible } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + allowedInstances = try container.decodeIfPresent(AllowedInstances.self, forKey: "allowedInstances") + description = try container.decodeIfPresent(String.self, forKey: "description") + enabledByDefault = try container.decodeIfPresent(Bool.self, forKey: "enabledByDefault") + key = try container.decodeIfPresent(Key.self, forKey: "key") + minInstances = try container.decodeIfPresent(Int.self, forKey: "minInstances") + name = try container.decodeIfPresent(String.self, forKey: "name") + options = try container.decodeIfPresent([CapabilityOption].self, forKey: "options") + visible = try container.decodeIfPresent(Bool.self, forKey: "visible") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(allowedInstances, forKey: "allowedInstances") + try container.encodeIfPresent(description, forKey: "description") + try container.encodeIfPresent(enabledByDefault, forKey: "enabledByDefault") + try container.encodeIfPresent(key, forKey: "key") + try container.encodeIfPresent(minInstances, forKey: "minInstances") + try container.encodeIfPresent(name, forKey: "name") + try container.encodeIfPresent(options, forKey: "options") + try container.encodeIfPresent(visible, forKey: "visible") + } + public enum AllowedInstances: String, Codable, CaseIterable { case entry = "ENTRY" case multiple = "MULTIPLE" diff --git a/Sources/Bagbutik-Models/Provisioning/Certificate.swift b/Sources/Bagbutik-Models/Provisioning/Certificate.swift index e42db5342..60763d4ec 100644 --- a/Sources/Bagbutik-Models/Provisioning/Certificate.swift +++ b/Sources/Bagbutik-Models/Provisioning/Certificate.swift @@ -28,28 +28,21 @@ public struct Certificate: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } /** @@ -84,5 +77,27 @@ public struct Certificate: Codable, Identifiable { self.platform = platform self.serialNumber = serialNumber } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + certificateContent = try container.decodeIfPresent(String.self, forKey: "certificateContent") + certificateType = try container.decodeIfPresent(CertificateType.self, forKey: "certificateType") + displayName = try container.decodeIfPresent(String.self, forKey: "displayName") + expirationDate = try container.decodeIfPresent(Date.self, forKey: "expirationDate") + name = try container.decodeIfPresent(String.self, forKey: "name") + platform = try container.decodeIfPresent(BundleIdPlatform.self, forKey: "platform") + serialNumber = try container.decodeIfPresent(String.self, forKey: "serialNumber") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(certificateContent, forKey: "certificateContent") + try container.encodeIfPresent(certificateType, forKey: "certificateType") + try container.encodeIfPresent(displayName, forKey: "displayName") + try container.encodeIfPresent(expirationDate, forKey: "expirationDate") + try container.encodeIfPresent(name, forKey: "name") + try container.encodeIfPresent(platform, forKey: "platform") + try container.encodeIfPresent(serialNumber, forKey: "serialNumber") + } } } diff --git a/Sources/Bagbutik-Models/Provisioning/CertificateCreateRequest.swift b/Sources/Bagbutik-Models/Provisioning/CertificateCreateRequest.swift index d445c3b3f..4826b6ea6 100644 --- a/Sources/Bagbutik-Models/Provisioning/CertificateCreateRequest.swift +++ b/Sources/Bagbutik-Models/Provisioning/CertificateCreateRequest.swift @@ -16,6 +16,16 @@ public struct CertificateCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # CertificateCreateRequest.Data The data element of the request body. @@ -32,22 +42,17 @@ public struct CertificateCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") } /** @@ -67,6 +72,18 @@ public struct CertificateCreateRequest: Codable, RequestBody { self.certificateType = certificateType self.csrContent = csrContent } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + certificateType = try container.decode(CertificateType.self, forKey: "certificateType") + csrContent = try container.decode(String.self, forKey: "csrContent") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(certificateType, forKey: "certificateType") + try container.encode(csrContent, forKey: "csrContent") + } } } } diff --git a/Sources/Bagbutik-Models/Provisioning/CertificateResponse.swift b/Sources/Bagbutik-Models/Provisioning/CertificateResponse.swift index 56ba8b317..005a926ba 100644 --- a/Sources/Bagbutik-Models/Provisioning/CertificateResponse.swift +++ b/Sources/Bagbutik-Models/Provisioning/CertificateResponse.swift @@ -20,4 +20,16 @@ public struct CertificateResponse: Codable { self.data = data self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Certificate.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/Provisioning/CertificatesResponse.swift b/Sources/Bagbutik-Models/Provisioning/CertificatesResponse.swift index 09f226970..422506a37 100644 --- a/Sources/Bagbutik-Models/Provisioning/CertificatesResponse.swift +++ b/Sources/Bagbutik-Models/Provisioning/CertificatesResponse.swift @@ -26,4 +26,18 @@ public struct CertificatesResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Certificate].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/Provisioning/CertificatesWithoutIncludesResponse.swift b/Sources/Bagbutik-Models/Provisioning/CertificatesWithoutIncludesResponse.swift index d8b0769cd..f78734c75 100644 --- a/Sources/Bagbutik-Models/Provisioning/CertificatesWithoutIncludesResponse.swift +++ b/Sources/Bagbutik-Models/Provisioning/CertificatesWithoutIncludesResponse.swift @@ -16,4 +16,18 @@ public struct CertificatesWithoutIncludesResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Certificate].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/Provisioning/Device.swift b/Sources/Bagbutik-Models/Provisioning/Device.swift index ee2ba5fa6..b2af8f381 100644 --- a/Sources/Bagbutik-Models/Provisioning/Device.swift +++ b/Sources/Bagbutik-Models/Provisioning/Device.swift @@ -28,28 +28,21 @@ public struct Device: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } /** @@ -85,6 +78,28 @@ public struct Device: Codable, Identifiable { self.udid = udid } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + addedDate = try container.decodeIfPresent(Date.self, forKey: "addedDate") + deviceClass = try container.decodeIfPresent(DeviceClass.self, forKey: "deviceClass") + model = try container.decodeIfPresent(String.self, forKey: "model") + name = try container.decodeIfPresent(String.self, forKey: "name") + platform = try container.decodeIfPresent(BundleIdPlatform.self, forKey: "platform") + status = try container.decodeIfPresent(Status.self, forKey: "status") + udid = try container.decodeIfPresent(String.self, forKey: "udid") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(addedDate, forKey: "addedDate") + try container.encodeIfPresent(deviceClass, forKey: "deviceClass") + try container.encodeIfPresent(model, forKey: "model") + try container.encodeIfPresent(name, forKey: "name") + try container.encodeIfPresent(platform, forKey: "platform") + try container.encodeIfPresent(status, forKey: "status") + try container.encodeIfPresent(udid, forKey: "udid") + } + public enum DeviceClass: String, Codable, CaseIterable { case appleTV = "APPLE_TV" case appleWatch = "APPLE_WATCH" diff --git a/Sources/Bagbutik-Models/Provisioning/DeviceCreateRequest.swift b/Sources/Bagbutik-Models/Provisioning/DeviceCreateRequest.swift index 38bb76664..ec56cd7db 100644 --- a/Sources/Bagbutik-Models/Provisioning/DeviceCreateRequest.swift +++ b/Sources/Bagbutik-Models/Provisioning/DeviceCreateRequest.swift @@ -16,6 +16,16 @@ public struct DeviceCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # DeviceCreateRequest.Data The data element of the request body. @@ -32,22 +42,17 @@ public struct DeviceCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") } /** @@ -70,6 +75,20 @@ public struct DeviceCreateRequest: Codable, RequestBody { self.platform = platform self.udid = udid } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + name = try container.decode(String.self, forKey: "name") + platform = try container.decode(BundleIdPlatform.self, forKey: "platform") + udid = try container.decode(String.self, forKey: "udid") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(name, forKey: "name") + try container.encode(platform, forKey: "platform") + try container.encode(udid, forKey: "udid") + } } } } diff --git a/Sources/Bagbutik-Models/Provisioning/DeviceResponse.swift b/Sources/Bagbutik-Models/Provisioning/DeviceResponse.swift index 56e310b56..4c559efd8 100644 --- a/Sources/Bagbutik-Models/Provisioning/DeviceResponse.swift +++ b/Sources/Bagbutik-Models/Provisioning/DeviceResponse.swift @@ -20,4 +20,16 @@ public struct DeviceResponse: Codable { self.data = data self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Device.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/Provisioning/DeviceUpdateRequest.swift b/Sources/Bagbutik-Models/Provisioning/DeviceUpdateRequest.swift index a1c0d1dfa..0fe614db1 100644 --- a/Sources/Bagbutik-Models/Provisioning/DeviceUpdateRequest.swift +++ b/Sources/Bagbutik-Models/Provisioning/DeviceUpdateRequest.swift @@ -16,6 +16,16 @@ public struct DeviceUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # DeviceUpdateRequest.Data The data element of the request body. @@ -36,25 +46,19 @@ public struct DeviceUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } /** @@ -74,6 +78,18 @@ public struct DeviceUpdateRequest: Codable, RequestBody { self.name = name self.status = status } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + name = try container.decodeIfPresent(String.self, forKey: "name") + status = try container.decodeIfPresent(Device.Attributes.Status.self, forKey: "status") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(name, forKey: "name") + try container.encodeIfPresent(status, forKey: "status") + } } } } diff --git a/Sources/Bagbutik-Models/Provisioning/DevicesResponse.swift b/Sources/Bagbutik-Models/Provisioning/DevicesResponse.swift index a80998159..e1156e1b6 100644 --- a/Sources/Bagbutik-Models/Provisioning/DevicesResponse.swift +++ b/Sources/Bagbutik-Models/Provisioning/DevicesResponse.swift @@ -26,4 +26,18 @@ public struct DevicesResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Device].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/Provisioning/DevicesWithoutIncludesResponse.swift b/Sources/Bagbutik-Models/Provisioning/DevicesWithoutIncludesResponse.swift index 2a52c5a28..6afc34f54 100644 --- a/Sources/Bagbutik-Models/Provisioning/DevicesWithoutIncludesResponse.swift +++ b/Sources/Bagbutik-Models/Provisioning/DevicesWithoutIncludesResponse.swift @@ -16,4 +16,18 @@ public struct DevicesWithoutIncludesResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Device].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/Provisioning/Profile.swift b/Sources/Bagbutik-Models/Provisioning/Profile.swift index 039523a2a..8ddead672 100644 --- a/Sources/Bagbutik-Models/Provisioning/Profile.swift +++ b/Sources/Bagbutik-Models/Provisioning/Profile.swift @@ -32,31 +32,23 @@ public struct Profile: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -95,6 +87,30 @@ public struct Profile: Codable, Identifiable { self.uuid = uuid } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + createdDate = try container.decodeIfPresent(Date.self, forKey: "createdDate") + expirationDate = try container.decodeIfPresent(Date.self, forKey: "expirationDate") + name = try container.decodeIfPresent(String.self, forKey: "name") + platform = try container.decodeIfPresent(BundleIdPlatform.self, forKey: "platform") + profileContent = try container.decodeIfPresent(String.self, forKey: "profileContent") + profileState = try container.decodeIfPresent(ProfileState.self, forKey: "profileState") + profileType = try container.decodeIfPresent(ProfileType.self, forKey: "profileType") + uuid = try container.decodeIfPresent(String.self, forKey: "uuid") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(createdDate, forKey: "createdDate") + try container.encodeIfPresent(expirationDate, forKey: "expirationDate") + try container.encodeIfPresent(name, forKey: "name") + try container.encodeIfPresent(platform, forKey: "platform") + try container.encodeIfPresent(profileContent, forKey: "profileContent") + try container.encodeIfPresent(profileState, forKey: "profileState") + try container.encodeIfPresent(profileType, forKey: "profileType") + try container.encodeIfPresent(uuid, forKey: "uuid") + } + public enum ProfileState: String, ParameterValue, Codable, CaseIterable { case active = "ACTIVE" case invalid = "INVALID" @@ -139,6 +155,20 @@ public struct Profile: Codable, Identifiable { self.devices = devices } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + bundleId = try container.decodeIfPresent(BundleId.self, forKey: "bundleId") + certificates = try container.decodeIfPresent(Certificates.self, forKey: "certificates") + devices = try container.decodeIfPresent(Devices.self, forKey: "devices") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(bundleId, forKey: "bundleId") + try container.encodeIfPresent(certificates, forKey: "certificates") + try container.encodeIfPresent(devices, forKey: "devices") + } + /** # Profile.Relationships.BundleId The data and links that describe the relationship between the resources. @@ -158,20 +188,15 @@ public struct Profile: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -190,22 +215,17 @@ public struct Profile: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -228,20 +248,15 @@ public struct Profile: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -268,23 +283,17 @@ public struct Profile: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } /** @@ -303,22 +312,17 @@ public struct Profile: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -341,20 +345,15 @@ public struct Profile: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -381,23 +380,17 @@ public struct Profile: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } /** @@ -416,22 +409,17 @@ public struct Profile: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -454,20 +442,15 @@ public struct Profile: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/Provisioning/ProfileCreateRequest.swift b/Sources/Bagbutik-Models/Provisioning/ProfileCreateRequest.swift index 4766e72fc..3356edff0 100644 --- a/Sources/Bagbutik-Models/Provisioning/ProfileCreateRequest.swift +++ b/Sources/Bagbutik-Models/Provisioning/ProfileCreateRequest.swift @@ -16,6 +16,16 @@ public struct ProfileCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # ProfileCreateRequest.Data The data element of the request body. @@ -36,25 +46,19 @@ public struct ProfileCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } /** @@ -74,6 +78,18 @@ public struct ProfileCreateRequest: Codable, RequestBody { self.name = name self.profileType = profileType } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + name = try container.decode(String.self, forKey: "name") + profileType = try container.decode(Profile.Attributes.ProfileType.self, forKey: "profileType") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(name, forKey: "name") + try container.encode(profileType, forKey: "profileType") + } } /** @@ -97,6 +113,20 @@ public struct ProfileCreateRequest: Codable, RequestBody { self.devices = devices } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + bundleId = try container.decode(BundleId.self, forKey: "bundleId") + certificates = try container.decode(Certificates.self, forKey: "certificates") + devices = try container.decodeIfPresent(Devices.self, forKey: "devices") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(bundleId, forKey: "bundleId") + try container.encode(certificates, forKey: "certificates") + try container.encodeIfPresent(devices, forKey: "devices") + } + /** # ProfileCreateRequest.Data.Relationships.BundleId The relationships to other resources that you can set with this request. @@ -111,6 +141,16 @@ public struct ProfileCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # ProfileCreateRequest.Data.Relationships.BundleId.Data The type and ID of the resource that you're relating with the resource you're creating. @@ -127,22 +167,17 @@ public struct ProfileCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -161,6 +196,16 @@ public struct ProfileCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # ProfileCreateRequest.Data.Relationships.Certificates.Data The type and ID of the resource that you're relating with the resource you're creating. @@ -177,22 +222,17 @@ public struct ProfileCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -212,17 +252,13 @@ public struct ProfileCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } /** @@ -241,22 +277,17 @@ public struct ProfileCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/Provisioning/ProfileResponse.swift b/Sources/Bagbutik-Models/Provisioning/ProfileResponse.swift index 01dbefa36..203599632 100644 --- a/Sources/Bagbutik-Models/Provisioning/ProfileResponse.swift +++ b/Sources/Bagbutik-Models/Provisioning/ProfileResponse.swift @@ -24,6 +24,20 @@ public struct ProfileResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Profile.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getBundleId() -> BundleId? { included?.compactMap { relationship -> BundleId? in guard case let .bundleId(bundleId) = relationship else { return nil } @@ -83,9 +97,5 @@ public struct ProfileResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/Provisioning/ProfilesResponse.swift b/Sources/Bagbutik-Models/Provisioning/ProfilesResponse.swift index 23a8e1db8..d2ef47923 100644 --- a/Sources/Bagbutik-Models/Provisioning/ProfilesResponse.swift +++ b/Sources/Bagbutik-Models/Provisioning/ProfilesResponse.swift @@ -30,6 +30,22 @@ public struct ProfilesResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Profile].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getBundleId(for profile: Profile) -> BundleId? { included?.compactMap { relationship -> BundleId? in guard case let .bundleId(bundleId) = relationship else { return nil } @@ -89,9 +105,5 @@ public struct ProfilesResponse: Codable, PagedResponse { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/Provisioning/ProfilesWithoutIncludesResponse.swift b/Sources/Bagbutik-Models/Provisioning/ProfilesWithoutIncludesResponse.swift index 360b8b77e..0274307e9 100644 --- a/Sources/Bagbutik-Models/Provisioning/ProfilesWithoutIncludesResponse.swift +++ b/Sources/Bagbutik-Models/Provisioning/ProfilesWithoutIncludesResponse.swift @@ -16,4 +16,18 @@ public struct ProfilesWithoutIncludesResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Profile].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/Reporting/AnalyticsReport.swift b/Sources/Bagbutik-Models/Reporting/AnalyticsReport.swift index c8ee9a2b4..ff2114892 100644 --- a/Sources/Bagbutik-Models/Reporting/AnalyticsReport.swift +++ b/Sources/Bagbutik-Models/Reporting/AnalyticsReport.swift @@ -26,28 +26,21 @@ public struct AnalyticsReport: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } public struct Attributes: Codable { @@ -61,6 +54,18 @@ public struct AnalyticsReport: Codable, Identifiable { self.name = name } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + category = try container.decodeIfPresent(Category.self, forKey: "category") + name = try container.decodeIfPresent(String.self, forKey: "name") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(category, forKey: "category") + try container.encodeIfPresent(name, forKey: "name") + } + public enum Category: String, Codable, CaseIterable { case appStoreEngagement = "APP_STORE_ENGAGEMENT" case appUsage = "APP_USAGE" diff --git a/Sources/Bagbutik-Models/Reporting/AnalyticsReportInstance.swift b/Sources/Bagbutik-Models/Reporting/AnalyticsReportInstance.swift index a0a691851..8e7a93f64 100644 --- a/Sources/Bagbutik-Models/Reporting/AnalyticsReportInstance.swift +++ b/Sources/Bagbutik-Models/Reporting/AnalyticsReportInstance.swift @@ -26,28 +26,21 @@ public struct AnalyticsReportInstance: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } /** @@ -69,6 +62,18 @@ public struct AnalyticsReportInstance: Codable, Identifiable { self.processingDate = processingDate } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + granularity = try container.decodeIfPresent(Granularity.self, forKey: "granularity") + processingDate = try container.decodeIfPresent(String.self, forKey: "processingDate") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(granularity, forKey: "granularity") + try container.encodeIfPresent(processingDate, forKey: "processingDate") + } + public enum Granularity: String, Codable, CaseIterable { case daily = "DAILY" case monthly = "MONTHLY" diff --git a/Sources/Bagbutik-Models/Reporting/AnalyticsReportInstanceResponse.swift b/Sources/Bagbutik-Models/Reporting/AnalyticsReportInstanceResponse.swift index 95bd7034e..fd6115c4e 100644 --- a/Sources/Bagbutik-Models/Reporting/AnalyticsReportInstanceResponse.swift +++ b/Sources/Bagbutik-Models/Reporting/AnalyticsReportInstanceResponse.swift @@ -20,4 +20,16 @@ public struct AnalyticsReportInstanceResponse: Codable { self.data = data self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AnalyticsReportInstance.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/Reporting/AnalyticsReportInstancesResponse.swift b/Sources/Bagbutik-Models/Reporting/AnalyticsReportInstancesResponse.swift index b5ccf9edf..c258a1e8d 100644 --- a/Sources/Bagbutik-Models/Reporting/AnalyticsReportInstancesResponse.swift +++ b/Sources/Bagbutik-Models/Reporting/AnalyticsReportInstancesResponse.swift @@ -25,4 +25,18 @@ public struct AnalyticsReportInstancesResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([AnalyticsReportInstance].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/Reporting/AnalyticsReportRequest.swift b/Sources/Bagbutik-Models/Reporting/AnalyticsReportRequest.swift index 9fdb610de..5f06743c4 100644 --- a/Sources/Bagbutik-Models/Reporting/AnalyticsReportRequest.swift +++ b/Sources/Bagbutik-Models/Reporting/AnalyticsReportRequest.swift @@ -29,31 +29,23 @@ public struct AnalyticsReportRequest: Codable, Identifiable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -74,6 +66,18 @@ public struct AnalyticsReportRequest: Codable, Identifiable, RequestBody { self.stoppedDueToInactivity = stoppedDueToInactivity } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + accessType = try container.decodeIfPresent(AccessType.self, forKey: "accessType") + stoppedDueToInactivity = try container.decodeIfPresent(Bool.self, forKey: "stoppedDueToInactivity") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(accessType, forKey: "accessType") + try container.encodeIfPresent(stoppedDueToInactivity, forKey: "stoppedDueToInactivity") + } + public enum AccessType: String, Codable, CaseIterable { case oneTimeSnapshot = "ONE_TIME_SNAPSHOT" case ongoing = "ONGOING" @@ -87,6 +91,16 @@ public struct AnalyticsReportRequest: Codable, Identifiable, RequestBody { self.reports = reports } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + reports = try container.decodeIfPresent(Reports.self, forKey: "reports") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(reports, forKey: "reports") + } + public struct Reports: Codable { @NullCodable public var data: [Data]? public var links: Links? @@ -102,23 +116,17 @@ public struct AnalyticsReportRequest: Codable, Identifiable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } /** @@ -137,22 +145,17 @@ public struct AnalyticsReportRequest: Codable, Identifiable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -175,20 +178,15 @@ public struct AnalyticsReportRequest: Codable, Identifiable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/Reporting/AnalyticsReportRequestCreateRequest.swift b/Sources/Bagbutik-Models/Reporting/AnalyticsReportRequestCreateRequest.swift index c789bc347..280fa93b4 100644 --- a/Sources/Bagbutik-Models/Reporting/AnalyticsReportRequestCreateRequest.swift +++ b/Sources/Bagbutik-Models/Reporting/AnalyticsReportRequestCreateRequest.swift @@ -17,6 +17,16 @@ public struct AnalyticsReportRequestCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AnalyticsReportRequestCreateRequest.Data The data structure that represents an analytics report request create request resource. @@ -37,25 +47,19 @@ public struct AnalyticsReportRequestCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } /** @@ -72,6 +76,16 @@ public struct AnalyticsReportRequestCreateRequest: Codable, RequestBody { public init(accessType: AnalyticsReportRequest.Attributes.AccessType) { self.accessType = accessType } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + accessType = try container.decode(AnalyticsReportRequest.Attributes.AccessType.self, forKey: "accessType") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(accessType, forKey: "accessType") + } } public struct Relationships: Codable { @@ -81,6 +95,16 @@ public struct AnalyticsReportRequestCreateRequest: Codable, RequestBody { self.app = app } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + app = try container.decode(App.self, forKey: "app") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(app, forKey: "app") + } + public struct App: Codable { public let data: Data @@ -88,6 +112,16 @@ public struct AnalyticsReportRequestCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AnalyticsReportRequestCreateRequest.Data.Relationships.App.Data The data structure that represents the app Apple ID for analytics report create request resource. @@ -105,22 +139,17 @@ public struct AnalyticsReportRequestCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/Reporting/AnalyticsReportRequestResponse.swift b/Sources/Bagbutik-Models/Reporting/AnalyticsReportRequestResponse.swift index 7f048f3a9..2b40b6e75 100644 --- a/Sources/Bagbutik-Models/Reporting/AnalyticsReportRequestResponse.swift +++ b/Sources/Bagbutik-Models/Reporting/AnalyticsReportRequestResponse.swift @@ -23,4 +23,18 @@ public struct AnalyticsReportRequestResponse: Codable { self.included = included self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AnalyticsReportRequest.self, forKey: "data") + included = try container.decodeIfPresent([AnalyticsReport].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/Reporting/AnalyticsReportRequestsResponse.swift b/Sources/Bagbutik-Models/Reporting/AnalyticsReportRequestsResponse.swift index 699349d3c..5234b68bc 100644 --- a/Sources/Bagbutik-Models/Reporting/AnalyticsReportRequestsResponse.swift +++ b/Sources/Bagbutik-Models/Reporting/AnalyticsReportRequestsResponse.swift @@ -28,4 +28,20 @@ public struct AnalyticsReportRequestsResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([AnalyticsReportRequest].self, forKey: "data") + included = try container.decodeIfPresent([AnalyticsReport].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/Reporting/AnalyticsReportResponse.swift b/Sources/Bagbutik-Models/Reporting/AnalyticsReportResponse.swift index ed182f1cc..158acb7a5 100644 --- a/Sources/Bagbutik-Models/Reporting/AnalyticsReportResponse.swift +++ b/Sources/Bagbutik-Models/Reporting/AnalyticsReportResponse.swift @@ -20,4 +20,16 @@ public struct AnalyticsReportResponse: Codable { self.data = data self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AnalyticsReport.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/Reporting/AnalyticsReportSegment.swift b/Sources/Bagbutik-Models/Reporting/AnalyticsReportSegment.swift index f5cc38ae5..b4bde879e 100644 --- a/Sources/Bagbutik-Models/Reporting/AnalyticsReportSegment.swift +++ b/Sources/Bagbutik-Models/Reporting/AnalyticsReportSegment.swift @@ -26,28 +26,21 @@ public struct AnalyticsReportSegment: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } /** @@ -71,5 +64,19 @@ public struct AnalyticsReportSegment: Codable, Identifiable { self.sizeInBytes = sizeInBytes self.url = url } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + checksum = try container.decodeIfPresent(String.self, forKey: "checksum") + sizeInBytes = try container.decodeIfPresent(Int.self, forKey: "sizeInBytes") + url = try container.decodeIfPresent(String.self, forKey: "url") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(checksum, forKey: "checksum") + try container.encodeIfPresent(sizeInBytes, forKey: "sizeInBytes") + try container.encodeIfPresent(url, forKey: "url") + } } } diff --git a/Sources/Bagbutik-Models/Reporting/AnalyticsReportSegmentResponse.swift b/Sources/Bagbutik-Models/Reporting/AnalyticsReportSegmentResponse.swift index 1027791da..c4f353ac5 100644 --- a/Sources/Bagbutik-Models/Reporting/AnalyticsReportSegmentResponse.swift +++ b/Sources/Bagbutik-Models/Reporting/AnalyticsReportSegmentResponse.swift @@ -20,4 +20,16 @@ public struct AnalyticsReportSegmentResponse: Codable { self.data = data self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(AnalyticsReportSegment.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/Reporting/AnalyticsReportSegmentsResponse.swift b/Sources/Bagbutik-Models/Reporting/AnalyticsReportSegmentsResponse.swift index eaff06e46..b2113e229 100644 --- a/Sources/Bagbutik-Models/Reporting/AnalyticsReportSegmentsResponse.swift +++ b/Sources/Bagbutik-Models/Reporting/AnalyticsReportSegmentsResponse.swift @@ -25,4 +25,18 @@ public struct AnalyticsReportSegmentsResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([AnalyticsReportSegment].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/Reporting/AnalyticsReportsResponse.swift b/Sources/Bagbutik-Models/Reporting/AnalyticsReportsResponse.swift index aea66add3..9aaf59c92 100644 --- a/Sources/Bagbutik-Models/Reporting/AnalyticsReportsResponse.swift +++ b/Sources/Bagbutik-Models/Reporting/AnalyticsReportsResponse.swift @@ -25,4 +25,18 @@ public struct AnalyticsReportsResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([AnalyticsReport].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/Reporting/DiagnosticLog.swift b/Sources/Bagbutik-Models/Reporting/DiagnosticLog.swift index c22e55362..5ac506e57 100644 --- a/Sources/Bagbutik-Models/Reporting/DiagnosticLog.swift +++ b/Sources/Bagbutik-Models/Reporting/DiagnosticLog.swift @@ -21,24 +21,18 @@ public struct DiagnosticLog: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case links - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") } } diff --git a/Sources/Bagbutik-Models/Reporting/DiagnosticLogCallStackNode.swift b/Sources/Bagbutik-Models/Reporting/DiagnosticLogCallStackNode.swift index 429472e88..923fb78e6 100644 --- a/Sources/Bagbutik-Models/Reporting/DiagnosticLogCallStackNode.swift +++ b/Sources/Bagbutik-Models/Reporting/DiagnosticLogCallStackNode.swift @@ -64,4 +64,38 @@ public struct DiagnosticLogCallStackNode: Codable { self.subFrames = subFrames self.symbolName = symbolName } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + address = try container.decodeIfPresent(String.self, forKey: "address") + binaryName = try container.decodeIfPresent(String.self, forKey: "binaryName") + binaryUUID = try container.decodeIfPresent(String.self, forKey: "binaryUUID") + fileName = try container.decodeIfPresent(String.self, forKey: "fileName") + insightsCategory = try container.decodeIfPresent(String.self, forKey: "insightsCategory") + isBlameFrame = try container.decodeIfPresent(Bool.self, forKey: "isBlameFrame") + lineNumber = try container.decodeIfPresent(String.self, forKey: "lineNumber") + offsetIntoBinaryTextSegment = try container.decodeIfPresent(String.self, forKey: "offsetIntoBinaryTextSegment") + offsetIntoSymbol = try container.decodeIfPresent(String.self, forKey: "offsetIntoSymbol") + rawFrame = try container.decodeIfPresent(String.self, forKey: "rawFrame") + sampleCount = try container.decodeIfPresent(Int.self, forKey: "sampleCount") + subFrames = try container.decodeIfPresent([DiagnosticLogCallStackNode].self, forKey: "subFrames") + symbolName = try container.decodeIfPresent(String.self, forKey: "symbolName") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(address, forKey: "address") + try container.encodeIfPresent(binaryName, forKey: "binaryName") + try container.encodeIfPresent(binaryUUID, forKey: "binaryUUID") + try container.encodeIfPresent(fileName, forKey: "fileName") + try container.encodeIfPresent(insightsCategory, forKey: "insightsCategory") + try container.encodeIfPresent(isBlameFrame, forKey: "isBlameFrame") + try container.encodeIfPresent(lineNumber, forKey: "lineNumber") + try container.encodeIfPresent(offsetIntoBinaryTextSegment, forKey: "offsetIntoBinaryTextSegment") + try container.encodeIfPresent(offsetIntoSymbol, forKey: "offsetIntoSymbol") + try container.encodeIfPresent(rawFrame, forKey: "rawFrame") + try container.encodeIfPresent(sampleCount, forKey: "sampleCount") + try container.encodeIfPresent(subFrames, forKey: "subFrames") + try container.encodeIfPresent(symbolName, forKey: "symbolName") + } } diff --git a/Sources/Bagbutik-Models/Reporting/DiagnosticLogs.swift b/Sources/Bagbutik-Models/Reporting/DiagnosticLogs.swift index 466dea42b..90241cb11 100644 --- a/Sources/Bagbutik-Models/Reporting/DiagnosticLogs.swift +++ b/Sources/Bagbutik-Models/Reporting/DiagnosticLogs.swift @@ -21,6 +21,18 @@ public struct DiagnosticLogs: Codable { self.version = version } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + productData = try container.decodeIfPresent([ProductData].self, forKey: "productData") + version = try container.decodeIfPresent(String.self, forKey: "version") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(productData, forKey: "productData") + try container.encodeIfPresent(version, forKey: "version") + } + /** # diagnosticLogs.ProductData The logs and insights for a diagnostic signature. @@ -45,6 +57,20 @@ public struct DiagnosticLogs: Codable { self.signatureId = signatureId } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + diagnosticInsights = try container.decodeIfPresent([DiagnosticInsights].self, forKey: "diagnosticInsights") + diagnosticLogs = try container.decodeIfPresent([DiagnosticLogs].self, forKey: "diagnosticLogs") + signatureId = try container.decodeIfPresent(String.self, forKey: "signatureId") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(diagnosticInsights, forKey: "diagnosticInsights") + try container.encodeIfPresent(diagnosticLogs, forKey: "diagnosticLogs") + try container.encodeIfPresent(signatureId, forKey: "signatureId") + } + /** # diagnosticLogs.ProductData.DiagnosticInsights Information about an insight including a descriptive string, category, and URL. @@ -68,6 +94,20 @@ public struct DiagnosticLogs: Codable { self.insightsString = insightsString self.insightsURL = insightsURL } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + insightsCategory = try container.decodeIfPresent(String.self, forKey: "insightsCategory") + insightsString = try container.decodeIfPresent(String.self, forKey: "insightsString") + insightsURL = try container.decodeIfPresent(String.self, forKey: "insightsURL") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(insightsCategory, forKey: "insightsCategory") + try container.encodeIfPresent(insightsString, forKey: "insightsString") + try container.encodeIfPresent(insightsURL, forKey: "insightsURL") + } } /** @@ -90,6 +130,18 @@ public struct DiagnosticLogs: Codable { self.diagnosticMetaData = diagnosticMetaData } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + callStackTree = try container.decodeIfPresent([CallStackTree].self, forKey: "callStackTree") + diagnosticMetaData = try container.decodeIfPresent(DiagnosticMetaData.self, forKey: "diagnosticMetaData") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(callStackTree, forKey: "callStackTree") + try container.encodeIfPresent(diagnosticMetaData, forKey: "diagnosticMetaData") + } + /** # diagnosticLogs.ProductData.DiagnosticLogs.CallStackTree The call stack representation of the diagnostic logs for single or multiple threads. @@ -110,6 +162,18 @@ public struct DiagnosticLogs: Codable { self.callStacks = callStacks } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + callStackPerThread = try container.decodeIfPresent(Bool.self, forKey: "callStackPerThread") + callStacks = try container.decodeIfPresent([CallStacks].self, forKey: "callStacks") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(callStackPerThread, forKey: "callStackPerThread") + try container.encodeIfPresent(callStacks, forKey: "callStacks") + } + /** # diagnosticLogs.ProductData.DiagnosticLogs.CallStackTree.CallStacks The root call stack frames of the diagnostic log. @@ -124,6 +188,16 @@ public struct DiagnosticLogs: Codable { public init(callStackRootFrames: [DiagnosticLogCallStackNode]? = nil) { self.callStackRootFrames = callStackRootFrames } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + callStackRootFrames = try container.decodeIfPresent([DiagnosticLogCallStackNode].self, forKey: "callStackRootFrames") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(callStackRootFrames, forKey: "callStackRootFrames") + } } } @@ -174,6 +248,32 @@ public struct DiagnosticLogs: Codable { self.platformArchitecture = platformArchitecture self.writesCaused = writesCaused } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appVersion = try container.decodeIfPresent(String.self, forKey: "appVersion") + buildVersion = try container.decodeIfPresent(String.self, forKey: "buildVersion") + bundleId = try container.decodeIfPresent(String.self, forKey: "bundleId") + deviceType = try container.decodeIfPresent(String.self, forKey: "deviceType") + event = try container.decodeIfPresent(String.self, forKey: "event") + eventDetail = try container.decodeIfPresent(String.self, forKey: "eventDetail") + osVersion = try container.decodeIfPresent(String.self, forKey: "osVersion") + platformArchitecture = try container.decodeIfPresent(String.self, forKey: "platformArchitecture") + writesCaused = try container.decodeIfPresent(String.self, forKey: "writesCaused") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(appVersion, forKey: "appVersion") + try container.encodeIfPresent(buildVersion, forKey: "buildVersion") + try container.encodeIfPresent(bundleId, forKey: "bundleId") + try container.encodeIfPresent(deviceType, forKey: "deviceType") + try container.encodeIfPresent(event, forKey: "event") + try container.encodeIfPresent(eventDetail, forKey: "eventDetail") + try container.encodeIfPresent(osVersion, forKey: "osVersion") + try container.encodeIfPresent(platformArchitecture, forKey: "platformArchitecture") + try container.encodeIfPresent(writesCaused, forKey: "writesCaused") + } } } } diff --git a/Sources/Bagbutik-Models/Reporting/DiagnosticSignature.swift b/Sources/Bagbutik-Models/Reporting/DiagnosticSignature.swift index 45169ba27..e820da162 100644 --- a/Sources/Bagbutik-Models/Reporting/DiagnosticSignature.swift +++ b/Sources/Bagbutik-Models/Reporting/DiagnosticSignature.swift @@ -28,28 +28,21 @@ public struct DiagnosticSignature: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } /** @@ -76,6 +69,20 @@ public struct DiagnosticSignature: Codable, Identifiable { self.weight = weight } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + diagnosticType = try container.decodeIfPresent(DiagnosticType.self, forKey: "diagnosticType") + signature = try container.decodeIfPresent(String.self, forKey: "signature") + weight = try container.decodeIfPresent(Double.self, forKey: "weight") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(diagnosticType, forKey: "diagnosticType") + try container.encodeIfPresent(signature, forKey: "signature") + try container.encodeIfPresent(weight, forKey: "weight") + } + public enum DiagnosticType: String, Codable, CaseIterable { case diskWrites = "DISK_WRITES" case hangs = "HANGS" diff --git a/Sources/Bagbutik-Models/Reporting/DiagnosticSignaturesResponse.swift b/Sources/Bagbutik-Models/Reporting/DiagnosticSignaturesResponse.swift index c809495e3..bdce78c59 100644 --- a/Sources/Bagbutik-Models/Reporting/DiagnosticSignaturesResponse.swift +++ b/Sources/Bagbutik-Models/Reporting/DiagnosticSignaturesResponse.swift @@ -26,4 +26,18 @@ public struct DiagnosticSignaturesResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([DiagnosticSignature].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/Reporting/Gzip.swift b/Sources/Bagbutik-Models/Reporting/Gzip.swift index 763694096..1b01aa7ee 100644 --- a/Sources/Bagbutik-Models/Reporting/Gzip.swift +++ b/Sources/Bagbutik-Models/Reporting/Gzip.swift @@ -7,4 +7,13 @@ public struct Gzip: BinaryResponse { public static func from(data: Data) -> Gzip { return Self(data: data) } + + public init(data: Data) { + self.data = data + } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } } diff --git a/Sources/Bagbutik-Models/Reporting/MetricsInsight.swift b/Sources/Bagbutik-Models/Reporting/MetricsInsight.swift index c816a09d3..5e55f07be 100644 --- a/Sources/Bagbutik-Models/Reporting/MetricsInsight.swift +++ b/Sources/Bagbutik-Models/Reporting/MetricsInsight.swift @@ -49,6 +49,32 @@ public struct MetricsInsight: Codable { self.summaryString = summaryString } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + highImpact = try container.decodeIfPresent(Bool.self, forKey: "highImpact") + latestVersion = try container.decodeIfPresent(String.self, forKey: "latestVersion") + maxLatestVersionValue = try container.decodeIfPresent(Double.self, forKey: "maxLatestVersionValue") + metric = try container.decodeIfPresent(String.self, forKey: "metric") + metricCategory = try container.decodeIfPresent(MetricCategory.self, forKey: "metricCategory") + populations = try container.decodeIfPresent([Populations].self, forKey: "populations") + referenceVersions = try container.decodeIfPresent(String.self, forKey: "referenceVersions") + subSystemLabel = try container.decodeIfPresent(String.self, forKey: "subSystemLabel") + summaryString = try container.decodeIfPresent(String.self, forKey: "summaryString") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(highImpact, forKey: "highImpact") + try container.encodeIfPresent(latestVersion, forKey: "latestVersion") + try container.encodeIfPresent(maxLatestVersionValue, forKey: "maxLatestVersionValue") + try container.encodeIfPresent(metric, forKey: "metric") + try container.encodeIfPresent(metricCategory, forKey: "metricCategory") + try container.encodeIfPresent(populations, forKey: "populations") + try container.encodeIfPresent(referenceVersions, forKey: "referenceVersions") + try container.encodeIfPresent(subSystemLabel, forKey: "subSystemLabel") + try container.encodeIfPresent(summaryString, forKey: "summaryString") + } + /** # MetricsInsight.Populations The value of a metric for a device type on the latest app version, and its percent change as compared with previous app versions. @@ -84,5 +110,25 @@ public struct MetricsInsight: Codable { self.referenceAverageValue = referenceAverageValue self.summaryString = summaryString } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + deltaPercentage = try container.decodeIfPresent(Double.self, forKey: "deltaPercentage") + device = try container.decodeIfPresent(String.self, forKey: "device") + latestVersionValue = try container.decodeIfPresent(Double.self, forKey: "latestVersionValue") + percentile = try container.decodeIfPresent(String.self, forKey: "percentile") + referenceAverageValue = try container.decodeIfPresent(Double.self, forKey: "referenceAverageValue") + summaryString = try container.decodeIfPresent(String.self, forKey: "summaryString") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(deltaPercentage, forKey: "deltaPercentage") + try container.encodeIfPresent(device, forKey: "device") + try container.encodeIfPresent(latestVersionValue, forKey: "latestVersionValue") + try container.encodeIfPresent(percentile, forKey: "percentile") + try container.encodeIfPresent(referenceAverageValue, forKey: "referenceAverageValue") + try container.encodeIfPresent(summaryString, forKey: "summaryString") + } } } diff --git a/Sources/Bagbutik-Models/Reporting/PerfPowerMetric.swift b/Sources/Bagbutik-Models/Reporting/PerfPowerMetric.swift index 9b7f83bc6..5c0a31dad 100644 --- a/Sources/Bagbutik-Models/Reporting/PerfPowerMetric.swift +++ b/Sources/Bagbutik-Models/Reporting/PerfPowerMetric.swift @@ -24,28 +24,21 @@ public struct PerfPowerMetric: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } /** @@ -71,6 +64,20 @@ public struct PerfPowerMetric: Codable, Identifiable { self.platform = platform } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + deviceType = try container.decodeIfPresent(String.self, forKey: "deviceType") + metricType = try container.decodeIfPresent(MetricType.self, forKey: "metricType") + platform = try container.decodeIfPresent(Platform.self, forKey: "platform") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(deviceType, forKey: "deviceType") + try container.encodeIfPresent(metricType, forKey: "metricType") + try container.encodeIfPresent(platform, forKey: "platform") + } + public enum MetricType: String, Codable, CaseIterable { case animation = "ANIMATION" case battery = "BATTERY" diff --git a/Sources/Bagbutik-Models/Reporting/XcodeMetrics.swift b/Sources/Bagbutik-Models/Reporting/XcodeMetrics.swift index b12499d75..5f7fb25b2 100644 --- a/Sources/Bagbutik-Models/Reporting/XcodeMetrics.swift +++ b/Sources/Bagbutik-Models/Reporting/XcodeMetrics.swift @@ -25,6 +25,20 @@ public struct XcodeMetrics: Codable { self.version = version } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + insights = try container.decodeIfPresent(Insights.self, forKey: "insights") + productData = try container.decodeIfPresent([ProductData].self, forKey: "productData") + version = try container.decodeIfPresent(String.self, forKey: "version") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(insights, forKey: "insights") + try container.encodeIfPresent(productData, forKey: "productData") + try container.encodeIfPresent(version, forKey: "version") + } + /** # xcodeMetrics.Insights Analysis of power and performance data collected for your app that includes regressions and trends. @@ -44,6 +58,18 @@ public struct XcodeMetrics: Codable { self.regressions = regressions self.trendingUp = trendingUp } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + regressions = try container.decodeIfPresent([MetricsInsight].self, forKey: "regressions") + trendingUp = try container.decodeIfPresent([MetricsInsight].self, forKey: "trendingUp") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(regressions, forKey: "regressions") + try container.encodeIfPresent(trendingUp, forKey: "trendingUp") + } } /** @@ -66,6 +92,18 @@ public struct XcodeMetrics: Codable { self.platform = platform } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + metricCategories = try container.decodeIfPresent([MetricCategories].self, forKey: "metricCategories") + platform = try container.decodeIfPresent(String.self, forKey: "platform") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(metricCategories, forKey: "metricCategories") + try container.encodeIfPresent(platform, forKey: "platform") + } + /** # xcodeMetrics.ProductData.MetricCategories A metric category and its associated array of data and measurements. @@ -86,6 +124,18 @@ public struct XcodeMetrics: Codable { self.metrics = metrics } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + identifier = try container.decodeIfPresent(MetricCategory.self, forKey: "identifier") + metrics = try container.decodeIfPresent([Metrics].self, forKey: "metrics") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(identifier, forKey: "identifier") + try container.encodeIfPresent(metrics, forKey: "metrics") + } + /** # xcodeMetrics.ProductData.MetricCategories.Metrics Data that relates to power and performance measurements for an app, including its datasets, goal keys, metrics identifier, and unit of measurement. @@ -114,6 +164,22 @@ public struct XcodeMetrics: Codable { self.unit = unit } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + datasets = try container.decodeIfPresent([Datasets].self, forKey: "datasets") + goalKeys = try container.decodeIfPresent([GoalKeys].self, forKey: "goalKeys") + identifier = try container.decodeIfPresent(String.self, forKey: "identifier") + unit = try container.decodeIfPresent(Unit.self, forKey: "unit") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(datasets, forKey: "datasets") + try container.encodeIfPresent(goalKeys, forKey: "goalKeys") + try container.encodeIfPresent(identifier, forKey: "identifier") + try container.encodeIfPresent(unit, forKey: "unit") + } + /** # xcodeMetrics.ProductData.MetricCategories.Metrics.Datasets A set of data containing metric values for each app version, filtered by percentile and device type. @@ -134,6 +200,18 @@ public struct XcodeMetrics: Codable { self.points = points } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + filterCriteria = try container.decodeIfPresent(FilterCriteria.self, forKey: "filterCriteria") + points = try container.decodeIfPresent([Points].self, forKey: "points") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(filterCriteria, forKey: "filterCriteria") + try container.encodeIfPresent(points, forKey: "points") + } + /** # xcodeMetrics.ProductData.MetricCategories.Metrics.Datasets.FilterCriteria The device and percentile criteria by which the system filters a metrics dataset. @@ -157,6 +235,20 @@ public struct XcodeMetrics: Codable { self.deviceMarketingName = deviceMarketingName self.percentile = percentile } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + device = try container.decodeIfPresent(String.self, forKey: "device") + deviceMarketingName = try container.decodeIfPresent(String.self, forKey: "deviceMarketingName") + percentile = try container.decodeIfPresent(String.self, forKey: "percentile") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(device, forKey: "device") + try container.encodeIfPresent(deviceMarketingName, forKey: "deviceMarketingName") + try container.encodeIfPresent(percentile, forKey: "percentile") + } } /** @@ -191,6 +283,24 @@ public struct XcodeMetrics: Codable { self.version = version } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + errorMargin = try container.decodeIfPresent(Double.self, forKey: "errorMargin") + goal = try container.decodeIfPresent(String.self, forKey: "goal") + percentageBreakdown = try container.decodeIfPresent(PercentageBreakdown.self, forKey: "percentageBreakdown") + value = try container.decodeIfPresent(Double.self, forKey: "value") + version = try container.decodeIfPresent(String.self, forKey: "version") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(errorMargin, forKey: "errorMargin") + try container.encodeIfPresent(goal, forKey: "goal") + try container.encodeIfPresent(percentageBreakdown, forKey: "percentageBreakdown") + try container.encodeIfPresent(value, forKey: "value") + try container.encodeIfPresent(version, forKey: "version") + } + /** # xcodeMetrics.ProductData.MetricCategories.Metrics.Datasets.Points.PercentageBreakdown A metric subtype and the percentage of the metric value it contributes. @@ -210,6 +320,18 @@ public struct XcodeMetrics: Codable { self.subSystemLabel = subSystemLabel self.value = value } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + subSystemLabel = try container.decodeIfPresent(String.self, forKey: "subSystemLabel") + value = try container.decodeIfPresent(Double.self, forKey: "value") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(subSystemLabel, forKey: "subSystemLabel") + try container.encodeIfPresent(value, forKey: "value") + } } } } @@ -237,6 +359,20 @@ public struct XcodeMetrics: Codable { self.lowerBound = lowerBound self.upperBound = upperBound } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + goalKey = try container.decodeIfPresent(String.self, forKey: "goalKey") + lowerBound = try container.decodeIfPresent(Int.self, forKey: "lowerBound") + upperBound = try container.decodeIfPresent(Int.self, forKey: "upperBound") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(goalKey, forKey: "goalKey") + try container.encodeIfPresent(lowerBound, forKey: "lowerBound") + try container.encodeIfPresent(upperBound, forKey: "upperBound") + } } /** @@ -258,6 +394,18 @@ public struct XcodeMetrics: Codable { self.displayName = displayName self.identifier = identifier } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + displayName = try container.decodeIfPresent(String.self, forKey: "displayName") + identifier = try container.decodeIfPresent(String.self, forKey: "identifier") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(displayName, forKey: "displayName") + try container.encodeIfPresent(identifier, forKey: "identifier") + } } } } diff --git a/Sources/Bagbutik-Models/TestFlight/AppBetaTestersLinkagesRequest.swift b/Sources/Bagbutik-Models/TestFlight/AppBetaTestersLinkagesRequest.swift index 5392bed32..82e770b51 100644 --- a/Sources/Bagbutik-Models/TestFlight/AppBetaTestersLinkagesRequest.swift +++ b/Sources/Bagbutik-Models/TestFlight/AppBetaTestersLinkagesRequest.swift @@ -16,6 +16,16 @@ public struct AppBetaTestersLinkagesRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # AppBetaTestersLinkagesRequest.Data The data element of the request body. @@ -34,22 +44,17 @@ public struct AppBetaTestersLinkagesRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/TestFlight/AppsBetaTesterUsagesV1MetricResponse.swift b/Sources/Bagbutik-Models/TestFlight/AppsBetaTesterUsagesV1MetricResponse.swift index d7b436121..0a95ccb16 100644 --- a/Sources/Bagbutik-Models/TestFlight/AppsBetaTesterUsagesV1MetricResponse.swift +++ b/Sources/Bagbutik-Models/TestFlight/AppsBetaTesterUsagesV1MetricResponse.swift @@ -25,6 +25,22 @@ public struct AppsBetaTesterUsagesV1MetricResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + included = try container.decodeIfPresent([BetaTester].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public struct Data: Codable { public var dataPoints: DataPoints? public var dimensions: Dimensions? @@ -36,6 +52,18 @@ public struct AppsBetaTesterUsagesV1MetricResponse: Codable, PagedResponse { self.dimensions = dimensions } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + dataPoints = try container.decodeIfPresent(DataPoints.self, forKey: "dataPoints") + dimensions = try container.decodeIfPresent(Dimensions.self, forKey: "dimensions") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(dataPoints, forKey: "dataPoints") + try container.encodeIfPresent(dimensions, forKey: "dimensions") + } + public struct DataPoints: Codable { public var end: Date? public var start: Date? @@ -50,6 +78,20 @@ public struct AppsBetaTesterUsagesV1MetricResponse: Codable, PagedResponse { self.values = values } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + end = try container.decodeIfPresent(Date.self, forKey: "end") + start = try container.decodeIfPresent(Date.self, forKey: "start") + values = try container.decodeIfPresent(Values.self, forKey: "values") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(end, forKey: "end") + try container.encodeIfPresent(start, forKey: "start") + try container.encodeIfPresent(values, forKey: "values") + } + public struct Values: Codable { public var crashCount: Int? public var feedbackCount: Int? @@ -63,6 +105,20 @@ public struct AppsBetaTesterUsagesV1MetricResponse: Codable, PagedResponse { self.feedbackCount = feedbackCount self.sessionCount = sessionCount } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + crashCount = try container.decodeIfPresent(Int.self, forKey: "crashCount") + feedbackCount = try container.decodeIfPresent(Int.self, forKey: "feedbackCount") + sessionCount = try container.decodeIfPresent(Int.self, forKey: "sessionCount") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(crashCount, forKey: "crashCount") + try container.encodeIfPresent(feedbackCount, forKey: "feedbackCount") + try container.encodeIfPresent(sessionCount, forKey: "sessionCount") + } } } @@ -73,6 +129,16 @@ public struct AppsBetaTesterUsagesV1MetricResponse: Codable, PagedResponse { self.betaTesters = betaTesters } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + betaTesters = try container.decodeIfPresent(BetaTesters.self, forKey: "betaTesters") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(betaTesters, forKey: "betaTesters") + } + public struct BetaTesters: Codable { public var links: Links? @@ -80,6 +146,16 @@ public struct AppsBetaTesterUsagesV1MetricResponse: Codable, PagedResponse { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + links = try container.decodeIfPresent(Links.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(links, forKey: "links") + } + public struct Links: Codable { public var groupBy: String? public var related: String? @@ -90,6 +166,18 @@ public struct AppsBetaTesterUsagesV1MetricResponse: Codable, PagedResponse { self.groupBy = groupBy self.related = related } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + groupBy = try container.decodeIfPresent(String.self, forKey: "groupBy") + related = try container.decodeIfPresent(String.self, forKey: "related") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(groupBy, forKey: "groupBy") + try container.encodeIfPresent(related, forKey: "related") + } } } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaAppClipInvocation.swift b/Sources/Bagbutik-Models/TestFlight/BetaAppClipInvocation.swift index 5a18d6b80..d8f7b249e 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaAppClipInvocation.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaAppClipInvocation.swift @@ -32,31 +32,23 @@ public struct BetaAppClipInvocation: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -73,6 +65,16 @@ public struct BetaAppClipInvocation: Codable, Identifiable { public init(url: String? = nil) { self.url = url } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + url = try container.decodeIfPresent(String.self, forKey: "url") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(url, forKey: "url") + } } /** @@ -90,6 +92,16 @@ public struct BetaAppClipInvocation: Codable, Identifiable { self.betaAppClipInvocationLocalizations = betaAppClipInvocationLocalizations } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + betaAppClipInvocationLocalizations = try container.decodeIfPresent(BetaAppClipInvocationLocalizations.self, forKey: "betaAppClipInvocationLocalizations") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(betaAppClipInvocationLocalizations, forKey: "betaAppClipInvocationLocalizations") + } + /** # BetaAppClipInvocation.Relationships.BetaAppClipInvocationLocalizations The data, links, and paging information that describe the relationship between the Beta App Clip Invocations and the Beta App Clip Invocation Localizations resources. @@ -115,23 +127,17 @@ public struct BetaAppClipInvocation: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } /** @@ -152,22 +158,17 @@ public struct BetaAppClipInvocation: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -192,20 +193,15 @@ public struct BetaAppClipInvocation: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaAppClipInvocationCreateRequest.swift b/Sources/Bagbutik-Models/TestFlight/BetaAppClipInvocationCreateRequest.swift index dfbb6cf45..2d5c30e98 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaAppClipInvocationCreateRequest.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaAppClipInvocationCreateRequest.swift @@ -21,6 +21,18 @@ public struct BetaAppClipInvocationCreateRequest: Codable, RequestBody { self.included = included } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + included = try container.decodeIfPresent([BetaAppClipInvocationLocalizationInlineCreate].self, forKey: "included") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + } + /** # BetaAppClipInvocationCreateRequest.Data The data element of the request body. @@ -44,25 +56,19 @@ public struct BetaAppClipInvocationCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } /** @@ -79,6 +85,16 @@ public struct BetaAppClipInvocationCreateRequest: Codable, RequestBody { public init(url: String) { self.url = url } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + url = try container.decode(String.self, forKey: "url") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(url, forKey: "url") + } } /** @@ -101,6 +117,18 @@ public struct BetaAppClipInvocationCreateRequest: Codable, RequestBody { self.buildBundle = buildBundle } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + betaAppClipInvocationLocalizations = try container.decode(BetaAppClipInvocationLocalizations.self, forKey: "betaAppClipInvocationLocalizations") + buildBundle = try container.decode(BuildBundle.self, forKey: "buildBundle") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(betaAppClipInvocationLocalizations, forKey: "betaAppClipInvocationLocalizations") + try container.encode(buildBundle, forKey: "buildBundle") + } + /** # BetaAppClipInvocationCreateRequest.Data.Relationships.BetaAppClipInvocationLocalizations The relationship to the Beta App Clip Invocation Localizations resource you set with the request that creates a Beta App Clip Invocations resource. @@ -116,6 +144,16 @@ public struct BetaAppClipInvocationCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # BetaAppClipInvocationCreateRequest.Data.Relationships.BetaAppClipInvocationLocalizations.Data The type and ID of the Beta App Clip Invocation Localizations resource that you’re relating with the Beta App Clip Invocations resource you’re creating. @@ -134,22 +172,17 @@ public struct BetaAppClipInvocationCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -169,6 +202,16 @@ public struct BetaAppClipInvocationCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # BetaAppClipInvocationCreateRequest.Data.Relationships.BuildBundle.Data The type and ID of the Build Bundles resource that you’re relating with the Beta App Clip Invocations resource you’re creating. @@ -187,22 +230,17 @@ public struct BetaAppClipInvocationCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaAppClipInvocationLocalization.swift b/Sources/Bagbutik-Models/TestFlight/BetaAppClipInvocationLocalization.swift index 0e1c616da..465e560c3 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaAppClipInvocationLocalization.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaAppClipInvocationLocalization.swift @@ -28,28 +28,21 @@ public struct BetaAppClipInvocationLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } /** @@ -71,5 +64,17 @@ public struct BetaAppClipInvocationLocalization: Codable, Identifiable { self.locale = locale self.title = title } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + locale = try container.decodeIfPresent(String.self, forKey: "locale") + title = try container.decodeIfPresent(String.self, forKey: "title") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(locale, forKey: "locale") + try container.encodeIfPresent(title, forKey: "title") + } } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaAppClipInvocationLocalizationCreateRequest.swift b/Sources/Bagbutik-Models/TestFlight/BetaAppClipInvocationLocalizationCreateRequest.swift index 2bf18b514..e88d20ea7 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaAppClipInvocationLocalizationCreateRequest.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaAppClipInvocationLocalizationCreateRequest.swift @@ -16,6 +16,16 @@ public struct BetaAppClipInvocationLocalizationCreateRequest: Codable, RequestBo self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # BetaAppClipInvocationLocalizationCreateRequest.Data The data element of the request body. @@ -39,25 +49,19 @@ public struct BetaAppClipInvocationLocalizationCreateRequest: Codable, RequestBo } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } /** @@ -79,6 +83,18 @@ public struct BetaAppClipInvocationLocalizationCreateRequest: Codable, RequestBo self.locale = locale self.title = title } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + locale = try container.decode(String.self, forKey: "locale") + title = try container.decode(String.self, forKey: "title") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(locale, forKey: "locale") + try container.encode(title, forKey: "title") + } } /** @@ -96,6 +112,16 @@ public struct BetaAppClipInvocationLocalizationCreateRequest: Codable, RequestBo self.betaAppClipInvocation = betaAppClipInvocation } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + betaAppClipInvocation = try container.decode(BetaAppClipInvocation.self, forKey: "betaAppClipInvocation") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(betaAppClipInvocation, forKey: "betaAppClipInvocation") + } + /** # BetaAppClipInvocationLocalizationCreateRequest.Data.Relationships.BetaAppClipInvocation The relationship to the Beta App Clip Invocations resource you set with the request that creates a Beta App Clip Invocation Localizations resource. @@ -111,6 +137,16 @@ public struct BetaAppClipInvocationLocalizationCreateRequest: Codable, RequestBo self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # BetaAppClipInvocationLocalizationCreateRequest.Data.Relationships.BetaAppClipInvocation.Data The type and ID of the Beta App Clip Invocations resource that you’re relating with the Beta App Clip Invocation Localizations resource you’re creating. @@ -129,22 +165,17 @@ public struct BetaAppClipInvocationLocalizationCreateRequest: Codable, RequestBo } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaAppClipInvocationLocalizationInlineCreate.swift b/Sources/Bagbutik-Models/TestFlight/BetaAppClipInvocationLocalizationInlineCreate.swift index dd4ea7fb2..2667b92e2 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaAppClipInvocationLocalizationInlineCreate.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaAppClipInvocationLocalizationInlineCreate.swift @@ -28,28 +28,21 @@ public struct BetaAppClipInvocationLocalizationInlineCreate: Codable, Identifiab } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decodeIfPresent(String.self, forKey: .id) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decodeIfPresent(String.self, forKey: "id") + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -71,6 +64,18 @@ public struct BetaAppClipInvocationLocalizationInlineCreate: Codable, Identifiab self.locale = locale self.title = title } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + locale = try container.decode(String.self, forKey: "locale") + title = try container.decode(String.self, forKey: "title") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(locale, forKey: "locale") + try container.encode(title, forKey: "title") + } } /** @@ -88,6 +93,16 @@ public struct BetaAppClipInvocationLocalizationInlineCreate: Codable, Identifiab self.betaAppClipInvocation = betaAppClipInvocation } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + betaAppClipInvocation = try container.decodeIfPresent(BetaAppClipInvocation.self, forKey: "betaAppClipInvocation") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(betaAppClipInvocation, forKey: "betaAppClipInvocation") + } + /** # BetaAppClipInvocationLocalizationInlineCreate.Relationships.BetaAppClipInvocation The relationship to the Beta App Clip Invocations resource you can set when you create a Beta App Clip Invocation Localizations resource. @@ -104,17 +119,13 @@ public struct BetaAppClipInvocationLocalizationInlineCreate: Codable, Identifiab } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } /** @@ -135,22 +146,17 @@ public struct BetaAppClipInvocationLocalizationInlineCreate: Codable, Identifiab } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaAppClipInvocationLocalizationResponse.swift b/Sources/Bagbutik-Models/TestFlight/BetaAppClipInvocationLocalizationResponse.swift index 0a6bd8dde..9acccadea 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaAppClipInvocationLocalizationResponse.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaAppClipInvocationLocalizationResponse.swift @@ -20,4 +20,16 @@ public struct BetaAppClipInvocationLocalizationResponse: Codable { self.data = data self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(BetaAppClipInvocationLocalization.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaAppClipInvocationLocalizationUpdateRequest.swift b/Sources/Bagbutik-Models/TestFlight/BetaAppClipInvocationLocalizationUpdateRequest.swift index 1ce7939e7..3b9171fcb 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaAppClipInvocationLocalizationUpdateRequest.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaAppClipInvocationLocalizationUpdateRequest.swift @@ -16,6 +16,16 @@ public struct BetaAppClipInvocationLocalizationUpdateRequest: Codable, RequestBo self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # BetaAppClipInvocationLocalizationUpdateRequest.Data The data element of the request body. @@ -39,25 +49,19 @@ public struct BetaAppClipInvocationLocalizationUpdateRequest: Codable, RequestBo } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } /** @@ -74,6 +78,16 @@ public struct BetaAppClipInvocationLocalizationUpdateRequest: Codable, RequestBo public init(title: String? = nil) { self.title = title } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + title = try container.decodeIfPresent(String.self, forKey: "title") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(title, forKey: "title") + } } } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaAppClipInvocationResponse.swift b/Sources/Bagbutik-Models/TestFlight/BetaAppClipInvocationResponse.swift index 0cba40b13..0343356b3 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaAppClipInvocationResponse.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaAppClipInvocationResponse.swift @@ -24,4 +24,18 @@ public struct BetaAppClipInvocationResponse: Codable { self.included = included self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(BetaAppClipInvocation.self, forKey: "data") + included = try container.decodeIfPresent([BetaAppClipInvocationLocalization].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaAppClipInvocationUpdateRequest.swift b/Sources/Bagbutik-Models/TestFlight/BetaAppClipInvocationUpdateRequest.swift index 84bafd00a..ddec3fd59 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaAppClipInvocationUpdateRequest.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaAppClipInvocationUpdateRequest.swift @@ -16,6 +16,16 @@ public struct BetaAppClipInvocationUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # BetaAppClipInvocationUpdateRequest.Data The data element of the request body. @@ -39,25 +49,19 @@ public struct BetaAppClipInvocationUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } /** @@ -74,6 +78,16 @@ public struct BetaAppClipInvocationUpdateRequest: Codable, RequestBody { public init(url: String? = nil) { self.url = url } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + url = try container.decodeIfPresent(String.self, forKey: "url") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(url, forKey: "url") + } } } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaAppLocalization.swift b/Sources/Bagbutik-Models/TestFlight/BetaAppLocalization.swift index 2569eebe2..98ce80d93 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaAppLocalization.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaAppLocalization.swift @@ -32,31 +32,23 @@ public struct BetaAppLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -96,6 +88,26 @@ public struct BetaAppLocalization: Codable, Identifiable { self.privacyPolicyUrl = privacyPolicyUrl self.tvOsPrivacyPolicy = tvOsPrivacyPolicy } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + description = try container.decodeIfPresent(String.self, forKey: "description") + feedbackEmail = try container.decodeIfPresent(String.self, forKey: "feedbackEmail") + locale = try container.decodeIfPresent(String.self, forKey: "locale") + marketingUrl = try container.decodeIfPresent(String.self, forKey: "marketingUrl") + privacyPolicyUrl = try container.decodeIfPresent(String.self, forKey: "privacyPolicyUrl") + tvOsPrivacyPolicy = try container.decodeIfPresent(String.self, forKey: "tvOsPrivacyPolicy") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(description, forKey: "description") + try container.encodeIfPresent(feedbackEmail, forKey: "feedbackEmail") + try container.encodeIfPresent(locale, forKey: "locale") + try container.encodeIfPresent(marketingUrl, forKey: "marketingUrl") + try container.encodeIfPresent(privacyPolicyUrl, forKey: "privacyPolicyUrl") + try container.encodeIfPresent(tvOsPrivacyPolicy, forKey: "tvOsPrivacyPolicy") + } } /** @@ -112,6 +124,16 @@ public struct BetaAppLocalization: Codable, Identifiable { self.app = app } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + app = try container.decodeIfPresent(App.self, forKey: "app") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(app, forKey: "app") + } + /** # BetaAppLocalization.Relationships.App The data and links that describe the relationship between the resources. @@ -131,20 +153,15 @@ public struct BetaAppLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -165,22 +182,17 @@ public struct BetaAppLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -203,20 +215,15 @@ public struct BetaAppLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaAppLocalizationCreateRequest.swift b/Sources/Bagbutik-Models/TestFlight/BetaAppLocalizationCreateRequest.swift index 9769dd195..68a67fd20 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaAppLocalizationCreateRequest.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaAppLocalizationCreateRequest.swift @@ -16,6 +16,16 @@ public struct BetaAppLocalizationCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # BetaAppLocalizationCreateRequest.Data The data element of the request body. @@ -39,25 +49,19 @@ public struct BetaAppLocalizationCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } /** @@ -97,6 +101,26 @@ public struct BetaAppLocalizationCreateRequest: Codable, RequestBody { self.privacyPolicyUrl = privacyPolicyUrl self.tvOsPrivacyPolicy = tvOsPrivacyPolicy } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + description = try container.decodeIfPresent(String.self, forKey: "description") + feedbackEmail = try container.decodeIfPresent(String.self, forKey: "feedbackEmail") + locale = try container.decode(String.self, forKey: "locale") + marketingUrl = try container.decodeIfPresent(String.self, forKey: "marketingUrl") + privacyPolicyUrl = try container.decodeIfPresent(String.self, forKey: "privacyPolicyUrl") + tvOsPrivacyPolicy = try container.decodeIfPresent(String.self, forKey: "tvOsPrivacyPolicy") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(description, forKey: "description") + try container.encodeIfPresent(feedbackEmail, forKey: "feedbackEmail") + try container.encode(locale, forKey: "locale") + try container.encodeIfPresent(marketingUrl, forKey: "marketingUrl") + try container.encodeIfPresent(privacyPolicyUrl, forKey: "privacyPolicyUrl") + try container.encodeIfPresent(tvOsPrivacyPolicy, forKey: "tvOsPrivacyPolicy") + } } /** @@ -113,6 +137,16 @@ public struct BetaAppLocalizationCreateRequest: Codable, RequestBody { self.app = app } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + app = try container.decode(App.self, forKey: "app") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(app, forKey: "app") + } + /** # BetaAppLocalizationCreateRequest.Data.Relationships.App The relationships to other resources that you can set with this request. @@ -127,6 +161,16 @@ public struct BetaAppLocalizationCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # BetaAppLocalizationCreateRequest.Data.Relationships.App.Data The type and ID of the resource that you're relating with the resource you're creating. @@ -145,22 +189,17 @@ public struct BetaAppLocalizationCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaAppLocalizationResponse.swift b/Sources/Bagbutik-Models/TestFlight/BetaAppLocalizationResponse.swift index 265ddd41e..764b21241 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaAppLocalizationResponse.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaAppLocalizationResponse.swift @@ -23,4 +23,18 @@ public struct BetaAppLocalizationResponse: Codable { self.included = included self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(BetaAppLocalization.self, forKey: "data") + included = try container.decodeIfPresent([App].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaAppLocalizationUpdateRequest.swift b/Sources/Bagbutik-Models/TestFlight/BetaAppLocalizationUpdateRequest.swift index c10b7e8a1..dc14501a2 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaAppLocalizationUpdateRequest.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaAppLocalizationUpdateRequest.swift @@ -16,6 +16,16 @@ public struct BetaAppLocalizationUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # BetaAppLocalizationUpdateRequest.Data The data element of the request body. @@ -39,25 +49,19 @@ public struct BetaAppLocalizationUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } /** @@ -91,6 +95,24 @@ public struct BetaAppLocalizationUpdateRequest: Codable, RequestBody { self.privacyPolicyUrl = privacyPolicyUrl self.tvOsPrivacyPolicy = tvOsPrivacyPolicy } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + description = try container.decodeIfPresent(String.self, forKey: "description") + feedbackEmail = try container.decodeIfPresent(String.self, forKey: "feedbackEmail") + marketingUrl = try container.decodeIfPresent(String.self, forKey: "marketingUrl") + privacyPolicyUrl = try container.decodeIfPresent(String.self, forKey: "privacyPolicyUrl") + tvOsPrivacyPolicy = try container.decodeIfPresent(String.self, forKey: "tvOsPrivacyPolicy") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(description, forKey: "description") + try container.encodeIfPresent(feedbackEmail, forKey: "feedbackEmail") + try container.encodeIfPresent(marketingUrl, forKey: "marketingUrl") + try container.encodeIfPresent(privacyPolicyUrl, forKey: "privacyPolicyUrl") + try container.encodeIfPresent(tvOsPrivacyPolicy, forKey: "tvOsPrivacyPolicy") + } } } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaAppLocalizationsResponse.swift b/Sources/Bagbutik-Models/TestFlight/BetaAppLocalizationsResponse.swift index 43a13b1c2..94b735df6 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaAppLocalizationsResponse.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaAppLocalizationsResponse.swift @@ -29,4 +29,20 @@ public struct BetaAppLocalizationsResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([BetaAppLocalization].self, forKey: "data") + included = try container.decodeIfPresent([App].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaAppLocalizationsWithoutIncludesResponse.swift b/Sources/Bagbutik-Models/TestFlight/BetaAppLocalizationsWithoutIncludesResponse.swift index 8d62d8306..30b948585 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaAppLocalizationsWithoutIncludesResponse.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaAppLocalizationsWithoutIncludesResponse.swift @@ -16,4 +16,18 @@ public struct BetaAppLocalizationsWithoutIncludesResponse: Codable, PagedRespons self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([BetaAppLocalization].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaAppReviewDetail.swift b/Sources/Bagbutik-Models/TestFlight/BetaAppReviewDetail.swift index a9a1a15a7..e6dcabd92 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaAppReviewDetail.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaAppReviewDetail.swift @@ -32,31 +32,23 @@ public struct BetaAppReviewDetail: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -102,6 +94,30 @@ public struct BetaAppReviewDetail: Codable, Identifiable { self.demoAccountRequired = demoAccountRequired self.notes = notes } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + contactEmail = try container.decodeIfPresent(String.self, forKey: "contactEmail") + contactFirstName = try container.decodeIfPresent(String.self, forKey: "contactFirstName") + contactLastName = try container.decodeIfPresent(String.self, forKey: "contactLastName") + contactPhone = try container.decodeIfPresent(String.self, forKey: "contactPhone") + demoAccountName = try container.decodeIfPresent(String.self, forKey: "demoAccountName") + demoAccountPassword = try container.decodeIfPresent(String.self, forKey: "demoAccountPassword") + demoAccountRequired = try container.decodeIfPresent(Bool.self, forKey: "demoAccountRequired") + notes = try container.decodeIfPresent(String.self, forKey: "notes") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(contactEmail, forKey: "contactEmail") + try container.encodeIfPresent(contactFirstName, forKey: "contactFirstName") + try container.encodeIfPresent(contactLastName, forKey: "contactLastName") + try container.encodeIfPresent(contactPhone, forKey: "contactPhone") + try container.encodeIfPresent(demoAccountName, forKey: "demoAccountName") + try container.encodeIfPresent(demoAccountPassword, forKey: "demoAccountPassword") + try container.encodeIfPresent(demoAccountRequired, forKey: "demoAccountRequired") + try container.encodeIfPresent(notes, forKey: "notes") + } } /** @@ -118,6 +134,16 @@ public struct BetaAppReviewDetail: Codable, Identifiable { self.app = app } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + app = try container.decodeIfPresent(App.self, forKey: "app") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(app, forKey: "app") + } + /** # BetaAppReviewDetail.Relationships.App The data and links that describe the relationship between the resources. @@ -137,20 +163,15 @@ public struct BetaAppReviewDetail: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -171,22 +192,17 @@ public struct BetaAppReviewDetail: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -209,20 +225,15 @@ public struct BetaAppReviewDetail: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaAppReviewDetailResponse.swift b/Sources/Bagbutik-Models/TestFlight/BetaAppReviewDetailResponse.swift index b07262a38..933e0257f 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaAppReviewDetailResponse.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaAppReviewDetailResponse.swift @@ -23,4 +23,18 @@ public struct BetaAppReviewDetailResponse: Codable { self.included = included self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(BetaAppReviewDetail.self, forKey: "data") + included = try container.decodeIfPresent([App].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaAppReviewDetailUpdateRequest.swift b/Sources/Bagbutik-Models/TestFlight/BetaAppReviewDetailUpdateRequest.swift index a1d65c9cb..3f86c8e29 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaAppReviewDetailUpdateRequest.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaAppReviewDetailUpdateRequest.swift @@ -16,6 +16,16 @@ public struct BetaAppReviewDetailUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # BetaAppReviewDetailUpdateRequest.Data The data element of the request body. @@ -39,25 +49,19 @@ public struct BetaAppReviewDetailUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } /** @@ -103,6 +107,30 @@ public struct BetaAppReviewDetailUpdateRequest: Codable, RequestBody { self.demoAccountRequired = demoAccountRequired self.notes = notes } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + contactEmail = try container.decodeIfPresent(String.self, forKey: "contactEmail") + contactFirstName = try container.decodeIfPresent(String.self, forKey: "contactFirstName") + contactLastName = try container.decodeIfPresent(String.self, forKey: "contactLastName") + contactPhone = try container.decodeIfPresent(String.self, forKey: "contactPhone") + demoAccountName = try container.decodeIfPresent(String.self, forKey: "demoAccountName") + demoAccountPassword = try container.decodeIfPresent(String.self, forKey: "demoAccountPassword") + demoAccountRequired = try container.decodeIfPresent(Bool.self, forKey: "demoAccountRequired") + notes = try container.decodeIfPresent(String.self, forKey: "notes") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(contactEmail, forKey: "contactEmail") + try container.encodeIfPresent(contactFirstName, forKey: "contactFirstName") + try container.encodeIfPresent(contactLastName, forKey: "contactLastName") + try container.encodeIfPresent(contactPhone, forKey: "contactPhone") + try container.encodeIfPresent(demoAccountName, forKey: "demoAccountName") + try container.encodeIfPresent(demoAccountPassword, forKey: "demoAccountPassword") + try container.encodeIfPresent(demoAccountRequired, forKey: "demoAccountRequired") + try container.encodeIfPresent(notes, forKey: "notes") + } } } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaAppReviewDetailWithoutIncludesResponse.swift b/Sources/Bagbutik-Models/TestFlight/BetaAppReviewDetailWithoutIncludesResponse.swift index b488da3ff..2e75e40cc 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaAppReviewDetailWithoutIncludesResponse.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaAppReviewDetailWithoutIncludesResponse.swift @@ -11,4 +11,16 @@ public struct BetaAppReviewDetailWithoutIncludesResponse: Codable { self.data = data self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(BetaAppReviewDetail.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaAppReviewDetailsResponse.swift b/Sources/Bagbutik-Models/TestFlight/BetaAppReviewDetailsResponse.swift index 7bd1128ff..0bb7a5d62 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaAppReviewDetailsResponse.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaAppReviewDetailsResponse.swift @@ -29,4 +29,20 @@ public struct BetaAppReviewDetailsResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([BetaAppReviewDetail].self, forKey: "data") + included = try container.decodeIfPresent([App].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaAppReviewSubmission.swift b/Sources/Bagbutik-Models/TestFlight/BetaAppReviewSubmission.swift index 11aac1b98..115ebb5ee 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaAppReviewSubmission.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaAppReviewSubmission.swift @@ -32,31 +32,23 @@ public struct BetaAppReviewSubmission: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -77,6 +69,18 @@ public struct BetaAppReviewSubmission: Codable, Identifiable { self.betaReviewState = betaReviewState self.submittedDate = submittedDate } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + betaReviewState = try container.decodeIfPresent(BetaReviewState.self, forKey: "betaReviewState") + submittedDate = try container.decodeIfPresent(Date.self, forKey: "submittedDate") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(betaReviewState, forKey: "betaReviewState") + try container.encodeIfPresent(submittedDate, forKey: "submittedDate") + } } /** @@ -93,6 +97,16 @@ public struct BetaAppReviewSubmission: Codable, Identifiable { self.build = build } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + build = try container.decodeIfPresent(Build.self, forKey: "build") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(build, forKey: "build") + } + /** # BetaAppReviewSubmission.Relationships.Build The data and links that describe the relationship between the resources. @@ -112,20 +126,15 @@ public struct BetaAppReviewSubmission: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -146,22 +155,17 @@ public struct BetaAppReviewSubmission: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -184,20 +188,15 @@ public struct BetaAppReviewSubmission: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaAppReviewSubmissionCreateRequest.swift b/Sources/Bagbutik-Models/TestFlight/BetaAppReviewSubmissionCreateRequest.swift index 4a198de28..fff508fdf 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaAppReviewSubmissionCreateRequest.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaAppReviewSubmissionCreateRequest.swift @@ -16,6 +16,16 @@ public struct BetaAppReviewSubmissionCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # BetaAppReviewSubmissionCreateRequest.Data The data element of the request body. @@ -34,22 +44,17 @@ public struct BetaAppReviewSubmissionCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(relationships, forKey: "relationships") } /** @@ -66,6 +71,16 @@ public struct BetaAppReviewSubmissionCreateRequest: Codable, RequestBody { self.build = build } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + build = try container.decode(Build.self, forKey: "build") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(build, forKey: "build") + } + /** # BetaAppReviewSubmissionCreateRequest.Data.Relationships.Build The relationships to other resources that you can set with this request. @@ -80,6 +95,16 @@ public struct BetaAppReviewSubmissionCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # BetaAppReviewSubmissionCreateRequest.Data.Relationships.Build.Data The type and ID of the resource that you're relating with the resource you're creating. @@ -98,22 +123,17 @@ public struct BetaAppReviewSubmissionCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaAppReviewSubmissionResponse.swift b/Sources/Bagbutik-Models/TestFlight/BetaAppReviewSubmissionResponse.swift index a21e23004..bf4277feb 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaAppReviewSubmissionResponse.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaAppReviewSubmissionResponse.swift @@ -23,4 +23,18 @@ public struct BetaAppReviewSubmissionResponse: Codable { self.included = included self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(BetaAppReviewSubmission.self, forKey: "data") + included = try container.decodeIfPresent([Build].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaAppReviewSubmissionWithoutIncludesResponse.swift b/Sources/Bagbutik-Models/TestFlight/BetaAppReviewSubmissionWithoutIncludesResponse.swift index 8356969a8..318f8bc0c 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaAppReviewSubmissionWithoutIncludesResponse.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaAppReviewSubmissionWithoutIncludesResponse.swift @@ -11,4 +11,16 @@ public struct BetaAppReviewSubmissionWithoutIncludesResponse: Codable { self.data = data self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(BetaAppReviewSubmission.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaAppReviewSubmissionsResponse.swift b/Sources/Bagbutik-Models/TestFlight/BetaAppReviewSubmissionsResponse.swift index a9a8a6a55..76d53a146 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaAppReviewSubmissionsResponse.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaAppReviewSubmissionsResponse.swift @@ -29,4 +29,20 @@ public struct BetaAppReviewSubmissionsResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([BetaAppReviewSubmission].self, forKey: "data") + included = try container.decodeIfPresent([Build].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaBuildLocalization.swift b/Sources/Bagbutik-Models/TestFlight/BetaBuildLocalization.swift index e6bff6966..ea6e8394b 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaBuildLocalization.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaBuildLocalization.swift @@ -32,31 +32,23 @@ public struct BetaBuildLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -80,6 +72,18 @@ public struct BetaBuildLocalization: Codable, Identifiable { self.locale = locale self.whatsNew = whatsNew } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + locale = try container.decodeIfPresent(String.self, forKey: "locale") + whatsNew = try container.decodeIfPresent(String.self, forKey: "whatsNew") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(locale, forKey: "locale") + try container.encodeIfPresent(whatsNew, forKey: "whatsNew") + } } /** @@ -96,6 +100,16 @@ public struct BetaBuildLocalization: Codable, Identifiable { self.build = build } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + build = try container.decodeIfPresent(Build.self, forKey: "build") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(build, forKey: "build") + } + /** # BetaBuildLocalization.Relationships.Build The data and links that describe the relationship between the resources. @@ -115,20 +129,15 @@ public struct BetaBuildLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -149,22 +158,17 @@ public struct BetaBuildLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -187,20 +191,15 @@ public struct BetaBuildLocalization: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaBuildLocalizationCreateRequest.swift b/Sources/Bagbutik-Models/TestFlight/BetaBuildLocalizationCreateRequest.swift index 3e104d4d7..32e448d8e 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaBuildLocalizationCreateRequest.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaBuildLocalizationCreateRequest.swift @@ -16,6 +16,16 @@ public struct BetaBuildLocalizationCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # BetaBuildLocalizationCreateRequest.Data The data element of the request body. @@ -39,25 +49,19 @@ public struct BetaBuildLocalizationCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } /** @@ -81,6 +85,18 @@ public struct BetaBuildLocalizationCreateRequest: Codable, RequestBody { self.locale = locale self.whatsNew = whatsNew } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + locale = try container.decode(String.self, forKey: "locale") + whatsNew = try container.decodeIfPresent(String.self, forKey: "whatsNew") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(locale, forKey: "locale") + try container.encodeIfPresent(whatsNew, forKey: "whatsNew") + } } /** @@ -97,6 +113,16 @@ public struct BetaBuildLocalizationCreateRequest: Codable, RequestBody { self.build = build } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + build = try container.decode(Build.self, forKey: "build") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(build, forKey: "build") + } + /** # BetaBuildLocalizationCreateRequest.Data.Relationships.Build The relationships to other resources that you can set with this request. @@ -111,6 +137,16 @@ public struct BetaBuildLocalizationCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # BetaBuildLocalizationCreateRequest.Data.Relationships.Build.Data The type and ID of the resource that you're relating with the resource you're creating. @@ -129,22 +165,17 @@ public struct BetaBuildLocalizationCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaBuildLocalizationResponse.swift b/Sources/Bagbutik-Models/TestFlight/BetaBuildLocalizationResponse.swift index b5f208d9b..582197b26 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaBuildLocalizationResponse.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaBuildLocalizationResponse.swift @@ -23,4 +23,18 @@ public struct BetaBuildLocalizationResponse: Codable { self.included = included self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(BetaBuildLocalization.self, forKey: "data") + included = try container.decodeIfPresent([Build].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaBuildLocalizationUpdateRequest.swift b/Sources/Bagbutik-Models/TestFlight/BetaBuildLocalizationUpdateRequest.swift index 649ee9292..ef4415ad9 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaBuildLocalizationUpdateRequest.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaBuildLocalizationUpdateRequest.swift @@ -16,6 +16,16 @@ public struct BetaBuildLocalizationUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # BetaBuildLocalizationUpdateRequest.Data The data element of the request body. @@ -39,25 +49,19 @@ public struct BetaBuildLocalizationUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } /** @@ -74,6 +78,16 @@ public struct BetaBuildLocalizationUpdateRequest: Codable, RequestBody { public init(whatsNew: String? = nil) { self.whatsNew = whatsNew } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + whatsNew = try container.decodeIfPresent(String.self, forKey: "whatsNew") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(whatsNew, forKey: "whatsNew") + } } } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaBuildLocalizationsResponse.swift b/Sources/Bagbutik-Models/TestFlight/BetaBuildLocalizationsResponse.swift index aff9e50ad..ea8f2cb27 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaBuildLocalizationsResponse.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaBuildLocalizationsResponse.swift @@ -29,4 +29,20 @@ public struct BetaBuildLocalizationsResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([BetaBuildLocalization].self, forKey: "data") + included = try container.decodeIfPresent([Build].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaBuildLocalizationsWithoutIncludesResponse.swift b/Sources/Bagbutik-Models/TestFlight/BetaBuildLocalizationsWithoutIncludesResponse.swift index f92de38ed..123412a9a 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaBuildLocalizationsWithoutIncludesResponse.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaBuildLocalizationsWithoutIncludesResponse.swift @@ -16,4 +16,18 @@ public struct BetaBuildLocalizationsWithoutIncludesResponse: Codable, PagedRespo self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([BetaBuildLocalization].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaBuildUsagesV1MetricResponse.swift b/Sources/Bagbutik-Models/TestFlight/BetaBuildUsagesV1MetricResponse.swift index 4acf3d14f..c0962443f 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaBuildUsagesV1MetricResponse.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaBuildUsagesV1MetricResponse.swift @@ -22,6 +22,20 @@ public struct BetaBuildUsagesV1MetricResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public struct Data: Codable { public var dataPoints: DataPoints? public var dimensions: Dimensions? @@ -33,6 +47,18 @@ public struct BetaBuildUsagesV1MetricResponse: Codable, PagedResponse { self.dimensions = dimensions } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + dataPoints = try container.decodeIfPresent(DataPoints.self, forKey: "dataPoints") + dimensions = try container.decodeIfPresent(Dimensions.self, forKey: "dimensions") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(dataPoints, forKey: "dataPoints") + try container.encodeIfPresent(dimensions, forKey: "dimensions") + } + public struct DataPoints: Codable { public var end: Date? public var start: Date? @@ -47,6 +73,20 @@ public struct BetaBuildUsagesV1MetricResponse: Codable, PagedResponse { self.values = values } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + end = try container.decodeIfPresent(Date.self, forKey: "end") + start = try container.decodeIfPresent(Date.self, forKey: "start") + values = try container.decodeIfPresent(Values.self, forKey: "values") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(end, forKey: "end") + try container.encodeIfPresent(start, forKey: "start") + try container.encodeIfPresent(values, forKey: "values") + } + public struct Values: Codable { public var crashCount: Int? public var feedbackCount: Int? @@ -66,6 +106,24 @@ public struct BetaBuildUsagesV1MetricResponse: Codable, PagedResponse { self.inviteCount = inviteCount self.sessionCount = sessionCount } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + crashCount = try container.decodeIfPresent(Int.self, forKey: "crashCount") + feedbackCount = try container.decodeIfPresent(Int.self, forKey: "feedbackCount") + installCount = try container.decodeIfPresent(Int.self, forKey: "installCount") + inviteCount = try container.decodeIfPresent(Int.self, forKey: "inviteCount") + sessionCount = try container.decodeIfPresent(Int.self, forKey: "sessionCount") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(crashCount, forKey: "crashCount") + try container.encodeIfPresent(feedbackCount, forKey: "feedbackCount") + try container.encodeIfPresent(installCount, forKey: "installCount") + try container.encodeIfPresent(inviteCount, forKey: "inviteCount") + try container.encodeIfPresent(sessionCount, forKey: "sessionCount") + } } } @@ -76,6 +134,16 @@ public struct BetaBuildUsagesV1MetricResponse: Codable, PagedResponse { self.bundleIds = bundleIds } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + bundleIds = try container.decodeIfPresent(BundleIds.self, forKey: "bundleIds") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(bundleIds, forKey: "bundleIds") + } + public struct BundleIds: Codable { public var links: Links? @@ -83,12 +151,32 @@ public struct BetaBuildUsagesV1MetricResponse: Codable, PagedResponse { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + links = try container.decodeIfPresent(Links.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(links, forKey: "links") + } + public struct Links: Codable { public var groupBy: String? public init(groupBy: String? = nil) { self.groupBy = groupBy } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + groupBy = try container.decodeIfPresent(String.self, forKey: "groupBy") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(groupBy, forKey: "groupBy") + } } } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaGroup.swift b/Sources/Bagbutik-Models/TestFlight/BetaGroup.swift index e1af8538a..a19f24cd4 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaGroup.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaGroup.swift @@ -32,31 +32,23 @@ public struct BetaGroup: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -111,6 +103,36 @@ public struct BetaGroup: Codable, Identifiable { self.publicLinkLimit = publicLinkLimit self.publicLinkLimitEnabled = publicLinkLimitEnabled } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + createdDate = try container.decodeIfPresent(Date.self, forKey: "createdDate") + feedbackEnabled = try container.decodeIfPresent(Bool.self, forKey: "feedbackEnabled") + hasAccessToAllBuilds = try container.decodeIfPresent(Bool.self, forKey: "hasAccessToAllBuilds") + iosBuildsAvailableForAppleSiliconMac = try container.decodeIfPresent(Bool.self, forKey: "iosBuildsAvailableForAppleSiliconMac") + isInternalGroup = try container.decodeIfPresent(Bool.self, forKey: "isInternalGroup") + name = try container.decodeIfPresent(String.self, forKey: "name") + publicLink = try container.decodeIfPresent(String.self, forKey: "publicLink") + publicLinkEnabled = try container.decodeIfPresent(Bool.self, forKey: "publicLinkEnabled") + publicLinkId = try container.decodeIfPresent(String.self, forKey: "publicLinkId") + publicLinkLimit = try container.decodeIfPresent(Int.self, forKey: "publicLinkLimit") + publicLinkLimitEnabled = try container.decodeIfPresent(Bool.self, forKey: "publicLinkLimitEnabled") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(createdDate, forKey: "createdDate") + try container.encodeIfPresent(feedbackEnabled, forKey: "feedbackEnabled") + try container.encodeIfPresent(hasAccessToAllBuilds, forKey: "hasAccessToAllBuilds") + try container.encodeIfPresent(iosBuildsAvailableForAppleSiliconMac, forKey: "iosBuildsAvailableForAppleSiliconMac") + try container.encodeIfPresent(isInternalGroup, forKey: "isInternalGroup") + try container.encodeIfPresent(name, forKey: "name") + try container.encodeIfPresent(publicLink, forKey: "publicLink") + try container.encodeIfPresent(publicLinkEnabled, forKey: "publicLinkEnabled") + try container.encodeIfPresent(publicLinkId, forKey: "publicLinkId") + try container.encodeIfPresent(publicLinkLimit, forKey: "publicLinkLimit") + try container.encodeIfPresent(publicLinkLimitEnabled, forKey: "publicLinkLimitEnabled") + } } /** @@ -134,6 +156,20 @@ public struct BetaGroup: Codable, Identifiable { self.builds = builds } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + app = try container.decodeIfPresent(App.self, forKey: "app") + betaTesters = try container.decodeIfPresent(BetaTesters.self, forKey: "betaTesters") + builds = try container.decodeIfPresent(Builds.self, forKey: "builds") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(app, forKey: "app") + try container.encodeIfPresent(betaTesters, forKey: "betaTesters") + try container.encodeIfPresent(builds, forKey: "builds") + } + /** # BetaGroup.Relationships.App The data and links that describe the relationship between the resources. @@ -153,20 +189,15 @@ public struct BetaGroup: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -187,22 +218,17 @@ public struct BetaGroup: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -225,20 +251,15 @@ public struct BetaGroup: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -265,23 +286,17 @@ public struct BetaGroup: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } /** @@ -302,22 +317,17 @@ public struct BetaGroup: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -340,20 +350,15 @@ public struct BetaGroup: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -380,23 +385,17 @@ public struct BetaGroup: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } /** @@ -417,22 +416,17 @@ public struct BetaGroup: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -455,20 +449,15 @@ public struct BetaGroup: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaGroupBetaTestersLinkagesRequest.swift b/Sources/Bagbutik-Models/TestFlight/BetaGroupBetaTestersLinkagesRequest.swift index 06f73ec1e..1d99b6f75 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaGroupBetaTestersLinkagesRequest.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaGroupBetaTestersLinkagesRequest.swift @@ -16,6 +16,16 @@ public struct BetaGroupBetaTestersLinkagesRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # BetaGroupBetaTestersLinkagesRequest.Data The data element of the request body. @@ -34,22 +44,17 @@ public struct BetaGroupBetaTestersLinkagesRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaGroupBetaTestersLinkagesResponse.swift b/Sources/Bagbutik-Models/TestFlight/BetaGroupBetaTestersLinkagesResponse.swift index fcfd25cca..c54a1bfd2 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaGroupBetaTestersLinkagesResponse.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaGroupBetaTestersLinkagesResponse.swift @@ -25,6 +25,20 @@ public struct BetaGroupBetaTestersLinkagesResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + /** # BetaGroupBetaTestersLinkagesResponse.Data The data element of the response body. @@ -43,22 +57,17 @@ public struct BetaGroupBetaTestersLinkagesResponse: Codable, PagedResponse { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaGroupBuildsLinkagesRequest.swift b/Sources/Bagbutik-Models/TestFlight/BetaGroupBuildsLinkagesRequest.swift index 1e7f9f3d6..5ea369d9d 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaGroupBuildsLinkagesRequest.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaGroupBuildsLinkagesRequest.swift @@ -16,6 +16,16 @@ public struct BetaGroupBuildsLinkagesRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # BetaGroupBuildsLinkagesRequest.Data The data element of the request body. @@ -34,22 +44,17 @@ public struct BetaGroupBuildsLinkagesRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaGroupBuildsLinkagesResponse.swift b/Sources/Bagbutik-Models/TestFlight/BetaGroupBuildsLinkagesResponse.swift index abf437fc9..100536d1d 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaGroupBuildsLinkagesResponse.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaGroupBuildsLinkagesResponse.swift @@ -25,6 +25,20 @@ public struct BetaGroupBuildsLinkagesResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + /** # BetaGroupBuildsLinkagesResponse.Data The data element of the response body. @@ -43,22 +57,17 @@ public struct BetaGroupBuildsLinkagesResponse: Codable, PagedResponse { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaGroupCreateRequest.swift b/Sources/Bagbutik-Models/TestFlight/BetaGroupCreateRequest.swift index 318b5190b..9db3f7dc3 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaGroupCreateRequest.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaGroupCreateRequest.swift @@ -16,6 +16,16 @@ public struct BetaGroupCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # BetaGroupCreateRequest.Data The data element of the request body. @@ -39,25 +49,19 @@ public struct BetaGroupCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } /** @@ -96,6 +100,28 @@ public struct BetaGroupCreateRequest: Codable, RequestBody { self.publicLinkLimit = publicLinkLimit self.publicLinkLimitEnabled = publicLinkLimitEnabled } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + feedbackEnabled = try container.decodeIfPresent(Bool.self, forKey: "feedbackEnabled") + hasAccessToAllBuilds = try container.decodeIfPresent(Bool.self, forKey: "hasAccessToAllBuilds") + isInternalGroup = try container.decodeIfPresent(Bool.self, forKey: "isInternalGroup") + name = try container.decode(String.self, forKey: "name") + publicLinkEnabled = try container.decodeIfPresent(Bool.self, forKey: "publicLinkEnabled") + publicLinkLimit = try container.decodeIfPresent(Int.self, forKey: "publicLinkLimit") + publicLinkLimitEnabled = try container.decodeIfPresent(Bool.self, forKey: "publicLinkLimitEnabled") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(feedbackEnabled, forKey: "feedbackEnabled") + try container.encodeIfPresent(hasAccessToAllBuilds, forKey: "hasAccessToAllBuilds") + try container.encodeIfPresent(isInternalGroup, forKey: "isInternalGroup") + try container.encode(name, forKey: "name") + try container.encodeIfPresent(publicLinkEnabled, forKey: "publicLinkEnabled") + try container.encodeIfPresent(publicLinkLimit, forKey: "publicLinkLimit") + try container.encodeIfPresent(publicLinkLimitEnabled, forKey: "publicLinkLimitEnabled") + } } /** @@ -119,6 +145,20 @@ public struct BetaGroupCreateRequest: Codable, RequestBody { self.builds = builds } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + app = try container.decode(App.self, forKey: "app") + betaTesters = try container.decodeIfPresent(BetaTesters.self, forKey: "betaTesters") + builds = try container.decodeIfPresent(Builds.self, forKey: "builds") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(app, forKey: "app") + try container.encodeIfPresent(betaTesters, forKey: "betaTesters") + try container.encodeIfPresent(builds, forKey: "builds") + } + /** # BetaGroupCreateRequest.Data.Relationships.App The relationships to other resources that you can set with this request. @@ -133,6 +173,16 @@ public struct BetaGroupCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # BetaGroupCreateRequest.Data.Relationships.App.Data The type and ID of the resource that you're relating with the resource you're creating. @@ -151,22 +201,17 @@ public struct BetaGroupCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -186,17 +231,13 @@ public struct BetaGroupCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } /** @@ -217,22 +258,17 @@ public struct BetaGroupCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -252,17 +288,13 @@ public struct BetaGroupCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } /** @@ -283,22 +315,17 @@ public struct BetaGroupCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaGroupResponse.swift b/Sources/Bagbutik-Models/TestFlight/BetaGroupResponse.swift index b96307e14..0c479cf65 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaGroupResponse.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaGroupResponse.swift @@ -24,6 +24,20 @@ public struct BetaGroupResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(BetaGroup.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getApp() -> App? { included?.compactMap { relationship -> App? in guard case let .app(app) = relationship else { return nil } @@ -83,9 +97,5 @@ public struct BetaGroupResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaGroupUpdateRequest.swift b/Sources/Bagbutik-Models/TestFlight/BetaGroupUpdateRequest.swift index 13fbca068..1642c4da9 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaGroupUpdateRequest.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaGroupUpdateRequest.swift @@ -16,6 +16,16 @@ public struct BetaGroupUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # BetaGroupUpdateRequest.Data The data element of the request body. @@ -39,25 +49,19 @@ public struct BetaGroupUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } /** @@ -93,6 +97,26 @@ public struct BetaGroupUpdateRequest: Codable, RequestBody { self.publicLinkLimit = publicLinkLimit self.publicLinkLimitEnabled = publicLinkLimitEnabled } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + feedbackEnabled = try container.decodeIfPresent(Bool.self, forKey: "feedbackEnabled") + iosBuildsAvailableForAppleSiliconMac = try container.decodeIfPresent(Bool.self, forKey: "iosBuildsAvailableForAppleSiliconMac") + name = try container.decodeIfPresent(String.self, forKey: "name") + publicLinkEnabled = try container.decodeIfPresent(Bool.self, forKey: "publicLinkEnabled") + publicLinkLimit = try container.decodeIfPresent(Int.self, forKey: "publicLinkLimit") + publicLinkLimitEnabled = try container.decodeIfPresent(Bool.self, forKey: "publicLinkLimitEnabled") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(feedbackEnabled, forKey: "feedbackEnabled") + try container.encodeIfPresent(iosBuildsAvailableForAppleSiliconMac, forKey: "iosBuildsAvailableForAppleSiliconMac") + try container.encodeIfPresent(name, forKey: "name") + try container.encodeIfPresent(publicLinkEnabled, forKey: "publicLinkEnabled") + try container.encodeIfPresent(publicLinkLimit, forKey: "publicLinkLimit") + try container.encodeIfPresent(publicLinkLimitEnabled, forKey: "publicLinkLimitEnabled") + } } } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaGroupsResponse.swift b/Sources/Bagbutik-Models/TestFlight/BetaGroupsResponse.swift index 7faa904be..b6e5c4861 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaGroupsResponse.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaGroupsResponse.swift @@ -30,6 +30,22 @@ public struct BetaGroupsResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([BetaGroup].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getApp(for betaGroup: BetaGroup) -> App? { included?.compactMap { relationship -> App? in guard case let .app(app) = relationship else { return nil } @@ -89,9 +105,5 @@ public struct BetaGroupsResponse: Codable, PagedResponse { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaGroupsWithoutIncludesResponse.swift b/Sources/Bagbutik-Models/TestFlight/BetaGroupsWithoutIncludesResponse.swift index dca45f453..b077f1f3b 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaGroupsWithoutIncludesResponse.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaGroupsWithoutIncludesResponse.swift @@ -16,4 +16,18 @@ public struct BetaGroupsWithoutIncludesResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([BetaGroup].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaLicenseAgreement.swift b/Sources/Bagbutik-Models/TestFlight/BetaLicenseAgreement.swift index be0e2aa6a..ae51e0ff5 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaLicenseAgreement.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaLicenseAgreement.swift @@ -32,31 +32,23 @@ public struct BetaLicenseAgreement: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -73,6 +65,16 @@ public struct BetaLicenseAgreement: Codable, Identifiable { public init(agreementText: String? = nil) { self.agreementText = agreementText } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + agreementText = try container.decodeIfPresent(String.self, forKey: "agreementText") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(agreementText, forKey: "agreementText") + } } /** @@ -89,6 +91,16 @@ public struct BetaLicenseAgreement: Codable, Identifiable { self.app = app } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + app = try container.decodeIfPresent(App.self, forKey: "app") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(app, forKey: "app") + } + /** # BetaLicenseAgreement.Relationships.App The data and links that describe the relationship between the resources. @@ -108,20 +120,15 @@ public struct BetaLicenseAgreement: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -142,22 +149,17 @@ public struct BetaLicenseAgreement: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -180,20 +182,15 @@ public struct BetaLicenseAgreement: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaLicenseAgreementResponse.swift b/Sources/Bagbutik-Models/TestFlight/BetaLicenseAgreementResponse.swift index 50a7432fb..2eb2ea453 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaLicenseAgreementResponse.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaLicenseAgreementResponse.swift @@ -23,4 +23,18 @@ public struct BetaLicenseAgreementResponse: Codable { self.included = included self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(BetaLicenseAgreement.self, forKey: "data") + included = try container.decodeIfPresent([App].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaLicenseAgreementUpdateRequest.swift b/Sources/Bagbutik-Models/TestFlight/BetaLicenseAgreementUpdateRequest.swift index 3c49afd61..3b62e9b1c 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaLicenseAgreementUpdateRequest.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaLicenseAgreementUpdateRequest.swift @@ -16,6 +16,16 @@ public struct BetaLicenseAgreementUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # BetaLicenseAgreementUpdateRequest.Data The data element of the request body. @@ -39,25 +49,19 @@ public struct BetaLicenseAgreementUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } /** @@ -74,6 +78,16 @@ public struct BetaLicenseAgreementUpdateRequest: Codable, RequestBody { public init(agreementText: String? = nil) { self.agreementText = agreementText } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + agreementText = try container.decodeIfPresent(String.self, forKey: "agreementText") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(agreementText, forKey: "agreementText") + } } } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaLicenseAgreementWithoutIncludesResponse.swift b/Sources/Bagbutik-Models/TestFlight/BetaLicenseAgreementWithoutIncludesResponse.swift index a3f8ec0c8..98f345dbe 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaLicenseAgreementWithoutIncludesResponse.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaLicenseAgreementWithoutIncludesResponse.swift @@ -11,4 +11,16 @@ public struct BetaLicenseAgreementWithoutIncludesResponse: Codable { self.data = data self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(BetaLicenseAgreement.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaLicenseAgreementsResponse.swift b/Sources/Bagbutik-Models/TestFlight/BetaLicenseAgreementsResponse.swift index 63d6e008f..4ae6a9efc 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaLicenseAgreementsResponse.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaLicenseAgreementsResponse.swift @@ -29,4 +29,20 @@ public struct BetaLicenseAgreementsResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([BetaLicenseAgreement].self, forKey: "data") + included = try container.decodeIfPresent([App].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaTester.swift b/Sources/Bagbutik-Models/TestFlight/BetaTester.swift index 40769900a..a87d15fa7 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaTester.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaTester.swift @@ -32,31 +32,23 @@ public struct BetaTester: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -86,6 +78,22 @@ public struct BetaTester: Codable, Identifiable { self.inviteType = inviteType self.lastName = lastName } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + email = try container.decodeIfPresent(String.self, forKey: "email") + firstName = try container.decodeIfPresent(String.self, forKey: "firstName") + inviteType = try container.decodeIfPresent(BetaInviteType.self, forKey: "inviteType") + lastName = try container.decodeIfPresent(String.self, forKey: "lastName") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(email, forKey: "email") + try container.encodeIfPresent(firstName, forKey: "firstName") + try container.encodeIfPresent(inviteType, forKey: "inviteType") + try container.encodeIfPresent(lastName, forKey: "lastName") + } } /** @@ -109,6 +117,20 @@ public struct BetaTester: Codable, Identifiable { self.builds = builds } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + apps = try container.decodeIfPresent(Apps.self, forKey: "apps") + betaGroups = try container.decodeIfPresent(BetaGroups.self, forKey: "betaGroups") + builds = try container.decodeIfPresent(Builds.self, forKey: "builds") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(apps, forKey: "apps") + try container.encodeIfPresent(betaGroups, forKey: "betaGroups") + try container.encodeIfPresent(builds, forKey: "builds") + } + /** # BetaTester.Relationships.Apps The data and links that describe the relationship between the resources. @@ -131,23 +153,17 @@ public struct BetaTester: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } /** @@ -166,22 +182,17 @@ public struct BetaTester: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -204,20 +215,15 @@ public struct BetaTester: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -244,23 +250,17 @@ public struct BetaTester: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } /** @@ -279,22 +279,17 @@ public struct BetaTester: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -317,20 +312,15 @@ public struct BetaTester: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -357,23 +347,17 @@ public struct BetaTester: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } /** @@ -392,22 +376,17 @@ public struct BetaTester: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -430,20 +409,15 @@ public struct BetaTester: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaTesterAppsLinkagesRequest.swift b/Sources/Bagbutik-Models/TestFlight/BetaTesterAppsLinkagesRequest.swift index 129532b69..711c18ae1 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaTesterAppsLinkagesRequest.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaTesterAppsLinkagesRequest.swift @@ -16,6 +16,16 @@ public struct BetaTesterAppsLinkagesRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # BetaTesterAppsLinkagesRequest.Data The data element of the request body. @@ -34,22 +44,17 @@ public struct BetaTesterAppsLinkagesRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaTesterAppsLinkagesResponse.swift b/Sources/Bagbutik-Models/TestFlight/BetaTesterAppsLinkagesResponse.swift index fc737700f..b44d65f10 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaTesterAppsLinkagesResponse.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaTesterAppsLinkagesResponse.swift @@ -25,6 +25,20 @@ public struct BetaTesterAppsLinkagesResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + /** # BetaTesterAppsLinkagesResponse.Data The data element of the response body. @@ -43,22 +57,17 @@ public struct BetaTesterAppsLinkagesResponse: Codable, PagedResponse { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaTesterBetaGroupsLinkagesRequest.swift b/Sources/Bagbutik-Models/TestFlight/BetaTesterBetaGroupsLinkagesRequest.swift index c0dc2dbc1..7dd7ba338 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaTesterBetaGroupsLinkagesRequest.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaTesterBetaGroupsLinkagesRequest.swift @@ -16,6 +16,16 @@ public struct BetaTesterBetaGroupsLinkagesRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # BetaTesterBetaGroupsLinkagesRequest.Data The data element of the request body. @@ -34,22 +44,17 @@ public struct BetaTesterBetaGroupsLinkagesRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaTesterBetaGroupsLinkagesResponse.swift b/Sources/Bagbutik-Models/TestFlight/BetaTesterBetaGroupsLinkagesResponse.swift index 696c3372b..4a5f9459b 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaTesterBetaGroupsLinkagesResponse.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaTesterBetaGroupsLinkagesResponse.swift @@ -25,6 +25,20 @@ public struct BetaTesterBetaGroupsLinkagesResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + /** # BetaTesterBetaGroupsLinkagesResponse.Data The data element of the response body. @@ -43,22 +57,17 @@ public struct BetaTesterBetaGroupsLinkagesResponse: Codable, PagedResponse { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaTesterBuildsLinkagesRequest.swift b/Sources/Bagbutik-Models/TestFlight/BetaTesterBuildsLinkagesRequest.swift index 27c1abc87..07b4c950d 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaTesterBuildsLinkagesRequest.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaTesterBuildsLinkagesRequest.swift @@ -16,6 +16,16 @@ public struct BetaTesterBuildsLinkagesRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # BetaTesterBuildsLinkagesRequest.Data The data element of the request body. @@ -34,22 +44,17 @@ public struct BetaTesterBuildsLinkagesRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaTesterBuildsLinkagesResponse.swift b/Sources/Bagbutik-Models/TestFlight/BetaTesterBuildsLinkagesResponse.swift index 94f076768..d880af660 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaTesterBuildsLinkagesResponse.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaTesterBuildsLinkagesResponse.swift @@ -25,6 +25,20 @@ public struct BetaTesterBuildsLinkagesResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + /** # BetaTesterBuildsLinkagesResponse.Data The data element of the response body. @@ -43,22 +57,17 @@ public struct BetaTesterBuildsLinkagesResponse: Codable, PagedResponse { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaTesterCreateRequest.swift b/Sources/Bagbutik-Models/TestFlight/BetaTesterCreateRequest.swift index fc4a1aab5..505ce6e02 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaTesterCreateRequest.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaTesterCreateRequest.swift @@ -16,6 +16,16 @@ public struct BetaTesterCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # BetaTesterCreateRequest.Data The data element of the request body. @@ -39,25 +49,19 @@ public struct BetaTesterCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -83,6 +87,20 @@ public struct BetaTesterCreateRequest: Codable, RequestBody { self.firstName = firstName self.lastName = lastName } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + email = try container.decode(String.self, forKey: "email") + firstName = try container.decodeIfPresent(String.self, forKey: "firstName") + lastName = try container.decodeIfPresent(String.self, forKey: "lastName") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(email, forKey: "email") + try container.encodeIfPresent(firstName, forKey: "firstName") + try container.encodeIfPresent(lastName, forKey: "lastName") + } } /** @@ -103,6 +121,18 @@ public struct BetaTesterCreateRequest: Codable, RequestBody { self.builds = builds } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + betaGroups = try container.decodeIfPresent(BetaGroups.self, forKey: "betaGroups") + builds = try container.decodeIfPresent(Builds.self, forKey: "builds") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(betaGroups, forKey: "betaGroups") + try container.encodeIfPresent(builds, forKey: "builds") + } + /** # BetaTesterCreateRequest.Data.Relationships.BetaGroups The relationships to other resources that you can set with this request. @@ -118,17 +148,13 @@ public struct BetaTesterCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } /** @@ -149,22 +175,17 @@ public struct BetaTesterCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -184,17 +205,13 @@ public struct BetaTesterCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } /** @@ -215,22 +232,17 @@ public struct BetaTesterCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaTesterInvitation.swift b/Sources/Bagbutik-Models/TestFlight/BetaTesterInvitation.swift index 633cfc70d..9c44cb171 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaTesterInvitation.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaTesterInvitation.swift @@ -24,24 +24,18 @@ public struct BetaTesterInvitation: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case links - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaTesterInvitationCreateRequest.swift b/Sources/Bagbutik-Models/TestFlight/BetaTesterInvitationCreateRequest.swift index 987ee9139..35219edaf 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaTesterInvitationCreateRequest.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaTesterInvitationCreateRequest.swift @@ -16,6 +16,16 @@ public struct BetaTesterInvitationCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # BetaTesterInvitationCreateRequest.Data The data element of the request body. @@ -34,22 +44,17 @@ public struct BetaTesterInvitationCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(relationships, forKey: "relationships") } /** @@ -70,6 +75,18 @@ public struct BetaTesterInvitationCreateRequest: Codable, RequestBody { self.betaTester = betaTester } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + app = try container.decode(App.self, forKey: "app") + betaTester = try container.decode(BetaTester.self, forKey: "betaTester") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(app, forKey: "app") + try container.encode(betaTester, forKey: "betaTester") + } + /** # BetaTesterInvitationCreateRequest.Data.Relationships.App The relationships to other resources that you can set with this request. @@ -84,6 +101,16 @@ public struct BetaTesterInvitationCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # BetaTesterInvitationCreateRequest.Data.Relationships.App.Data The type and ID of the resource that you're relating with the resource you're creating. @@ -102,22 +129,17 @@ public struct BetaTesterInvitationCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -136,6 +158,16 @@ public struct BetaTesterInvitationCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # BetaTesterInvitationCreateRequest.Data.Relationships.BetaTester.Data The type and ID of the resource that you're relating with the resource you're creating. @@ -154,22 +186,17 @@ public struct BetaTesterInvitationCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaTesterInvitationResponse.swift b/Sources/Bagbutik-Models/TestFlight/BetaTesterInvitationResponse.swift index 7997cf87a..0b193063d 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaTesterInvitationResponse.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaTesterInvitationResponse.swift @@ -20,4 +20,16 @@ public struct BetaTesterInvitationResponse: Codable { self.data = data self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(BetaTesterInvitation.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaTesterResponse.swift b/Sources/Bagbutik-Models/TestFlight/BetaTesterResponse.swift index d80897b15..ac4335733 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaTesterResponse.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaTesterResponse.swift @@ -24,6 +24,20 @@ public struct BetaTesterResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(BetaTester.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getApps() -> [App] { guard let appIds = data.relationships?.apps?.data?.map(\.id), let apps = included?.compactMap({ relationship -> App? in @@ -88,9 +102,5 @@ public struct BetaTesterResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaTesterUsagesV1MetricResponse.swift b/Sources/Bagbutik-Models/TestFlight/BetaTesterUsagesV1MetricResponse.swift index b84e41c91..2981de743 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaTesterUsagesV1MetricResponse.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaTesterUsagesV1MetricResponse.swift @@ -22,6 +22,20 @@ public struct BetaTesterUsagesV1MetricResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public struct Data: Codable { public var dataPoints: DataPoints? public var dimensions: Dimensions? @@ -33,6 +47,18 @@ public struct BetaTesterUsagesV1MetricResponse: Codable, PagedResponse { self.dimensions = dimensions } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + dataPoints = try container.decodeIfPresent(DataPoints.self, forKey: "dataPoints") + dimensions = try container.decodeIfPresent(Dimensions.self, forKey: "dimensions") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(dataPoints, forKey: "dataPoints") + try container.encodeIfPresent(dimensions, forKey: "dimensions") + } + public struct DataPoints: Codable { public var end: Date? public var start: Date? @@ -47,6 +73,20 @@ public struct BetaTesterUsagesV1MetricResponse: Codable, PagedResponse { self.values = values } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + end = try container.decodeIfPresent(Date.self, forKey: "end") + start = try container.decodeIfPresent(Date.self, forKey: "start") + values = try container.decodeIfPresent(Values.self, forKey: "values") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(end, forKey: "end") + try container.encodeIfPresent(start, forKey: "start") + try container.encodeIfPresent(values, forKey: "values") + } + public struct Values: Codable { public var crashCount: Int? public var feedbackCount: Int? @@ -60,6 +100,20 @@ public struct BetaTesterUsagesV1MetricResponse: Codable, PagedResponse { self.feedbackCount = feedbackCount self.sessionCount = sessionCount } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + crashCount = try container.decodeIfPresent(Int.self, forKey: "crashCount") + feedbackCount = try container.decodeIfPresent(Int.self, forKey: "feedbackCount") + sessionCount = try container.decodeIfPresent(Int.self, forKey: "sessionCount") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(crashCount, forKey: "crashCount") + try container.encodeIfPresent(feedbackCount, forKey: "feedbackCount") + try container.encodeIfPresent(sessionCount, forKey: "sessionCount") + } } } @@ -70,6 +124,16 @@ public struct BetaTesterUsagesV1MetricResponse: Codable, PagedResponse { self.apps = apps } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + apps = try container.decodeIfPresent(Apps.self, forKey: "apps") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(apps, forKey: "apps") + } + public struct Apps: Codable { public var links: Links? @@ -77,6 +141,16 @@ public struct BetaTesterUsagesV1MetricResponse: Codable, PagedResponse { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + links = try container.decodeIfPresent(Links.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(links, forKey: "links") + } + public struct Links: Codable { public var groupBy: String? public var related: String? @@ -87,6 +161,18 @@ public struct BetaTesterUsagesV1MetricResponse: Codable, PagedResponse { self.groupBy = groupBy self.related = related } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + groupBy = try container.decodeIfPresent(String.self, forKey: "groupBy") + related = try container.decodeIfPresent(String.self, forKey: "related") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(groupBy, forKey: "groupBy") + try container.encodeIfPresent(related, forKey: "related") + } } } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaTestersResponse.swift b/Sources/Bagbutik-Models/TestFlight/BetaTestersResponse.swift index 4390acb58..84ab4e406 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaTestersResponse.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaTestersResponse.swift @@ -30,6 +30,22 @@ public struct BetaTestersResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([BetaTester].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getApps(for betaTester: BetaTester) -> [App] { guard let appIds = betaTester.relationships?.apps?.data?.map(\.id), let apps = included?.compactMap({ relationship -> App? in @@ -94,9 +110,5 @@ public struct BetaTestersResponse: Codable, PagedResponse { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/TestFlight/BetaTestersWithoutIncludesResponse.swift b/Sources/Bagbutik-Models/TestFlight/BetaTestersWithoutIncludesResponse.swift index f1635012e..2fbd6df56 100644 --- a/Sources/Bagbutik-Models/TestFlight/BetaTestersWithoutIncludesResponse.swift +++ b/Sources/Bagbutik-Models/TestFlight/BetaTestersWithoutIncludesResponse.swift @@ -16,4 +16,18 @@ public struct BetaTestersWithoutIncludesResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([BetaTester].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/TestFlight/Build.swift b/Sources/Bagbutik-Models/TestFlight/Build.swift index 8da2acfad..d82e9fcab 100644 --- a/Sources/Bagbutik-Models/TestFlight/Build.swift +++ b/Sources/Bagbutik-Models/TestFlight/Build.swift @@ -32,31 +32,23 @@ public struct Build: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -112,6 +104,36 @@ public struct Build: Codable, Identifiable { self.version = version } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + buildAudienceType = try container.decodeIfPresent(BuildAudienceType.self, forKey: "buildAudienceType") + computedMinMacOsVersion = try container.decodeIfPresent(String.self, forKey: "computedMinMacOsVersion") + expirationDate = try container.decodeIfPresent(Date.self, forKey: "expirationDate") + expired = try container.decodeIfPresent(Bool.self, forKey: "expired") + iconAssetToken = try container.decodeIfPresent(ImageAsset.self, forKey: "iconAssetToken") + lsMinimumSystemVersion = try container.decodeIfPresent(String.self, forKey: "lsMinimumSystemVersion") + minOsVersion = try container.decodeIfPresent(String.self, forKey: "minOsVersion") + processingState = try container.decodeIfPresent(ProcessingState.self, forKey: "processingState") + uploadedDate = try container.decodeIfPresent(Date.self, forKey: "uploadedDate") + usesNonExemptEncryption = try container.decodeIfPresent(Bool.self, forKey: "usesNonExemptEncryption") + version = try container.decodeIfPresent(String.self, forKey: "version") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(buildAudienceType, forKey: "buildAudienceType") + try container.encodeIfPresent(computedMinMacOsVersion, forKey: "computedMinMacOsVersion") + try container.encodeIfPresent(expirationDate, forKey: "expirationDate") + try container.encodeIfPresent(expired, forKey: "expired") + try container.encodeIfPresent(iconAssetToken, forKey: "iconAssetToken") + try container.encodeIfPresent(lsMinimumSystemVersion, forKey: "lsMinimumSystemVersion") + try container.encodeIfPresent(minOsVersion, forKey: "minOsVersion") + try container.encodeIfPresent(processingState, forKey: "processingState") + try container.encodeIfPresent(uploadedDate, forKey: "uploadedDate") + try container.encodeIfPresent(usesNonExemptEncryption, forKey: "usesNonExemptEncryption") + try container.encodeIfPresent(version, forKey: "version") + } + public enum ProcessingState: String, ParameterValue, Codable, CaseIterable { case failed = "FAILED" case invalid = "INVALID" @@ -166,6 +188,36 @@ public struct Build: Codable, Identifiable { self.preReleaseVersion = preReleaseVersion } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + app = try container.decodeIfPresent(App.self, forKey: "app") + appEncryptionDeclaration = try container.decodeIfPresent(AppEncryptionDeclaration.self, forKey: "appEncryptionDeclaration") + appStoreVersion = try container.decodeIfPresent(AppStoreVersion.self, forKey: "appStoreVersion") + betaAppReviewSubmission = try container.decodeIfPresent(BetaAppReviewSubmission.self, forKey: "betaAppReviewSubmission") + betaBuildLocalizations = try container.decodeIfPresent(BetaBuildLocalizations.self, forKey: "betaBuildLocalizations") + betaGroups = try container.decodeIfPresent(BetaGroups.self, forKey: "betaGroups") + buildBetaDetail = try container.decodeIfPresent(BuildBetaDetail.self, forKey: "buildBetaDetail") + buildBundles = try container.decodeIfPresent(BuildBundles.self, forKey: "buildBundles") + icons = try container.decodeIfPresent(Icons.self, forKey: "icons") + individualTesters = try container.decodeIfPresent(IndividualTesters.self, forKey: "individualTesters") + preReleaseVersion = try container.decodeIfPresent(PreReleaseVersion.self, forKey: "preReleaseVersion") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(app, forKey: "app") + try container.encodeIfPresent(appEncryptionDeclaration, forKey: "appEncryptionDeclaration") + try container.encodeIfPresent(appStoreVersion, forKey: "appStoreVersion") + try container.encodeIfPresent(betaAppReviewSubmission, forKey: "betaAppReviewSubmission") + try container.encodeIfPresent(betaBuildLocalizations, forKey: "betaBuildLocalizations") + try container.encodeIfPresent(betaGroups, forKey: "betaGroups") + try container.encodeIfPresent(buildBetaDetail, forKey: "buildBetaDetail") + try container.encodeIfPresent(buildBundles, forKey: "buildBundles") + try container.encodeIfPresent(icons, forKey: "icons") + try container.encodeIfPresent(individualTesters, forKey: "individualTesters") + try container.encodeIfPresent(preReleaseVersion, forKey: "preReleaseVersion") + } + /** # Build.Relationships.App The data and links that describe the relationship between the resources. @@ -185,20 +237,15 @@ public struct Build: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -219,22 +266,17 @@ public struct Build: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -257,20 +299,15 @@ public struct Build: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -294,20 +331,15 @@ public struct Build: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -328,22 +360,17 @@ public struct Build: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -366,20 +393,15 @@ public struct Build: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -403,20 +425,15 @@ public struct Build: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -435,22 +452,17 @@ public struct Build: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -473,20 +485,15 @@ public struct Build: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -510,20 +517,15 @@ public struct Build: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -544,22 +546,17 @@ public struct Build: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -582,20 +579,15 @@ public struct Build: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -622,23 +614,17 @@ public struct Build: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } /** @@ -659,22 +645,17 @@ public struct Build: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -697,20 +678,15 @@ public struct Build: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -738,23 +714,17 @@ public struct Build: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } public struct Data: Codable, Identifiable { @@ -766,22 +736,17 @@ public struct Build: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -797,20 +762,15 @@ public struct Build: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -834,20 +794,15 @@ public struct Build: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -868,22 +823,17 @@ public struct Build: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -906,20 +856,15 @@ public struct Build: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -949,23 +894,17 @@ public struct Build: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } /** @@ -986,22 +925,17 @@ public struct Build: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -1026,20 +960,15 @@ public struct Build: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -1066,23 +995,17 @@ public struct Build: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } /** @@ -1101,22 +1024,17 @@ public struct Build: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -1139,20 +1057,15 @@ public struct Build: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -1179,23 +1092,17 @@ public struct Build: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } /** @@ -1216,22 +1123,17 @@ public struct Build: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -1254,20 +1156,15 @@ public struct Build: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -1291,20 +1188,15 @@ public struct Build: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -1325,22 +1217,17 @@ public struct Build: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -1363,20 +1250,15 @@ public struct Build: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/TestFlight/BuildAppEncryptionDeclarationLinkageRequest.swift b/Sources/Bagbutik-Models/TestFlight/BuildAppEncryptionDeclarationLinkageRequest.swift index e87f1a95a..cc5993ca0 100644 --- a/Sources/Bagbutik-Models/TestFlight/BuildAppEncryptionDeclarationLinkageRequest.swift +++ b/Sources/Bagbutik-Models/TestFlight/BuildAppEncryptionDeclarationLinkageRequest.swift @@ -17,17 +17,13 @@ public struct BuildAppEncryptionDeclarationLinkageRequest: Codable, RequestBody } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } /** @@ -48,22 +44,17 @@ public struct BuildAppEncryptionDeclarationLinkageRequest: Codable, RequestBody } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/TestFlight/BuildAppEncryptionDeclarationLinkageResponse.swift b/Sources/Bagbutik-Models/TestFlight/BuildAppEncryptionDeclarationLinkageResponse.swift index c5c377c7e..c7daa7c63 100644 --- a/Sources/Bagbutik-Models/TestFlight/BuildAppEncryptionDeclarationLinkageResponse.swift +++ b/Sources/Bagbutik-Models/TestFlight/BuildAppEncryptionDeclarationLinkageResponse.swift @@ -21,6 +21,18 @@ public struct BuildAppEncryptionDeclarationLinkageResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } + /** # BuildAppEncryptionDeclarationLinkageResponse.Data The data element of the response body. @@ -39,22 +51,17 @@ public struct BuildAppEncryptionDeclarationLinkageResponse: Codable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/TestFlight/BuildBetaDetail.swift b/Sources/Bagbutik-Models/TestFlight/BuildBetaDetail.swift index 63fef16fe..2708bd82b 100644 --- a/Sources/Bagbutik-Models/TestFlight/BuildBetaDetail.swift +++ b/Sources/Bagbutik-Models/TestFlight/BuildBetaDetail.swift @@ -32,31 +32,23 @@ public struct BuildBetaDetail: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -82,6 +74,20 @@ public struct BuildBetaDetail: Codable, Identifiable { self.externalBuildState = externalBuildState self.internalBuildState = internalBuildState } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + autoNotifyEnabled = try container.decodeIfPresent(Bool.self, forKey: "autoNotifyEnabled") + externalBuildState = try container.decodeIfPresent(ExternalBetaState.self, forKey: "externalBuildState") + internalBuildState = try container.decodeIfPresent(InternalBetaState.self, forKey: "internalBuildState") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(autoNotifyEnabled, forKey: "autoNotifyEnabled") + try container.encodeIfPresent(externalBuildState, forKey: "externalBuildState") + try container.encodeIfPresent(internalBuildState, forKey: "internalBuildState") + } } /** @@ -98,6 +104,16 @@ public struct BuildBetaDetail: Codable, Identifiable { self.build = build } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + build = try container.decodeIfPresent(Build.self, forKey: "build") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(build, forKey: "build") + } + /** # BuildBetaDetail.Relationships.Build The data and links that describe the relationship between the resources. @@ -117,20 +133,15 @@ public struct BuildBetaDetail: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -151,22 +162,17 @@ public struct BuildBetaDetail: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -189,20 +195,15 @@ public struct BuildBetaDetail: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/TestFlight/BuildBetaDetailResponse.swift b/Sources/Bagbutik-Models/TestFlight/BuildBetaDetailResponse.swift index 7f4281904..dec49b59f 100644 --- a/Sources/Bagbutik-Models/TestFlight/BuildBetaDetailResponse.swift +++ b/Sources/Bagbutik-Models/TestFlight/BuildBetaDetailResponse.swift @@ -23,4 +23,18 @@ public struct BuildBetaDetailResponse: Codable { self.included = included self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(BuildBetaDetail.self, forKey: "data") + included = try container.decodeIfPresent([Build].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/TestFlight/BuildBetaDetailUpdateRequest.swift b/Sources/Bagbutik-Models/TestFlight/BuildBetaDetailUpdateRequest.swift index bc4668da9..d4ebe46dc 100644 --- a/Sources/Bagbutik-Models/TestFlight/BuildBetaDetailUpdateRequest.swift +++ b/Sources/Bagbutik-Models/TestFlight/BuildBetaDetailUpdateRequest.swift @@ -16,6 +16,16 @@ public struct BuildBetaDetailUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # BuildBetaDetailUpdateRequest.Data The data element of the request body. @@ -39,25 +49,19 @@ public struct BuildBetaDetailUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } /** @@ -74,6 +78,16 @@ public struct BuildBetaDetailUpdateRequest: Codable, RequestBody { public init(autoNotifyEnabled: Bool? = nil) { self.autoNotifyEnabled = autoNotifyEnabled } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + autoNotifyEnabled = try container.decodeIfPresent(Bool.self, forKey: "autoNotifyEnabled") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(autoNotifyEnabled, forKey: "autoNotifyEnabled") + } } } } diff --git a/Sources/Bagbutik-Models/TestFlight/BuildBetaDetailsResponse.swift b/Sources/Bagbutik-Models/TestFlight/BuildBetaDetailsResponse.swift index 512a2df18..5a6c95d42 100644 --- a/Sources/Bagbutik-Models/TestFlight/BuildBetaDetailsResponse.swift +++ b/Sources/Bagbutik-Models/TestFlight/BuildBetaDetailsResponse.swift @@ -29,4 +29,20 @@ public struct BuildBetaDetailsResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([BuildBetaDetail].self, forKey: "data") + included = try container.decodeIfPresent([Build].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/TestFlight/BuildBetaGroupsLinkagesRequest.swift b/Sources/Bagbutik-Models/TestFlight/BuildBetaGroupsLinkagesRequest.swift index 55f441bc7..b63bb758e 100644 --- a/Sources/Bagbutik-Models/TestFlight/BuildBetaGroupsLinkagesRequest.swift +++ b/Sources/Bagbutik-Models/TestFlight/BuildBetaGroupsLinkagesRequest.swift @@ -16,6 +16,16 @@ public struct BuildBetaGroupsLinkagesRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # BuildBetaGroupsLinkagesRequest.Data The data element of the request body. @@ -34,22 +44,17 @@ public struct BuildBetaGroupsLinkagesRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/TestFlight/BuildBetaNotification.swift b/Sources/Bagbutik-Models/TestFlight/BuildBetaNotification.swift index a99cef946..5c55c2445 100644 --- a/Sources/Bagbutik-Models/TestFlight/BuildBetaNotification.swift +++ b/Sources/Bagbutik-Models/TestFlight/BuildBetaNotification.swift @@ -24,24 +24,18 @@ public struct BuildBetaNotification: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case links - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") } } diff --git a/Sources/Bagbutik-Models/TestFlight/BuildBetaNotificationCreateRequest.swift b/Sources/Bagbutik-Models/TestFlight/BuildBetaNotificationCreateRequest.swift index 8e56b0073..077ef653f 100644 --- a/Sources/Bagbutik-Models/TestFlight/BuildBetaNotificationCreateRequest.swift +++ b/Sources/Bagbutik-Models/TestFlight/BuildBetaNotificationCreateRequest.swift @@ -16,6 +16,16 @@ public struct BuildBetaNotificationCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # BuildBetaNotificationCreateRequest.Data The data element of the request body. @@ -34,22 +44,17 @@ public struct BuildBetaNotificationCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(relationships, forKey: "relationships") } /** @@ -66,6 +71,16 @@ public struct BuildBetaNotificationCreateRequest: Codable, RequestBody { self.build = build } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + build = try container.decode(Build.self, forKey: "build") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(build, forKey: "build") + } + /** # BuildBetaNotificationCreateRequest.Data.Relationships.Build The relationships to other resources that you can set with this request. @@ -80,6 +95,16 @@ public struct BuildBetaNotificationCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # BuildBetaNotificationCreateRequest.Data.Relationships.Build.Data The type and ID of the resource that you're relating with the resource you're creating. @@ -98,22 +123,17 @@ public struct BuildBetaNotificationCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/TestFlight/BuildBetaNotificationResponse.swift b/Sources/Bagbutik-Models/TestFlight/BuildBetaNotificationResponse.swift index 985e28537..d552d3329 100644 --- a/Sources/Bagbutik-Models/TestFlight/BuildBetaNotificationResponse.swift +++ b/Sources/Bagbutik-Models/TestFlight/BuildBetaNotificationResponse.swift @@ -20,4 +20,16 @@ public struct BuildBetaNotificationResponse: Codable { self.data = data self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(BuildBetaNotification.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/TestFlight/BuildIndividualTestersLinkagesRequest.swift b/Sources/Bagbutik-Models/TestFlight/BuildIndividualTestersLinkagesRequest.swift index 7f80da6a7..6fe40231e 100644 --- a/Sources/Bagbutik-Models/TestFlight/BuildIndividualTestersLinkagesRequest.swift +++ b/Sources/Bagbutik-Models/TestFlight/BuildIndividualTestersLinkagesRequest.swift @@ -16,6 +16,16 @@ public struct BuildIndividualTestersLinkagesRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # BuildIndividualTestersLinkagesRequest.Data The data element of the request body. @@ -34,22 +44,17 @@ public struct BuildIndividualTestersLinkagesRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/TestFlight/BuildIndividualTestersLinkagesResponse.swift b/Sources/Bagbutik-Models/TestFlight/BuildIndividualTestersLinkagesResponse.swift index f0dc81510..d95d60d3a 100644 --- a/Sources/Bagbutik-Models/TestFlight/BuildIndividualTestersLinkagesResponse.swift +++ b/Sources/Bagbutik-Models/TestFlight/BuildIndividualTestersLinkagesResponse.swift @@ -25,6 +25,20 @@ public struct BuildIndividualTestersLinkagesResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + /** # BuildIndividualTestersLinkagesResponse.Data The data element of the response body. @@ -43,22 +57,17 @@ public struct BuildIndividualTestersLinkagesResponse: Codable, PagedResponse { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/TestFlight/BuildResponse.swift b/Sources/Bagbutik-Models/TestFlight/BuildResponse.swift index 56abb4801..9226a02ca 100644 --- a/Sources/Bagbutik-Models/TestFlight/BuildResponse.swift +++ b/Sources/Bagbutik-Models/TestFlight/BuildResponse.swift @@ -24,6 +24,20 @@ public struct BuildResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Build.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getApp() -> App? { included?.compactMap { relationship -> App? in guard case let .app(app) = relationship else { return nil } @@ -194,9 +208,5 @@ public struct BuildResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/TestFlight/BuildUpdateRequest.swift b/Sources/Bagbutik-Models/TestFlight/BuildUpdateRequest.swift index 604007007..394d4e565 100644 --- a/Sources/Bagbutik-Models/TestFlight/BuildUpdateRequest.swift +++ b/Sources/Bagbutik-Models/TestFlight/BuildUpdateRequest.swift @@ -16,6 +16,16 @@ public struct BuildUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # BuildUpdateRequest.Data The data element of the request body. @@ -43,28 +53,21 @@ public struct BuildUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -86,6 +89,18 @@ public struct BuildUpdateRequest: Codable, RequestBody { self.expired = expired self.usesNonExemptEncryption = usesNonExemptEncryption } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + expired = try container.decodeIfPresent(Bool.self, forKey: "expired") + usesNonExemptEncryption = try container.decodeIfPresent(Bool.self, forKey: "usesNonExemptEncryption") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(expired, forKey: "expired") + try container.encodeIfPresent(usesNonExemptEncryption, forKey: "usesNonExemptEncryption") + } } /** @@ -102,6 +117,16 @@ public struct BuildUpdateRequest: Codable, RequestBody { self.appEncryptionDeclaration = appEncryptionDeclaration } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + appEncryptionDeclaration = try container.decodeIfPresent(AppEncryptionDeclaration.self, forKey: "appEncryptionDeclaration") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(appEncryptionDeclaration, forKey: "appEncryptionDeclaration") + } + /** # BuildUpdateRequest.Data.Relationships.AppEncryptionDeclaration The data and links that describe the relationship between the resources. @@ -117,17 +142,13 @@ public struct BuildUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } /** @@ -148,22 +169,17 @@ public struct BuildUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/TestFlight/BuildWithoutIncludesResponse.swift b/Sources/Bagbutik-Models/TestFlight/BuildWithoutIncludesResponse.swift index debb4095a..8e93db9ce 100644 --- a/Sources/Bagbutik-Models/TestFlight/BuildWithoutIncludesResponse.swift +++ b/Sources/Bagbutik-Models/TestFlight/BuildWithoutIncludesResponse.swift @@ -11,4 +11,16 @@ public struct BuildWithoutIncludesResponse: Codable { self.data = data self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Build.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/TestFlight/BuildsResponse.swift b/Sources/Bagbutik-Models/TestFlight/BuildsResponse.swift index 5741c196c..7147ecffd 100644 --- a/Sources/Bagbutik-Models/TestFlight/BuildsResponse.swift +++ b/Sources/Bagbutik-Models/TestFlight/BuildsResponse.swift @@ -30,6 +30,22 @@ public struct BuildsResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Build].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getApp(for build: Build) -> App? { included?.compactMap { relationship -> App? in guard case let .app(app) = relationship else { return nil } @@ -200,9 +216,5 @@ public struct BuildsResponse: Codable, PagedResponse { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/TestFlight/BuildsWithoutIncludesResponse.swift b/Sources/Bagbutik-Models/TestFlight/BuildsWithoutIncludesResponse.swift index 052c7bc1f..b3cecade7 100644 --- a/Sources/Bagbutik-Models/TestFlight/BuildsWithoutIncludesResponse.swift +++ b/Sources/Bagbutik-Models/TestFlight/BuildsWithoutIncludesResponse.swift @@ -16,4 +16,18 @@ public struct BuildsWithoutIncludesResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Build].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/TestFlight/ImageAsset.swift b/Sources/Bagbutik-Models/TestFlight/ImageAsset.swift index 391c017d7..e1f48507e 100644 --- a/Sources/Bagbutik-Models/TestFlight/ImageAsset.swift +++ b/Sources/Bagbutik-Models/TestFlight/ImageAsset.swift @@ -21,4 +21,18 @@ public struct ImageAsset: Codable { self.templateUrl = templateUrl self.width = width } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + height = try container.decodeIfPresent(Int.self, forKey: "height") + templateUrl = try container.decodeIfPresent(String.self, forKey: "templateUrl") + width = try container.decodeIfPresent(Int.self, forKey: "width") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(height, forKey: "height") + try container.encodeIfPresent(templateUrl, forKey: "templateUrl") + try container.encodeIfPresent(width, forKey: "width") + } } diff --git a/Sources/Bagbutik-Models/TestFlight/PreReleaseVersionsResponse.swift b/Sources/Bagbutik-Models/TestFlight/PreReleaseVersionsResponse.swift index dafc63df2..4b4e0ced6 100644 --- a/Sources/Bagbutik-Models/TestFlight/PreReleaseVersionsResponse.swift +++ b/Sources/Bagbutik-Models/TestFlight/PreReleaseVersionsResponse.swift @@ -30,6 +30,22 @@ public struct PreReleaseVersionsResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([PrereleaseVersion].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getApp(for prereleaseVersion: PrereleaseVersion) -> App? { included?.compactMap { relationship -> App? in guard case let .app(app) = relationship else { return nil } @@ -72,9 +88,5 @@ public struct PreReleaseVersionsResponse: Codable, PagedResponse { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/TestFlight/PreReleaseVersionsWithoutIncludesResponse.swift b/Sources/Bagbutik-Models/TestFlight/PreReleaseVersionsWithoutIncludesResponse.swift index c43bf1f8d..5d227bcc5 100644 --- a/Sources/Bagbutik-Models/TestFlight/PreReleaseVersionsWithoutIncludesResponse.swift +++ b/Sources/Bagbutik-Models/TestFlight/PreReleaseVersionsWithoutIncludesResponse.swift @@ -16,4 +16,18 @@ public struct PreReleaseVersionsWithoutIncludesResponse: Codable, PagedResponse self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([PrereleaseVersion].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/TestFlight/PrereleaseVersion.swift b/Sources/Bagbutik-Models/TestFlight/PrereleaseVersion.swift index 039e94abb..7257357df 100644 --- a/Sources/Bagbutik-Models/TestFlight/PrereleaseVersion.swift +++ b/Sources/Bagbutik-Models/TestFlight/PrereleaseVersion.swift @@ -32,31 +32,23 @@ public struct PrereleaseVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -78,6 +70,18 @@ public struct PrereleaseVersion: Codable, Identifiable { self.platform = platform self.version = version } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + platform = try container.decodeIfPresent(Platform.self, forKey: "platform") + version = try container.decodeIfPresent(String.self, forKey: "version") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(platform, forKey: "platform") + try container.encodeIfPresent(version, forKey: "version") + } } /** @@ -98,6 +102,18 @@ public struct PrereleaseVersion: Codable, Identifiable { self.builds = builds } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + app = try container.decodeIfPresent(App.self, forKey: "app") + builds = try container.decodeIfPresent(Builds.self, forKey: "builds") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(app, forKey: "app") + try container.encodeIfPresent(builds, forKey: "builds") + } + /** # PrereleaseVersion.Relationships.App The data and links that describe the relationship between the resources. @@ -117,20 +133,15 @@ public struct PrereleaseVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -151,22 +162,17 @@ public struct PrereleaseVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -189,20 +195,15 @@ public struct PrereleaseVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -229,23 +230,17 @@ public struct PrereleaseVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } /** @@ -266,22 +261,17 @@ public struct PrereleaseVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -304,20 +294,15 @@ public struct PrereleaseVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/TestFlight/PrereleaseVersionResponse.swift b/Sources/Bagbutik-Models/TestFlight/PrereleaseVersionResponse.swift index 9341c2e03..52f891feb 100644 --- a/Sources/Bagbutik-Models/TestFlight/PrereleaseVersionResponse.swift +++ b/Sources/Bagbutik-Models/TestFlight/PrereleaseVersionResponse.swift @@ -24,6 +24,20 @@ public struct PrereleaseVersionResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(PrereleaseVersion.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getApp() -> App? { included?.compactMap { relationship -> App? in guard case let .app(app) = relationship else { return nil } @@ -66,9 +80,5 @@ public struct PrereleaseVersionResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/TestFlight/PrereleaseVersionWithoutIncludesResponse.swift b/Sources/Bagbutik-Models/TestFlight/PrereleaseVersionWithoutIncludesResponse.swift index 02ac30fa8..e33b2f304 100644 --- a/Sources/Bagbutik-Models/TestFlight/PrereleaseVersionWithoutIncludesResponse.swift +++ b/Sources/Bagbutik-Models/TestFlight/PrereleaseVersionWithoutIncludesResponse.swift @@ -11,4 +11,16 @@ public struct PrereleaseVersionWithoutIncludesResponse: Codable { self.data = data self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(PrereleaseVersion.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/Users/User.swift b/Sources/Bagbutik-Models/Users/User.swift index c345397e4..270626164 100644 --- a/Sources/Bagbutik-Models/Users/User.swift +++ b/Sources/Bagbutik-Models/Users/User.swift @@ -32,31 +32,23 @@ public struct User: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -94,6 +86,26 @@ public struct User: Codable, Identifiable { self.roles = roles self.username = username } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + allAppsVisible = try container.decodeIfPresent(Bool.self, forKey: "allAppsVisible") + firstName = try container.decodeIfPresent(String.self, forKey: "firstName") + lastName = try container.decodeIfPresent(String.self, forKey: "lastName") + provisioningAllowed = try container.decodeIfPresent(Bool.self, forKey: "provisioningAllowed") + roles = try container.decodeIfPresent([UserRole].self, forKey: "roles") + username = try container.decodeIfPresent(String.self, forKey: "username") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(allAppsVisible, forKey: "allAppsVisible") + try container.encodeIfPresent(firstName, forKey: "firstName") + try container.encodeIfPresent(lastName, forKey: "lastName") + try container.encodeIfPresent(provisioningAllowed, forKey: "provisioningAllowed") + try container.encodeIfPresent(roles, forKey: "roles") + try container.encodeIfPresent(username, forKey: "username") + } } /** @@ -110,6 +122,16 @@ public struct User: Codable, Identifiable { self.visibleApps = visibleApps } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + visibleApps = try container.decodeIfPresent(VisibleApps.self, forKey: "visibleApps") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(visibleApps, forKey: "visibleApps") + } + /** # User.Relationships.VisibleApps The data and links that describe the relationship between the resources. @@ -132,23 +154,17 @@ public struct User: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } /** @@ -169,22 +185,17 @@ public struct User: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -207,20 +218,15 @@ public struct User: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/Users/UserInvitation.swift b/Sources/Bagbutik-Models/Users/UserInvitation.swift index 3b921f962..6cb3ef984 100644 --- a/Sources/Bagbutik-Models/Users/UserInvitation.swift +++ b/Sources/Bagbutik-Models/Users/UserInvitation.swift @@ -32,31 +32,23 @@ public struct UserInvitation: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -98,6 +90,28 @@ public struct UserInvitation: Codable, Identifiable { self.provisioningAllowed = provisioningAllowed self.roles = roles } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + allAppsVisible = try container.decodeIfPresent(Bool.self, forKey: "allAppsVisible") + email = try container.decodeIfPresent(String.self, forKey: "email") + expirationDate = try container.decodeIfPresent(Date.self, forKey: "expirationDate") + firstName = try container.decodeIfPresent(String.self, forKey: "firstName") + lastName = try container.decodeIfPresent(String.self, forKey: "lastName") + provisioningAllowed = try container.decodeIfPresent(Bool.self, forKey: "provisioningAllowed") + roles = try container.decodeIfPresent([UserRole].self, forKey: "roles") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(allAppsVisible, forKey: "allAppsVisible") + try container.encodeIfPresent(email, forKey: "email") + try container.encodeIfPresent(expirationDate, forKey: "expirationDate") + try container.encodeIfPresent(firstName, forKey: "firstName") + try container.encodeIfPresent(lastName, forKey: "lastName") + try container.encodeIfPresent(provisioningAllowed, forKey: "provisioningAllowed") + try container.encodeIfPresent(roles, forKey: "roles") + } } /** @@ -114,6 +128,16 @@ public struct UserInvitation: Codable, Identifiable { self.visibleApps = visibleApps } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + visibleApps = try container.decodeIfPresent(VisibleApps.self, forKey: "visibleApps") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(visibleApps, forKey: "visibleApps") + } + /** # UserInvitation.Relationships.VisibleApps The data and links that describe the relationship between the resources. @@ -136,23 +160,17 @@ public struct UserInvitation: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } /** @@ -173,22 +191,17 @@ public struct UserInvitation: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -211,20 +224,15 @@ public struct UserInvitation: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/Users/UserInvitationCreateRequest.swift b/Sources/Bagbutik-Models/Users/UserInvitationCreateRequest.swift index be6a0c916..b1bbf1cc7 100644 --- a/Sources/Bagbutik-Models/Users/UserInvitationCreateRequest.swift +++ b/Sources/Bagbutik-Models/Users/UserInvitationCreateRequest.swift @@ -16,6 +16,16 @@ public struct UserInvitationCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # UserInvitationCreateRequest.Data The data element of the request body. @@ -39,25 +49,19 @@ public struct UserInvitationCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -95,6 +99,26 @@ public struct UserInvitationCreateRequest: Codable, RequestBody { self.provisioningAllowed = provisioningAllowed self.roles = roles } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + allAppsVisible = try container.decodeIfPresent(Bool.self, forKey: "allAppsVisible") + email = try container.decode(String.self, forKey: "email") + firstName = try container.decode(String.self, forKey: "firstName") + lastName = try container.decode(String.self, forKey: "lastName") + provisioningAllowed = try container.decodeIfPresent(Bool.self, forKey: "provisioningAllowed") + roles = try container.decode([UserRole].self, forKey: "roles") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(allAppsVisible, forKey: "allAppsVisible") + try container.encode(email, forKey: "email") + try container.encode(firstName, forKey: "firstName") + try container.encode(lastName, forKey: "lastName") + try container.encodeIfPresent(provisioningAllowed, forKey: "provisioningAllowed") + try container.encode(roles, forKey: "roles") + } } /** @@ -111,6 +135,16 @@ public struct UserInvitationCreateRequest: Codable, RequestBody { self.visibleApps = visibleApps } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + visibleApps = try container.decodeIfPresent(VisibleApps.self, forKey: "visibleApps") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(visibleApps, forKey: "visibleApps") + } + /** # UserInvitationCreateRequest.Data.Relationships.VisibleApps The relationships to other resources that you can set with this request. @@ -126,17 +160,13 @@ public struct UserInvitationCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } /** @@ -157,22 +187,17 @@ public struct UserInvitationCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/Users/UserInvitationResponse.swift b/Sources/Bagbutik-Models/Users/UserInvitationResponse.swift index d6b2525c2..5514175ba 100644 --- a/Sources/Bagbutik-Models/Users/UserInvitationResponse.swift +++ b/Sources/Bagbutik-Models/Users/UserInvitationResponse.swift @@ -23,4 +23,18 @@ public struct UserInvitationResponse: Codable { self.included = included self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(UserInvitation.self, forKey: "data") + included = try container.decodeIfPresent([App].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/Users/UserInvitationsResponse.swift b/Sources/Bagbutik-Models/Users/UserInvitationsResponse.swift index 15ed00bba..d53a6f8ef 100644 --- a/Sources/Bagbutik-Models/Users/UserInvitationsResponse.swift +++ b/Sources/Bagbutik-Models/Users/UserInvitationsResponse.swift @@ -29,4 +29,20 @@ public struct UserInvitationsResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([UserInvitation].self, forKey: "data") + included = try container.decodeIfPresent([App].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/Users/UserResponse.swift b/Sources/Bagbutik-Models/Users/UserResponse.swift index 5606fe4e2..0403c5715 100644 --- a/Sources/Bagbutik-Models/Users/UserResponse.swift +++ b/Sources/Bagbutik-Models/Users/UserResponse.swift @@ -23,4 +23,18 @@ public struct UserResponse: Codable { self.included = included self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(User.self, forKey: "data") + included = try container.decodeIfPresent([App].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/Users/UserUpdateRequest.swift b/Sources/Bagbutik-Models/Users/UserUpdateRequest.swift index 70f070418..2aa61bf12 100644 --- a/Sources/Bagbutik-Models/Users/UserUpdateRequest.swift +++ b/Sources/Bagbutik-Models/Users/UserUpdateRequest.swift @@ -16,6 +16,16 @@ public struct UserUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # UserUpdateRequest.Data The data element of the request body. @@ -43,28 +53,21 @@ public struct UserUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -90,6 +93,20 @@ public struct UserUpdateRequest: Codable, RequestBody { self.provisioningAllowed = provisioningAllowed self.roles = roles } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + allAppsVisible = try container.decodeIfPresent(Bool.self, forKey: "allAppsVisible") + provisioningAllowed = try container.decodeIfPresent(Bool.self, forKey: "provisioningAllowed") + roles = try container.decodeIfPresent([UserRole].self, forKey: "roles") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(allAppsVisible, forKey: "allAppsVisible") + try container.encodeIfPresent(provisioningAllowed, forKey: "provisioningAllowed") + try container.encodeIfPresent(roles, forKey: "roles") + } } /** @@ -106,6 +123,16 @@ public struct UserUpdateRequest: Codable, RequestBody { self.visibleApps = visibleApps } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + visibleApps = try container.decodeIfPresent(VisibleApps.self, forKey: "visibleApps") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(visibleApps, forKey: "visibleApps") + } + /** # UserUpdateRequest.Data.Relationships.VisibleApps The data and links that describe the relationship between the resources. @@ -121,17 +148,13 @@ public struct UserUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } /** @@ -152,22 +175,17 @@ public struct UserUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/Users/UserVisibleAppsLinkagesRequest.swift b/Sources/Bagbutik-Models/Users/UserVisibleAppsLinkagesRequest.swift index ca2947f72..f971158e3 100644 --- a/Sources/Bagbutik-Models/Users/UserVisibleAppsLinkagesRequest.swift +++ b/Sources/Bagbutik-Models/Users/UserVisibleAppsLinkagesRequest.swift @@ -16,6 +16,16 @@ public struct UserVisibleAppsLinkagesRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # UserVisibleAppsLinkagesRequest.Data The data element of the request body. @@ -34,22 +44,17 @@ public struct UserVisibleAppsLinkagesRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/Users/UserVisibleAppsLinkagesResponse.swift b/Sources/Bagbutik-Models/Users/UserVisibleAppsLinkagesResponse.swift index 39a18fc48..688128da9 100644 --- a/Sources/Bagbutik-Models/Users/UserVisibleAppsLinkagesResponse.swift +++ b/Sources/Bagbutik-Models/Users/UserVisibleAppsLinkagesResponse.swift @@ -25,6 +25,20 @@ public struct UserVisibleAppsLinkagesResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Data].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + /** # UserVisibleAppsLinkagesResponse.Data The data element of the response body. @@ -43,22 +57,17 @@ public struct UserVisibleAppsLinkagesResponse: Codable, PagedResponse { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/Users/UsersResponse.swift b/Sources/Bagbutik-Models/Users/UsersResponse.swift index 1a7904e04..31efacb69 100644 --- a/Sources/Bagbutik-Models/Users/UsersResponse.swift +++ b/Sources/Bagbutik-Models/Users/UsersResponse.swift @@ -29,4 +29,20 @@ public struct UsersResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([User].self, forKey: "data") + included = try container.decodeIfPresent([App].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/XcodeCloud/CiAction.swift b/Sources/Bagbutik-Models/XcodeCloud/CiAction.swift index 216cc400a..4f244fab0 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/CiAction.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/CiAction.swift @@ -45,6 +45,30 @@ public struct CiAction: Codable { self.testConfiguration = testConfiguration } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + actionType = try container.decodeIfPresent(CiActionType.self, forKey: "actionType") + buildDistributionAudience = try container.decodeIfPresent(BuildAudienceType.self, forKey: "buildDistributionAudience") + destination = try container.decodeIfPresent(Destination.self, forKey: "destination") + isRequiredToPass = try container.decodeIfPresent(Bool.self, forKey: "isRequiredToPass") + name = try container.decodeIfPresent(String.self, forKey: "name") + platform = try container.decodeIfPresent(Platform.self, forKey: "platform") + scheme = try container.decodeIfPresent(String.self, forKey: "scheme") + testConfiguration = try container.decodeIfPresent(TestConfiguration.self, forKey: "testConfiguration") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(actionType, forKey: "actionType") + try container.encodeIfPresent(buildDistributionAudience, forKey: "buildDistributionAudience") + try container.encodeIfPresent(destination, forKey: "destination") + try container.encodeIfPresent(isRequiredToPass, forKey: "isRequiredToPass") + try container.encodeIfPresent(name, forKey: "name") + try container.encodeIfPresent(platform, forKey: "platform") + try container.encodeIfPresent(scheme, forKey: "scheme") + try container.encodeIfPresent(testConfiguration, forKey: "testConfiguration") + } + public enum Destination: String, Codable, CaseIterable { case anyIosDevice = "ANY_IOS_DEVICE" case anyIosSimulator = "ANY_IOS_SIMULATOR" @@ -90,6 +114,20 @@ public struct CiAction: Codable { self.testPlanName = testPlanName } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + kind = try container.decodeIfPresent(Kind.self, forKey: "kind") + testDestinations = try container.decodeIfPresent([CiTestDestination].self, forKey: "testDestinations") + testPlanName = try container.decodeIfPresent(String.self, forKey: "testPlanName") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(kind, forKey: "kind") + try container.encodeIfPresent(testDestinations, forKey: "testDestinations") + try container.encodeIfPresent(testPlanName, forKey: "testPlanName") + } + public enum Kind: String, Codable, CaseIterable { case specificTestPlans = "SPECIFIC_TEST_PLANS" case useSchemeSettings = "USE_SCHEME_SETTINGS" diff --git a/Sources/Bagbutik-Models/XcodeCloud/CiArtifact.swift b/Sources/Bagbutik-Models/XcodeCloud/CiArtifact.swift index 9de7f0d69..d69bd0f93 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/CiArtifact.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/CiArtifact.swift @@ -28,28 +28,21 @@ public struct CiArtifact: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } /** @@ -80,6 +73,22 @@ public struct CiArtifact: Codable, Identifiable { self.fileType = fileType } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + downloadUrl = try container.decodeIfPresent(String.self, forKey: "downloadUrl") + fileName = try container.decodeIfPresent(String.self, forKey: "fileName") + fileSize = try container.decodeIfPresent(Int.self, forKey: "fileSize") + fileType = try container.decodeIfPresent(FileType.self, forKey: "fileType") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(downloadUrl, forKey: "downloadUrl") + try container.encodeIfPresent(fileName, forKey: "fileName") + try container.encodeIfPresent(fileSize, forKey: "fileSize") + try container.encodeIfPresent(fileType, forKey: "fileType") + } + public enum FileType: String, Codable, CaseIterable { case archive = "ARCHIVE" case archiveExport = "ARCHIVE_EXPORT" diff --git a/Sources/Bagbutik-Models/XcodeCloud/CiArtifactResponse.swift b/Sources/Bagbutik-Models/XcodeCloud/CiArtifactResponse.swift index 670bc06de..37333592f 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/CiArtifactResponse.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/CiArtifactResponse.swift @@ -20,4 +20,16 @@ public struct CiArtifactResponse: Codable { self.data = data self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(CiArtifact.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/XcodeCloud/CiArtifactsResponse.swift b/Sources/Bagbutik-Models/XcodeCloud/CiArtifactsResponse.swift index b3719c631..687df278a 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/CiArtifactsResponse.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/CiArtifactsResponse.swift @@ -26,4 +26,18 @@ public struct CiArtifactsResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([CiArtifact].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/XcodeCloud/CiBranchPatterns.swift b/Sources/Bagbutik-Models/XcodeCloud/CiBranchPatterns.swift index 79759afe8..c342bea4c 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/CiBranchPatterns.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/CiBranchPatterns.swift @@ -21,6 +21,18 @@ public struct CiBranchPatterns: Codable { self.patterns = patterns } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + isAllMatch = try container.decodeIfPresent(Bool.self, forKey: "isAllMatch") + patterns = try container.decodeIfPresent([Patterns].self, forKey: "patterns") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(isAllMatch, forKey: "isAllMatch") + try container.encodeIfPresent(patterns, forKey: "patterns") + } + /** # CiBranchPatterns.Patterns A case-sensitive pattern Xcode Cloud uses to determine if a change meets branch names you configure for a workflow’s start condition. @@ -40,5 +52,17 @@ public struct CiBranchPatterns: Codable { self.isPrefix = isPrefix self.pattern = pattern } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + isPrefix = try container.decodeIfPresent(Bool.self, forKey: "isPrefix") + pattern = try container.decodeIfPresent(String.self, forKey: "pattern") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(isPrefix, forKey: "isPrefix") + try container.encodeIfPresent(pattern, forKey: "pattern") + } } } diff --git a/Sources/Bagbutik-Models/XcodeCloud/CiBranchStartCondition.swift b/Sources/Bagbutik-Models/XcodeCloud/CiBranchStartCondition.swift index ff0759c0f..d5c0e7384 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/CiBranchStartCondition.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/CiBranchStartCondition.swift @@ -24,4 +24,18 @@ public struct CiBranchStartCondition: Codable { self.filesAndFoldersRule = filesAndFoldersRule self.source = source } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + autoCancel = try container.decodeIfPresent(Bool.self, forKey: "autoCancel") + filesAndFoldersRule = try container.decodeIfPresent(CiFilesAndFoldersRule.self, forKey: "filesAndFoldersRule") + source = try container.decodeIfPresent(CiBranchPatterns.self, forKey: "source") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(autoCancel, forKey: "autoCancel") + try container.encodeIfPresent(filesAndFoldersRule, forKey: "filesAndFoldersRule") + try container.encodeIfPresent(source, forKey: "source") + } } diff --git a/Sources/Bagbutik-Models/XcodeCloud/CiBuildAction.swift b/Sources/Bagbutik-Models/XcodeCloud/CiBuildAction.swift index 760007d46..07a0900ff 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/CiBuildAction.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/CiBuildAction.swift @@ -32,31 +32,23 @@ public struct CiBuildAction: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -102,6 +94,30 @@ public struct CiBuildAction: Codable, Identifiable { self.name = name self.startedDate = startedDate } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + actionType = try container.decodeIfPresent(CiActionType.self, forKey: "actionType") + completionStatus = try container.decodeIfPresent(CiCompletionStatus.self, forKey: "completionStatus") + executionProgress = try container.decodeIfPresent(CiExecutionProgress.self, forKey: "executionProgress") + finishedDate = try container.decodeIfPresent(Date.self, forKey: "finishedDate") + isRequiredToPass = try container.decodeIfPresent(Bool.self, forKey: "isRequiredToPass") + issueCounts = try container.decodeIfPresent(CiIssueCounts.self, forKey: "issueCounts") + name = try container.decodeIfPresent(String.self, forKey: "name") + startedDate = try container.decodeIfPresent(Date.self, forKey: "startedDate") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(actionType, forKey: "actionType") + try container.encodeIfPresent(completionStatus, forKey: "completionStatus") + try container.encodeIfPresent(executionProgress, forKey: "executionProgress") + try container.encodeIfPresent(finishedDate, forKey: "finishedDate") + try container.encodeIfPresent(isRequiredToPass, forKey: "isRequiredToPass") + try container.encodeIfPresent(issueCounts, forKey: "issueCounts") + try container.encodeIfPresent(name, forKey: "name") + try container.encodeIfPresent(startedDate, forKey: "startedDate") + } } /** @@ -119,6 +135,16 @@ public struct CiBuildAction: Codable, Identifiable { self.buildRun = buildRun } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + buildRun = try container.decodeIfPresent(BuildRun.self, forKey: "buildRun") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(buildRun, forKey: "buildRun") + } + /** # CiBuildAction.Relationships.BuildRun The data and links that describe the relationship between the Build Actions and Build Runs resources. @@ -140,20 +166,15 @@ public struct CiBuildAction: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -174,22 +195,17 @@ public struct CiBuildAction: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -214,20 +230,15 @@ public struct CiBuildAction: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/XcodeCloud/CiBuildActionResponse.swift b/Sources/Bagbutik-Models/XcodeCloud/CiBuildActionResponse.swift index 15aea9618..3ca304768 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/CiBuildActionResponse.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/CiBuildActionResponse.swift @@ -24,4 +24,18 @@ public struct CiBuildActionResponse: Codable { self.included = included self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(CiBuildAction.self, forKey: "data") + included = try container.decodeIfPresent([CiBuildRun].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/XcodeCloud/CiBuildActionsResponse.swift b/Sources/Bagbutik-Models/XcodeCloud/CiBuildActionsResponse.swift index e440ddace..3942cd679 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/CiBuildActionsResponse.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/CiBuildActionsResponse.swift @@ -30,4 +30,20 @@ public struct CiBuildActionsResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([CiBuildAction].self, forKey: "data") + included = try container.decodeIfPresent([CiBuildRun].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/XcodeCloud/CiBuildRun.swift b/Sources/Bagbutik-Models/XcodeCloud/CiBuildRun.swift index 54b97033f..f52b91413 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/CiBuildRun.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/CiBuildRun.swift @@ -32,31 +32,23 @@ public struct CiBuildRun: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -119,6 +111,38 @@ public struct CiBuildRun: Codable, Identifiable { self.startedDate = startedDate } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + cancelReason = try container.decodeIfPresent(CancelReason.self, forKey: "cancelReason") + completionStatus = try container.decodeIfPresent(CiCompletionStatus.self, forKey: "completionStatus") + createdDate = try container.decodeIfPresent(Date.self, forKey: "createdDate") + destinationCommit = try container.decodeIfPresent(DestinationCommit.self, forKey: "destinationCommit") + executionProgress = try container.decodeIfPresent(CiExecutionProgress.self, forKey: "executionProgress") + finishedDate = try container.decodeIfPresent(Date.self, forKey: "finishedDate") + isPullRequestBuild = try container.decodeIfPresent(Bool.self, forKey: "isPullRequestBuild") + issueCounts = try container.decodeIfPresent(CiIssueCounts.self, forKey: "issueCounts") + number = try container.decodeIfPresent(Int.self, forKey: "number") + sourceCommit = try container.decodeIfPresent(SourceCommit.self, forKey: "sourceCommit") + startReason = try container.decodeIfPresent(StartReason.self, forKey: "startReason") + startedDate = try container.decodeIfPresent(Date.self, forKey: "startedDate") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(cancelReason, forKey: "cancelReason") + try container.encodeIfPresent(completionStatus, forKey: "completionStatus") + try container.encodeIfPresent(createdDate, forKey: "createdDate") + try container.encodeIfPresent(destinationCommit, forKey: "destinationCommit") + try container.encodeIfPresent(executionProgress, forKey: "executionProgress") + try container.encodeIfPresent(finishedDate, forKey: "finishedDate") + try container.encodeIfPresent(isPullRequestBuild, forKey: "isPullRequestBuild") + try container.encodeIfPresent(issueCounts, forKey: "issueCounts") + try container.encodeIfPresent(number, forKey: "number") + try container.encodeIfPresent(sourceCommit, forKey: "sourceCommit") + try container.encodeIfPresent(startReason, forKey: "startReason") + try container.encodeIfPresent(startedDate, forKey: "startedDate") + } + public enum CancelReason: String, Codable, CaseIterable { case automaticallyByNewerBuild = "AUTOMATICALLY_BY_NEWER_BUILD" case manuallyByUser = "MANUALLY_BY_USER" @@ -155,6 +179,24 @@ public struct CiBuildRun: Codable, Identifiable { self.message = message self.webUrl = webUrl } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + author = try container.decodeIfPresent(CiGitUser.self, forKey: "author") + commitSha = try container.decodeIfPresent(String.self, forKey: "commitSha") + committer = try container.decodeIfPresent(CiGitUser.self, forKey: "committer") + message = try container.decodeIfPresent(String.self, forKey: "message") + webUrl = try container.decodeIfPresent(String.self, forKey: "webUrl") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(author, forKey: "author") + try container.encodeIfPresent(commitSha, forKey: "commitSha") + try container.encodeIfPresent(committer, forKey: "committer") + try container.encodeIfPresent(message, forKey: "message") + try container.encodeIfPresent(webUrl, forKey: "webUrl") + } } /** @@ -188,6 +230,24 @@ public struct CiBuildRun: Codable, Identifiable { self.message = message self.webUrl = webUrl } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + author = try container.decodeIfPresent(CiGitUser.self, forKey: "author") + commitSha = try container.decodeIfPresent(String.self, forKey: "commitSha") + committer = try container.decodeIfPresent(CiGitUser.self, forKey: "committer") + message = try container.decodeIfPresent(String.self, forKey: "message") + webUrl = try container.decodeIfPresent(String.self, forKey: "webUrl") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(author, forKey: "author") + try container.encodeIfPresent(commitSha, forKey: "commitSha") + try container.encodeIfPresent(committer, forKey: "committer") + try container.encodeIfPresent(message, forKey: "message") + try container.encodeIfPresent(webUrl, forKey: "webUrl") + } } public enum StartReason: String, Codable, CaseIterable { @@ -236,6 +296,26 @@ public struct CiBuildRun: Codable, Identifiable { self.workflow = workflow } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + builds = try container.decodeIfPresent(Builds.self, forKey: "builds") + destinationBranch = try container.decodeIfPresent(DestinationBranch.self, forKey: "destinationBranch") + product = try container.decodeIfPresent(Product.self, forKey: "product") + pullRequest = try container.decodeIfPresent(PullRequest.self, forKey: "pullRequest") + sourceBranchOrTag = try container.decodeIfPresent(SourceBranchOrTag.self, forKey: "sourceBranchOrTag") + workflow = try container.decodeIfPresent(Workflow.self, forKey: "workflow") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(builds, forKey: "builds") + try container.encodeIfPresent(destinationBranch, forKey: "destinationBranch") + try container.encodeIfPresent(product, forKey: "product") + try container.encodeIfPresent(pullRequest, forKey: "pullRequest") + try container.encodeIfPresent(sourceBranchOrTag, forKey: "sourceBranchOrTag") + try container.encodeIfPresent(workflow, forKey: "workflow") + } + /** # CiBuildRun.Relationships.Builds The data, links, and paging information that describe the relationship between the Build Runs and the Builds resources. @@ -261,23 +341,17 @@ public struct CiBuildRun: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } /** @@ -298,22 +372,17 @@ public struct CiBuildRun: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -338,20 +407,15 @@ public struct CiBuildRun: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -377,20 +441,15 @@ public struct CiBuildRun: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -411,22 +470,17 @@ public struct CiBuildRun: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -451,20 +505,15 @@ public struct CiBuildRun: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -490,20 +539,15 @@ public struct CiBuildRun: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -524,22 +568,17 @@ public struct CiBuildRun: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -564,20 +603,15 @@ public struct CiBuildRun: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -603,20 +637,15 @@ public struct CiBuildRun: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -637,22 +666,17 @@ public struct CiBuildRun: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -677,20 +701,15 @@ public struct CiBuildRun: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -716,20 +735,15 @@ public struct CiBuildRun: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -750,22 +764,17 @@ public struct CiBuildRun: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -790,20 +799,15 @@ public struct CiBuildRun: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -829,20 +833,15 @@ public struct CiBuildRun: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -863,22 +862,17 @@ public struct CiBuildRun: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -903,20 +897,15 @@ public struct CiBuildRun: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/XcodeCloud/CiBuildRunCreateRequest.swift b/Sources/Bagbutik-Models/XcodeCloud/CiBuildRunCreateRequest.swift index ca8777445..c2aff5416 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/CiBuildRunCreateRequest.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/CiBuildRunCreateRequest.swift @@ -16,6 +16,16 @@ public struct CiBuildRunCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # CiBuildRunCreateRequest.Data The data element of the request you use to start a new Xcode Cloud build. @@ -39,25 +49,19 @@ public struct CiBuildRunCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -74,6 +78,16 @@ public struct CiBuildRunCreateRequest: Codable, RequestBody { public init(clean: Bool? = nil) { self.clean = clean } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + clean = try container.decodeIfPresent(Bool.self, forKey: "clean") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(clean, forKey: "clean") + } } /** @@ -104,6 +118,22 @@ public struct CiBuildRunCreateRequest: Codable, RequestBody { self.workflow = workflow } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + buildRun = try container.decodeIfPresent(BuildRun.self, forKey: "buildRun") + pullRequest = try container.decodeIfPresent(PullRequest.self, forKey: "pullRequest") + sourceBranchOrTag = try container.decodeIfPresent(SourceBranchOrTag.self, forKey: "sourceBranchOrTag") + workflow = try container.decodeIfPresent(Workflow.self, forKey: "workflow") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(buildRun, forKey: "buildRun") + try container.encodeIfPresent(pullRequest, forKey: "pullRequest") + try container.encodeIfPresent(sourceBranchOrTag, forKey: "sourceBranchOrTag") + try container.encodeIfPresent(workflow, forKey: "workflow") + } + /** # CiBuildRunCreateRequest.Data.Relationships.BuildRun The relationship to the Build Runs resource you can set with the request that creates a Build Runs resource. @@ -120,17 +150,13 @@ public struct CiBuildRunCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } /** @@ -151,22 +177,17 @@ public struct CiBuildRunCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -187,17 +208,13 @@ public struct CiBuildRunCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } /** @@ -218,22 +235,17 @@ public struct CiBuildRunCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -254,17 +266,13 @@ public struct CiBuildRunCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } /** @@ -285,22 +293,17 @@ public struct CiBuildRunCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -321,17 +324,13 @@ public struct CiBuildRunCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } /** @@ -352,22 +351,17 @@ public struct CiBuildRunCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/XcodeCloud/CiBuildRunResponse.swift b/Sources/Bagbutik-Models/XcodeCloud/CiBuildRunResponse.swift index b09d0ee9f..79f11d8ca 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/CiBuildRunResponse.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/CiBuildRunResponse.swift @@ -25,6 +25,20 @@ public struct CiBuildRunResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(CiBuildRun.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getBuilds() -> [Build] { guard let buildIds = data.relationships?.builds?.data?.map(\.id), let builds = included?.compactMap({ relationship -> Build? in @@ -110,9 +124,5 @@ public struct CiBuildRunResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/XcodeCloud/CiBuildRunsResponse.swift b/Sources/Bagbutik-Models/XcodeCloud/CiBuildRunsResponse.swift index 3b283b6f5..beff343a1 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/CiBuildRunsResponse.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/CiBuildRunsResponse.swift @@ -31,6 +31,22 @@ public struct CiBuildRunsResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([CiBuildRun].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getBuilds(for ciBuildRun: CiBuildRun) -> [Build] { guard let buildIds = ciBuildRun.relationships?.builds?.data?.map(\.id), let builds = included?.compactMap({ relationship -> Build? in @@ -116,9 +132,5 @@ public struct CiBuildRunsResponse: Codable, PagedResponse { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/XcodeCloud/CiFilesAndFoldersRule.swift b/Sources/Bagbutik-Models/XcodeCloud/CiFilesAndFoldersRule.swift index 883663f3a..ca3c6ca7c 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/CiFilesAndFoldersRule.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/CiFilesAndFoldersRule.swift @@ -21,6 +21,18 @@ public struct CiFilesAndFoldersRule: Codable { self.mode = mode } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + matchers = try container.decodeIfPresent([CiStartConditionFileMatcher].self, forKey: "matchers") + mode = try container.decodeIfPresent(Mode.self, forKey: "mode") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(matchers, forKey: "matchers") + try container.encodeIfPresent(mode, forKey: "mode") + } + public enum Mode: String, Codable, CaseIterable { case doNotStartIfAllFilesMatch = "DO_NOT_START_IF_ALL_FILES_MATCH" case startIfAnyFileMatches = "START_IF_ANY_FILE_MATCHES" diff --git a/Sources/Bagbutik-Models/XcodeCloud/CiGitUser.swift b/Sources/Bagbutik-Models/XcodeCloud/CiGitUser.swift index d0f64544a..3f92682bc 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/CiGitUser.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/CiGitUser.swift @@ -20,4 +20,16 @@ public struct CiGitUser: Codable { self.avatarUrl = avatarUrl self.displayName = displayName } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + avatarUrl = try container.decodeIfPresent(String.self, forKey: "avatarUrl") + displayName = try container.decodeIfPresent(String.self, forKey: "displayName") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(avatarUrl, forKey: "avatarUrl") + try container.encodeIfPresent(displayName, forKey: "displayName") + } } diff --git a/Sources/Bagbutik-Models/XcodeCloud/CiIssue.swift b/Sources/Bagbutik-Models/XcodeCloud/CiIssue.swift index cae12a175..69b5b0922 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/CiIssue.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/CiIssue.swift @@ -28,28 +28,21 @@ public struct CiIssue: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } /** @@ -80,6 +73,22 @@ public struct CiIssue: Codable, Identifiable { self.message = message } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + category = try container.decodeIfPresent(String.self, forKey: "category") + fileSource = try container.decodeIfPresent(FileLocation.self, forKey: "fileSource") + issueType = try container.decodeIfPresent(IssueType.self, forKey: "issueType") + message = try container.decodeIfPresent(String.self, forKey: "message") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(category, forKey: "category") + try container.encodeIfPresent(fileSource, forKey: "fileSource") + try container.encodeIfPresent(issueType, forKey: "issueType") + try container.encodeIfPresent(message, forKey: "message") + } + public enum IssueType: String, Codable, CaseIterable { case analyzerWarning = "ANALYZER_WARNING" case error = "ERROR" diff --git a/Sources/Bagbutik-Models/XcodeCloud/CiIssueCounts.swift b/Sources/Bagbutik-Models/XcodeCloud/CiIssueCounts.swift index 5b135b7cc..28e8f0ee2 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/CiIssueCounts.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/CiIssueCounts.swift @@ -28,4 +28,20 @@ public struct CiIssueCounts: Codable { self.testFailures = testFailures self.warnings = warnings } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + analyzerWarnings = try container.decodeIfPresent(Int.self, forKey: "analyzerWarnings") + errors = try container.decodeIfPresent(Int.self, forKey: "errors") + testFailures = try container.decodeIfPresent(Int.self, forKey: "testFailures") + warnings = try container.decodeIfPresent(Int.self, forKey: "warnings") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(analyzerWarnings, forKey: "analyzerWarnings") + try container.encodeIfPresent(errors, forKey: "errors") + try container.encodeIfPresent(testFailures, forKey: "testFailures") + try container.encodeIfPresent(warnings, forKey: "warnings") + } } diff --git a/Sources/Bagbutik-Models/XcodeCloud/CiIssueResponse.swift b/Sources/Bagbutik-Models/XcodeCloud/CiIssueResponse.swift index c7579742b..5a3cdfebc 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/CiIssueResponse.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/CiIssueResponse.swift @@ -20,4 +20,16 @@ public struct CiIssueResponse: Codable { self.data = data self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(CiIssue.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/XcodeCloud/CiIssuesResponse.swift b/Sources/Bagbutik-Models/XcodeCloud/CiIssuesResponse.swift index e644b4b27..30bea234f 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/CiIssuesResponse.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/CiIssuesResponse.swift @@ -26,4 +26,18 @@ public struct CiIssuesResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([CiIssue].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/XcodeCloud/CiMacOsVersion.swift b/Sources/Bagbutik-Models/XcodeCloud/CiMacOsVersion.swift index af8b40bb6..86225b9b3 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/CiMacOsVersion.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/CiMacOsVersion.swift @@ -32,31 +32,23 @@ public struct CiMacOsVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -78,6 +70,18 @@ public struct CiMacOsVersion: Codable, Identifiable { self.name = name self.version = version } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + name = try container.decodeIfPresent(String.self, forKey: "name") + version = try container.decodeIfPresent(String.self, forKey: "version") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(name, forKey: "name") + try container.encodeIfPresent(version, forKey: "version") + } } /** @@ -95,6 +99,16 @@ public struct CiMacOsVersion: Codable, Identifiable { self.xcodeVersions = xcodeVersions } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + xcodeVersions = try container.decodeIfPresent(XcodeVersions.self, forKey: "xcodeVersions") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(xcodeVersions, forKey: "xcodeVersions") + } + /** # CiMacOsVersion.Relationships.XcodeVersions The data, links, and paging information that describe the relationship between the macOS Versions and Xcode Versions resources. @@ -120,23 +134,17 @@ public struct CiMacOsVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } /** @@ -157,22 +165,17 @@ public struct CiMacOsVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -197,20 +200,15 @@ public struct CiMacOsVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/XcodeCloud/CiMacOsVersionResponse.swift b/Sources/Bagbutik-Models/XcodeCloud/CiMacOsVersionResponse.swift index 09a188287..3746a05f1 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/CiMacOsVersionResponse.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/CiMacOsVersionResponse.swift @@ -24,4 +24,18 @@ public struct CiMacOsVersionResponse: Codable { self.included = included self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(CiMacOsVersion.self, forKey: "data") + included = try container.decodeIfPresent([CiXcodeVersion].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/XcodeCloud/CiMacOsVersionsResponse.swift b/Sources/Bagbutik-Models/XcodeCloud/CiMacOsVersionsResponse.swift index cd51a0dc8..0a6c00004 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/CiMacOsVersionsResponse.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/CiMacOsVersionsResponse.swift @@ -30,4 +30,20 @@ public struct CiMacOsVersionsResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([CiMacOsVersion].self, forKey: "data") + included = try container.decodeIfPresent([CiXcodeVersion].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/XcodeCloud/CiManualBranchStartCondition.swift b/Sources/Bagbutik-Models/XcodeCloud/CiManualBranchStartCondition.swift index d559fc637..d0ab223dd 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/CiManualBranchStartCondition.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/CiManualBranchStartCondition.swift @@ -7,4 +7,14 @@ public struct CiManualBranchStartCondition: Codable { public init(source: CiBranchPatterns? = nil) { self.source = source } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + source = try container.decodeIfPresent(CiBranchPatterns.self, forKey: "source") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(source, forKey: "source") + } } diff --git a/Sources/Bagbutik-Models/XcodeCloud/CiManualPullRequestStartCondition.swift b/Sources/Bagbutik-Models/XcodeCloud/CiManualPullRequestStartCondition.swift index f0f8e5379..115c6cbe8 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/CiManualPullRequestStartCondition.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/CiManualPullRequestStartCondition.swift @@ -11,4 +11,16 @@ public struct CiManualPullRequestStartCondition: Codable { self.destination = destination self.source = source } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + destination = try container.decodeIfPresent(CiBranchPatterns.self, forKey: "destination") + source = try container.decodeIfPresent(CiBranchPatterns.self, forKey: "source") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(destination, forKey: "destination") + try container.encodeIfPresent(source, forKey: "source") + } } diff --git a/Sources/Bagbutik-Models/XcodeCloud/CiManualTagStartCondition.swift b/Sources/Bagbutik-Models/XcodeCloud/CiManualTagStartCondition.swift index 34e5f7279..02d6b48f5 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/CiManualTagStartCondition.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/CiManualTagStartCondition.swift @@ -7,4 +7,14 @@ public struct CiManualTagStartCondition: Codable { public init(source: CiTagPatterns? = nil) { self.source = source } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + source = try container.decodeIfPresent(CiTagPatterns.self, forKey: "source") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(source, forKey: "source") + } } diff --git a/Sources/Bagbutik-Models/XcodeCloud/CiProduct.swift b/Sources/Bagbutik-Models/XcodeCloud/CiProduct.swift index 3333ed2fd..62cabb411 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/CiProduct.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/CiProduct.swift @@ -32,31 +32,23 @@ public struct CiProduct: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -83,6 +75,20 @@ public struct CiProduct: Codable, Identifiable { self.productType = productType } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + createdDate = try container.decodeIfPresent(Date.self, forKey: "createdDate") + name = try container.decodeIfPresent(String.self, forKey: "name") + productType = try container.decodeIfPresent(ProductType.self, forKey: "productType") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(createdDate, forKey: "createdDate") + try container.encodeIfPresent(name, forKey: "name") + try container.encodeIfPresent(productType, forKey: "productType") + } + public enum ProductType: String, ParameterValue, Codable, CaseIterable { case app = "APP" case framework = "FRAMEWORK" @@ -113,6 +119,20 @@ public struct CiProduct: Codable, Identifiable { self.primaryRepositories = primaryRepositories } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + app = try container.decodeIfPresent(App.self, forKey: "app") + bundleId = try container.decodeIfPresent(BundleId.self, forKey: "bundleId") + primaryRepositories = try container.decodeIfPresent(PrimaryRepositories.self, forKey: "primaryRepositories") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(app, forKey: "app") + try container.encodeIfPresent(bundleId, forKey: "bundleId") + try container.encodeIfPresent(primaryRepositories, forKey: "primaryRepositories") + } + /** # CiProduct.Relationships.App The data and links that describe the relationship between the Products and Apps resources. @@ -134,20 +154,15 @@ public struct CiProduct: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -168,22 +183,17 @@ public struct CiProduct: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -208,20 +218,15 @@ public struct CiProduct: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -247,20 +252,15 @@ public struct CiProduct: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -281,22 +281,17 @@ public struct CiProduct: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -321,20 +316,15 @@ public struct CiProduct: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -364,23 +354,17 @@ public struct CiProduct: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } /** @@ -401,22 +385,17 @@ public struct CiProduct: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -441,20 +420,15 @@ public struct CiProduct: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/XcodeCloud/CiProductResponse.swift b/Sources/Bagbutik-Models/XcodeCloud/CiProductResponse.swift index e7aa156aa..8397645fe 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/CiProductResponse.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/CiProductResponse.swift @@ -25,6 +25,20 @@ public struct CiProductResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(CiProduct.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getApp() -> App? { included?.compactMap { relationship -> App? in guard case let .app(app) = relationship else { return nil } @@ -79,9 +93,5 @@ public struct CiProductResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/XcodeCloud/CiProductsResponse.swift b/Sources/Bagbutik-Models/XcodeCloud/CiProductsResponse.swift index 003e6ad51..7fb4ead79 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/CiProductsResponse.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/CiProductsResponse.swift @@ -31,6 +31,22 @@ public struct CiProductsResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([CiProduct].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getApp(for ciProduct: CiProduct) -> App? { included?.compactMap { relationship -> App? in guard case let .app(app) = relationship else { return nil } @@ -85,9 +101,5 @@ public struct CiProductsResponse: Codable, PagedResponse { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/XcodeCloud/CiPullRequestStartCondition.swift b/Sources/Bagbutik-Models/XcodeCloud/CiPullRequestStartCondition.swift index 56031b5f0..d478efe02 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/CiPullRequestStartCondition.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/CiPullRequestStartCondition.swift @@ -28,4 +28,20 @@ public struct CiPullRequestStartCondition: Codable { self.filesAndFoldersRule = filesAndFoldersRule self.source = source } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + autoCancel = try container.decodeIfPresent(Bool.self, forKey: "autoCancel") + destination = try container.decodeIfPresent(CiBranchPatterns.self, forKey: "destination") + filesAndFoldersRule = try container.decodeIfPresent(CiFilesAndFoldersRule.self, forKey: "filesAndFoldersRule") + source = try container.decodeIfPresent(CiBranchPatterns.self, forKey: "source") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(autoCancel, forKey: "autoCancel") + try container.encodeIfPresent(destination, forKey: "destination") + try container.encodeIfPresent(filesAndFoldersRule, forKey: "filesAndFoldersRule") + try container.encodeIfPresent(source, forKey: "source") + } } diff --git a/Sources/Bagbutik-Models/XcodeCloud/CiScheduledStartCondition.swift b/Sources/Bagbutik-Models/XcodeCloud/CiScheduledStartCondition.swift index 49cb0e40f..7ef1c1e9c 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/CiScheduledStartCondition.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/CiScheduledStartCondition.swift @@ -21,6 +21,18 @@ public struct CiScheduledStartCondition: Codable { self.source = source } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + schedule = try container.decodeIfPresent(Schedule.self, forKey: "schedule") + source = try container.decodeIfPresent(CiBranchPatterns.self, forKey: "source") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(schedule, forKey: "schedule") + try container.encodeIfPresent(source, forKey: "source") + } + /** # CiScheduledStartCondition.Schedule The schedule of an Xcode Cloud workflow that starts a new build based on a schedule. @@ -53,6 +65,24 @@ public struct CiScheduledStartCondition: Codable { self.timezone = timezone } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + days = try container.decodeIfPresent(Items.self, forKey: "days") + frequency = try container.decodeIfPresent(Frequency.self, forKey: "frequency") + hour = try container.decodeIfPresent(Int.self, forKey: "hour") + minute = try container.decodeIfPresent(Int.self, forKey: "minute") + timezone = try container.decodeIfPresent(String.self, forKey: "timezone") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(days, forKey: "days") + try container.encodeIfPresent(frequency, forKey: "frequency") + try container.encodeIfPresent(hour, forKey: "hour") + try container.encodeIfPresent(minute, forKey: "minute") + try container.encodeIfPresent(timezone, forKey: "timezone") + } + public enum Frequency: String, Codable, CaseIterable { case daily = "DAILY" case hourly = "HOURLY" diff --git a/Sources/Bagbutik-Models/XcodeCloud/CiStartConditionFileMatcher.swift b/Sources/Bagbutik-Models/XcodeCloud/CiStartConditionFileMatcher.swift index 056ef4216..9a96e69e6 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/CiStartConditionFileMatcher.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/CiStartConditionFileMatcher.swift @@ -24,4 +24,18 @@ public struct CiStartConditionFileMatcher: Codable { self.fileExtension = fileExtension self.fileName = fileName } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + directory = try container.decodeIfPresent(String.self, forKey: "directory") + fileExtension = try container.decodeIfPresent(String.self, forKey: "fileExtension") + fileName = try container.decodeIfPresent(String.self, forKey: "fileName") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(directory, forKey: "directory") + try container.encodeIfPresent(fileExtension, forKey: "fileExtension") + try container.encodeIfPresent(fileName, forKey: "fileName") + } } diff --git a/Sources/Bagbutik-Models/XcodeCloud/CiTagPatterns.swift b/Sources/Bagbutik-Models/XcodeCloud/CiTagPatterns.swift index 35a04bf73..6e1f1af76 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/CiTagPatterns.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/CiTagPatterns.swift @@ -21,6 +21,18 @@ public struct CiTagPatterns: Codable { self.patterns = patterns } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + isAllMatch = try container.decodeIfPresent(Bool.self, forKey: "isAllMatch") + patterns = try container.decodeIfPresent([Patterns].self, forKey: "patterns") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(isAllMatch, forKey: "isAllMatch") + try container.encodeIfPresent(patterns, forKey: "patterns") + } + /** # CiTagPatterns.Patterns A case-sensitive pattern Xcode Cloud uses to determine if a change meets tag names you configure for a workflow’s start condition. @@ -40,5 +52,17 @@ public struct CiTagPatterns: Codable { self.isPrefix = isPrefix self.pattern = pattern } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + isPrefix = try container.decodeIfPresent(Bool.self, forKey: "isPrefix") + pattern = try container.decodeIfPresent(String.self, forKey: "pattern") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(isPrefix, forKey: "isPrefix") + try container.encodeIfPresent(pattern, forKey: "pattern") + } } } diff --git a/Sources/Bagbutik-Models/XcodeCloud/CiTagStartCondition.swift b/Sources/Bagbutik-Models/XcodeCloud/CiTagStartCondition.swift index 6cb67b324..be722418b 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/CiTagStartCondition.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/CiTagStartCondition.swift @@ -24,4 +24,18 @@ public struct CiTagStartCondition: Codable { self.filesAndFoldersRule = filesAndFoldersRule self.source = source } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + autoCancel = try container.decodeIfPresent(Bool.self, forKey: "autoCancel") + filesAndFoldersRule = try container.decodeIfPresent(CiFilesAndFoldersRule.self, forKey: "filesAndFoldersRule") + source = try container.decodeIfPresent(CiTagPatterns.self, forKey: "source") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(autoCancel, forKey: "autoCancel") + try container.encodeIfPresent(filesAndFoldersRule, forKey: "filesAndFoldersRule") + try container.encodeIfPresent(source, forKey: "source") + } } diff --git a/Sources/Bagbutik-Models/XcodeCloud/CiTestDestination.swift b/Sources/Bagbutik-Models/XcodeCloud/CiTestDestination.swift index e5b6c49a3..6ec74d39c 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/CiTestDestination.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/CiTestDestination.swift @@ -32,4 +32,22 @@ public struct CiTestDestination: Codable { self.runtimeIdentifier = runtimeIdentifier self.runtimeName = runtimeName } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + deviceTypeIdentifier = try container.decodeIfPresent(String.self, forKey: "deviceTypeIdentifier") + deviceTypeName = try container.decodeIfPresent(String.self, forKey: "deviceTypeName") + kind = try container.decodeIfPresent(CiTestDestinationKind.self, forKey: "kind") + runtimeIdentifier = try container.decodeIfPresent(String.self, forKey: "runtimeIdentifier") + runtimeName = try container.decodeIfPresent(String.self, forKey: "runtimeName") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(deviceTypeIdentifier, forKey: "deviceTypeIdentifier") + try container.encodeIfPresent(deviceTypeName, forKey: "deviceTypeName") + try container.encodeIfPresent(kind, forKey: "kind") + try container.encodeIfPresent(runtimeIdentifier, forKey: "runtimeIdentifier") + try container.encodeIfPresent(runtimeName, forKey: "runtimeName") + } } diff --git a/Sources/Bagbutik-Models/XcodeCloud/CiTestResult.swift b/Sources/Bagbutik-Models/XcodeCloud/CiTestResult.swift index deb6fc151..bcc70d021 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/CiTestResult.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/CiTestResult.swift @@ -28,28 +28,21 @@ public struct CiTestResult: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } /** @@ -88,6 +81,26 @@ public struct CiTestResult: Codable, Identifiable { self.status = status } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + className = try container.decodeIfPresent(String.self, forKey: "className") + destinationTestResults = try container.decodeIfPresent([DestinationTestResults].self, forKey: "destinationTestResults") + fileSource = try container.decodeIfPresent(FileLocation.self, forKey: "fileSource") + message = try container.decodeIfPresent(String.self, forKey: "message") + name = try container.decodeIfPresent(String.self, forKey: "name") + status = try container.decodeIfPresent(CiTestStatus.self, forKey: "status") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(className, forKey: "className") + try container.encodeIfPresent(destinationTestResults, forKey: "destinationTestResults") + try container.encodeIfPresent(fileSource, forKey: "fileSource") + try container.encodeIfPresent(message, forKey: "message") + try container.encodeIfPresent(name, forKey: "name") + try container.encodeIfPresent(status, forKey: "status") + } + /** # CiTestResult.Attributes.DestinationTestResults The results of a test action Xcode Cloud performed using a specific test destination. @@ -119,6 +132,24 @@ public struct CiTestResult: Codable, Identifiable { self.status = status self.uuid = uuid } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + deviceName = try container.decodeIfPresent(String.self, forKey: "deviceName") + duration = try container.decodeIfPresent(Double.self, forKey: "duration") + osVersion = try container.decodeIfPresent(String.self, forKey: "osVersion") + status = try container.decodeIfPresent(CiTestStatus.self, forKey: "status") + uuid = try container.decodeIfPresent(String.self, forKey: "uuid") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(deviceName, forKey: "deviceName") + try container.encodeIfPresent(duration, forKey: "duration") + try container.encodeIfPresent(osVersion, forKey: "osVersion") + try container.encodeIfPresent(status, forKey: "status") + try container.encodeIfPresent(uuid, forKey: "uuid") + } } } } diff --git a/Sources/Bagbutik-Models/XcodeCloud/CiTestResultResponse.swift b/Sources/Bagbutik-Models/XcodeCloud/CiTestResultResponse.swift index 37ccb9b9f..ac2f13198 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/CiTestResultResponse.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/CiTestResultResponse.swift @@ -20,4 +20,16 @@ public struct CiTestResultResponse: Codable { self.data = data self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(CiTestResult.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/XcodeCloud/CiTestResultsResponse.swift b/Sources/Bagbutik-Models/XcodeCloud/CiTestResultsResponse.swift index baf8fec8d..8e11ea089 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/CiTestResultsResponse.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/CiTestResultsResponse.swift @@ -26,4 +26,18 @@ public struct CiTestResultsResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([CiTestResult].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/XcodeCloud/CiWorkflow.swift b/Sources/Bagbutik-Models/XcodeCloud/CiWorkflow.swift index 1361e1f56..eb3242e3a 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/CiWorkflow.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/CiWorkflow.swift @@ -32,31 +32,23 @@ public struct CiWorkflow: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -127,6 +119,44 @@ public struct CiWorkflow: Codable, Identifiable { self.scheduledStartCondition = scheduledStartCondition self.tagStartCondition = tagStartCondition } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + actions = try container.decodeIfPresent([CiAction].self, forKey: "actions") + branchStartCondition = try container.decodeIfPresent(CiBranchStartCondition.self, forKey: "branchStartCondition") + clean = try container.decodeIfPresent(Bool.self, forKey: "clean") + containerFilePath = try container.decodeIfPresent(String.self, forKey: "containerFilePath") + description = try container.decodeIfPresent(String.self, forKey: "description") + isEnabled = try container.decodeIfPresent(Bool.self, forKey: "isEnabled") + isLockedForEditing = try container.decodeIfPresent(Bool.self, forKey: "isLockedForEditing") + lastModifiedDate = try container.decodeIfPresent(Date.self, forKey: "lastModifiedDate") + manualBranchStartCondition = try container.decodeIfPresent(CiManualBranchStartCondition.self, forKey: "manualBranchStartCondition") + manualPullRequestStartCondition = try container.decodeIfPresent(CiManualPullRequestStartCondition.self, forKey: "manualPullRequestStartCondition") + manualTagStartCondition = try container.decodeIfPresent(CiManualTagStartCondition.self, forKey: "manualTagStartCondition") + name = try container.decodeIfPresent(String.self, forKey: "name") + pullRequestStartCondition = try container.decodeIfPresent(CiPullRequestStartCondition.self, forKey: "pullRequestStartCondition") + scheduledStartCondition = try container.decodeIfPresent(CiScheduledStartCondition.self, forKey: "scheduledStartCondition") + tagStartCondition = try container.decodeIfPresent(CiTagStartCondition.self, forKey: "tagStartCondition") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(actions, forKey: "actions") + try container.encodeIfPresent(branchStartCondition, forKey: "branchStartCondition") + try container.encodeIfPresent(clean, forKey: "clean") + try container.encodeIfPresent(containerFilePath, forKey: "containerFilePath") + try container.encodeIfPresent(description, forKey: "description") + try container.encodeIfPresent(isEnabled, forKey: "isEnabled") + try container.encodeIfPresent(isLockedForEditing, forKey: "isLockedForEditing") + try container.encodeIfPresent(lastModifiedDate, forKey: "lastModifiedDate") + try container.encodeIfPresent(manualBranchStartCondition, forKey: "manualBranchStartCondition") + try container.encodeIfPresent(manualPullRequestStartCondition, forKey: "manualPullRequestStartCondition") + try container.encodeIfPresent(manualTagStartCondition, forKey: "manualTagStartCondition") + try container.encodeIfPresent(name, forKey: "name") + try container.encodeIfPresent(pullRequestStartCondition, forKey: "pullRequestStartCondition") + try container.encodeIfPresent(scheduledStartCondition, forKey: "scheduledStartCondition") + try container.encodeIfPresent(tagStartCondition, forKey: "tagStartCondition") + } } /** @@ -157,6 +187,22 @@ public struct CiWorkflow: Codable, Identifiable { self.xcodeVersion = xcodeVersion } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + macOsVersion = try container.decodeIfPresent(MacOsVersion.self, forKey: "macOsVersion") + product = try container.decodeIfPresent(Product.self, forKey: "product") + repository = try container.decodeIfPresent(Repository.self, forKey: "repository") + xcodeVersion = try container.decodeIfPresent(XcodeVersion.self, forKey: "xcodeVersion") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(macOsVersion, forKey: "macOsVersion") + try container.encodeIfPresent(product, forKey: "product") + try container.encodeIfPresent(repository, forKey: "repository") + try container.encodeIfPresent(xcodeVersion, forKey: "xcodeVersion") + } + /** # CiWorkflow.Relationships.MacOsVersion The data and links that describe the relationship between the Workflows and the macOS Versions resources. @@ -178,20 +224,15 @@ public struct CiWorkflow: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -212,22 +253,17 @@ public struct CiWorkflow: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -252,20 +288,15 @@ public struct CiWorkflow: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -291,20 +322,15 @@ public struct CiWorkflow: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -325,22 +351,17 @@ public struct CiWorkflow: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -365,20 +386,15 @@ public struct CiWorkflow: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -404,20 +420,15 @@ public struct CiWorkflow: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -438,22 +449,17 @@ public struct CiWorkflow: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -478,20 +484,15 @@ public struct CiWorkflow: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -517,20 +518,15 @@ public struct CiWorkflow: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -551,22 +547,17 @@ public struct CiWorkflow: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -591,20 +582,15 @@ public struct CiWorkflow: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/XcodeCloud/CiWorkflowCreateRequest.swift b/Sources/Bagbutik-Models/XcodeCloud/CiWorkflowCreateRequest.swift index 765fd89d1..974595ae4 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/CiWorkflowCreateRequest.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/CiWorkflowCreateRequest.swift @@ -16,6 +16,16 @@ public struct CiWorkflowCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # CiWorkflowCreateRequest.Data The data element of the request you use to create a new Xcode Cloud workflow. @@ -39,25 +49,19 @@ public struct CiWorkflowCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decode(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decode(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encode(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encode(relationships, forKey: "relationships") } /** @@ -124,6 +128,42 @@ public struct CiWorkflowCreateRequest: Codable, RequestBody { self.scheduledStartCondition = scheduledStartCondition self.tagStartCondition = tagStartCondition } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + actions = try container.decode([CiAction].self, forKey: "actions") + branchStartCondition = try container.decodeIfPresent(CiBranchStartCondition.self, forKey: "branchStartCondition") + clean = try container.decode(Bool.self, forKey: "clean") + containerFilePath = try container.decode(String.self, forKey: "containerFilePath") + description = try container.decode(String.self, forKey: "description") + isEnabled = try container.decode(Bool.self, forKey: "isEnabled") + isLockedForEditing = try container.decodeIfPresent(Bool.self, forKey: "isLockedForEditing") + manualBranchStartCondition = try container.decodeIfPresent(CiManualBranchStartCondition.self, forKey: "manualBranchStartCondition") + manualPullRequestStartCondition = try container.decodeIfPresent(CiManualPullRequestStartCondition.self, forKey: "manualPullRequestStartCondition") + manualTagStartCondition = try container.decodeIfPresent(CiManualTagStartCondition.self, forKey: "manualTagStartCondition") + name = try container.decode(String.self, forKey: "name") + pullRequestStartCondition = try container.decodeIfPresent(CiPullRequestStartCondition.self, forKey: "pullRequestStartCondition") + scheduledStartCondition = try container.decodeIfPresent(CiScheduledStartCondition.self, forKey: "scheduledStartCondition") + tagStartCondition = try container.decodeIfPresent(CiTagStartCondition.self, forKey: "tagStartCondition") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(actions, forKey: "actions") + try container.encodeIfPresent(branchStartCondition, forKey: "branchStartCondition") + try container.encode(clean, forKey: "clean") + try container.encode(containerFilePath, forKey: "containerFilePath") + try container.encode(description, forKey: "description") + try container.encode(isEnabled, forKey: "isEnabled") + try container.encodeIfPresent(isLockedForEditing, forKey: "isLockedForEditing") + try container.encodeIfPresent(manualBranchStartCondition, forKey: "manualBranchStartCondition") + try container.encodeIfPresent(manualPullRequestStartCondition, forKey: "manualPullRequestStartCondition") + try container.encodeIfPresent(manualTagStartCondition, forKey: "manualTagStartCondition") + try container.encode(name, forKey: "name") + try container.encodeIfPresent(pullRequestStartCondition, forKey: "pullRequestStartCondition") + try container.encodeIfPresent(scheduledStartCondition, forKey: "scheduledStartCondition") + try container.encodeIfPresent(tagStartCondition, forKey: "tagStartCondition") + } } /** @@ -154,6 +194,22 @@ public struct CiWorkflowCreateRequest: Codable, RequestBody { self.xcodeVersion = xcodeVersion } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + macOsVersion = try container.decode(MacOsVersion.self, forKey: "macOsVersion") + product = try container.decode(Product.self, forKey: "product") + repository = try container.decode(Repository.self, forKey: "repository") + xcodeVersion = try container.decode(XcodeVersion.self, forKey: "xcodeVersion") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(macOsVersion, forKey: "macOsVersion") + try container.encode(product, forKey: "product") + try container.encode(repository, forKey: "repository") + try container.encode(xcodeVersion, forKey: "xcodeVersion") + } + /** # CiWorkflowCreateRequest.Data.Relationships.MacOsVersion The relationship to the macOS Versions resource you set with the request that creates a Workflows resource. @@ -169,6 +225,16 @@ public struct CiWorkflowCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # CiWorkflowCreateRequest.Data.Relationships.MacOsVersion.Data The type and ID of the macOS Versions resource that you’re relating with the Workflows resource you’re creating. @@ -187,22 +253,17 @@ public struct CiWorkflowCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -222,6 +283,16 @@ public struct CiWorkflowCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # CiWorkflowCreateRequest.Data.Relationships.Product.Data The type and ID of the Products resource that you’re relating with the Workflows resource you’re creating. @@ -240,22 +311,17 @@ public struct CiWorkflowCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -275,6 +341,16 @@ public struct CiWorkflowCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # CiWorkflowCreateRequest.Data.Relationships.Repository.Data The type and ID of the Repositories resource that you’re relating with the Workflows resource you’re creating. @@ -293,22 +369,17 @@ public struct CiWorkflowCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -328,6 +399,16 @@ public struct CiWorkflowCreateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # CiWorkflowCreateRequest.Data.Relationships.XcodeVersion.Data The type and ID of the Xcode Versions resource that you’re relating with the Workflows resource you’re creating. @@ -346,22 +427,17 @@ public struct CiWorkflowCreateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/XcodeCloud/CiWorkflowResponse.swift b/Sources/Bagbutik-Models/XcodeCloud/CiWorkflowResponse.swift index b63efa359..cd78c686d 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/CiWorkflowResponse.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/CiWorkflowResponse.swift @@ -25,6 +25,20 @@ public struct CiWorkflowResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(CiWorkflow.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getMacOsVersion() -> CiMacOsVersion? { included?.compactMap { relationship -> CiMacOsVersion? in guard case let .ciMacOsVersion(macOsVersion) = relationship else { return nil } @@ -86,9 +100,5 @@ public struct CiWorkflowResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/XcodeCloud/CiWorkflowUpdateRequest.swift b/Sources/Bagbutik-Models/XcodeCloud/CiWorkflowUpdateRequest.swift index 4b111ab2f..e1880b261 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/CiWorkflowUpdateRequest.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/CiWorkflowUpdateRequest.swift @@ -16,6 +16,16 @@ public struct CiWorkflowUpdateRequest: Codable, RequestBody { self.data = data } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + } + /** # CiWorkflowUpdateRequest.Data The data element of the request you use to update an Xcode Cloud workflow. @@ -43,28 +53,21 @@ public struct CiWorkflowUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -131,6 +134,42 @@ public struct CiWorkflowUpdateRequest: Codable, RequestBody { self.scheduledStartCondition = scheduledStartCondition self.tagStartCondition = tagStartCondition } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + actions = try container.decodeIfPresent([CiAction].self, forKey: "actions") + branchStartCondition = try container.decodeIfPresent(CiBranchStartCondition.self, forKey: "branchStartCondition") + clean = try container.decodeIfPresent(Bool.self, forKey: "clean") + containerFilePath = try container.decodeIfPresent(String.self, forKey: "containerFilePath") + description = try container.decodeIfPresent(String.self, forKey: "description") + isEnabled = try container.decodeIfPresent(Bool.self, forKey: "isEnabled") + isLockedForEditing = try container.decodeIfPresent(Bool.self, forKey: "isLockedForEditing") + manualBranchStartCondition = try container.decodeIfPresent(CiManualBranchStartCondition.self, forKey: "manualBranchStartCondition") + manualPullRequestStartCondition = try container.decodeIfPresent(CiManualPullRequestStartCondition.self, forKey: "manualPullRequestStartCondition") + manualTagStartCondition = try container.decodeIfPresent(CiManualTagStartCondition.self, forKey: "manualTagStartCondition") + name = try container.decodeIfPresent(String.self, forKey: "name") + pullRequestStartCondition = try container.decodeIfPresent(CiPullRequestStartCondition.self, forKey: "pullRequestStartCondition") + scheduledStartCondition = try container.decodeIfPresent(CiScheduledStartCondition.self, forKey: "scheduledStartCondition") + tagStartCondition = try container.decodeIfPresent(CiTagStartCondition.self, forKey: "tagStartCondition") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(actions, forKey: "actions") + try container.encodeIfPresent(branchStartCondition, forKey: "branchStartCondition") + try container.encodeIfPresent(clean, forKey: "clean") + try container.encodeIfPresent(containerFilePath, forKey: "containerFilePath") + try container.encodeIfPresent(description, forKey: "description") + try container.encodeIfPresent(isEnabled, forKey: "isEnabled") + try container.encodeIfPresent(isLockedForEditing, forKey: "isLockedForEditing") + try container.encodeIfPresent(manualBranchStartCondition, forKey: "manualBranchStartCondition") + try container.encodeIfPresent(manualPullRequestStartCondition, forKey: "manualPullRequestStartCondition") + try container.encodeIfPresent(manualTagStartCondition, forKey: "manualTagStartCondition") + try container.encodeIfPresent(name, forKey: "name") + try container.encodeIfPresent(pullRequestStartCondition, forKey: "pullRequestStartCondition") + try container.encodeIfPresent(scheduledStartCondition, forKey: "scheduledStartCondition") + try container.encodeIfPresent(tagStartCondition, forKey: "tagStartCondition") + } } /** @@ -153,6 +192,18 @@ public struct CiWorkflowUpdateRequest: Codable, RequestBody { self.xcodeVersion = xcodeVersion } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + macOsVersion = try container.decodeIfPresent(MacOsVersion.self, forKey: "macOsVersion") + xcodeVersion = try container.decodeIfPresent(XcodeVersion.self, forKey: "xcodeVersion") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(macOsVersion, forKey: "macOsVersion") + try container.encodeIfPresent(xcodeVersion, forKey: "xcodeVersion") + } + /** # CiWorkflowUpdateRequest.Data.Relationships.MacOsVersion The relationship to the macOS Versions resource you can set with the request that updates a Workflows resource. @@ -169,17 +220,13 @@ public struct CiWorkflowUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } /** @@ -200,22 +247,17 @@ public struct CiWorkflowUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -236,17 +278,13 @@ public struct CiWorkflowUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } /** @@ -267,22 +305,17 @@ public struct CiWorkflowUpdateRequest: Codable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } diff --git a/Sources/Bagbutik-Models/XcodeCloud/CiWorkflowsResponse.swift b/Sources/Bagbutik-Models/XcodeCloud/CiWorkflowsResponse.swift index 3908481e1..e6fb712cc 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/CiWorkflowsResponse.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/CiWorkflowsResponse.swift @@ -31,6 +31,22 @@ public struct CiWorkflowsResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([CiWorkflow].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getMacOsVersion(for ciWorkflow: CiWorkflow) -> CiMacOsVersion? { included?.compactMap { relationship -> CiMacOsVersion? in guard case let .ciMacOsVersion(macOsVersion) = relationship else { return nil } @@ -92,9 +108,5 @@ public struct CiWorkflowsResponse: Codable, PagedResponse { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/XcodeCloud/CiXcodeVersion.swift b/Sources/Bagbutik-Models/XcodeCloud/CiXcodeVersion.swift index 079554833..685811bcc 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/CiXcodeVersion.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/CiXcodeVersion.swift @@ -32,31 +32,23 @@ public struct CiXcodeVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -83,6 +75,20 @@ public struct CiXcodeVersion: Codable, Identifiable { self.version = version } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + name = try container.decodeIfPresent(String.self, forKey: "name") + testDestinations = try container.decodeIfPresent([TestDestinations].self, forKey: "testDestinations") + version = try container.decodeIfPresent(String.self, forKey: "version") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(name, forKey: "name") + try container.encodeIfPresent(testDestinations, forKey: "testDestinations") + try container.encodeIfPresent(version, forKey: "version") + } + /** # CiXcodeVersion.Attributes.TestDestinations The test destinations available for an Xcode version. @@ -111,6 +117,22 @@ public struct CiXcodeVersion: Codable, Identifiable { self.kind = kind } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + availableRuntimes = try container.decodeIfPresent([AvailableRuntimes].self, forKey: "availableRuntimes") + deviceTypeIdentifier = try container.decodeIfPresent(String.self, forKey: "deviceTypeIdentifier") + deviceTypeName = try container.decodeIfPresent(String.self, forKey: "deviceTypeName") + kind = try container.decodeIfPresent(CiTestDestinationKind.self, forKey: "kind") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(availableRuntimes, forKey: "availableRuntimes") + try container.encodeIfPresent(deviceTypeIdentifier, forKey: "deviceTypeIdentifier") + try container.encodeIfPresent(deviceTypeName, forKey: "deviceTypeName") + try container.encodeIfPresent(kind, forKey: "kind") + } + /** # CiXcodeVersion.Attributes.TestDestinations.AvailableRuntimes The data structure that represents the available runtimes for test destinations of an Xcode Versions resource. @@ -130,6 +152,18 @@ public struct CiXcodeVersion: Codable, Identifiable { self.runtimeIdentifier = runtimeIdentifier self.runtimeName = runtimeName } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + runtimeIdentifier = try container.decodeIfPresent(String.self, forKey: "runtimeIdentifier") + runtimeName = try container.decodeIfPresent(String.self, forKey: "runtimeName") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(runtimeIdentifier, forKey: "runtimeIdentifier") + try container.encodeIfPresent(runtimeName, forKey: "runtimeName") + } } } } @@ -149,6 +183,16 @@ public struct CiXcodeVersion: Codable, Identifiable { self.macOsVersions = macOsVersions } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + macOsVersions = try container.decodeIfPresent(MacOsVersions.self, forKey: "macOsVersions") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(macOsVersions, forKey: "macOsVersions") + } + /** # CiXcodeVersion.Relationships.MacOsVersions The data, links, and paging information that describe the relationship between the Xcode Versions and the macOS Versions resources. @@ -174,23 +218,17 @@ public struct CiXcodeVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent([Data].self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) - meta = try container.decodeIfPresent(PagingInformation.self, forKey: .meta) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Data].self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - try container.encodeIfPresent(meta, forKey: .meta) - } - - private enum CodingKeys: String, CodingKey { - case data - case links - case meta + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") } /** @@ -211,22 +249,17 @@ public struct CiXcodeVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -251,20 +284,15 @@ public struct CiXcodeVersion: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/XcodeCloud/CiXcodeVersionResponse.swift b/Sources/Bagbutik-Models/XcodeCloud/CiXcodeVersionResponse.swift index 0942c90d2..9be4bbef7 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/CiXcodeVersionResponse.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/CiXcodeVersionResponse.swift @@ -24,4 +24,18 @@ public struct CiXcodeVersionResponse: Codable { self.included = included self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(CiXcodeVersion.self, forKey: "data") + included = try container.decodeIfPresent([CiMacOsVersion].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/XcodeCloud/CiXcodeVersionsResponse.swift b/Sources/Bagbutik-Models/XcodeCloud/CiXcodeVersionsResponse.swift index ff57cd956..fa6caae53 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/CiXcodeVersionsResponse.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/CiXcodeVersionsResponse.swift @@ -30,4 +30,20 @@ public struct CiXcodeVersionsResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([CiXcodeVersion].self, forKey: "data") + included = try container.decodeIfPresent([CiMacOsVersion].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/XcodeCloud/FileLocation.swift b/Sources/Bagbutik-Models/XcodeCloud/FileLocation.swift index f43aeb9a4..935b43f1d 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/FileLocation.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/FileLocation.swift @@ -20,4 +20,16 @@ public struct FileLocation: Codable { self.lineNumber = lineNumber self.path = path } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + lineNumber = try container.decodeIfPresent(Int.self, forKey: "lineNumber") + path = try container.decodeIfPresent(String.self, forKey: "path") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(lineNumber, forKey: "lineNumber") + try container.encodeIfPresent(path, forKey: "path") + } } diff --git a/Sources/Bagbutik-Models/XcodeCloud/ScmGitReference.swift b/Sources/Bagbutik-Models/XcodeCloud/ScmGitReference.swift index eb57b425c..2aca6efa0 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/ScmGitReference.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/ScmGitReference.swift @@ -32,31 +32,23 @@ public struct ScmGitReference: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -86,6 +78,22 @@ public struct ScmGitReference: Codable, Identifiable { self.kind = kind self.name = name } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + canonicalName = try container.decodeIfPresent(String.self, forKey: "canonicalName") + isDeleted = try container.decodeIfPresent(Bool.self, forKey: "isDeleted") + kind = try container.decodeIfPresent(CiGitRefKind.self, forKey: "kind") + name = try container.decodeIfPresent(String.self, forKey: "name") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(canonicalName, forKey: "canonicalName") + try container.encodeIfPresent(isDeleted, forKey: "isDeleted") + try container.encodeIfPresent(kind, forKey: "kind") + try container.encodeIfPresent(name, forKey: "name") + } } /** @@ -103,6 +111,16 @@ public struct ScmGitReference: Codable, Identifiable { self.repository = repository } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + repository = try container.decodeIfPresent(Repository.self, forKey: "repository") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(repository, forKey: "repository") + } + /** # ScmGitReference.Relationships.Repository The data and links that describe the relationship between the Git References and the Repositories resources. @@ -124,20 +142,15 @@ public struct ScmGitReference: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -158,22 +171,17 @@ public struct ScmGitReference: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -198,20 +206,15 @@ public struct ScmGitReference: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/XcodeCloud/ScmGitReferenceResponse.swift b/Sources/Bagbutik-Models/XcodeCloud/ScmGitReferenceResponse.swift index 41ba45640..016fc1d52 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/ScmGitReferenceResponse.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/ScmGitReferenceResponse.swift @@ -24,4 +24,18 @@ public struct ScmGitReferenceResponse: Codable { self.included = included self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(ScmGitReference.self, forKey: "data") + included = try container.decodeIfPresent([ScmRepository].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/XcodeCloud/ScmGitReferencesResponse.swift b/Sources/Bagbutik-Models/XcodeCloud/ScmGitReferencesResponse.swift index 82481a5ce..d0fa501fd 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/ScmGitReferencesResponse.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/ScmGitReferencesResponse.swift @@ -30,4 +30,20 @@ public struct ScmGitReferencesResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([ScmGitReference].self, forKey: "data") + included = try container.decodeIfPresent([ScmRepository].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/XcodeCloud/ScmProvider.swift b/Sources/Bagbutik-Models/XcodeCloud/ScmProvider.swift index 3781b0e1b..38688534e 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/ScmProvider.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/ScmProvider.swift @@ -28,28 +28,21 @@ public struct ScmProvider: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") } /** @@ -71,5 +64,17 @@ public struct ScmProvider: Codable, Identifiable { self.scmProviderType = scmProviderType self.url = url } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + scmProviderType = try container.decodeIfPresent(ScmProviderType.self, forKey: "scmProviderType") + url = try container.decodeIfPresent(String.self, forKey: "url") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(scmProviderType, forKey: "scmProviderType") + try container.encodeIfPresent(url, forKey: "url") + } } } diff --git a/Sources/Bagbutik-Models/XcodeCloud/ScmProviderResponse.swift b/Sources/Bagbutik-Models/XcodeCloud/ScmProviderResponse.swift index 06e54c802..fecd8c974 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/ScmProviderResponse.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/ScmProviderResponse.swift @@ -20,4 +20,16 @@ public struct ScmProviderResponse: Codable { self.data = data self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(ScmProvider.self, forKey: "data") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/XcodeCloud/ScmProviderType.swift b/Sources/Bagbutik-Models/XcodeCloud/ScmProviderType.swift index 5c1e4dd4f..a98b2afb1 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/ScmProviderType.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/ScmProviderType.swift @@ -25,6 +25,20 @@ public struct ScmProviderType: Codable { self.kind = kind } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + displayName = try container.decodeIfPresent(String.self, forKey: "displayName") + isOnPremise = try container.decodeIfPresent(Bool.self, forKey: "isOnPremise") + kind = try container.decodeIfPresent(Kind.self, forKey: "kind") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(displayName, forKey: "displayName") + try container.encodeIfPresent(isOnPremise, forKey: "isOnPremise") + try container.encodeIfPresent(kind, forKey: "kind") + } + public enum Kind: String, Codable, CaseIterable { case bitbucketCloud = "BITBUCKET_CLOUD" case bitbucketServer = "BITBUCKET_SERVER" diff --git a/Sources/Bagbutik-Models/XcodeCloud/ScmProvidersResponse.swift b/Sources/Bagbutik-Models/XcodeCloud/ScmProvidersResponse.swift index 021742f6c..cb7846b19 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/ScmProvidersResponse.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/ScmProvidersResponse.swift @@ -26,4 +26,18 @@ public struct ScmProvidersResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([ScmProvider].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/XcodeCloud/ScmPullRequest.swift b/Sources/Bagbutik-Models/XcodeCloud/ScmPullRequest.swift index b4d0ab54c..95e36f5f7 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/ScmPullRequest.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/ScmPullRequest.swift @@ -32,31 +32,23 @@ public struct ScmPullRequest: Codable, Identifiable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -114,6 +106,36 @@ public struct ScmPullRequest: Codable, Identifiable, RequestBody { self.title = title self.webUrl = webUrl } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + destinationBranchName = try container.decodeIfPresent(String.self, forKey: "destinationBranchName") + destinationRepositoryName = try container.decodeIfPresent(String.self, forKey: "destinationRepositoryName") + destinationRepositoryOwner = try container.decodeIfPresent(String.self, forKey: "destinationRepositoryOwner") + isClosed = try container.decodeIfPresent(Bool.self, forKey: "isClosed") + isCrossRepository = try container.decodeIfPresent(Bool.self, forKey: "isCrossRepository") + number = try container.decodeIfPresent(Int.self, forKey: "number") + sourceBranchName = try container.decodeIfPresent(String.self, forKey: "sourceBranchName") + sourceRepositoryName = try container.decodeIfPresent(String.self, forKey: "sourceRepositoryName") + sourceRepositoryOwner = try container.decodeIfPresent(String.self, forKey: "sourceRepositoryOwner") + title = try container.decodeIfPresent(String.self, forKey: "title") + webUrl = try container.decodeIfPresent(String.self, forKey: "webUrl") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(destinationBranchName, forKey: "destinationBranchName") + try container.encodeIfPresent(destinationRepositoryName, forKey: "destinationRepositoryName") + try container.encodeIfPresent(destinationRepositoryOwner, forKey: "destinationRepositoryOwner") + try container.encodeIfPresent(isClosed, forKey: "isClosed") + try container.encodeIfPresent(isCrossRepository, forKey: "isCrossRepository") + try container.encodeIfPresent(number, forKey: "number") + try container.encodeIfPresent(sourceBranchName, forKey: "sourceBranchName") + try container.encodeIfPresent(sourceRepositoryName, forKey: "sourceRepositoryName") + try container.encodeIfPresent(sourceRepositoryOwner, forKey: "sourceRepositoryOwner") + try container.encodeIfPresent(title, forKey: "title") + try container.encodeIfPresent(webUrl, forKey: "webUrl") + } } /** @@ -131,6 +153,16 @@ public struct ScmPullRequest: Codable, Identifiable, RequestBody { self.repository = repository } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + repository = try container.decodeIfPresent(Repository.self, forKey: "repository") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(repository, forKey: "repository") + } + /** # ScmPullRequest.Relationships.Repository The data and links that describe the relationship between the Pull Requests and the Repositories resources. @@ -152,20 +184,15 @@ public struct ScmPullRequest: Codable, Identifiable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -186,22 +213,17 @@ public struct ScmPullRequest: Codable, Identifiable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -226,20 +248,15 @@ public struct ScmPullRequest: Codable, Identifiable, RequestBody { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/XcodeCloud/ScmPullRequestResponse.swift b/Sources/Bagbutik-Models/XcodeCloud/ScmPullRequestResponse.swift index 333b6bb18..125377265 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/ScmPullRequestResponse.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/ScmPullRequestResponse.swift @@ -24,4 +24,18 @@ public struct ScmPullRequestResponse: Codable { self.included = included self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(ScmPullRequest.self, forKey: "data") + included = try container.decodeIfPresent([ScmRepository].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } } diff --git a/Sources/Bagbutik-Models/XcodeCloud/ScmPullRequestsResponse.swift b/Sources/Bagbutik-Models/XcodeCloud/ScmPullRequestsResponse.swift index 2b21b5e86..24aecdb9e 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/ScmPullRequestsResponse.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/ScmPullRequestsResponse.swift @@ -30,4 +30,20 @@ public struct ScmPullRequestsResponse: Codable, PagedResponse { self.links = links self.meta = meta } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([ScmPullRequest].self, forKey: "data") + included = try container.decodeIfPresent([ScmRepository].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } } diff --git a/Sources/Bagbutik-Models/XcodeCloud/ScmRepositoriesResponse.swift b/Sources/Bagbutik-Models/XcodeCloud/ScmRepositoriesResponse.swift index 0aefc1e6e..056f3adfd 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/ScmRepositoriesResponse.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/ScmRepositoriesResponse.swift @@ -31,6 +31,22 @@ public struct ScmRepositoriesResponse: Codable, PagedResponse { self.meta = meta } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([ScmRepository].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + meta = try container.decodeIfPresent(PagingInformation.self, forKey: "meta") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + try container.encodeIfPresent(meta, forKey: "meta") + } + public func getDefaultBranch(for scmRepository: ScmRepository) -> ScmGitReference? { included?.compactMap { relationship -> ScmGitReference? in guard case let .scmGitReference(defaultBranch) = relationship else { return nil } @@ -68,9 +84,5 @@ public struct ScmRepositoriesResponse: Codable, PagedResponse { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/Bagbutik-Models/XcodeCloud/ScmRepository.swift b/Sources/Bagbutik-Models/XcodeCloud/ScmRepository.swift index 6d5ffd192..99835e555 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/ScmRepository.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/ScmRepository.swift @@ -32,31 +32,23 @@ public struct ScmRepository: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - links = try container.decodeIfPresent(ResourceLinks.self, forKey: .links) - attributes = try container.decodeIfPresent(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + links = try container.decodeIfPresent(ResourceLinks.self, forKey: "links") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encodeIfPresent(links, forKey: .links) - try container.encode(type, forKey: .type) - try container.encodeIfPresent(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case attributes - case id - case links - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(links, forKey: "links") + try container.encode(type, forKey: "type") + try container.encodeIfPresent(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -90,6 +82,24 @@ public struct ScmRepository: Codable, Identifiable { self.repositoryName = repositoryName self.sshCloneUrl = sshCloneUrl } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + httpCloneUrl = try container.decodeIfPresent(String.self, forKey: "httpCloneUrl") + lastAccessedDate = try container.decodeIfPresent(Date.self, forKey: "lastAccessedDate") + ownerName = try container.decodeIfPresent(String.self, forKey: "ownerName") + repositoryName = try container.decodeIfPresent(String.self, forKey: "repositoryName") + sshCloneUrl = try container.decodeIfPresent(String.self, forKey: "sshCloneUrl") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(httpCloneUrl, forKey: "httpCloneUrl") + try container.encodeIfPresent(lastAccessedDate, forKey: "lastAccessedDate") + try container.encodeIfPresent(ownerName, forKey: "ownerName") + try container.encodeIfPresent(repositoryName, forKey: "repositoryName") + try container.encodeIfPresent(sshCloneUrl, forKey: "sshCloneUrl") + } } /** @@ -112,6 +122,18 @@ public struct ScmRepository: Codable, Identifiable { self.scmProvider = scmProvider } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + defaultBranch = try container.decodeIfPresent(DefaultBranch.self, forKey: "defaultBranch") + scmProvider = try container.decodeIfPresent(ScmProvider.self, forKey: "scmProvider") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(defaultBranch, forKey: "defaultBranch") + try container.encodeIfPresent(scmProvider, forKey: "scmProvider") + } + /** # ScmRepository.Relationships.DefaultBranch The data and links that describe the relationship between the Repositories resource and the Git References resource that represents the default branch. @@ -133,20 +155,15 @@ public struct ScmRepository: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -167,22 +184,17 @@ public struct ScmRepository: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -207,20 +219,15 @@ public struct ScmRepository: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } @@ -246,20 +253,15 @@ public struct ScmRepository: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) - links = try container.decodeIfPresent(Links.self, forKey: .links) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") + links = try container.decodeIfPresent(Links.self, forKey: "links") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - try container.encodeIfPresent(links, forKey: .links) - } - - private enum CodingKeys: String, CodingKey { - case data - case links + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(links, forKey: "links") } /** @@ -280,22 +282,17 @@ public struct ScmRepository: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } @@ -320,20 +317,15 @@ public struct ScmRepository: Codable, Identifiable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - related = try container.decodeIfPresent(String.self, forKey: .related) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + related = try container.decodeIfPresent(String.self, forKey: "related") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(related, forKey: .related) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case itself = "self" - case related + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(related, forKey: "related") + try container.encodeIfPresent(itself, forKey: "self") } } } diff --git a/Sources/Bagbutik-Models/XcodeCloud/ScmRepositoryResponse.swift b/Sources/Bagbutik-Models/XcodeCloud/ScmRepositoryResponse.swift index df9b1f379..f3123eeee 100644 --- a/Sources/Bagbutik-Models/XcodeCloud/ScmRepositoryResponse.swift +++ b/Sources/Bagbutik-Models/XcodeCloud/ScmRepositoryResponse.swift @@ -25,6 +25,20 @@ public struct ScmRepositoryResponse: Codable { self.links = links } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(ScmRepository.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + links = try container.decode(DocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + try container.encode(links, forKey: "links") + } + public func getDefaultBranch() -> ScmGitReference? { included?.compactMap { relationship -> ScmGitReference? in guard case let .scmGitReference(defaultBranch) = relationship else { return nil } @@ -62,9 +76,5 @@ public struct ScmRepositoryResponse: Codable { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } diff --git a/Sources/BagbutikGenerator/Generator.swift b/Sources/BagbutikGenerator/Generator.swift index d450a811f..7987c2afd 100644 --- a/Sources/BagbutikGenerator/Generator.swift +++ b/Sources/BagbutikGenerator/Generator.swift @@ -92,7 +92,7 @@ public class Generator { try removeChildren(at: coreModelsDirURL) try await withThrowingTaskGroup(of: Void.self) { taskGroup in - let operationRenderer = OperationRenderer(docsLoader: docsLoader) + let operationRenderer = OperationRenderer(docsLoader: docsLoader, shouldFormat: true) spec.paths.values.forEach { path in taskGroup.addTask { try path.operations.forEach { operation in @@ -170,16 +170,16 @@ public class Generator { let renderedSchema: String switch schema { case .enum(let enumSchema): - renderedSchema = try EnumSchemaRenderer(docsLoader: docsLoader) + renderedSchema = try EnumSchemaRenderer(docsLoader: docsLoader, shouldFormat: true) .render(enumSchema: enumSchema) case .object(let objectSchema): - renderedSchema = try ObjectSchemaRenderer(docsLoader: docsLoader) + renderedSchema = try ObjectSchemaRenderer(docsLoader: docsLoader, shouldFormat: true) .render(objectSchema: objectSchema, otherSchemas: otherSchemas) case .binary(let binarySchema): - renderedSchema = try BinarySchemaRenderer(docsLoader: docsLoader) + renderedSchema = try BinarySchemaRenderer(docsLoader: docsLoader, shouldFormat: true) .render(binarySchema: binarySchema) case .plainText(let plainTextSchema): - renderedSchema = try PlainTextSchemaRenderer(docsLoader: docsLoader) + renderedSchema = try PlainTextSchemaRenderer(docsLoader: docsLoader, shouldFormat: true) .render(plainTextSchema: plainTextSchema) } var imports = ["import Foundation"] diff --git a/Sources/BagbutikGenerator/Renderers/BinarySchemaRenderer.swift b/Sources/BagbutikGenerator/Renderers/BinarySchemaRenderer.swift index 62297337a..168690273 100644 --- a/Sources/BagbutikGenerator/Renderers/BinarySchemaRenderer.swift +++ b/Sources/BagbutikGenerator/Renderers/BinarySchemaRenderer.swift @@ -1,5 +1,4 @@ import BagbutikSpecDecoder -import SwiftFormat /// A renderer which renders binary schemas public class BinarySchemaRenderer: Renderer { @@ -16,16 +15,24 @@ public class BinarySchemaRenderer: Renderer { public let data: Data public static func from(data: Data) -> \(binarySchema.name) { - return Self.init(data: data) + return Self(data: data) + } + + public init(data: Data) { + self.data = data } - } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + self.data = try container.decode(Data.self, forKey: "data") + } + } """ if let url = binarySchema.url, case .object(let objectDocumentation) = try docsLoader.resolveDocumentationForSchema(withDocsUrl: url), let abstract = objectDocumentation.abstract { rendered = "/// \(abstract)\n" + rendered } - return try SwiftFormat.format(rendered) + return try format(rendered) } } diff --git a/Sources/BagbutikGenerator/Renderers/EnumSchemaRenderer.swift b/Sources/BagbutikGenerator/Renderers/EnumSchemaRenderer.swift index a013016a8..176f2aac7 100644 --- a/Sources/BagbutikGenerator/Renderers/EnumSchemaRenderer.swift +++ b/Sources/BagbutikGenerator/Renderers/EnumSchemaRenderer.swift @@ -1,6 +1,5 @@ import BagbutikDocsCollector import BagbutikSpecDecoder -import SwiftFormat /// A renderer which renders enum schemas public class EnumSchemaRenderer: Renderer { @@ -48,6 +47,6 @@ public class EnumSchemaRenderer: Renderer { rendered += "case \($0.id) = \"\($0.value)\"\n" } rendered += "}" - return try SwiftFormat.format(rendered) + return try format(rendered) } } diff --git a/Sources/BagbutikGenerator/Renderers/ObjectSchemaRenderer.swift b/Sources/BagbutikGenerator/Renderers/ObjectSchemaRenderer.swift index 86f3d129e..348b2f235 100644 --- a/Sources/BagbutikGenerator/Renderers/ObjectSchemaRenderer.swift +++ b/Sources/BagbutikGenerator/Renderers/ObjectSchemaRenderer.swift @@ -1,7 +1,6 @@ import BagbutikDocsCollector import BagbutikSpecDecoder import Foundation -import SwiftFormat /// A renderer which renders object schemas public class ObjectSchemaRenderer: Renderer { @@ -41,7 +40,7 @@ public class ObjectSchemaRenderer: Renderer { if objectSchema.properties["links"]?.type == .schemaRef("PagedDocumentLinks") { protocols.append("PagedResponse") } - rendered += renderStruct(named: objectSchema.name, protocols: protocols) { + rendered += try renderStruct(named: objectSchema.name, protocols: protocols) { let propertiesInfo = PropertiesInfo(for: objectSchema, documentation: documentation, docsLoader: docsLoader) var structContent = [String]() if case .arrayOfSchemaRef(let schemaRef) = objectSchema.properties["data"]?.type { @@ -63,53 +62,50 @@ public class ObjectSchemaRenderer: Renderer { structContent.append(renderInitializer(parameters: deprecatedPublicInitParameters, deprecated: true, content: { createInitContent(propertiesInfo.deprecatedPublicInitPropertyNames) })) } structContent.append(renderInitializer(parameters: propertiesInfo.publicInitParameters, content: { createInitContent(propertiesInfo.publicInitPropertyNames) })) - if propertiesInfo.needsCustomCoding { - structContent.append(renderInitializer(parameters: [.init(prefix: "from", name: "decoder", type: "Decoder")], throwing: true, content: { - var functionContent = "let container = try decoder.container(keyedBy: CodingKeys.self)\n" - functionContent += propertiesInfo.decodableProperties.map { decodableProperty in - if decodableProperty.optional { - return "\(decodableProperty.name.safeName) = try container.decodeIfPresent(\(decodableProperty.type).self, forKey: .\(decodableProperty.name.safeName))" - } else { - return "\(decodableProperty.name.safeName) = try container.decode(\(decodableProperty.type).self, forKey: .\(decodableProperty.name.safeName))" - } - }.joined(separator: "\n") - if propertiesInfo.hasTypeConstant { - functionContent += #""" + structContent.append(renderInitializer(parameters: [.init(prefix: "from", name: "decoder", type: "Decoder")], throwing: true, content: { + var functionContent = "let container = try decoder.container(keyedBy: AnyCodingKey.self)\n" + functionContent += propertiesInfo.decodableProperties.map { decodableProperty in + if decodableProperty.optional { + return "\(decodableProperty.name.safeName) = try container.decodeIfPresent(\(decodableProperty.type).self, forKey: \"\(decodableProperty.name.idealName)\")" + } else { + return "\(decodableProperty.name.safeName) = try container.decode(\(decodableProperty.type).self, forKey: \"\(decodableProperty.name.idealName)\")" + } + }.joined(separator: "\n") + if propertiesInfo.hasTypeConstant { + functionContent += #""" - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") - } - """# + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } - return functionContent - })) - structContent.append(renderFunction(named: "encode", parameters: [.init(prefix: "to", name: "encoder", type: "Encoder")], throwing: true, content: { - var functionContent = "var container = encoder.container(keyedBy: CodingKeys.self)\n" - functionContent += propertiesInfo.encodableProperties.map { encodableProperty in - if encodableProperty.optional, !encodableProperty.nullCodable { - return "try container.encodeIfPresent(\(encodableProperty.name.safeName), forKey: .\(encodableProperty.name.safeName))" - } else { - return "try container.encode(\(encodableProperty.name.safeName), forKey: .\(encodableProperty.name.safeName))" - } - }.joined(separator: "\n") - return functionContent - })) - structContent.append(renderEnum(named: "CodingKeys", access: "private", rawType: "String", protocols: ["CodingKey"], cases: propertiesInfo.codingKeys)) - } + """# + } + return functionContent + })) + structContent.append(renderFunction(named: "encode", parameters: [.init(prefix: "to", name: "encoder", type: "Encoder")], throwing: true, content: { + var functionContent = "var container = encoder.container(keyedBy: AnyCodingKey.self)\n" + functionContent += propertiesInfo.encodableProperties.map { encodableProperty in + if encodableProperty.optional, !encodableProperty.nullCodable { + return "try container.encodeIfPresent(\(encodableProperty.name.safeName), forKey: \"\(encodableProperty.name.idealName)\")" + } else { + return "try container.encode(\(encodableProperty.name.safeName), forKey: \"\(encodableProperty.name.idealName)\")" + } + }.joined(separator: "\n") + return functionContent + })) structContent.append(contentsOf: createIncludedGetters(for: objectSchema, otherSchemas: otherSchemas)) - structContent.append(contentsOf: objectSchema.subSchemas.map { subSchema -> String in + structContent.append(contentsOf: try objectSchema.subSchemas.map { subSchema -> String in switch subSchema { case .objectSchema(let objectSchema): - return try! render(objectSchema: objectSchema, otherSchemas: otherSchemas) + return try render(objectSchema: objectSchema, otherSchemas: otherSchemas) case .enumSchema(let enumSchema): - return try! EnumSchemaRenderer(docsLoader: docsLoader).render(enumSchema: enumSchema) + return try EnumSchemaRenderer(docsLoader: docsLoader).render(enumSchema: enumSchema) case .oneOf(let name, let oneOfSchema): - return try! OneOfSchemaRenderer().render(name: name, oneOfSchema: oneOfSchema) + return try! OneOfSchemaRenderer(docsLoader: docsLoader).render(name: name, oneOfSchema: oneOfSchema) } }) return structContent.joined(separator: "\n\n") } - return try SwiftFormat.format(rendered) + return try format(rendered) } private struct PropertiesInfo { @@ -118,11 +114,9 @@ public class ObjectSchemaRenderer: Renderer { let deprecatedPublicInitPropertyNames: [PropertyName] let publicInitParameters: [FunctionParameter] let publicInitPropertyNames: [PropertyName] - let codingKeys: [EnumCase] let encodableProperties: [CodableProperty] let decodableProperties: [CodableProperty] let hasTypeConstant: Bool - let needsCustomCoding: Bool init(for objectSchema: ObjectSchema, documentation: ObjectDocumentation?, docsLoader: DocsLoader) { var objectSchema = objectSchema @@ -136,7 +130,6 @@ public class ObjectSchemaRenderer: Renderer { return $0.key < $1.key } let initParameters = sortedProperties.filter { !$0.value.type.isConstant } - var hasNullCodableWrappedProperty = false properties = sortedProperties.map { property -> RenderProperty in let rendered: String switch property.value.type { @@ -155,7 +148,6 @@ public class ObjectSchemaRenderer: Renderer { var wrapper = "" if id == "data", type == "Data" || type == "[Data]" || type == "[Item]", isOptional { wrapper += "@NullCodable " - hasNullCodableWrappedProperty = true } rendered = wrapper + PropertyRenderer(docsLoader: docsLoader) .renderProperty(id: id, @@ -172,10 +164,8 @@ public class ObjectSchemaRenderer: Renderer { deprecatedPublicInitPropertyNames = initParameters.map { PropertyName(idealName: $0.key) } publicInitParameters = Self.createFunctionParameters(from: initParameters.filter { !$0.value.deprecated }, requiredProperties: objectSchema.requiredProperties) publicInitPropertyNames = initParameters.filter { !$0.value.deprecated }.map { PropertyName(idealName: $0.key) } - codingKeys = sortedProperties.map { - let propertyName = PropertyName(idealName: $0.key) - return EnumCase(id: propertyName.safeName, value: propertyName.idealName) - } + let hasTypeConstant = sortedProperties.contains { $0.key == "type" && $0.value.type.isConstant } + self.hasTypeConstant = hasTypeConstant encodableProperties = sortedProperties.map { let propertyName = PropertyName(idealName: $0.key) let type = $0.value.type.description @@ -185,9 +175,7 @@ public class ObjectSchemaRenderer: Renderer { optional: !objectSchema.requiredProperties.contains($0.key) && $0.key != "type", nullCodable: propertyName.safeName == "data" && type == "Data" || type == "[Data]" || type == "[Item]") } - decodableProperties = encodableProperties.filter { $0.name.idealName != "type" } - hasTypeConstant = sortedProperties.contains(where: { $0.key == "type" && $0.value.type.isConstant }) - needsCustomCoding = hasTypeConstant || hasNullCodableWrappedProperty || sortedProperties.contains(where: { PropertyName(idealName: $0.key).hasDifferentSafeName }) + decodableProperties = encodableProperties.filter { !hasTypeConstant || $0.name.idealName != "type" } } private static func createFunctionParameters(from parameters: [Dictionary.Element], requiredProperties: [String]) -> [FunctionParameter] { diff --git a/Sources/BagbutikGenerator/Renderers/OneOfSchemaRenderer.swift b/Sources/BagbutikGenerator/Renderers/OneOfSchemaRenderer.swift index 34ea344c9..978660560 100644 --- a/Sources/BagbutikGenerator/Renderers/OneOfSchemaRenderer.swift +++ b/Sources/BagbutikGenerator/Renderers/OneOfSchemaRenderer.swift @@ -1,9 +1,8 @@ import BagbutikSpecDecoder import Foundation -import SwiftFormat /// A renderer which renders one of schemas -public class OneOfSchemaRenderer { +public class OneOfSchemaRenderer: Renderer { /** Render an one of schema @@ -13,14 +12,11 @@ public class OneOfSchemaRenderer { - Returns: The rendered one of schema */ public func render(name: String, oneOfSchema: OneOfSchema) throws -> String { - var rendered = "public enum \(name): Codable {\n" let options = oneOfSchema.options .map { EnumCase(id: $0.schemaName.lowercasedFirstLetter(), value: $0.schemaName) } .sorted { $0.id < $1.id } - options.forEach { - rendered += "case \($0.id)(\($0.value))\n" - } - rendered += "\npublic init(from decoder: Decoder) throws {\n" + + var rendered = "public init(from decoder: Decoder) throws {\n" options.enumerated().forEach { let option = $0.element var renderedOption = """ @@ -55,14 +51,16 @@ public class OneOfSchemaRenderer { """ } rendered += """ - } - } - - private enum CodingKeys: String, CodingKey { - case type } } """ - return try SwiftFormat.format(rendered) + + rendered = renderEnum(named: name, + protocols: ["Codable"], + cases: options, + caseValueIsAssociated: true, + content: rendered) + + return try format(rendered) } } diff --git a/Sources/BagbutikGenerator/Renderers/OperationRenderer.swift b/Sources/BagbutikGenerator/Renderers/OperationRenderer.swift index 32e4e796e..0c7ecb4a3 100644 --- a/Sources/BagbutikGenerator/Renderers/OperationRenderer.swift +++ b/Sources/BagbutikGenerator/Renderers/OperationRenderer.swift @@ -1,7 +1,6 @@ import BagbutikDocsCollector import BagbutikSpecDecoder import Foundation -import SwiftFormat /// Errors that can occur when rendering an operation public enum OperationRendererError: Error { @@ -119,7 +118,7 @@ public class OperationRenderer: Renderer { } if parametersInfo.requiresWrapperStruct { rendered += "\n\n" - rendered += renderStruct(named: operationName) { + rendered += try renderStruct(named: operationName) { var structContent = [String]() if !parametersInfo.fields.isEmpty { structContent.append(""" @@ -183,11 +182,11 @@ public class OperationRenderer: Renderer { cases: parametersInfo.sorts)) """) } - parametersInfo.customs.sorted(by: { $0.key < $1.key }).forEach { _, value in + try parametersInfo.customs.sorted(by: { $0.key < $1.key }).forEach { _, value in guard case .enum(let type, let values) = value.type else { return } let enumName = value.name.split(separator: ".").map { $0.capitalizingFirstLetter() }.joined() let enumSchema = EnumSchema(name: enumName, type: type, caseValues: values, additionalProtocols: ["ParameterValue"]) - let rendered = try! EnumSchemaRenderer(docsLoader: docsLoader) + let rendered = try EnumSchemaRenderer(docsLoader: docsLoader) .render(enumSchema: enumSchema) structContent.append(""" \(renderDocumentationBlock { value.documentation.capitalizingFirstLetter() }) @@ -207,7 +206,7 @@ public class OperationRenderer: Renderer { return structContent.joined(separator: "\n\n") } } - return try SwiftFormat.format(rendered) + return try format(rendered) } private static let pathParameterRegex = try! NSRegularExpression(pattern: #"\{(.*)\}"#, options: []) @@ -241,7 +240,7 @@ public class OperationRenderer: Renderer { if values.count > 0 { let enumName = name.split(separator: ".").map { $0.capitalizingFirstLetter() }.joined() let enumSchema = EnumSchema(name: enumName, type: type, caseValues: values, additionalProtocols: ["ParameterValue"]) - let rendered = try! EnumSchemaRenderer(docsLoader: docsLoader) + let rendered = try EnumSchemaRenderer(docsLoader: docsLoader) .render(enumSchema: enumSchema) fieldSubSchemas[name] = rendered fields.append(EnumCase(id: name, value: "[\(enumName)]", deprecated: deprecated, documentation: documentation)) @@ -254,7 +253,7 @@ public class OperationRenderer: Renderer { case .enum(let type, let values): let enumName = name.split(separator: ".").map { $0.capitalizingFirstLetter() }.joined() let enumSchema = EnumSchema(name: enumName, type: type, caseValues: values, additionalProtocols: ["ParameterValue"]) - let rendered = try! EnumSchemaRenderer(docsLoader: docsLoader) + let rendered = try EnumSchemaRenderer(docsLoader: docsLoader) .render(enumSchema: enumSchema) filterSubSchemas[name] = rendered filters.append(EnumCase(id: name, value: "[\(enumName)]", documentation: documentation)) diff --git a/Sources/BagbutikGenerator/Renderers/PlainTextSchemaRenderer.swift b/Sources/BagbutikGenerator/Renderers/PlainTextSchemaRenderer.swift index dd754bc45..b0add5e42 100644 --- a/Sources/BagbutikGenerator/Renderers/PlainTextSchemaRenderer.swift +++ b/Sources/BagbutikGenerator/Renderers/PlainTextSchemaRenderer.swift @@ -1,6 +1,5 @@ import BagbutikDocsCollector import BagbutikSpecDecoder -import SwiftFormat /// A renderer which renders plain text schemas public class PlainTextSchemaRenderer: Renderer { @@ -19,14 +18,22 @@ public class PlainTextSchemaRenderer: Renderer { public static func from(text: String) -> \(plainTextSchema.name) { return Self.init(text: text) } + + public init(text: String) { + self.text = text + } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + self.text = try container.decode(String.self, forKey: "text") + } } - """ if let url = plainTextSchema.url, case .object(let objectDocumentation) = try docsLoader.resolveDocumentationForSchema(withDocsUrl: url), let abstract = objectDocumentation.abstract { rendered = "/// \(abstract)\n" + rendered } - return try SwiftFormat.format(rendered) + return try format(rendered) } } diff --git a/Sources/BagbutikGenerator/Renderers/Renderer.swift b/Sources/BagbutikGenerator/Renderers/Renderer.swift index e2c4e604b..9c422bc8a 100644 --- a/Sources/BagbutikGenerator/Renderers/Renderer.swift +++ b/Sources/BagbutikGenerator/Renderers/Renderer.swift @@ -1,12 +1,16 @@ import BagbutikDocsCollector import BagbutikSpecDecoder +import Foundation +import SwiftFormat /// A base class for the renderes which contains a default environment for Swift code rendering public class Renderer { let docsLoader: DocsLoader + let shouldFormat: Bool - public init(docsLoader: DocsLoader) { + public init(docsLoader: DocsLoader, shouldFormat: Bool = false) { self.docsLoader = docsLoader + self.shouldFormat = shouldFormat } internal func escapeReservedKeywords(in searchString: String) -> String { @@ -134,6 +138,11 @@ public class Renderer { """ } + internal func format(_ source: String) throws -> String { + guard shouldFormat else { return source } + return try SwiftFormat.format(source) + } + struct FunctionParameter { let prefix: String? let name: String diff --git a/Tests/BagbutikGeneratorTests/Renderers/BinarySchemaRendererTests.swift b/Tests/BagbutikGeneratorTests/Renderers/BinarySchemaRendererTests.swift index 2b0f7366f..f815a6cd1 100644 --- a/Tests/BagbutikGeneratorTests/Renderers/BinarySchemaRendererTests.swift +++ b/Tests/BagbutikGeneratorTests/Renderers/BinarySchemaRendererTests.swift @@ -10,7 +10,7 @@ final class BinarySchemaRendererTests: XCTestCase { "some://url": .object( .init(id: "/gzip", title: "Gzip", abstract: "Some summary", discussion: nil, properties: [:], subDocumentationIds: [])) ]) - let renderer = BinarySchemaRenderer(docsLoader: docsLoader) + let renderer = BinarySchemaRenderer(docsLoader: docsLoader, shouldFormat: true) let schema = BinarySchema(name: "Gzip", url: "some://url") // When let rendered = try renderer.render(binarySchema: schema) @@ -23,6 +23,15 @@ final class BinarySchemaRendererTests: XCTestCase { public static func from(data: Data) -> Gzip { return Self(data: data) } + + public init(data: Data) { + self.data = data + } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } } """#) @@ -31,7 +40,7 @@ final class BinarySchemaRendererTests: XCTestCase { func testRender_NoDocumentation() throws { // Given let docsLoader = DocsLoader(schemaDocumentationById: [:]) - let renderer = BinarySchemaRenderer(docsLoader: docsLoader) + let renderer = BinarySchemaRenderer(docsLoader: docsLoader, shouldFormat: true) let schema = BinarySchema(name: "Gzip", url: "some://url") // When let rendered = try renderer.render(binarySchema: schema) @@ -43,6 +52,15 @@ final class BinarySchemaRendererTests: XCTestCase { public static func from(data: Data) -> Gzip { return Self(data: data) } + + public init(data: Data) { + self.data = data + } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode(Data.self, forKey: "data") + } } """#) diff --git a/Tests/BagbutikGeneratorTests/Renderers/EnumSchemaRendererTests.swift b/Tests/BagbutikGeneratorTests/Renderers/EnumSchemaRendererTests.swift index 47bd31c4c..8b067b56c 100644 --- a/Tests/BagbutikGeneratorTests/Renderers/EnumSchemaRendererTests.swift +++ b/Tests/BagbutikGeneratorTests/Renderers/EnumSchemaRendererTests.swift @@ -11,7 +11,7 @@ final class EnumSchemaRendererTests: XCTestCase { "IOS": "A string that represents iOS.", "TV_OS": "A string that represents tvOS." ]))]) - let renderer = EnumSchemaRenderer(docsLoader: docsLoader) + let renderer = EnumSchemaRenderer(docsLoader: docsLoader, shouldFormat: true) let schema = EnumSchema(name: "Platform", type: "string", url: "/platform", caseValues: ["MAC_OS", "IOS", "TV_OS"]) // When let rendered = try renderer.render(enumSchema: schema) @@ -40,7 +40,7 @@ final class EnumSchemaRendererTests: XCTestCase { func testRenderWithAdditionalProtocol() throws { // Given - let renderer = EnumSchemaRenderer(docsLoader: DocsLoader()) + let renderer = EnumSchemaRenderer(docsLoader: DocsLoader(), shouldFormat: true) let schema = EnumSchema(name: "AppCategories", type: "string", caseValues: ["parent", "platforms", "subcategories"], additionalProtocols: ["ParameterValue"]) // When let rendered = try renderer.render(enumSchema: schema) diff --git a/Tests/BagbutikGeneratorTests/Renderers/ObjectSchemaRendererTests.swift b/Tests/BagbutikGeneratorTests/Renderers/ObjectSchemaRendererTests.swift index 4fb926a94..0caf4591f 100644 --- a/Tests/BagbutikGeneratorTests/Renderers/ObjectSchemaRendererTests.swift +++ b/Tests/BagbutikGeneratorTests/Renderers/ObjectSchemaRendererTests.swift @@ -9,7 +9,7 @@ final class ObjectSchemaRendererTests: XCTestCase { let docsLoader = DocsLoader(schemaDocumentationById: ["/person": .object( .init(id: "/person", title: "Person", abstract: nil, discussion: nil, properties: [:], subDocumentationIds: []))] ) - let renderer = ObjectSchemaRenderer(docsLoader: docsLoader) + let renderer = ObjectSchemaRenderer(docsLoader: docsLoader, shouldFormat: true) let schema = ObjectSchema(name: "Person", url: "some://url", properties: ["name": .init(type: .simple(.init(type: "string")))]) @@ -23,6 +23,16 @@ final class ObjectSchemaRendererTests: XCTestCase { public init(name: String? = nil) { self.name = name } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + name = try container.decodeIfPresent(String.self, forKey: "name") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(name, forKey: "name") + } } """#) @@ -33,7 +43,7 @@ final class ObjectSchemaRendererTests: XCTestCase { let docsLoader = DocsLoader(schemaDocumentationById: ["some://url": .object( .init(id: "/person", title: "Person", abstract: "A person with a name.", discussion: "What is a person?", properties: ["name": .init(required: false, description: "The person's name")], subDocumentationIds: []))] ) - let renderer = ObjectSchemaRenderer(docsLoader: docsLoader) + let renderer = ObjectSchemaRenderer(docsLoader: docsLoader, shouldFormat: true) let schema = ObjectSchema(name: "Person", url: "some://url", properties: ["name": .init(type: .simple(.init(type: "string")))]) @@ -57,6 +67,16 @@ final class ObjectSchemaRendererTests: XCTestCase { public init(name: String? = nil) { self.name = name } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + name = try container.decodeIfPresent(String.self, forKey: "name") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(name, forKey: "name") + } } """#) @@ -70,7 +90,7 @@ final class ObjectSchemaRendererTests: XCTestCase { "name": .init(required: false, description: "The person's name") ], subDocumentationIds: []))] ) - let renderer = ObjectSchemaRenderer(docsLoader: docsLoader) + let renderer = ObjectSchemaRenderer(docsLoader: docsLoader, shouldFormat: true) let schema = ObjectSchema(name: "Person", url: "some://url", properties: ["name": .init(type: .simple(.string), deprecated: true), @@ -104,6 +124,18 @@ final class ObjectSchemaRendererTests: XCTestCase { public init(age: Int? = nil) { self.age = age } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + age = try container.decodeIfPresent(Int.self, forKey: "age") + name = try container.decodeIfPresent(String.self, forKey: "name") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(age, forKey: "age") + try container.encodeIfPresent(name, forKey: "name") + } } """#) @@ -116,7 +148,7 @@ final class ObjectSchemaRendererTests: XCTestCase { "name": .init(required: false, description: "The person's name") ], subDocumentationIds: []))] ) - let renderer = ObjectSchemaRenderer(docsLoader: docsLoader) + let renderer = ObjectSchemaRenderer(docsLoader: docsLoader, shouldFormat: true) let schema = ObjectSchema(name: "PersonCreateRequest", url: "some://url", properties: ["name": .init(type: .simple(.init(type: "string")))]) @@ -138,6 +170,16 @@ final class ObjectSchemaRendererTests: XCTestCase { public init(name: String? = nil) { self.name = name } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + name = try container.decodeIfPresent(String.self, forKey: "name") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(name, forKey: "name") + } } """#) @@ -150,7 +192,7 @@ final class ObjectSchemaRendererTests: XCTestCase { "data": .init(required: true, description: "") ], subDocumentationIds: []))] ) - let renderer = ObjectSchemaRenderer(docsLoader: docsLoader) + let renderer = ObjectSchemaRenderer(docsLoader: docsLoader, shouldFormat: true) let schema = ObjectSchema(name: "PersonCarLinkageRequest", url: "some://url", properties: ["data": .init(type: .schema(.init( @@ -179,17 +221,13 @@ final class ObjectSchemaRendererTests: XCTestCase { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } /** @@ -208,22 +246,17 @@ final class ObjectSchemaRendererTests: XCTestCase { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -241,7 +274,7 @@ final class ObjectSchemaRendererTests: XCTestCase { "self": .init(required: false, description: "A reference to the person") ], subDocumentationIds: []))] ) - let renderer = ObjectSchemaRenderer(docsLoader: docsLoader) + let renderer = ObjectSchemaRenderer(docsLoader: docsLoader, shouldFormat: true) let schema = ObjectSchema(name: "Person", url: "some://url", properties: ["firstName": .init(type: .simple(.init(type: "string"))), @@ -279,26 +312,19 @@ final class ObjectSchemaRendererTests: XCTestCase { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - firstName = try container.decode(String.self, forKey: .firstName) - id = try container.decodeIfPresent(String.self, forKey: .id) - lastName = try container.decodeIfPresent(String.self, forKey: .lastName) - itself = try container.decodeIfPresent(String.self, forKey: .itself) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + firstName = try container.decode(String.self, forKey: "firstName") + id = try container.decodeIfPresent(String.self, forKey: "id") + lastName = try container.decodeIfPresent(String.self, forKey: "lastName") + itself = try container.decodeIfPresent(String.self, forKey: "self") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(firstName, forKey: .firstName) - try container.encodeIfPresent(id, forKey: .id) - try container.encodeIfPresent(lastName, forKey: .lastName) - try container.encodeIfPresent(itself, forKey: .itself) - } - - private enum CodingKeys: String, CodingKey { - case firstName - case id - case itself = "self" - case lastName + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(firstName, forKey: "firstName") + try container.encodeIfPresent(id, forKey: "id") + try container.encodeIfPresent(lastName, forKey: "lastName") + try container.encodeIfPresent(itself, forKey: "self") } } @@ -312,7 +338,7 @@ final class ObjectSchemaRendererTests: XCTestCase { "attributes": .init(required: true, description: "The resource's attributes."), ], subDocumentationIds: []))] ) - let renderer = ObjectSchemaRenderer(docsLoader: docsLoader) + let renderer = ObjectSchemaRenderer(docsLoader: docsLoader, shouldFormat: true) let attributesSchema = ObjectSchema(name: "Attributes", url: "some://url/attributes", properties: ["age": .init(type: .simple(.init(type: "integer")))]) @@ -345,12 +371,34 @@ final class ObjectSchemaRendererTests: XCTestCase { self.attributes = attributes } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + name = try container.decodeIfPresent(String.self, forKey: "name") + attributes = try container.decodeIfPresent(Attributes.self, forKey: "attributes") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(name, forKey: "name") + try container.encodeIfPresent(attributes, forKey: "attributes") + } + public struct Attributes: Codable { public var age: Int? public init(age: Int? = nil) { self.age = age } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + age = try container.decodeIfPresent(Int.self, forKey: "age") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(age, forKey: "age") + } } } @@ -367,7 +415,7 @@ final class ObjectSchemaRendererTests: XCTestCase { "some://url/relationships": .object( .init(id: "/person/relationships", title: "Relationships", abstract: "The relationships you included in the request and those on which you can operate.", discussion: nil, properties: [:], subDocumentationIds: [])) ]) - let renderer = ObjectSchemaRenderer(docsLoader: docsLoader) + let renderer = ObjectSchemaRenderer(docsLoader: docsLoader, shouldFormat: true) let relationshipsSchema = ObjectSchema(name: "Relationships", url: "some://url/relationships", properties: ["children": .init(type: .arrayOfSchemaRef("Child"))]) @@ -400,6 +448,18 @@ final class ObjectSchemaRendererTests: XCTestCase { self.relationships = relationships } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + name = try container.decodeIfPresent(String.self, forKey: "name") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(name, forKey: "name") + try container.encodeIfPresent(relationships, forKey: "relationships") + } + /** # Relationships The relationships you included in the request and those on which you can operate. @@ -413,6 +473,16 @@ final class ObjectSchemaRendererTests: XCTestCase { public init(children: [Child]? = nil) { self.children = children } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + children = try container.decodeIfPresent([Child].self, forKey: "children") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(children, forKey: "children") + } } } @@ -430,7 +500,7 @@ final class ObjectSchemaRendererTests: XCTestCase { "connection": .init(required: false, description: "The person's connection") ], subDocumentationIds: [])) ]) - let renderer = ObjectSchemaRenderer(docsLoader: docsLoader) + let renderer = ObjectSchemaRenderer(docsLoader: docsLoader, shouldFormat: true) let schema = ObjectSchema(name: "Person", url: "some://url", properties: ["name": .init(type: .simple(.init(type: "string"))), @@ -469,6 +539,22 @@ final class ObjectSchemaRendererTests: XCTestCase { self.preference = preference } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + connection = try container.decodeIfPresent(Connection.self, forKey: "connection") + name = try container.decodeIfPresent(String.self, forKey: "name") + pet = try container.decodeIfPresent(Pet.self, forKey: "pet") + preference = try container.decodeIfPresent(Preference.self, forKey: "preference") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(connection, forKey: "connection") + try container.encodeIfPresent(name, forKey: "name") + try container.encodeIfPresent(pet, forKey: "pet") + try container.encodeIfPresent(preference, forKey: "preference") + } + public enum Connection: Codable { case computer(Computer) case phone(Phone) @@ -492,10 +578,6 @@ final class ObjectSchemaRendererTests: XCTestCase { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } public struct Pet: Codable { @@ -504,6 +586,16 @@ final class ObjectSchemaRendererTests: XCTestCase { public init(name: String? = nil) { self.name = name } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + name = try container.decodeIfPresent(String.self, forKey: "name") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(name, forKey: "name") + } } public enum Preference: String, Codable, CaseIterable { @@ -518,7 +610,7 @@ final class ObjectSchemaRendererTests: XCTestCase { func testPagedResponse() throws { // Given let docsLoader = DocsLoader(schemaDocumentationById: [:]) - let renderer = ObjectSchemaRenderer(docsLoader: docsLoader) + let renderer = ObjectSchemaRenderer(docsLoader: docsLoader, shouldFormat: true) let schema = ObjectSchema(name: "PersonsResponse", url: "some://url", properties: ["data": .init(type: .arrayOfSchemaRef("Person")), @@ -540,6 +632,18 @@ final class ObjectSchemaRendererTests: XCTestCase { self.data = data self.links = links } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decode([Person].self, forKey: "data") + links = try container.decode(PagedDocumentLinks.self, forKey: "links") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") + try container.encode(links, forKey: "links") + } } """#) @@ -548,7 +652,7 @@ final class ObjectSchemaRendererTests: XCTestCase { func testGetterForIncludedNonPagedResponse() throws { // Given let docsLoader = DocsLoader(schemaDocumentationById: [:]) - let renderer = ObjectSchemaRenderer(docsLoader: docsLoader) + let renderer = ObjectSchemaRenderer(docsLoader: docsLoader, shouldFormat: true) let schema = ObjectSchema( name: "BuildResponse", url: "some://url", @@ -631,6 +735,18 @@ final class ObjectSchemaRendererTests: XCTestCase { self.included = included } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Build.self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + } + public func getIndividualTesters() -> [BetaTester] { guard let individualTesterIds = data.relationships?.individualTesters?.data?.map(\.id), let individualTesters = included?.compactMap({ relationship -> BetaTester? in @@ -678,10 +794,6 @@ final class ObjectSchemaRendererTests: XCTestCase { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } @@ -691,7 +803,7 @@ final class ObjectSchemaRendererTests: XCTestCase { func testGetterForIncludedPagedResponse() throws { // Given let docsLoader = DocsLoader(schemaDocumentationById: [:]) - let renderer = ObjectSchemaRenderer(docsLoader: docsLoader) + let renderer = ObjectSchemaRenderer(docsLoader: docsLoader, shouldFormat: true) let schema = ObjectSchema( name: "BuildsResponse", url: "some://url", @@ -797,6 +909,18 @@ final class ObjectSchemaRendererTests: XCTestCase { self.included = included } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent([Build].self, forKey: "data") + included = try container.decodeIfPresent([Included].self, forKey: "included") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(data, forKey: "data") + try container.encodeIfPresent(included, forKey: "included") + } + public func getIndividualTesters(for build: Build) -> [BetaTester] { guard let individualTesterIds = build.relationships?.individualTesters?.data?.map(\.id), let individualTesters = included?.compactMap({ relationship -> BetaTester? in @@ -844,10 +968,6 @@ final class ObjectSchemaRendererTests: XCTestCase { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } } @@ -864,7 +984,7 @@ final class ObjectSchemaRendererTests: XCTestCase { "some://url/relationships": .object( .init(id: "/person/relationships", title: "Relationships", abstract: "The relationships you included in the request and those on which you can operate.", discussion: nil, properties: [:], subDocumentationIds: [])) ]) - let renderer = ObjectSchemaRenderer(docsLoader: docsLoader) + let renderer = ObjectSchemaRenderer(docsLoader: docsLoader, shouldFormat: true) let attributesSchema = ObjectSchema(name: "Attributes", url: "some://url/attributes", properties: ["age": .init(type: .simple(.init(type: "integer")))]) @@ -909,31 +1029,23 @@ final class ObjectSchemaRendererTests: XCTestCase { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - age = try container.decodeIfPresent(Int.self, forKey: .age) - name = try container.decode(String.self, forKey: .name) - attributes = try container.decode(Attributes.self, forKey: .attributes) - relationships = try container.decodeIfPresent(Relationships.self, forKey: .relationships) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + age = try container.decodeIfPresent(Int.self, forKey: "age") + name = try container.decode(String.self, forKey: "name") + attributes = try container.decode(Attributes.self, forKey: "attributes") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(age, forKey: .age) - try container.encode(name, forKey: .name) - try container.encode(type, forKey: .type) - try container.encode(attributes, forKey: .attributes) - try container.encodeIfPresent(relationships, forKey: .relationships) - } - - private enum CodingKeys: String, CodingKey { - case age - case attributes - case name - case relationships - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(age, forKey: "age") + try container.encode(name, forKey: "name") + try container.encode(type, forKey: "type") + try container.encode(attributes, forKey: "attributes") + try container.encodeIfPresent(relationships, forKey: "relationships") } /** @@ -950,6 +1062,16 @@ final class ObjectSchemaRendererTests: XCTestCase { public init(age: Int? = nil) { self.age = age } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + age = try container.decodeIfPresent(Int.self, forKey: "age") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(age, forKey: "age") + } } /** @@ -965,6 +1087,16 @@ final class ObjectSchemaRendererTests: XCTestCase { public init(children: [Child]? = nil) { self.children = children } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + children = try container.decodeIfPresent([Child].self, forKey: "children") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(children, forKey: "children") + } } } @@ -979,7 +1111,7 @@ final class ObjectSchemaRendererTests: XCTestCase { "some://url/relationships": .object( .init(id: "/person/relationships", title: "Relationships", abstract: "The relationships you included in the request and those on which you can operate.", discussion: nil, properties: [:], subDocumentationIds: [])) ]) - let renderer = ObjectSchemaRenderer(docsLoader: docsLoader) + let renderer = ObjectSchemaRenderer(docsLoader: docsLoader, shouldFormat: true) let relationshipsSchema = ObjectSchema(name: "Relationships", url: "some://url/relationships", properties: ["bundleId": .init(type: .schema(.init(name: "BundleId", url: "some://url/relationship/bundleid", properties: [ @@ -1013,6 +1145,18 @@ final class ObjectSchemaRendererTests: XCTestCase { self.relationships = relationships } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decode(String.self, forKey: "id") + relationships = try container.decodeIfPresent(Relationships.self, forKey: "relationships") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(id, forKey: "id") + try container.encodeIfPresent(relationships, forKey: "relationships") + } + /** # Relationships The relationships you included in the request and those on which you can operate. @@ -1027,6 +1171,16 @@ final class ObjectSchemaRendererTests: XCTestCase { self.bundleId = bundleId } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + bundleId = try container.decodeIfPresent(BundleId.self, forKey: "bundleId") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(bundleId, forKey: "bundleId") + } + public struct BundleId: Codable { @NullCodable public var data: Data? @@ -1035,17 +1189,13 @@ final class ObjectSchemaRendererTests: XCTestCase { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - data = try container.decodeIfPresent(Data.self, forKey: .data) + let container = try decoder.container(keyedBy: AnyCodingKey.self) + data = try container.decodeIfPresent(Data.self, forKey: "data") } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(data, forKey: .data) - } - - private enum CodingKeys: String, CodingKey { - case data + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encode(data, forKey: "data") } public struct Data: Codable, Identifiable { @@ -1057,22 +1207,17 @@ final class ObjectSchemaRendererTests: XCTestCase { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decodeIfPresent(String.self, forKey: .id) - if try container.decode(String.self, forKey: .type) != type { - throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Not matching \(type)") + let container = try decoder.container(keyedBy: AnyCodingKey.self) + id = try container.decodeIfPresent(String.self, forKey: "id") + if try container.decode(String.self, forKey: "type") != type { + throw DecodingError.dataCorruptedError(forKey: "type", in: container, debugDescription: "Not matching \(type)") } } public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(id, forKey: .id) - try container.encode(type, forKey: .type) - } - - private enum CodingKeys: String, CodingKey { - case id - case type + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(id, forKey: "id") + try container.encode(type, forKey: "type") } } } @@ -1105,7 +1250,7 @@ final class ObjectSchemaRendererTests: XCTestCase { """ let schema = try JSONDecoder().decode([String: ObjectSchema].self, from: json.data(using: .utf8)!)["phoneNumber"]! let docsLoader = DocsLoader(schemaDocumentationById: [:]) - let renderer = ObjectSchemaRenderer(docsLoader: docsLoader) + let renderer = ObjectSchemaRenderer(docsLoader: docsLoader, shouldFormat: true) // When let rendered = try renderer.render(objectSchema: schema, otherSchemas: [:]) // Then @@ -1124,6 +1269,20 @@ final class ObjectSchemaRendererTests: XCTestCase { self.type = type } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + intent = try container.decodeIfPresent(String.self, forKey: "intent") + number = try container.decodeIfPresent(String.self, forKey: "number") + type = try container.decode(PhoneNumberType.self, forKey: "type") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: AnyCodingKey.self) + try container.encodeIfPresent(intent, forKey: "intent") + try container.encodeIfPresent(number, forKey: "number") + try container.encode(type, forKey: "type") + } + public enum PhoneNumberType: String, Codable, CaseIterable { case fax = "FAX" case landline = "LANDLINE" diff --git a/Tests/BagbutikGeneratorTests/Renderers/OneOfSchemaRendererTests.swift b/Tests/BagbutikGeneratorTests/Renderers/OneOfSchemaRendererTests.swift index cee7a724e..86cdc404c 100644 --- a/Tests/BagbutikGeneratorTests/Renderers/OneOfSchemaRendererTests.swift +++ b/Tests/BagbutikGeneratorTests/Renderers/OneOfSchemaRendererTests.swift @@ -1,3 +1,4 @@ +@testable import BagbutikDocsCollector @testable import BagbutikGenerator @testable import BagbutikSpecDecoder import XCTest @@ -5,7 +6,7 @@ import XCTest final class OneOfSchemaRendererTests: XCTestCase { func testRender() throws { // Given - let renderer = OneOfSchemaRenderer() + let renderer = OneOfSchemaRenderer(docsLoader: DocsLoader(), shouldFormat: true) let schema = OneOfSchema(options: [.schemaRef("BundleId"), .schemaRef("Certificate"), .schemaRef("Device")]) // When let rendered = try renderer.render(name: "Included", oneOfSchema: schema) @@ -39,10 +40,6 @@ final class OneOfSchemaRendererTests: XCTestCase { try value.encode(to: encoder) } } - - private enum CodingKeys: String, CodingKey { - case type - } } """#) diff --git a/Tests/BagbutikGeneratorTests/Renderers/OperationRendererTests.swift b/Tests/BagbutikGeneratorTests/Renderers/OperationRendererTests.swift index b90612189..0db74b122 100644 --- a/Tests/BagbutikGeneratorTests/Renderers/OperationRendererTests.swift +++ b/Tests/BagbutikGeneratorTests/Renderers/OperationRendererTests.swift @@ -13,7 +13,7 @@ final class OperationRendererTests: XCTestCase { .init(status: 200, reason: "OK", description: nil) ])] ) - let renderer = OperationRenderer(docsLoader: docsLoader) + let renderer = OperationRenderer(docsLoader: docsLoader, shouldFormat: true) let parameters: [Parameter] = [ .limit(name: "limit", documentation: "maximum resources per page", maximum: 200) ] @@ -54,7 +54,7 @@ final class OperationRendererTests: XCTestCase { .init(status: 200, reason: "OK", description: nil) ])] ) - let renderer = OperationRenderer(docsLoader: docsLoader) + let renderer = OperationRenderer(docsLoader: docsLoader, shouldFormat: true) let parameters: [Parameter] = [ .include(type: .enum(type: "string", values: ["pets"])), .limit(name: "pets", documentation: "maximum number of related pets returned (when they are included)", maximum: 10) @@ -114,7 +114,7 @@ final class OperationRendererTests: XCTestCase { .init(status: 200, reason: "OK", description: nil) ])] ) - let renderer = OperationRenderer(docsLoader: docsLoader) + let renderer = OperationRenderer(docsLoader: docsLoader, shouldFormat: true) let parameters: [Parameter] = [ .limit(name: "limit", documentation: "maximum resources per page", maximum: 200), .custom(name: "period", type: Parameter.ParameterValueType.simple(type: .string), documentation: "the duration of the reporting period"), @@ -171,7 +171,7 @@ final class OperationRendererTests: XCTestCase { func testRenderNoDocumentaion() throws { // Given let docsLoader = DocsLoader(operationDocumentationById: [:]) - let renderer = OperationRenderer(docsLoader: docsLoader) + let renderer = OperationRenderer(docsLoader: docsLoader, shouldFormat: true) let parameters: [Parameter] = [ .limit(name: "limit", documentation: "maximum resources per page", maximum: 200) ] @@ -205,7 +205,7 @@ final class OperationRendererTests: XCTestCase { func testRenderDeprecated() throws { // Given let docsLoader = DocsLoader(operationDocumentationById: [:]) - let renderer = OperationRenderer(docsLoader: docsLoader) + let renderer = OperationRenderer(docsLoader: docsLoader, shouldFormat: true) let parameters: [Parameter] = [ .limit(name: "limit", documentation: "maximum resources per page", maximum: 200) ] @@ -242,7 +242,7 @@ final class OperationRendererTests: XCTestCase { let docsLoader = DocsLoader(operationDocumentationById: ["apps-get_collection": .init(id: "apps-get_collection", title: "Documentation title", abstract: "Documentation summary", discussion: "Documentation discussion", pathParameters: [:], queryParameters: [:], body: nil, responses: [])] ) - let renderer = OperationRenderer(docsLoader: docsLoader) + let renderer = OperationRenderer(docsLoader: docsLoader, shouldFormat: true) let parameters: [Parameter] = [ .fields(name: "name", type: .simple(type: .init(type: "string")), deprecated: false, documentation: "The name of the user"), .fields(name: "vehicles", type: .enum(type: "string", values: ["car", "bicycle"]), deprecated: true, documentation: "Fields for included vehicles"), @@ -395,7 +395,7 @@ final class OperationRendererTests: XCTestCase { let docsLoader = DocsLoader(operationDocumentationById: ["apps-get_collection": .init(id: "apps-get_collection", title: "Documentation title", abstract: "Documentation summary", discussion: "Documentation discussion", pathParameters: [:], queryParameters: [:], body: nil, responses: [])] ) - let renderer = OperationRenderer(docsLoader: docsLoader) + let renderer = OperationRenderer(docsLoader: docsLoader, shouldFormat: true) let requestBody = RequestBody(name: "UserUpdateRequest", documentation: "User representation") let operation = Operation(id: "apps-get_collection", name: "updateUser", method: .patch, requestBody: requestBody, successResponseType: "UpdateUserResponse", errorResponseType: "ErrorResponse") let parameters: [Path.Parameter] = [.init(name: "id", description: "Id of the user to update")] @@ -442,7 +442,7 @@ final class OperationRendererTests: XCTestCase { let operation = Operation(id: "apps-get_collection", name: "listUsers", method: .get, parameters: parameters, successResponseType: "UsersResponse", errorResponseType: "ErrorResponse") let path = Path(path: "/users", info: .init(mainType: "User", version: "V1", isRelationship: false), operations: [operation]) // When - XCTAssertThrowsError(try OperationRenderer(docsLoader: docsLoader).render(operation: operation, in: path)) { + XCTAssertThrowsError(try OperationRenderer(docsLoader: docsLoader, shouldFormat: true).render(operation: operation, in: path)) { // Then XCTAssertEqual($0 as? OperationRendererError, OperationRendererError.unknownTypeOfExists(name: "hair")) } @@ -459,7 +459,7 @@ final class OperationRendererTests: XCTestCase { let operation = Operation(id: "apps-get_collection", name: "listUsers", method: .get, parameters: parameters, successResponseType: "UsersResponse", errorResponseType: "ErrorResponse") let path = Path(path: "/users", info: .init(mainType: "User", version: "V1", isRelationship: false), operations: [operation]) // When - XCTAssertThrowsError(try OperationRenderer(docsLoader: docsLoader).render(operation: operation, in: path)) { + XCTAssertThrowsError(try OperationRenderer(docsLoader: docsLoader, shouldFormat: true).render(operation: operation, in: path)) { // Then XCTAssertEqual($0 as? OperationRendererError, OperationRendererError.unknownTypeOfInclude) } @@ -476,7 +476,7 @@ final class OperationRendererTests: XCTestCase { let operation = Operation(id: "apps-get_collection", name: "listUsers", method: .get, parameters: parameters, successResponseType: "UsersResponse", errorResponseType: "ErrorResponse") let path = Path(path: "/users", info: .init(mainType: "User", version: "V1", isRelationship: false), operations: [operation]) // When - XCTAssertThrowsError(try OperationRenderer(docsLoader: docsLoader).render(operation: operation, in: path)) { + XCTAssertThrowsError(try OperationRenderer(docsLoader: docsLoader, shouldFormat: true).render(operation: operation, in: path)) { // Then XCTAssertEqual($0 as? OperationRendererError, OperationRendererError.unknownTypeOfSort) } @@ -487,7 +487,7 @@ final class OperationRendererTests: XCTestCase { let docsLoader = DocsLoader(operationDocumentationById: ["apps-get_collection": .init(id: "apps-get_collection", title: "Documentation title", abstract: "Documentation summary", discussion: "Documentation discussion", pathParameters: [:], queryParameters: [:], body: nil, responses: [])] ) - let renderer = OperationRenderer(docsLoader: docsLoader) + let renderer = OperationRenderer(docsLoader: docsLoader, shouldFormat: true) let parameters: [Parameter] = [ .fields(name: "subscriptionOfferCodeOneTimeUseCodes", type: .enum(type: "String", values: ["active", "createdDate", "expirationDate", "numberOfCodes", "offerCode", "values"]), deprecated: false, documentation: ""), .fields(name: "subscriptionOfferCodeOneTimeUseCodeValues", type: .enum(type: "String", values: []), deprecated: false, documentation: ""), diff --git a/Tests/BagbutikGeneratorTests/Renderers/PlainTextSchemaRendererTests.swift b/Tests/BagbutikGeneratorTests/Renderers/PlainTextSchemaRendererTests.swift index 179a54ae7..01f5a3578 100644 --- a/Tests/BagbutikGeneratorTests/Renderers/PlainTextSchemaRendererTests.swift +++ b/Tests/BagbutikGeneratorTests/Renderers/PlainTextSchemaRendererTests.swift @@ -10,7 +10,7 @@ final class PlainTextSchemaRendererTests: XCTestCase { "some://url": .object( .init(id: "/csv", title: "Csv", abstract: "Some summary", discussion: nil, properties: [:], subDocumentationIds: [])) ]) - let renderer = PlainTextSchemaRenderer(docsLoader: docsLoader) + let renderer = PlainTextSchemaRenderer(docsLoader: docsLoader, shouldFormat: true) let schema = PlainTextSchema(name: "Csv", url: "some://url") // When let rendered = try renderer.render(plainTextSchema: schema) @@ -23,6 +23,15 @@ final class PlainTextSchemaRendererTests: XCTestCase { public static func from(text: String) -> Csv { return Self(text: text) } + + public init(text: String) { + self.text = text + } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + text = try container.decode(String.self, forKey: "text") + } } """#) @@ -31,7 +40,7 @@ final class PlainTextSchemaRendererTests: XCTestCase { func testRender_NoDocumentation() throws { // Given let docsLoader = DocsLoader(schemaDocumentationById: [:]) - let renderer = PlainTextSchemaRenderer(docsLoader: docsLoader) + let renderer = PlainTextSchemaRenderer(docsLoader: docsLoader, shouldFormat: true) let schema = PlainTextSchema(name: "Csv", url: "some://url") // When let rendered = try renderer.render(plainTextSchema: schema) @@ -43,6 +52,15 @@ final class PlainTextSchemaRendererTests: XCTestCase { public static func from(text: String) -> Csv { return Self(text: text) } + + public init(text: String) { + self.text = text + } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: AnyCodingKey.self) + text = try container.decode(String.self, forKey: "text") + } } """#) diff --git a/Tests/BagbutikGeneratorTests/Renderers/PropertyRendererTests.swift b/Tests/BagbutikGeneratorTests/Renderers/PropertyRendererTests.swift index c329fc20f..c6b259f3e 100644 --- a/Tests/BagbutikGeneratorTests/Renderers/PropertyRendererTests.swift +++ b/Tests/BagbutikGeneratorTests/Renderers/PropertyRendererTests.swift @@ -5,7 +5,7 @@ import XCTest final class PropertyRendererTests: XCTestCase { func testRenderNonReservedButOptional() throws { // Given - let renderer = PropertyRenderer(docsLoader: DocsLoader()) + let renderer = PropertyRenderer(docsLoader: DocsLoader(), shouldFormat: true) // When let rendered = renderer.renderProperty(id: "name", type: "string", optional: true, isSimpleType: true) // Then @@ -14,7 +14,7 @@ final class PropertyRendererTests: XCTestCase { func testRenderReservedButNotOptional() throws { // Given - let renderer = PropertyRenderer(docsLoader: DocsLoader()) + let renderer = PropertyRenderer(docsLoader: DocsLoader(), shouldFormat: true) // When let rendered = renderer.renderProperty(id: "required", type: "bool", optional: false, isSimpleType: true) // Then @@ -23,7 +23,7 @@ final class PropertyRendererTests: XCTestCase { func testNoNullCodableOnNonSimpleOptionalNotData() throws { // Given - let renderer = PropertyRenderer(docsLoader: DocsLoader()) + let renderer = PropertyRenderer(docsLoader: DocsLoader(), shouldFormat: true) // When let rendered = renderer.renderProperty(id: "device", type: "Device", optional: true, isSimpleType: false) // Then @@ -32,7 +32,7 @@ final class PropertyRendererTests: XCTestCase { func testNoNullCodableOnNonSimpleNotOptional() throws { // Given - let renderer = PropertyRenderer(docsLoader: DocsLoader()) + let renderer = PropertyRenderer(docsLoader: DocsLoader(), shouldFormat: true) // When let rendered = renderer.renderProperty(id: "device", type: "Device", optional: false, isSimpleType: false) // Then @@ -41,7 +41,7 @@ final class PropertyRendererTests: XCTestCase { func testRenderDeprecated() throws { // Given - let renderer = PropertyRenderer(docsLoader: DocsLoader()) + let renderer = PropertyRenderer(docsLoader: DocsLoader(), shouldFormat: true) // When let rendered = renderer.renderProperty(id: "name", type: "string", optional: true, isSimpleType: true, deprecated: true) // Then diff --git a/codecov.yml b/codecov.yml index eacf63fe9..bb9d4a9fe 100644 --- a/codecov.yml +++ b/codecov.yml @@ -1,5 +1,6 @@ ignore: - "Sources/Bagbutik-Core/Models" + - "Sources/Bagbutik-Core/AnyCodingKey.swift" - "Sources/Bagbutik-Models/AppStore" - "Sources/Bagbutik-Models/GameCenter" - "Sources/Bagbutik-Models/Marketplaces"