|
35 | 35 | }
|
36 | 36 | }
|
37 | 37 | }
|
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. |
41 | 38 |
|
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 |
| - |
59 | 39 | @Section(title: "Configuring your target to use the Swift OpenAPI Generator plugin") {
|
60 | 40 |
|
61 |
| - Let's extend this sample package to call our `GreetingService` API. |
| 41 | + Let's extend this app to call our `GreetingService` API. |
62 | 42 |
|
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. |
64 | 44 |
|
65 | 45 | @Steps {
|
66 | 46 | @Step {
|
67 | 47 | Add the two configuration files required by the Swift OpenAPI Generator build plugin.
|
68 | 48 |
|
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"… |
70 | 50 | @Code(name: "Sources/openapi.yaml", file: client.openapi.yaml)
|
71 | 51 | }
|
72 | 52 | @Step {
|
|
101 | 81 | @Step {
|
102 | 82 | 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`.
|
103 | 83 |
|
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. |
105 | 85 | }
|
106 | 86 | @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. |
108 | 88 |
|
109 | 89 | Click the plus button and add the OpenAPIGenerator plugin.
|
110 | 90 | }
|
111 | 91 | @Step {
|
112 | 92 | 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.
|
113 | 93 |
|
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. |
115 | 95 | }
|
116 | 96 | }
|
117 | 97 | }
|
|
123 | 103 |
|
124 | 104 | @Steps {
|
125 | 105 | @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`. |
127 | 107 |
|
128 | 108 | Import the OpenAPIURLSession library, which provides a transport implementation that uses Foundation's URLSession to perform network calls.
|
129 | 109 |
|
|
166 | 146 | @Code(name: "GreetingClient.swift", file: client.xcode.6.swift)
|
167 | 147 | }
|
168 | 148 | @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. |
170 | 150 |
|
171 | 151 | @Code(name: "App.swift", file: client.xcode.7.swift, reset: true)
|
172 | 152 | }
|
|
0 commit comments