-
Notifications
You must be signed in to change notification settings - Fork 172
Add namespace-based types file splitting #925
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
base: main
Are you sure you want to change the base?
Changes from all commits
a2013a8
d2949a8
eb817f7
b002759
3979529
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This source file is part of the SwiftOpenAPIGenerator open source project | ||
| // | ||
| // Copyright (c) 2023 Apple Inc. and the SwiftOpenAPIGenerator project authors | ||
| // Licensed under Apache License v2.0 | ||
| // | ||
| // See LICENSE.txt for license information | ||
| // See CONTRIBUTORS.txt for the list of SwiftOpenAPIGenerator project authors | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| /// Configuration for generated output files. | ||
| public struct OutputOptions: Sendable, Codable, Equatable { | ||
|
|
||
| /// Options that only affect `Types.swift` generation. | ||
| public var types: TypesOutputOptions? | ||
|
Comment on lines
+18
to
+19
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we foresee a need to have this level of distinction in the config? Are we anticipating output options that only affect types that we wouldn't want to also apply to the client and server outputs?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do think splitting client/server could be useful later for very large specs, but I see it as a separate strategy rather than this namespace strategy. Client/Server outputs are mostly flat operation methods that reference Operations types, while |
||
|
|
||
| /// Creates output options. | ||
| /// - Parameter types: Options that only affect `Types.swift` generation. | ||
| public init(types: TypesOutputOptions? = nil) { self.types = types } | ||
| } | ||
|
|
||
| /// Configuration for generated types output files. | ||
| public struct TypesOutputOptions: Sendable, Codable, Equatable { | ||
|
|
||
| /// Optional configuration for splitting generated types across files. | ||
| public var fileSplitting: TypesFileSplittingConfig? | ||
|
|
||
| /// Creates types output options. | ||
| /// - Parameter fileSplitting: Optional configuration for splitting generated types across files. | ||
| public init(fileSplitting: TypesFileSplittingConfig? = nil) { self.fileSplitting = fileSplitting } | ||
| } | ||
|
|
||
| /// Configuration for splitting generated types across files. | ||
| public struct TypesFileSplittingConfig: Sendable, Codable, Equatable { | ||
|
|
||
| /// The strategy to use when splitting generated types across files. | ||
| public var strategy: TypesFileSplittingStrategy | ||
|
|
||
| /// Creates a file splitting configuration. | ||
| /// - Parameter strategy: The strategy to use when splitting generated types across files. | ||
| public init(strategy: TypesFileSplittingStrategy) { | ||
| self.strategy = strategy | ||
| } | ||
| } | ||
|
|
||
| /// A strategy for splitting generated types across files. | ||
| public enum TypesFileSplittingStrategy: String, Sendable, Codable, Equatable, CaseIterable { | ||
|
|
||
| /// Splits generated types into a small fixed set of files by top-level namespace. | ||
| case namespace | ||
| } | ||
|
|
||
| extension TypesFileSplittingConfig { | ||
|
|
||
| /// Returns the Swift output file names emitted by the configuration. | ||
| /// - Parameter primaryTypesFileName: The file name for the primary generated types file. | ||
| /// - Returns: The emitted Swift output file names. | ||
| public func outputFileNames(primaryTypesFileName: String) -> [String] { | ||
| switch strategy { | ||
| case .namespace: | ||
| return [ | ||
| primaryTypesFileName, | ||
| GeneratorMode.outputFileName(primaryTypesFileName, "Components"), | ||
| GeneratorMode.outputFileName(primaryTypesFileName, "Operations"), | ||
| ] | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uses a fresh renderer for each file because TextBasedRenderer owns a stateful StringCodeWriter and would accumulate rendered swift for multiple file outputs