Skip to content

Commit d5f6a6a

Browse files
authored
Avoid repeating dependency names in code (apple#630)
### Motivation A small refactor - avoid repeating the dependency names in code. ### Modifications Factor out the dependency names into a single place. ### Result Less duplication that needs to be kept in sync manually. ### Test Plan All tests still pass.
1 parent 86ae4f6 commit d5f6a6a

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

Sources/_OpenAPIGeneratorCore/Translator/CommonTypes/Constants.swift

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ import OpenAPIKit
1717
/// in the Runtime library, so they need to be kept in sync.
1818
enum Constants {
1919

20+
/// Constants related to the library dependencies.
21+
enum Import {
22+
23+
/// The module name of the OpenAPI runtime library.
24+
static let runtime: String = "OpenAPIRuntime"
25+
26+
/// The module name of the HTTP types library.
27+
static let httpTypes: String = "HTTPTypes"
28+
}
29+
2030
/// Constants related to the generated Swift files.
2131
enum File {
2232

@@ -25,7 +35,7 @@ enum Constants {
2535

2636
/// The descriptions of modules imported by every generated file.
2737
static let imports: [ImportDescription] = [
28-
ImportDescription(moduleName: "OpenAPIRuntime", spi: "Generated"),
38+
ImportDescription(moduleName: Constants.Import.runtime, spi: "Generated"),
2939
ImportDescription(
3040
moduleName: "Foundation",
3141
moduleTypes: ["struct Foundation.URL", "struct Foundation.Data", "struct Foundation.Date"],
@@ -34,7 +44,8 @@ enum Constants {
3444
]
3545

3646
/// The descriptions of modules imported by client and server files.
37-
static let clientServerImports: [ImportDescription] = imports + [ImportDescription(moduleName: "HTTPTypes")]
47+
static let clientServerImports: [ImportDescription] =
48+
imports + [ImportDescription(moduleName: Constants.Import.httpTypes)]
3849
}
3950

4051
/// Constants related to the OpenAPI server object.

Sources/_OpenAPIGeneratorCore/Translator/TypeAssignment/Builtins.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ extension TypeName {
3636
/// OpenAPIRuntime module.
3737
/// - Parameter name: The name of the type.
3838
/// - Returns: A TypeName representing the specified type within the OpenAPIRuntime module.
39-
static func runtime(_ name: String) -> TypeName { TypeName(swiftKeyPath: ["OpenAPIRuntime", name]) }
39+
static func runtime(_ name: String) -> TypeName { TypeName(swiftKeyPath: [Constants.Import.runtime, name]) }
4040

4141
/// Returns a type name for a type with the specified name in the
4242
/// HTTPTypes module.
4343
/// - Parameter name: The name of the type.
4444
/// - Returns: A TypeName representing the type with the given name in the HTTPTypes module.
45-
static func httpTypes(_ name: String) -> TypeName { TypeName(swiftKeyPath: ["HTTPTypes", name]) }
45+
static func httpTypes(_ name: String) -> TypeName { TypeName(swiftKeyPath: [Constants.Import.httpTypes, name]) }
4646

4747
/// Returns the type name for the Date type.
4848
static var date: Self { .foundation("Date") }

0 commit comments

Comments
 (0)