Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid repeating dependency names in code #630

Merged
merged 3 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ import OpenAPIKit
/// in the Runtime library, so they need to be kept in sync.
enum Constants {

/// Constants related to the library dependencies.
enum Import {

/// The module name of the OpenAPI runtime library.
static let runtime: String = "OpenAPIRuntime"

/// The module name of the HTTP types library.
static let httpTypes: String = "HTTPTypes"
}

/// Constants related to the generated Swift files.
enum File {

Expand All @@ -25,7 +35,7 @@ enum Constants {

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

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

/// Constants related to the OpenAPI server object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ extension TypeName {
/// OpenAPIRuntime module.
/// - Parameter name: The name of the type.
/// - Returns: A TypeName representing the specified type within the OpenAPIRuntime module.
static func runtime(_ name: String) -> TypeName { TypeName(swiftKeyPath: ["OpenAPIRuntime", name]) }
static func runtime(_ name: String) -> TypeName { TypeName(swiftKeyPath: [Constants.Import.runtime, name]) }

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

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