|
1 | 1 | # Examples of using Swift OpenAPI Generator
|
2 | 2 |
|
3 |
| -This directory contains examples of how to use Swift OpenAPI Generator and |
4 |
| -integrate with other packages in the ecosystem. |
| 3 | +This directory contains examples of how to use and |
| 4 | +integrate Swift OpenAPI Generator with other packages in the ecosystem. |
5 | 5 |
|
6 |
| -> **Disclaimer:** Many of these examples have been deliberately simplified and are |
7 |
| -> intended for illustrative purposes only. |
| 6 | +> Important: Many of these examples have been deliberately simplified and are intended for illustrative purposes only. |
8 | 7 |
|
9 |
| -## Getting started |
| 8 | +All the examples can be found in the [Examples](https://github.com/apple/swift-openapi-generator/tree/main/Examples) directory of the [Swift OpenAPI Generator](https://github.com/apple/swift-openapi-generator) repository. |
10 | 9 |
|
11 |
| -Each of the following packages shows an end-to-end working example with the given transport. |
| 10 | +To run an example locally, for example [hello-world-urlsession-client-example](https://github.com/apple/swift-openapi-generator/tree/main/Examples/hello-world-urlsession-client-example), clone the Swift OpenAPI Generator repository, and run the example, as shown below: |
12 | 11 |
|
| 12 | +```console |
| 13 | +% git clone https://github.com/apple/swift-openapi-generator |
| 14 | +% cd swift-openapi-generator/Examples |
| 15 | +% swift run --package-path hello-world-urlsession-client-example |
| 16 | +``` |
13 | 17 |
|
| 18 | +## Getting started |
| 19 | + |
| 20 | +Each of the following packages shows an end-to-end working example with the given transport. |
14 | 21 |
|
15 |
| -- [hello-world-async-http-client-example](./hello-world-async-http-client-example) - A CLI client using the AsyncHTTPClient library. |
16 |
| -- [hello-world-hummingbird-server-example](./hello-world-hummingbird-server-example) - A CLI server using the Hummingbird web framework. |
17 |
| -- [hello-world-urlsession-client-example](./hello-world-urlsession-client-example) - A CLI client using the URLSession HTTP client library. |
18 |
| -- [hello-world-vapor-server-example](./hello-world-vapor-server-example) - A CLI client using the Vapor web framework. |
| 22 | +- [hello-world-urlsession-client-example](./hello-world-urlsession-client-example) - A CLI client using the [URLSession](https://developer.apple.com/documentation/foundation/urlsession) API. |
| 23 | +- [hello-world-async-http-client-example](./hello-world-async-http-client-example) - A CLI client using the [AsyncHTTPClient](https://github.com/swift-server/async-http-client) library. |
| 24 | +- [hello-world-vapor-server-example](./hello-world-vapor-server-example) - A CLI server using the [Vapor](https://github.com/vapor/vapor) web framework. |
| 25 | +- [hello-world-hummingbird-server-example](./hello-world-hummingbird-server-example) - A CLI server using the [Hummingbird](https://github.com/hummingbird-project/hummingbird) web framework. |
| 26 | +- [HelloWorldiOSClientAppExample](./HelloWorldiOSClientAppExample) - An iOS client SwiftUI app with a mock server for unit and UI tests. |
19 | 27 | - [curated-client-library-example](./curated-client-library-example) - A library that hides the generated API and exports a hand-written interface, allowing decoupled versioning.
|
20 |
| -- [HelloWorldiOSClientAppExample](./HelloWorldiOSClientAppExample) - An iOS client SwiftUI app with mock server for unit and UI tests. |
21 | 28 |
|
22 | 29 | ## Various content types
|
23 | 30 |
|
24 | 31 | The following packages show working with various content types, such as JSON, URL-encoded request bodies, plain text, raw bytes, and multipart bodies.
|
25 | 32 |
|
26 |
| -- [various-content-types-client-example](./various-content-types-client-example) - A client showing how to request and handle the various content types. |
| 33 | +- [various-content-types-client-example](./various-content-types-client-example) - A client showing how to provide and handle the various content types. |
27 | 34 | - [various-content-types-server-example](./various-content-types-server-example) - A server showing how to handle and provide the various content types.
|
28 | 35 |
|
29 | 36 | ## Integrations
|
30 | 37 |
|
31 |
| -- [swagger-ui-endpoint-example](./swagger-ui-endpoint-example) - A server with endpoints its raw OpenAPI document and Swagger UI. |
32 |
| -- [postgres-database-example](./postgres-database-example) - A server using a Postgres database for persistent state. |
33 |
| -- [command-line-client-example](./command-line-client-example) - A client with a rich CLI using Swift Argument Parser. |
| 38 | +- [swagger-ui-endpoint-example](./swagger-ui-endpoint-example) - A server with endpoints for its raw OpenAPI document and interactive documentation using [Swagger UI](https://github.com/swagger-api/swagger-ui). |
| 39 | +- [postgres-database-example](./postgres-database-example) - A server using a [Postgres](https://www.postgresql.org) database for persistent state. |
| 40 | +- [command-line-client-example](./command-line-client-example) - A client with a rich command-line interface using [Swift Argument Parser](https://github.com/apple/swift-argument-parser). |
34 | 41 |
|
35 | 42 | ## Middleware
|
36 | 43 |
|
37 |
| -- [logging-middleware-oslog-example](./logging-middleware-oslog-example) - A middleware that logs requests and responses using OSLog. |
38 |
| -- [logging-middleware-swift-log-example](./logging-middleware-swift-log-example) - A middleware that logs requests and responses using Swift Log. |
39 |
| -- [metrics-middleware-example](./metrics-middleware-example) - A middleware that collects metrics using Swift Metrics. |
40 |
| -- [tracing-middleware-example](./tracing-middleware-example) - A middleware that collects traces using Swift Distributed Tracing. |
41 |
| -- [retrying-middleware-example](./retrying-middleware-example) - A middleware that retries failed requests. |
42 |
| -- [auth-client-middleware-example](./auth-client-middleware-example) - An middleware that injects a token header. |
43 |
| -- [auth-server-middleware-example](./auth-server-middleware-example) - An middleware that inspects a token header. |
| 44 | +- [logging-middleware-oslog-example](./logging-middleware-oslog-example) - A middleware that logs requests and responses using [OSLog](https://developer.apple.com/documentation/os/oslog) (only available on Apple platforms, such as macOS, iOS, and more). |
| 45 | +- [logging-middleware-swift-log-example](./logging-middleware-swift-log-example) - A middleware that logs requests and responses using [SwiftLog](https://github.com/apple/swift-log). |
| 46 | +- [metrics-middleware-example](./metrics-middleware-example) - A middleware that collects metrics using [SwiftMetrics](https://github.com/apple/swift-metrics). |
| 47 | +- [tracing-middleware-example](./tracing-middleware-example) - A middleware that emits traces using [Swift Distributed Tracing](https://github.com/apple/swift-distributed-tracing). |
| 48 | +- [retrying-middleware-example](./retrying-middleware-example) - A middleware that retries some failed requests. |
| 49 | +- [auth-client-middleware-example](./auth-client-middleware-example) - A middleware that injects a token header. |
| 50 | +- [auth-server-middleware-example](./auth-server-middleware-example) - A middleware that inspects a token header. |
44 | 51 |
|
45 | 52 | ## Ahead-of-time (manual) code generation
|
46 | 53 |
|
47 |
| -The recommended way to use Swift OpenAPI generator is by integrating the _build plugin_, which all of the examples above use. The build plugin generates Swift code from your OpenAPI document at build time, and you don't check in the generated code into git. |
| 54 | +The recommended way to use Swift OpenAPI generator is by integrating the _build plugin_, which all of the examples above use. The build plugin generates Swift code from your OpenAPI document at build time, and you don't check in the generated code into your git repository. |
48 | 55 |
|
49 | 56 | However, if you cannot use the build plugin, for example because you must check in your generated code, use the _command plugin_, which you trigger manually either in Xcode or on the command line. See the following example for this workflow:
|
50 | 57 |
|
51 |
| -- [manual-generation-package-plugin-example](./manual-generation-package-plugin-example) - A client using the Swift package plugin for manual code generation. |
| 58 | +- [manual-generation-package-plugin-example](./manual-generation-package-plugin-example) - A client using the Swift package command plugin for manual code generation. |
52 | 59 |
|
53 |
| -If you can't even use the command plugin, for example because your package is not allowed to depend on swift-openapi-generator directly, you can invoke the generator CLI manually from a Makefile. See the following example for this workflow: |
| 60 | +If you can't even use the command plugin, for example because your package is not allowed to depend on Swift OpenAPI Generator, you can invoke the generator CLI manually from a Makefile. See the following example for this workflow: |
54 | 61 |
|
55 | 62 | - [manual-generation-generator-cli-example](./manual-generation-generator-cli-example) - A client using the `swift-openapi-generator` CLI for manual code generation.
|
56 | 63 |
|
57 | 64 | ## Deprecated
|
58 | 65 |
|
59 | 66 | The following examples will be removed before 1.0.0 is released and is preserved for backwards compatibility with currently published tutorials that point to it.
|
60 | 67 |
|
61 |
| -- [`GreetingService`](./GreetingService) - a Vapor-based CLI server, use `HelloWorldVaporServer` instead |
62 |
| -- [`GreetingServiceClient`](./GreetingServiceClient) - a URLSession-based CLI client, use `HelloWorldURLSessionClient` instead |
| 68 | +- [`GreetingService`](./GreetingService) - A Vapor-based CLI server, use [`hello-world-vapor-server-example`](./hello-world-vapor-server-example) instead. |
| 69 | +- [`GreetingServiceClient`](./GreetingServiceClient) - A URLSession-based CLI client, use [`hello-world-urlsession-client-example`](./hello-world-urlsession-client-example) instead. |
0 commit comments