diff --git a/Amplify.xcodeproj/project.pbxproj b/Amplify.xcodeproj/project.pbxproj index b63b127fca..9e7c2a648d 100644 --- a/Amplify.xcodeproj/project.pbxproj +++ b/Amplify.xcodeproj/project.pbxproj @@ -111,6 +111,7 @@ 21A3FDB62464590600E76120 /* ModelMultipleOwnerAuthRuleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21A3FDB52464590600E76120 /* ModelMultipleOwnerAuthRuleTests.swift */; }; 21A3FDB9246494CD00E76120 /* GraphQLRequestAuthRuleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21A3FDB8246494CD00E76120 /* GraphQLRequestAuthRuleTests.swift */; }; 21A3FDBF2465FA1500E76120 /* AuthRule+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21A3FDBE2465FA1500E76120 /* AuthRule+Extension.swift */; }; + 21AD4257249BFFE00016FE95 /* DeprecatedTodo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21AD4255249BFFDF0016FE95 /* DeprecatedTodo.swift */; }; 21C395B3245729EC00597EA2 /* AppSyncErrorType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21C395B2245729EC00597EA2 /* AppSyncErrorType.swift */; }; 21D79FDA237617C60057D00D /* SubscriptionEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21D79FD9237617C60057D00D /* SubscriptionEvent.swift */; }; 21D79FE32377F4120057D00D /* SubscriptionConnectionState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21D79FE22377F4120057D00D /* SubscriptionConnectionState.swift */; }; @@ -757,6 +758,7 @@ 21A3FDB52464590600E76120 /* ModelMultipleOwnerAuthRuleTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModelMultipleOwnerAuthRuleTests.swift; sourceTree = ""; }; 21A3FDB8246494CD00E76120 /* GraphQLRequestAuthRuleTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GraphQLRequestAuthRuleTests.swift; sourceTree = ""; }; 21A3FDBE2465FA1500E76120 /* AuthRule+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AuthRule+Extension.swift"; sourceTree = ""; }; + 21AD4255249BFFDF0016FE95 /* DeprecatedTodo.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = DeprecatedTodo.swift; path = Deprecated/DeprecatedTodo.swift; sourceTree = ""; }; 21C395B2245729EC00597EA2 /* AppSyncErrorType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppSyncErrorType.swift; sourceTree = ""; }; 21D79FD9237617C60057D00D /* SubscriptionEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubscriptionEvent.swift; sourceTree = ""; }; 21D79FE22377F4120057D00D /* SubscriptionConnectionState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubscriptionConnectionState.swift; sourceTree = ""; }; @@ -2228,6 +2230,7 @@ B952182D237E21B900F53237 /* Models */ = { isa = PBXGroup; children = ( + 21AD4255249BFFDF0016FE95 /* DeprecatedTodo.swift */, 216E45E9248E91420035E3CE /* NonModel */, FAF512AD23986791001ADF4E /* AmplifyModels.swift */, 214F49CB24898E8400DA616C /* Article.swift */, @@ -4489,6 +4492,7 @@ 21F40A4023A295470074678E /* TestCommonConstants.swift in Sources */, 214F497C2486D8A200DA616C /* UserFollowers.swift in Sources */, B9521835237E21BA00F53237 /* Comment.swift in Sources */, + 21AD4257249BFFE00016FE95 /* DeprecatedTodo.swift in Sources */, 216E45EF248E914F0035E3CE /* Todo+Schema.swift in Sources */, FACA361E2327FC8E000E74F6 /* MockAnalyticsCategoryPlugin.swift in Sources */, 2129BE012394627B006363A1 /* PostCommentModelRegistration.swift in Sources */, diff --git a/Amplify/Categories/DataStore/Model/Embedded.swift b/Amplify/Categories/DataStore/Model/Embedded.swift index 7ca0c64bd0..975def678e 100644 --- a/Amplify/Categories/DataStore/Model/Embedded.swift +++ b/Amplify/Categories/DataStore/Model/Embedded.swift @@ -12,7 +12,7 @@ import Foundation /// A `Embeddable` type can be used in a `Model` as an embedded type. All types embedded in a `Model` as an /// `embedded(type:)` or `embeddedCollection(of:)` must comform to the `Embeddable` protocol except for Swift's Basic /// types embedded as a collection. A collection of String can be embedded in the `Model` as -/// `embeddedCollection(of: String.self)` without needing to conform to Embeddable. +/// `embeddedCollection(of: String.self)` without needing to conform to Embeddable. public protocol Embeddable: Codable { /// A reference to the `ModelSchema` associated with this embedded type. diff --git a/Amplify/Categories/DataStore/Model/Schema/ModelSchema+Definition.swift b/Amplify/Categories/DataStore/Model/Schema/ModelSchema+Definition.swift index 4c5420b8b0..732ad627bc 100644 --- a/Amplify/Categories/DataStore/Model/Schema/ModelSchema+Definition.swift +++ b/Amplify/Categories/DataStore/Model/Schema/ModelSchema+Definition.swift @@ -33,6 +33,14 @@ public enum ModelFieldType { } } + @available(*, deprecated, message: """ + This has been replaced with `.embedded(type)` and `.embeddedCollection(of)` \ + Please use Amplify CLI 4.21.4 or newer to re-generate your Models to conform to Embeddable type. + """) + public static func customType(_ type: Codable.Type) -> ModelFieldType { + return .embedded(type: type) + } + public static func from(type: Any.Type) -> ModelFieldType { if type is String.Type { return .string diff --git a/AmplifyTestCommon/Models/Deprecated/DeprecatedTodo.swift b/AmplifyTestCommon/Models/Deprecated/DeprecatedTodo.swift new file mode 100644 index 0000000000..a1a65d8a89 --- /dev/null +++ b/AmplifyTestCommon/Models/Deprecated/DeprecatedTodo.swift @@ -0,0 +1,69 @@ +// +// Copyright 2018-2020 Amazon.com, +// Inc. or its affiliates. All Rights Reserved. +// +// SPDX-License-Identifier: Apache-2.0 +// + +// swiftlint:disable all +import Amplify +import Foundation +/* +The schema used to codegen this model: + type DeprecatedTodo @model { + id: ID! + description: String + note: Note + } + type Note { + name: String! + color: String! + } + + Amplify CLI version used is less than 4.21.4. `.customType` has since been replaced with `.embedded(type)` and + `.embeddedCollection(of)`. Please use Amplify CLI 4.21.4 or newer to re-generate your Models to conform to + Embeddable type. + */ + +public struct DeprecatedTodo: Model { + public let id: String + public var description: String? + public var note: Note? + + public init(id: String = UUID().uuidString, + description: String? = nil, + note: Note? = nil) { + self.id = id + self.description = description + self.note = note + } +} + +extension DeprecatedTodo { + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case id + case description + case note + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema + + public static let schema = defineSchema { model in + let deprecatedTodo = DeprecatedTodo.keys + + model.pluralName = "DeprecatedTodos" + + model.fields( + .id(), + .field(deprecatedTodo.description, is: .optional, ofType: .string), + .field(deprecatedTodo.note, is: .optional, ofType: .customType(Note.self)) + ) + } +} + +public struct Note: Codable { + var name: String + var color: String +}