Skip to content

Commit 330771a

Browse files
authored
[Docs] Add the Examples index to the docc docs (#468)
### Motivation Copy the Examples/README.md contents to the docc docs as well, as it's a great starting point. ### Modifications Some more polish + copied the contents (and updated links) for the examples. ### Result Easier to get started with examples when landing in the docc docs. ### Test Plan Tested that all the links work.
1 parent a1b29f4 commit 330771a

File tree

5 files changed

+109
-41
lines changed

5 files changed

+109
-41
lines changed

Examples/README.md

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,69 @@
11
# Examples of using Swift OpenAPI Generator
22

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.
55

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.
87
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.
109

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:
1211

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+
```
1317

18+
## Getting started
19+
20+
Each of the following packages shows an end-to-end working example with the given transport.
1421

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.
1927
- [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.
2128

2229
## Various content types
2330

2431
The following packages show working with various content types, such as JSON, URL-encoded request bodies, plain text, raw bytes, and multipart bodies.
2532

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.
2734
- [various-content-types-server-example](./various-content-types-server-example) - A server showing how to handle and provide the various content types.
2835

2936
## Integrations
3037

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).
3441

3542
## Middleware
3643

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.
4451

4552
## Ahead-of-time (manual) code generation
4653

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.
4855

4956
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:
5057

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.
5259

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:
5461

5562
- [manual-generation-generator-cli-example](./manual-generation-generator-cli-example) - A client using the `swift-openapi-generator` CLI for manual code generation.
5663

5764
## Deprecated
5865

5966
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.
6067

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.

Examples/logging-middleware-oslog-example/Sources/HelloWorldURLSessionClient/HelloWorldURLSessionClient.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import LoggingMiddleware
2626
let response = try await client.getGreeting()
2727
print(try response.ok.body.json.message)
2828
#else //canImport(Darwin)
29-
print("This example uses OSLog, so is only supported on Darwin platforms")
29+
print("This example uses OSLog, so is only supported on Apple platforms")
3030
exit(EXIT_FAILURE)
3131
#endif //canImport(Darwin)
3232
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Checking out an example project
2+
3+
Check out a working example to learn how packages using Swift OpenAPI Generator can be structured and integrated with the ecosystem.
4+
5+
## Overview
6+
7+
The following examples show how to use and integrate Swift OpenAPI Generator with other packages in the ecosystem.
8+
9+
> Important: Many of these examples have been deliberately simplified and are intended for illustrative purposes only.
10+
11+
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.
12+
13+
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:
14+
15+
```console
16+
% git clone https://github.com/apple/swift-openapi-generator
17+
% cd swift-openapi-generator/Examples
18+
% swift run --package-path hello-world-urlsession-client-example
19+
```
20+
21+
## Getting started
22+
23+
Each of the following packages shows an end-to-end working example with the given transport.
24+
25+
- [hello-world-urlsession-client-example](https://github.com/apple/swift-openapi-generator/tree/main/Examples/hello-world-urlsession-client-example) - A CLI client using the [URLSession](https://developer.apple.com/documentation/foundation/urlsession) API.
26+
- [hello-world-async-http-client-example](https://github.com/apple/swift-openapi-generator/tree/main/Examples/hello-world-async-http-client-example) - A CLI client using the [AsyncHTTPClient](https://github.com/swift-server/async-http-client) library.
27+
- [hello-world-vapor-server-example](https://github.com/apple/swift-openapi-generator/tree/main/Examples/hello-world-vapor-server-example) - A CLI server using the [Vapor](https://github.com/vapor/vapor) web framework.
28+
- [hello-world-hummingbird-server-example](https://github.com/apple/swift-openapi-generator/tree/main/Examples/hello-world-hummingbird-server-example) - A CLI server using the [Hummingbird](https://github.com/hummingbird-project/hummingbird) web framework.
29+
- [HelloWorldiOSClientAppExample](https://github.com/apple/swift-openapi-generator/tree/main/Examples/HelloWorldiOSClientAppExample) - An iOS client SwiftUI app with a mock server for unit and UI tests.
30+
- [curated-client-library-example](https://github.com/apple/swift-openapi-generator/tree/main/Examples/curated-client-library-example) - A library that hides the generated API and exports a hand-written interface, allowing decoupled versioning.
31+
32+
## Various content types
33+
34+
The following packages show working with various content types, such as JSON, URL-encoded request bodies, plain text, raw bytes, and multipart bodies.
35+
36+
- [various-content-types-client-example](https://github.com/apple/swift-openapi-generator/tree/main/Examples/various-content-types-client-example) - A client showing how to provide and handle the various content types.
37+
- [various-content-types-server-example](https://github.com/apple/swift-openapi-generator/tree/main/Examples/various-content-types-server-example) - A server showing how to handle and provide the various content types.
38+
39+
## Integrations
40+
41+
- [swagger-ui-endpoint-example](https://github.com/apple/swift-openapi-generator/tree/main/Examples/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).
42+
- [postgres-database-example](https://github.com/apple/swift-openapi-generator/tree/main/Examples/postgres-database-example) - A server using a [Postgres](https://www.postgresql.org) database for persistent state.
43+
- [command-line-client-example](https://github.com/apple/swift-openapi-generator/tree/main/Examples/command-line-client-example) - A client with a rich command-line interface using [Swift Argument Parser](https://github.com/apple/swift-argument-parser).
44+
45+
## Middleware
46+
47+
- [logging-middleware-oslog-example](https://github.com/apple/swift-openapi-generator/tree/main/Examples/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).
48+
- [logging-middleware-swift-log-example](https://github.com/apple/swift-openapi-generator/tree/main/Examples/logging-middleware-swift-log-example) - A middleware that logs requests and responses using [SwiftLog](https://github.com/apple/swift-log).
49+
- [metrics-middleware-example](https://github.com/apple/swift-openapi-generator/tree/main/Examples/metrics-middleware-example) - A middleware that collects metrics using [SwiftMetrics](https://github.com/apple/swift-metrics).
50+
- [tracing-middleware-example](https://github.com/apple/swift-openapi-generator/tree/main/Examples/tracing-middleware-example) - A middleware that emits traces using [Swift Distributed Tracing](https://github.com/apple/swift-distributed-tracing).
51+
- [retrying-middleware-example](https://github.com/apple/swift-openapi-generator/tree/main/Examples/retrying-middleware-example) - A middleware that retries some failed requests.
52+
- [auth-client-middleware-example](https://github.com/apple/swift-openapi-generator/tree/main/Examples/auth-client-middleware-example) - A middleware that injects a token header.
53+
- [auth-server-middleware-example](https://github.com/apple/swift-openapi-generator/tree/main/Examples/auth-server-middleware-example) - A middleware that inspects a token header.
54+
55+
## Ahead-of-time (manual) code generation
56+
57+
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.
58+
59+
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:
60+
61+
- [manual-generation-package-plugin-example](https://github.com/apple/swift-openapi-generator/tree/main/Examples/manual-generation-package-plugin-example) - A client using the Swift package command plugin for manual code generation.
62+
63+
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:
64+
65+
- [manual-generation-generator-cli-example](https://github.com/apple/swift-openapi-generator/tree/main/Examples/manual-generation-generator-cli-example) - A client using the `swift-openapi-generator` CLI for manual code generation.
66+
67+
## Deprecated
68+
69+
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.
70+
71+
- [`GreetingService`](https://github.com/apple/swift-openapi-generator/tree/main/Examples/GreetingService) - A Vapor-based CLI server, use [`hello-world-vapor-server-example`](https://github.com/apple/swift-openapi-generator/tree/main/Examples/hello-world-vapor-server-example) instead.
72+
- [`GreetingServiceClient`](https://github.com/apple/swift-openapi-generator/tree/main/Examples/GreetingServiceClient) - A URLSession-based CLI client, use [`hello-world-urlsession-client-example`](https://github.com/apple/swift-openapi-generator/tree/main/Examples/hello-world-urlsession-client-example) instead.

Sources/swift-openapi-generator/Documentation.docc/Articles/Starting-with-an-example-project.md

Lines changed: 0 additions & 11 deletions
This file was deleted.

Sources/swift-openapi-generator/Documentation.docc/Swift-OpenAPI-Generator.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ The code is generated at build-time, so it's always in sync with the OpenAPI doc
1616

1717
### Getting started
1818

19-
> Tip: In a rush? Check out a working example: <doc:Starting-with-an-example-project>.
19+
> Tip: In a rush? Get started quickly by <doc:Checking-out-an-example-project>.
2020
2121
Alternatively, to integrate Swift OpenAPI Generator into your existing project, or to create a new one, follow one of our _getting started_ guides:
2222
- <doc:ClientXcode>
@@ -68,7 +68,7 @@ The generated code, runtime library, and transports are supported on more platfo
6868
## Topics
6969

7070
### Essentials
71-
- <doc:Starting-with-an-example-project>
71+
- <doc:Checking-out-an-example-project>
7272
- <doc:ClientSwiftPM>
7373
- <doc:ClientXcode>
7474
- <doc:ServerSwiftPM>

0 commit comments

Comments
 (0)