Skip to content

Commit 343cdf4

Browse files
authored
Fix documentation and add support for CI-ing it (#679)
* Fix documentation and add support for CI-ing it * Fixup license header
1 parent 91b2640 commit 343cdf4

11 files changed

+61
-17
lines changed

Sources/AsyncHTTPClient/AsyncAwait/HTTPClientResponse.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ extension HTTPClientResponse {
8787
self.storage = storage
8888
}
8989

90-
/// Accumulates `Body` of ``ByteBuffer``s into a single ``ByteBuffer``.
90+
/// Accumulates `Body` of `ByteBuffer`s into a single `ByteBuffer`.
9191
/// - Parameters:
9292
/// - maxBytes: The maximum number of bytes this method is allowed to accumulate
9393
/// - Throws: `NIOTooManyBytesError` if the the sequence contains more than `maxBytes`.

Sources/AsyncHTTPClient/Docs.docc/index.md

+15-13
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
This package provides simple HTTP Client library built on top of SwiftNIO.
44

5+
## Overview
6+
57
This library provides the following:
68
- First class support for Swift Concurrency (since version 1.9.0)
79
- Asynchronous and non-blocking request methods
@@ -17,7 +19,7 @@ This library provides the following:
1719

1820
---
1921

20-
## Getting Started
22+
### Getting Started
2123

2224
#### Adding the dependency
2325

@@ -71,13 +73,13 @@ httpClient.get(url: "https://apple.com/").whenComplete { result in
7173
}
7274
```
7375

74-
You should always shut down ``HTTPClient`` instances you created using ``HTTPClient/shutdown()-96ayw()``. Please note that you must not call ``HTTPClient/shutdown()-96ayw()`` before all requests of the HTTP client have finished, or else the in-flight requests will likely fail because their network connections are interrupted.
76+
You should always shut down ``HTTPClient`` instances you created using ``HTTPClient/shutdown()-9gcpw``. Please note that you must not call ``HTTPClient/shutdown()-9gcpw`` before all requests of the HTTP client have finished, or else the in-flight requests will likely fail because their network connections are interrupted.
7577

76-
### async/await examples
78+
#### async/await examples
7779

7880
Examples for the async/await API can be found in the [`Examples` folder](https://github.com/swift-server/async-http-client/tree/main/Examples) in the repository.
7981

80-
## Usage guide
82+
### Usage guide
8183

8284
The default HTTP Method is `GET`. In case you need to have more control over the method, or you want to add headers or body, use the ``HTTPClientRequest`` struct:
8385

@@ -134,14 +136,14 @@ httpClient.execute(request: request).whenComplete { result in
134136
}
135137
```
136138

137-
### Redirects following
139+
#### Redirects following
138140
Enable follow-redirects behavior using the client configuration:
139141
```swift
140142
let httpClient = HTTPClient(eventLoopGroupProvider: .createNew,
141143
configuration: HTTPClient.Configuration(followRedirects: true))
142144
```
143145

144-
### Timeouts
146+
#### Timeouts
145147
Timeouts (connect and read) can also be set using the client configuration:
146148
```swift
147149
let timeout = HTTPClient.Configuration.Timeout(connect: .seconds(1), read: .seconds(1))
@@ -153,11 +155,11 @@ or on a per-request basis:
153155
httpClient.execute(request: request, deadline: .now() + .milliseconds(1))
154156
```
155157

156-
### Streaming
158+
#### Streaming
157159
When dealing with larger amount of data, it's critical to stream the response body instead of aggregating in-memory.
158160
The following example demonstrates how to count the number of bytes in a streaming response body:
159161

160-
#### Using Swift Concurrency
162+
##### Using Swift Concurrency
161163
```swift
162164
let httpClient = HTTPClient(eventLoopGroupProvider: .createNew)
163165
do {
@@ -189,7 +191,7 @@ do {
189191
try await httpClient.shutdown()
190192
```
191193

192-
#### Using HTTPClientResponseDelegate and SwiftNIO EventLoopFuture
194+
##### Using HTTPClientResponseDelegate and SwiftNIO EventLoopFuture
193195

194196
```swift
195197
import NIOCore
@@ -251,7 +253,7 @@ httpClient.execute(request: request, delegate: delegate).futureResult.whenSucces
251253
}
252254
```
253255

254-
### File downloads
256+
#### File downloads
255257

256258
Based on the `HTTPClientResponseDelegate` example above you can build more complex delegates,
257259
the built-in `FileDownloadDelegate` is one of them. It allows streaming the downloaded data
@@ -280,7 +282,7 @@ client.execute(request: request, delegate: delegate).futureResult
280282
}
281283
```
282284

283-
### Unix Domain Socket Paths
285+
#### Unix Domain Socket Paths
284286
Connecting to servers bound to socket paths is easy:
285287
```swift
286288
let httpClient = HTTPClient(eventLoopGroupProvider: .createNew)
@@ -314,7 +316,7 @@ let secureSocketPathBasedURL = URL(
314316
)
315317
```
316318

317-
### Disabling HTTP/2
319+
#### Disabling HTTP/2
318320
The exclusive use of HTTP/1 is possible by setting ``HTTPClient/Configuration/httpVersion-swift.property`` to ``HTTPClient/Configuration/HTTPVersion-swift.struct/http1Only`` on the ``HTTPClient/Configuration``:
319321
```swift
320322
var configuration = HTTPClient.Configuration()
@@ -325,7 +327,7 @@ let client = HTTPClient(
325327
)
326328
```
327329

328-
## Security
330+
### Security
329331

330332
AsyncHTTPClient's security process is documented on [GitHub](https://github.com/swift-server/async-http-client/blob/main/SECURITY.md).
331333

Sources/AsyncHTTPClient/HTTPClient.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ public class HTTPClient {
228228
/// Shuts down the ``HTTPClient`` and releases its resources.
229229
///
230230
/// - note: You cannot use this method if you sharted the ``HTTPClient`` with
231-
/// ``init(eventLoopGroupProvider: .createNew)`` because that will shut down the ``EventLoopGroup`` the
231+
/// `init(eventLoopGroupProvider: .createNew)` because that will shut down the `EventLoopGroup` the
232232
/// returned future would run in.
233233
public func shutdown() -> EventLoopFuture<Void> {
234234
switch self.eventLoopGroupProvider {

Sources/AsyncHTTPClient/HTTPHandler.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ public final class ResponseAccumulator: HTTPClientResponseDelegate {
388388
/// until it will abort the request and throw an ``ResponseTooBigError``.
389389
///
390390
/// Default is 2^32.
391-
/// - precondition: not allowed to exceed 2^32 because ``ByteBuffer`` can not store more bytes
391+
/// - precondition: not allowed to exceed 2^32 because `ByteBuffer` can not store more bytes
392392
public let maxBodySize: Int
393393

394394
public convenience init(request: HTTPClient.Request) {
@@ -400,7 +400,7 @@ public final class ResponseAccumulator: HTTPClientResponseDelegate {
400400
/// - maxBodySize: Maximum size in bytes of the HTTP response body that ``ResponseAccumulator`` will accept
401401
/// until it will abort the request and throw an ``ResponseTooBigError``.
402402
/// Default is 2^32.
403-
/// - precondition: maxBodySize is not allowed to exceed 2^32 because ``ByteBuffer`` can not store more bytes
403+
/// - precondition: maxBodySize is not allowed to exceed 2^32 because `ByteBuffer` can not store more bytes
404404
/// - warning: You can use ``ResponseAccumulator`` for just one request.
405405
/// If you start another request, you need to initiate another ``ResponseAccumulator``.
406406
public init(request: HTTPClient.Request, maxBodySize: Int) {

docker/docker-compose.2004.55.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ services:
99
ubuntu_version: "focal"
1010
swift_version: "5.5"
1111

12+
documentation-check:
13+
image: async-http-client:20.04-5.5
14+
1215
test:
1316
image: async-http-client:20.04-5.5
1417
command: /bin/bash -xcl "swift test --parallel -Xswiftc -warnings-as-errors $${SANITIZER_ARG-}"

docker/docker-compose.2004.56.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ services:
99
ubuntu_version: "focal"
1010
swift_version: "5.6"
1111

12+
documentation-check:
13+
image: async-http-client:20.04-5.6
14+
1215
test:
1316
image: async-http-client:20.04-5.6
1417
environment: []

docker/docker-compose.2204.57.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ services:
99
ubuntu_version: "jammy"
1010
swift_version: "5.7"
1111

12+
documentation-check:
13+
image: async-http-client:22.04-5.7
14+
1215
test:
1316
image: async-http-client:22.04-5.7
1417
environment: []

docker/docker-compose.2204.58.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ services:
88
args:
99
base_image: "swiftlang/swift:nightly-5.8-jammy"
1010

11+
documentation-check:
12+
image: async-http-client:22.04-5.8
13+
1114
test:
1215
image: async-http-client:22.04-5.8
1316
environment:

docker/docker-compose.2204.main.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ services:
88
args:
99
base_image: "swiftlang/swift:nightly-main-jammy"
1010

11+
documentation-check:
12+
image: async-http-client:22.04-main
13+
1114
test:
1215
image: async-http-client:22.04-main
1316
environment:

docker/docker-compose.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ services:
2626
<<: *common
2727
command: /bin/bash -xcl "./scripts/soundness.sh"
2828

29+
documentation-check:
30+
<<: *common
31+
command: /bin/bash -xcl "./scripts/check-docs.sh"
32+
2933
test:
3034
<<: *common
3135
command: /bin/bash -xcl "swift test --parallel -Xswiftc -warnings-as-errors --enable-test-discovery $${SANITIZER_ARG-} $${IMPORT_CHECK_ARG-}"

scripts/check-docs.sh

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
##===----------------------------------------------------------------------===##
3+
##
4+
## This source file is part of the AsyncHTTPClient open source project
5+
##
6+
## Copyright (c) 2023 Apple Inc. and the AsyncHTTPClient project authors
7+
## Licensed under Apache License v2.0
8+
##
9+
## See LICENSE.txt for license information
10+
## See CONTRIBUTORS.txt for the list of AsyncHTTPClient project authors
11+
##
12+
## SPDX-License-Identifier: Apache-2.0
13+
##
14+
##===----------------------------------------------------------------------===##
15+
16+
set -eu
17+
18+
raw_targets=$(sed -E -n -e 's/^.* - documentation_targets: \[(.*)\].*$/\1/p' .spi.yml)
19+
targets=(${raw_targets//,/ })
20+
21+
for target in "${targets[@]}"; do
22+
swift package plugin generate-documentation --target "$target" --warnings-as-errors --analyze --level detailed
23+
done

0 commit comments

Comments
 (0)