Skip to content

Commit 4b0b0b8

Browse files
committed
Merge branch 'hd-mime-type-params' of github.com:czechboy0/swift-openapi-runtime into hd-mime-type-params
2 parents 6604f96 + 0950840 commit 4b0b0b8

35 files changed

+444
-645
lines changed

.github/workflows/pull_request.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: PR
2+
3+
on:
4+
pull_request:
5+
types: [opened, reopened, synchronize]
6+
7+
jobs:
8+
soundness:
9+
name: Soundness
10+
uses: apple/swift-nio/.github/workflows/soundness.yml@main
11+
with:
12+
api_breakage_check_enabled: true
13+
broken_symlink_check_enabled: true
14+
docs_check_enabled: true
15+
format_check_enabled: true
16+
license_header_check_enabled: true
17+
license_header_check_project_name: "SwiftOpenAPIGenerator"
18+
shell_check_enabled: true
19+
unacceptable_language_check_enabled: true
20+
21+
unit-tests:
22+
name: Unit tests
23+
uses: apple/swift-nio/.github/workflows/unit_tests.yml@main
24+
with:
25+
linux_5_8_enabled: false
26+
linux_5_9_arguments_override: "--explicit-target-dependency-import-check error"
27+
linux_5_10_arguments_override: "--explicit-target-dependency-import-check error"
28+
linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error"
29+
linux_nightly_main_enabled: false
30+
31+
integration-test:
32+
name: Integration test
33+
uses: apple/swift-nio/.github/workflows/swift_matrix.yml@main
34+
with:
35+
name: "Integration test"
36+
matrix_linux_command: "apt-get update -yq && apt-get install -yq jq && ./scripts/run-integration-test.sh"
37+
matrix_linux_5_8_enabled: false
38+
matrix_linux_nightly_main_enabled: false
39+
40+
swift-6-language-mode:
41+
name: Swift 6 Language Mode
42+
uses: apple/swift-nio/.github/workflows/swift_6_language_mode.yml@main
43+
if: false # Disabled for now.

.github/workflows/scheduled.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Scheduled
2+
3+
on:
4+
schedule:
5+
- cron: "0 8,20 * * *"
6+
7+
jobs:
8+
unit-tests:
9+
name: Unit tests
10+
uses: apple/swift-nio/.github/workflows/unit_tests.yml@main
11+
with:
12+
linux_5_8_enabled: false
13+
linux_5_9_arguments_override: "--explicit-target-dependency-import-check error"
14+
linux_5_10_arguments_override: "--explicit-target-dependency-import-check error"
15+
linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error"
16+
linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error"
17+
18+
integration-test:
19+
name: Integration test
20+
uses: apple/swift-nio/.github/workflows/swift_matrix.yml@main
21+
with:
22+
name: "Integration test"
23+
matrix_linux_command: "apt-get update -yq && apt-get install -yq jq && ./scripts/run-integration-test.sh"
24+
matrix_linux_5_8_enabled: false

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ xcuserdata/
66
DerivedData/
77
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
88
.vscode
9-
/Package.resolved
9+
Package.resolved
1010
.ci/
1111
.docc-build/
1212
.swiftpm

.licenseignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.gitignore
2+
.licenseignore
3+
.swiftformatignore
4+
.spi.yml
5+
.swift-format
6+
.github/
7+
**.md
8+
**.txt
9+
**Package.swift
10+
docker/*

.swiftformatignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**Package.swift
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the SwiftOpenAPIGenerator open source project
4+
//
5+
// Copyright (c) 2024 Apple Inc. and the SwiftOpenAPIGenerator project authors
6+
// Licensed under Apache License v2.0
7+
//
8+
// See LICENSE.txt for license information
9+
// See CONTRIBUTORS.txt for the list of SwiftOpenAPIGenerator project authors
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
import Benchmark
15+
import OpenAPIRuntime
16+
import Foundation
17+
18+
let benchmarks = {
19+
let defaultMetrics: [BenchmarkMetric] = [.mallocCountTotal, .cpuTotal]
20+
21+
Benchmark(
22+
"ISO8601DateTranscoder.encode(_:)",
23+
configuration: Benchmark.Configuration(
24+
metrics: defaultMetrics,
25+
scalingFactor: .kilo,
26+
maxDuration: .seconds(10_000_000),
27+
maxIterations: 5
28+
)
29+
) { benchmark in
30+
let transcoder = ISO8601DateTranscoder()
31+
benchmark.startMeasurement()
32+
for _ in benchmark.scaledIterations { blackHole(try transcoder.encode(.distantFuture)) }
33+
}
34+
35+
Benchmark(
36+
"ISO8601DateFormatter.string(from:)",
37+
configuration: Benchmark.Configuration(
38+
metrics: defaultMetrics,
39+
scalingFactor: .kilo,
40+
maxDuration: .seconds(10_000_000),
41+
maxIterations: 5
42+
)
43+
) { benchmark in
44+
let formatter = ISO8601DateFormatter()
45+
benchmark.startMeasurement()
46+
for _ in benchmark.scaledIterations { blackHole(formatter.string(from: .distantFuture)) }
47+
}
48+
49+
Benchmark(
50+
"Date.ISO8601Format(_:)",
51+
configuration: Benchmark.Configuration(
52+
metrics: defaultMetrics,
53+
scalingFactor: .kilo,
54+
maxDuration: .seconds(10_000_000),
55+
maxIterations: 5
56+
)
57+
) { benchmark in
58+
benchmark.startMeasurement()
59+
for _ in benchmark.scaledIterations { blackHole(Date.distantFuture.ISO8601Format()) }
60+
}
61+
}

Benchmarks/Package.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// swift-tools-version: 5.9
2+
import PackageDescription
3+
4+
let package = Package(
5+
name: "swift-openapi-runtime-benchmarks",
6+
platforms: [ .macOS("14") ],
7+
dependencies: [
8+
.package(name: "swift-openapi-runtime", path: "../"),
9+
.package(url: "https://github.com/ordo-one/package-benchmark.git", from: "1.22.0"),
10+
],
11+
targets: [
12+
.executableTarget(
13+
name: "OpenAPIRuntimeBenchmarks",
14+
dependencies: [
15+
.product(name: "Benchmark", package: "package-benchmark"),
16+
.product(name: "OpenAPIRuntime", package: "swift-openapi-runtime"),
17+
],
18+
path: "Benchmarks/OpenAPIRuntimeBenchmarks",
19+
plugins: [
20+
.plugin(name: "BenchmarkPlugin", package: "package-benchmark")
21+
]
22+
),
23+
]
24+
)

CONTRIBUTING.md

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,28 +56,40 @@ A good patch is:
5656
3. Documented, adding API documentation as needed to cover new functions and properties.
5757
4. Accompanied by a great commit message, using our commit message template.
5858

59-
### Run `./scripts/soundness.sh`
59+
### Run CI checks locally
6060

61-
The scripts directory contains a [soundness.sh script](https://github.com/apple/swift-openapi-runtime/blob/main/scripts/soundness.sh)
62-
that enforces additional checks, like license headers and formatting style.
61+
You can run the Github Actions workflows locally using
62+
[act](https://github.com/nektos/act). To run all the jobs that run on a pull
63+
request, use the following command:
6364

64-
Please make sure to `./scripts/soundness.sh` before pushing a change upstream, otherwise it is likely the PR validation will fail
65-
on minor changes such as a missing `self.` or similar formatting issues.
65+
```
66+
% act pull_request
67+
```
6668

67-
For frequent contributors, we recommend adding the script as a [git pre-push hook](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks), which you can do via executing the following command in the project root directory:
69+
To run just a single job, use `workflow_call -j <job>`, and specify the inputs
70+
the job expects. For example, to run just shellcheck:
71+
72+
```
73+
% act workflow_call -j soundness --input shell_check_enabled=true
74+
```
6875

69-
```bash
70-
cat << EOF > .git/hooks/pre-push
76+
To bind-mount the working directory to the container, rather than a copy, use
77+
`--bind`. For example, to run just the formatting, and have the results
78+
reflected in your working directory:
7179

72-
if [[ -f "scripts/soundness.sh" ]]; then
73-
scripts/soundness.sh
74-
fi
75-
EOF
80+
```
81+
% act --bind workflow_call -j soundness --input format_check_enabled=true
7682
```
7783

78-
Which makes the script execute, and only allow the `git push` to complete if the check has passed.
84+
If you'd like `act` to always run with certain flags, these can be be placed in
85+
an `.actrc` file either in the current working directory or your home
86+
directory, for example:
7987

80-
In the case of formatting issues, you can then `git add` the formatting changes, and attempt the push again.
88+
```
89+
--container-architecture=linux/amd64
90+
--remote-name upstream
91+
--action-offline-mode
92+
```
8193

8294
## How to contribute your work
8395

Package.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ let package = Package(
3434
],
3535
dependencies: [
3636
.package(url: "https://github.com/apple/swift-http-types", from: "1.0.0"),
37-
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
3837
],
3938
targets: [
4039
.target(

Sources/OpenAPIRuntime/Deprecated/Deprecated.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,37 @@ extension Configuration {
5959
)
6060
}
6161
}
62+
63+
extension AsyncSequence where Element == ArraySlice<UInt8>, Self: Sendable {
64+
/// Returns another sequence that decodes each event's data as the provided type using the provided decoder.
65+
///
66+
/// Use this method if the event's `data` field is not JSON, or if you don't want to parse it using `asDecodedServerSentEventsWithJSONData`.
67+
/// - Returns: A sequence that provides the events.
68+
@available(*, deprecated, renamed: "asDecodedServerSentEvents(while:)") @_disfavoredOverload
69+
public func asDecodedServerSentEvents() -> ServerSentEventsDeserializationSequence<
70+
ServerSentEventsLineDeserializationSequence<Self>
71+
> { asDecodedServerSentEvents(while: { _ in true }) }
72+
/// Returns another sequence that decodes each event's data as the provided type using the provided decoder.
73+
///
74+
/// Use this method if the event's `data` field is JSON.
75+
/// - Parameters:
76+
/// - dataType: The type to decode the JSON data into.
77+
/// - decoder: The JSON decoder to use.
78+
/// - Returns: A sequence that provides the events with the decoded JSON data.
79+
@available(*, deprecated, renamed: "asDecodedServerSentEventsWithJSONData(of:decoder:while:)") @_disfavoredOverload
80+
public func asDecodedServerSentEventsWithJSONData<JSONDataType: Decodable>(
81+
of dataType: JSONDataType.Type = JSONDataType.self,
82+
decoder: JSONDecoder = .init()
83+
) -> AsyncThrowingMapSequence<
84+
ServerSentEventsDeserializationSequence<ServerSentEventsLineDeserializationSequence<Self>>,
85+
ServerSentEventWithJSONData<JSONDataType>
86+
> { asDecodedServerSentEventsWithJSONData(of: dataType, decoder: decoder, while: { _ in true }) }
87+
}
88+
89+
extension ServerSentEventsDeserializationSequence {
90+
/// Creates a new sequence.
91+
/// - Parameter upstream: The upstream sequence of arbitrary byte chunks.
92+
@available(*, deprecated, renamed: "init(upstream:while:)") @_disfavoredOverload public init(upstream: Upstream) {
93+
self.init(upstream: upstream, while: { _ in true })
94+
}
95+
}

0 commit comments

Comments
 (0)