-
Update SPM Versions
- Ensure the Swift Package Manager (SPM) versions are up to date in
Package.swift
.
- Ensure the Swift Package Manager (SPM) versions are up to date in
-
Update OpenAPI Schema
- Update the
openapi.yaml
file with your OpenAPI schema description.
- Update the
-
Build the Project
- Navigate to the project folder and run:
swift build
- Note: You will encounter some errors because the handler in
GenServer.swift
does not manage the endpoints. This is acceptable as the code generator can still be used for the client and types.
- Navigate to the project folder and run:
-
Generate Types
- Run the following command to generate types in the
Generated
folder:swift run swift-openapi-generator generate --mode types --output-directory Generated Sources/openapi.yaml
- Run the following command to generate types in the
-
Generate Client
- Run the following command to generate the client in the
Generated
folder:swift run swift-openapi-generator generate --mode client --output-directory Generated Sources/openapi.yaml
- Run the following command to generate the client in the
-
Include Generated Files
- Include
Client.swift
andTypes.swift
in your iOS project.
- Include
-
Add Required SPM Dependencies
- Add the following Swift Package Manager dependencies to your iOS project:
-
Match SPM Versions
- Ensure that the SPM versions match the versions specified in
Package.swift
(see step 1).
- Ensure that the SPM versions match the versions specified in
-
Use the Generated Code
- You can now use the generated code in your iOS project. Example:
let client = Client(serverURL: Servers.server1(), transport: URLSessionTransport()) let apiCall = try? await client.get_sol_api_sol_cities() switch apiCall { case .ok(let okResponse): let cities = try? okResponse.body.json case .internalServerError(let internalServerError): print("Error: \(internalServerError)") case .undocumented(let statusCode, let undocumentedPayload): print("Undocumented response: \(statusCode)") case .none: print("No response") }
- You can now use the generated code in your iOS project. Example:
- If you want to create a local server, update
GenServer.swift
accordingly.