Skip to content

Commit 4a3c485

Browse files
authored
Default the access modifier to internal (#441)
### Motivation After further consideration, `internal` seems the be the right default for access modifier of the generated, mirroring Swift itself. ### Modifications Switch the default to `internal` and update docs. ### Result `accessModifier: internal` is the default now. ### Test Plan Updated tests.
1 parent ca0e344 commit 4a3c485

File tree

8 files changed

+20
-39
lines changed

8 files changed

+20
-39
lines changed
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
generate:
2-
- client
2+
- client
33
additionalImports:
4-
- Types
4+
- Types
5+
accessModifier: package
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
generate:
2-
- server
2+
- server
33
additionalImports:
4-
- Types
4+
- Types
5+
accessModifier: package
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
generate:
2-
- types
2+
- types
3+
accessModifier: package

Sources/_OpenAPIGeneratorCore/Config.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public struct Config: Sendable {
2727
public var access: AccessModifier
2828

2929
/// The default access modifier.
30-
public static let defaultAccessModifier: AccessModifier = .package
30+
public static let defaultAccessModifier: AccessModifier = .internal
3131

3232
/// Additional imports to add to each generated file.
3333
public var additionalImports: [String]

Sources/swift-openapi-generator/Documentation.docc/Articles/Configuring-the-generator.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ The configuration file has the following keys:
3232
- `server`: Server code that can be used with any server transport (depends on code from `types`).
3333
- `accessModifier` (optional): a string. Customizes the visibility of the API of the generated code.
3434
- `public`: Generated API is accessible from other modules and other packages (if included in a product).
35-
- `package` (default): Generated API is accessible from other modules within the same package or project.
36-
- `internal`: Generated API is accessible from the containing module only.
35+
- `package`: Generated API is accessible from other modules within the same package or project.
36+
- `internal` (default): Generated API is accessible from the containing module only.
3737
- `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.
3838
- `filter`: (optional): Filters to apply to the OpenAPI document before generation.
3939
- `operations`: Operations with these operation IDs will be included in the filter.

Sources/swift-openapi-generator/Documentation.docc/Tutorials/ClientXcode.tutorial

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -35,38 +35,18 @@
3535
}
3636
}
3737
}
38-
39-
@Section(title: "(Optional) Creating a new Xcode target") {
40-
In an existing Xcode project that already contains an app target, create a new Xcode target for the generated client.
4138

42-
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.
43-
@Steps {
44-
@Step {
45-
In the Project Navigator, click on the project.
46-
}
47-
@Step {
48-
In the Project Editor, click the plus button at the bottom of the list titled Targets.
49-
}
50-
@Step {
51-
Select the Framework template, click Next.
52-
}
53-
@Step {
54-
Give the framework a name, for example "GeneratedClient", make sure the framework gets embedded in your app, and click Finish.
55-
}
56-
}
57-
}
58-
5939
@Section(title: "Configuring your target to use the Swift OpenAPI Generator plugin") {
6040

61-
Let's extend this sample package to call our `GreetingService` API.
41+
Let's extend this app to call our `GreetingService` API.
6242

63-
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.
43+
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.
6444

6545
@Steps {
6646
@Step {
6747
Add the two configuration files required by the Swift OpenAPI Generator build plugin.
6848

69-
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"…
49+
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"…
7050
@Code(name: "Sources/openapi.yaml", file: client.openapi.yaml)
7151
}
7252
@Step {
@@ -101,17 +81,17 @@
10181
@Step {
10282
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`.
10383

104-
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.
84+
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.
10585
}
10686
@Step {
107-
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.
87+
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.
10888

10989
Click the plus button and add the OpenAPIGenerator plugin.
11090
}
11191
@Step {
11292
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.
11393

114-
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.
94+
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.
11595
}
11696
}
11797
}
@@ -123,7 +103,7 @@
123103

124104
@Steps {
125105
@Step {
126-
Create a new Swift file in the GeneratedClient framework called `GreetingClient.swift`.
106+
Create a new Swift file in the GreetingServiceClient app target called `GreetingClient.swift`.
127107

128108
Import the OpenAPIURLSession library, which provides a transport implementation that uses Foundation's URLSession to perform network calls.
129109

@@ -166,7 +146,7 @@
166146
@Code(name: "GreetingClient.swift", file: client.xcode.6.swift)
167147
}
168148
@Step {
169-
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.
149+
Finally, in your app target, integrate the client to fetch the personalized greeting, for example to show it in the UI.
170150

171151
@Code(name: "App.swift", file: client.xcode.7.swift, reset: true)
172152
}
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
import GeneratedClient
2-
31
let greeting = try await GreetingClient().getGreeting(name: "App")
42
// Display the greeting text in the UI.

Tests/OpenAPIGeneratorCoreTests/Test_Config.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ import OpenAPIKit
1616
@testable import _OpenAPIGeneratorCore
1717

1818
final class Test_Config: Test_Core {
19-
func testDefaultAccessModifier() { XCTAssertEqual(Config.defaultAccessModifier, .package) }
19+
func testDefaultAccessModifier() { XCTAssertEqual(Config.defaultAccessModifier, .internal) }
2020
}

0 commit comments

Comments
 (0)