diff --git a/IntegrationTest/Sources/Client/openapi-generator-config.yaml b/IntegrationTest/Sources/Client/openapi-generator-config.yaml index 58c44106..d553a2b1 100644 --- a/IntegrationTest/Sources/Client/openapi-generator-config.yaml +++ b/IntegrationTest/Sources/Client/openapi-generator-config.yaml @@ -1,4 +1,5 @@ generate: -- client + - client additionalImports: -- Types + - Types +accessModifier: package diff --git a/IntegrationTest/Sources/Server/openapi-generator-config.yaml b/IntegrationTest/Sources/Server/openapi-generator-config.yaml index e16a9cb1..7ccd1197 100644 --- a/IntegrationTest/Sources/Server/openapi-generator-config.yaml +++ b/IntegrationTest/Sources/Server/openapi-generator-config.yaml @@ -1,4 +1,5 @@ generate: -- server + - server additionalImports: -- Types + - Types +accessModifier: package diff --git a/IntegrationTest/Sources/Types/openapi-generator-config.yaml b/IntegrationTest/Sources/Types/openapi-generator-config.yaml index 03d0a64d..7e4ffe46 100644 --- a/IntegrationTest/Sources/Types/openapi-generator-config.yaml +++ b/IntegrationTest/Sources/Types/openapi-generator-config.yaml @@ -1,2 +1,3 @@ generate: -- types + - types +accessModifier: package diff --git a/Sources/_OpenAPIGeneratorCore/Config.swift b/Sources/_OpenAPIGeneratorCore/Config.swift index bcc6f2ba..6172b709 100644 --- a/Sources/_OpenAPIGeneratorCore/Config.swift +++ b/Sources/_OpenAPIGeneratorCore/Config.swift @@ -27,7 +27,7 @@ public struct Config: Sendable { public var access: AccessModifier /// The default access modifier. - public static let defaultAccessModifier: AccessModifier = .package + public static let defaultAccessModifier: AccessModifier = .internal /// Additional imports to add to each generated file. public var additionalImports: [String] diff --git a/Sources/swift-openapi-generator/Documentation.docc/Articles/Configuring-the-generator.md b/Sources/swift-openapi-generator/Documentation.docc/Articles/Configuring-the-generator.md index 998e3e51..918bee30 100644 --- a/Sources/swift-openapi-generator/Documentation.docc/Articles/Configuring-the-generator.md +++ b/Sources/swift-openapi-generator/Documentation.docc/Articles/Configuring-the-generator.md @@ -32,8 +32,8 @@ The configuration file has the following keys: - `server`: Server code that can be used with any server transport (depends on code from `types`). - `accessModifier` (optional): a string. Customizes the visibility of the API of the generated code. - `public`: Generated API is accessible from other modules and other packages (if included in a product). - - `package` (default): Generated API is accessible from other modules within the same package or project. - - `internal`: Generated API is accessible from the containing module only. + - `package`: Generated API is accessible from other modules within the same package or project. + - `internal` (default): Generated API is accessible from the containing module only. - `additionalImports` (optional): array of strings. Each string value is a Swift module name. An import statement will be added to the generated source files for each module. - `filter`: (optional): Filters to apply to the OpenAPI document before generation. - `operations`: Operations with these operation IDs will be included in the filter. diff --git a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/ClientXcode.tutorial b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/ClientXcode.tutorial index 136acff4..a1fea028 100644 --- a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/ClientXcode.tutorial +++ b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/ClientXcode.tutorial @@ -35,38 +35,18 @@ } } } - - @Section(title: "(Optional) Creating a new Xcode target") { - In an existing Xcode project that already contains an app target, create a new Xcode target for the generated client. - While this isn't required and you can generate the client Swift code into your app target, it is recommended to keep the generated code in a separate framework to avoid potential file and type name conflicts. - @Steps { - @Step { - In the Project Navigator, click on the project. - } - @Step { - In the Project Editor, click the plus button at the bottom of the list titled Targets. - } - @Step { - Select the Framework template, click Next. - } - @Step { - Give the framework a name, for example "GeneratedClient", make sure the framework gets embedded in your app, and click Finish. - } - } - } - @Section(title: "Configuring your target to use the Swift OpenAPI Generator plugin") { - Let's extend this sample package to call our `GreetingService` API. + Let's extend this app to call our `GreetingService` API. - We will generate the client code into an Xcode target created in the previous step, called "GeneratedClient". You can generate the code into any target in your project. + We will generate the client code into your existing Xcode app target, for example called "GreetingServiceClient". Note that you can generate the code into any target in your project, and in larger projects, it can be helpful to generate the code into a dedicated framework or library. @Steps { @Step { Add the two configuration files required by the Swift OpenAPI Generator build plugin. - The first is the OpenAPI document. Add it to to the "GeneratedClient" target by right-clicking on the "GeneratedClient" folder in the project navigator, and choosing Add Files to "GeneratedClient"… + The first is the OpenAPI document. Add it to to the "GreetingServiceClient" target by right-clicking on the "GreetingServiceClient" folder in the project navigator, and choosing Add Files to "GreetingServiceClient"… @Code(name: "Sources/openapi.yaml", file: client.openapi.yaml) } @Step { @@ -101,17 +81,17 @@ @Step { Repeat the same steps two more times, with the packages `https://github.com/apple/swift-openapi-runtime` and `https://github.com/apple/swift-openapi-urlsession`. - This time, do check the library products to be added to the **GeneratedClient target**. Note, this might not be the default target Xcode offers to add the libraries to. + This time, do check the library products to be added to the **GreetingServiceClient target**. Note, this might not be the default target Xcode offers to add the libraries to. } @Step { - To finish configuring the build plugin in your target, navigate to the Build Phases tab of the GeneratedClient in the Project Editor, and expand the Run Build Tool Plug-ins section. + To finish configuring the build plugin in your target, navigate to the Build Phases tab of the GreetingServiceClient in the Project Editor, and expand the Run Build Tool Plug-ins section. Click the plus button and add the OpenAPIGenerator plugin. } @Step { To verify everything is configured correctly, choose Product -> Build. If this is the first time using the plugin, you will be asked for confirmation that you trust the plugin. To continue, click Trust & Enable All. - Xcode now builds the Swift OpenAPI Generator plugin itself, and then runs it on the configuration files `openapi.yaml` and `openapi-generator-config.yaml` to generate a Swift client for GreetingService. Once it finishes, the `Client` type will become available in the GeneratedClient target. + Xcode now builds the Swift OpenAPI Generator plugin itself, and then runs it on the configuration files `openapi.yaml` and `openapi-generator-config.yaml` to generate a Swift client for GreetingService. Once it finishes, the `Client` type will become available in the GreetingServiceClient target. } } } @@ -123,7 +103,7 @@ @Steps { @Step { - Create a new Swift file in the GeneratedClient framework called `GreetingClient.swift`. + Create a new Swift file in the GreetingServiceClient app target called `GreetingClient.swift`. Import the OpenAPIURLSession library, which provides a transport implementation that uses Foundation's URLSession to perform network calls. @@ -166,7 +146,7 @@ @Code(name: "GreetingClient.swift", file: client.xcode.6.swift) } @Step { - Finally, in your app target, import the framework with the generated client and fetch the personalized greeting, for example to show it in the UI. + Finally, in your app target, integrate the client to fetch the personalized greeting, for example to show it in the UI. @Code(name: "App.swift", file: client.xcode.7.swift, reset: true) } diff --git a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.xcode.7.swift b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.xcode.7.swift index a9ecbb52..9dbef833 100644 --- a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.xcode.7.swift +++ b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.xcode.7.swift @@ -1,4 +1,2 @@ -import GeneratedClient - let greeting = try await GreetingClient().getGreeting(name: "App") // Display the greeting text in the UI. diff --git a/Tests/OpenAPIGeneratorCoreTests/Test_Config.swift b/Tests/OpenAPIGeneratorCoreTests/Test_Config.swift index 6181ed13..da8c522f 100644 --- a/Tests/OpenAPIGeneratorCoreTests/Test_Config.swift +++ b/Tests/OpenAPIGeneratorCoreTests/Test_Config.swift @@ -16,5 +16,5 @@ import OpenAPIKit @testable import _OpenAPIGeneratorCore final class Test_Config: Test_Core { - func testDefaultAccessModifier() { XCTAssertEqual(Config.defaultAccessModifier, .package) } + func testDefaultAccessModifier() { XCTAssertEqual(Config.defaultAccessModifier, .internal) } }