Skip to content

Commit

Permalink
Addressing feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
BobaFetters committed Nov 19, 2024
1 parent 60579a5 commit 5f2bc7b
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1315,7 +1315,7 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase {
"schemaTypes" : {
"moduleType" : {
"swiftPackage" : {
"dependencyType" : {
"apolloSDKVersion" : {
"default" : {
}
Expand Down Expand Up @@ -1507,7 +1507,7 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase {
"schemaTypes" : {
"moduleType" : {
"swiftPackage" : {
"dependencyType" : {
"apolloSDKVersion" : {
"default" : {
}
Expand Down Expand Up @@ -1638,7 +1638,7 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase {
output: .init(
schemaTypes: .init(
path: "/output/path",
moduleType: .swiftPackage(dependencyType: .default)
moduleType: .swiftPackage(apolloSDKVersion: .default)
),
operations: .absolute(path: "/absolute/path", accessModifier: .internal)
)
Expand Down Expand Up @@ -1699,7 +1699,7 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase {
"schemaTypes" : {
"moduleType" : {
"swiftPackage" : {
"dependencyType" : {
"apolloSDKVersion" : {
"default" : {
}
Expand Down Expand Up @@ -1739,7 +1739,7 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase {
output: .init(
schemaTypes: .init(
path: "/output/path",
moduleType: .swiftPackage(dependencyType: .branch(name: "branchName"))
moduleType: .swiftPackage(apolloSDKVersion: .branch(name: "branchName"))
),
operations: .absolute(path: "/absolute/path", accessModifier: .internal)
)
Expand Down Expand Up @@ -1800,7 +1800,7 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase {
"schemaTypes" : {
"moduleType" : {
"swiftPackage" : {
"dependencyType" : {
"apolloSDKVersion" : {
"branch" : {
"name" : "branchName"
}
Expand Down Expand Up @@ -1840,7 +1840,7 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase {
output: .init(
schemaTypes: .init(
path: "/output/path",
moduleType: .swiftPackage(dependencyType: .commit(hash: "hash"))
moduleType: .swiftPackage(apolloSDKVersion: .commit(hash: "hash"))
),
operations: .absolute(path: "/absolute/path", accessModifier: .internal)
)
Expand Down Expand Up @@ -1901,7 +1901,7 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase {
"schemaTypes" : {
"moduleType" : {
"swiftPackage" : {
"dependencyType" : {
"apolloSDKVersion" : {
"commit" : {
"hash" : "hash"
}
Expand Down Expand Up @@ -1941,7 +1941,7 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase {
output: .init(
schemaTypes: .init(
path: "/output/path",
moduleType: .swiftPackage(dependencyType: .local(path: "path"))
moduleType: .swiftPackage(apolloSDKVersion: .local(path: "path"))
),
operations: .absolute(path: "/absolute/path", accessModifier: .internal)
)
Expand Down Expand Up @@ -2002,7 +2002,7 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase {
"schemaTypes" : {
"moduleType" : {
"swiftPackage" : {
"dependencyType" : {
"apolloSDKVersion" : {
"local" : {
"path" : "path"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@ class SwiftPackageManagerModuleTemplateTests: XCTestCase {

private func buildSubject(
testMockConfig: ApolloCodegenConfiguration.TestMockFileOutput = .none,
config: ApolloCodegenConfiguration = .mock(schemaNamespace: "TestModule"),
dependencyType: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType.ApolloDependencyType = .default
config: ApolloCodegenConfiguration = .mock(schemaNamespace: "TestModule")
) {
subject = .init(
testMockConfig: testMockConfig,
config: .init(config: config),
dependencyType: dependencyType
config: .init(config: config)
)
}

Expand Down Expand Up @@ -152,7 +150,14 @@ class SwiftPackageManagerModuleTemplateTests: XCTestCase {

func test__packageDescription__generatesDefaultVersionDependency() {
// given
buildSubject(dependencyType: .default)
buildSubject(config: .mock(
schemaNamespace: "TestModule",
output: .init(
schemaTypes: .init(
path: "path/",
moduleType: .swiftPackage(apolloSDKVersion: .default)
))
))

let expected = """
dependencies: [
Expand All @@ -169,7 +174,14 @@ class SwiftPackageManagerModuleTemplateTests: XCTestCase {
func test__packageDescription__generatesBranchVersionDependency() {
// given
let branchName = "testBranch"
buildSubject(dependencyType: .branch(name: branchName))
buildSubject(config: .mock(
schemaNamespace: "TestModule",
output: .init(
schemaTypes: .init(
path: "path/",
moduleType: .swiftPackage(apolloSDKVersion: .branch(name: branchName))
))
))

let expected = """
dependencies: [
Expand All @@ -186,7 +198,14 @@ class SwiftPackageManagerModuleTemplateTests: XCTestCase {
func test__packageDescription__generatesCommitVersionDependency() {
// given
let hash = "testHash"
buildSubject(dependencyType: .commit(hash: hash))
buildSubject(config: .mock(
schemaNamespace: "TestModule",
output: .init(
schemaTypes: .init(
path: "path/",
moduleType: .swiftPackage(apolloSDKVersion: .commit(hash: hash))
))
))

let expected = """
dependencies: [
Expand All @@ -203,7 +222,14 @@ class SwiftPackageManagerModuleTemplateTests: XCTestCase {
func test__packageDescription__generatesLocalVersionDependency() {
// given
let path = "localPath"
buildSubject(dependencyType: .local(path: path))
buildSubject(config: .mock(
schemaNamespace: "TestModule",
output: .init(
schemaTypes: .init(
path: "path/",
moduleType: .swiftPackage(apolloSDKVersion: .local(path: path))
))
))

let expected = """
dependencies: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public struct ApolloCodegenConfiguration: Codable, Equatable {
moduleType: ModuleType
) {
self.path = path
self.moduleType = moduleType == .swiftPackageManager ? .swiftPackage(dependencyType: .default) : moduleType
self.moduleType = moduleType == .swiftPackageManager ? .swiftPackage(apolloSDKVersion: .default) : moduleType
}

/// Compatible dependency manager automation.
Expand All @@ -283,12 +283,12 @@ public struct ApolloCodegenConfiguration: Codable, Equatable {
case embeddedInTarget(name: String, accessModifier: AccessModifier = .internal)
/// Generates a `Package.swift` file that is suitable for linking the generated schema types
/// files to your project using Swift Package Manager.
@available(*, deprecated, message: "Use .swiftPackage(dependencyType:) case instead.")
/// Attention: This case has been deprecated, use .swiftPackage(apolloSDKVersion:) case instead.
case swiftPackageManager
/// Generates a `Package.swift` file that is suitable for linking then generated schema types
/// files to your project using Swift Package Manager. Uses the `dependencyType` associated
/// value to determine how to setup the dependency on `apollo-ios`.
case swiftPackage(dependencyType: ApolloDependencyType = .default)
case swiftPackage(apolloSDKVersion: ApolloSDKVersion = .default)
/// No module will be created for the generated types and you are required to create the
/// module to support your preferred dependency manager. You must specify the name of the
/// module you will create in the `schemaNamespace` property as this will be used in `import`
Expand Down Expand Up @@ -326,23 +326,23 @@ public struct ApolloCodegenConfiguration: Codable, Equatable {
self = .embeddedInTarget(name: name, accessModifier: accessModifier)

case .swiftPackageManager:
self = .swiftPackage(dependencyType: .default)
self = .swiftPackage(apolloSDKVersion: .default)

case .swiftPackage:
let nestedContainer = try container.nestedContainer(
keyedBy: SwiftPackageCodingKeys.self,
forKey: .swiftPackage
)

let dependencyType = try nestedContainer.decodeIfPresent(ApolloDependencyType.self, forKey: .dependencyType) ?? .default
self = .swiftPackage(dependencyType: dependencyType)
let apolloSDKVersion = try nestedContainer.decodeIfPresent(ApolloSDKVersion.self, forKey: .apolloSDKVersion) ?? .default
self = .swiftPackage(apolloSDKVersion: apolloSDKVersion)

case .other:
self = .other
}
}

public enum ApolloDependencyType: Codable, Equatable {
public enum ApolloSDKVersion: Codable, Equatable {
case `default`
case branch(name: String)
case commit(hash: String)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,12 @@ struct SchemaModuleFileGenerator {
let errors: [ApolloCodegen.NonFatalError]

switch config.output.schemaTypes.moduleType {
case .swiftPackageManager:
case .swiftPackageManager,
.swiftPackage(_):
filePath = pathURL.appendingPathComponent("Package.swift").path
(rendered, errors) = SwiftPackageManagerModuleTemplate(
testMockConfig: config.output.testMocks,
config: config,
dependencyType: .default
).render()
case .swiftPackage(let dependencyType):
filePath = pathURL.appendingPathComponent("Package.swift").path
(rendered, errors) = SwiftPackageManagerModuleTemplate(
testMockConfig: config.output.testMocks,
config: config,
dependencyType: dependencyType
config: config
).render()

case .embeddedInTarget:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,22 @@ struct SwiftPackageManagerModuleTemplate: TemplateRenderer {

let config: ApolloCodegen.ConfigurationContext

let dependencyType: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType.ApolloDependencyType
let apolloSDKVersion: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType.ApolloSDKVersion

init(
testMockConfig: ApolloCodegenConfiguration.TestMockFileOutput,
config: ApolloCodegen.ConfigurationContext
) {
self.testMockConfig = testMockConfig
self.config = config

switch config.config.output.schemaTypes.moduleType {
case .swiftPackage(let apolloSDKVersion):
self.apolloSDKVersion = apolloSDKVersion
default:
self.apolloSDKVersion = .default
}
}

func renderHeaderTemplate(
nonFatalErrorRecorder: ApolloCodegen.NonFatalError.Recorder
Expand Down Expand Up @@ -44,7 +59,7 @@ struct SwiftPackageManagerModuleTemplate: TemplateRenderer {
"""})
],
dependencies: [
\(dependencyType.dependencyString),
\(apolloSDKVersion.dependencyString),
],
targets: [
.target(
Expand Down Expand Up @@ -84,7 +99,7 @@ struct SwiftPackageManagerModuleTemplate: TemplateRenderer {
}
}

fileprivate extension ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType.ApolloDependencyType {
fileprivate extension ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType.ApolloSDKVersion {
var dependencyString: TemplateString {
switch self {
case .default:
Expand Down

0 comments on commit 5f2bc7b

Please sign in to comment.