Skip to content

Commit

Permalink
Dependencies update (#10)
Browse files Browse the repository at this point in the history
## Description

<!--- 
Please include a summary of the change and which issue is fixed. Please
also include relevant motivation and context.
-->

request-dl 3.0.2
swift-docc-plugin 1.3.0
swift-openapi-runtime 1.3.2
swift 5.9

## Type of change

<!--- Please delete options that are not relevant. -->

- [x] New feature (non-breaking change which adds functionality)

## Checklist

<!--- Please delete options that are not relevant. -->

- [x] My code follows the code style of this project.
- [x] I have added tests to cover my changes.
- [x] All new and existing tests passed.

---------

Co-authored-by: brennobemoura <37243584+brennobemoura@users.noreply.github.com>
  • Loading branch information
o-nnerb and o-nnerb committed Jan 31, 2024
1 parent 812a251 commit c051acf
Show file tree
Hide file tree
Showing 8 changed files with 214 additions and 90 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/code-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
code-coverage:
uses: request-dl/.github/.github/workflows/code-coverage.yml@main
with:
xcode-version: 14.3.1
xcode-version: 15.2
platform: macOS-13
package-tests: swift-openapi-request-dlPackageTests
target: OpenAPIRequestDL
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
fail-fast: false
matrix:
platform: [macOS-latest, ubuntu-latest]
swift-version: [5.8]
swift-version: [5.9]
uses: request-dl/.github/.github/workflows/swift.yml@main
with:
swift-version: ${{ matrix.swift-version }}
Expand Down
72 changes: 54 additions & 18 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,26 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/swift-server/async-http-client",
"state" : {
"revision" : "78db67e5bf4a8543075787f228e8920097319281",
"version" : "1.18.0"
"revision" : "291438696abdd48d2a83b52465c176efbd94512b",
"version" : "1.20.1"
}
},
{
"identity" : "request-dl",
"kind" : "remoteSourceControl",
"location" : "https://github.com/request-dl/request-dl.git",
"state" : {
"revision" : "79c43ec8ce5e8ef38d4049a68e8321e4c42ad8ff",
"version" : "3.0.0"
"revision" : "75f4c68c456ddf1ba0327845e3104eaa392764fd",
"version" : "3.0.2"
}
},
{
"identity" : "swift-algorithms",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-algorithms",
"state" : {
"revision" : "f6919dfc309e7f1b56224378b11e28bab5bccc42",
"version" : "1.2.0"
}
},
{
Expand All @@ -41,8 +50,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-docc-plugin",
"state" : {
"revision" : "9b1258905c21fc1b97bf03d1b4ca12c4ec4e5fda",
"version" : "1.2.0"
"revision" : "26ac5758409154cc448d7ab82389c520fa8a8247",
"version" : "1.3.0"
}
},
{
Expand All @@ -54,31 +63,40 @@
"version" : "1.0.0"
}
},
{
"identity" : "swift-http-types",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-http-types",
"state" : {
"revision" : "12358d55a3824bd5fed310b999ea8cf83a9a1a65",
"version" : "1.0.3"
}
},
{
"identity" : "swift-log",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-log.git",
"state" : {
"revision" : "32e8d724467f8fe623624570367e3d50c5638e46",
"version" : "1.5.2"
"revision" : "e97a6fcb1ab07462881ac165fdbb37f067e205d5",
"version" : "1.5.4"
}
},
{
"identity" : "swift-nio",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio.git",
"state" : {
"revision" : "6213ba7a06febe8fef60563a4a7d26a4085783cf",
"version" : "2.54.0"
"revision" : "635b2589494c97e48c62514bc8b37ced762e0a62",
"version" : "2.63.0"
}
},
{
"identity" : "swift-nio-extras",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-extras.git",
"state" : {
"revision" : "0e0d0aab665ff1a0659ce75ac003081f2b1c8997",
"version" : "1.19.0"
"revision" : "363da63c1966405764f380c627409b2f9d9e710b",
"version" : "1.21.0"
}
},
{
Expand All @@ -95,26 +113,44 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-ssl.git",
"state" : {
"revision" : "e866a626e105042a6a72a870c88b4c531ba05f83",
"version" : "2.24.0"
"revision" : "7c381eb6083542b124a6c18fae742f55001dc2b5",
"version" : "2.26.0"
}
},
{
"identity" : "swift-nio-transport-services",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-transport-services.git",
"state" : {
"revision" : "41f4098903878418537020075a4d8a6e20a0b182",
"version" : "1.17.0"
"revision" : "6cbe0ed2b394f21ab0d46b9f0c50c6be964968ce",
"version" : "1.20.1"
}
},
{
"identity" : "swift-numerics",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-numerics.git",
"state" : {
"revision" : "0a5bc04095a675662cf24757cc0640aa2204253b",
"version" : "1.0.2"
}
},
{
"identity" : "swift-openapi-runtime",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-openapi-runtime",
"state" : {
"revision" : "e81f70f2a8b445224dc6b97d0c31ed0d190e04de",
"version" : "0.1.4"
"revision" : "76951d77a0609599d2dc233e7e40808a74767c6a",
"version" : "1.3.2"
}
},
{
"identity" : "swift-system",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-system.git",
"state" : {
"revision" : "025bcb1165deab2e20d4eaba79967ce73013f496",
"version" : "1.2.1"
}
}
],
Expand Down
8 changes: 4 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version: 5.8
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand All @@ -15,15 +15,15 @@ let package = Package(
dependencies: [
.package(
url: "https://github.com/request-dl/request-dl.git",
from: "3.0.0"
from: "3.0.2"
),
.package(
url: "https://github.com/apple/swift-openapi-runtime",
from: "0.1.4"
from: "1.3.2"
),
.package(
url: "https://github.com/apple/swift-docc-plugin",
from: "1.2.0"
from: "1.3.0"
)
],
targets: [
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ add the following dependency to your Package.swift file:

```swift
dependencies: [
.package(url: "https://github.com/request-dl/swift-openapi-request-dl.git", from: "0.1.1")
.package(url: "https://github.com/request-dl/swift-openapi-request-dl.git", from: "1.0.0")
]
```

Expand Down
67 changes: 54 additions & 13 deletions Sources/OpenAPIRequestDL/OpenAPIRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,74 @@
*/

import OpenAPIRuntime
import HTTPTypes
import RequestDL
import Foundation

struct OpenAPIRequest: Property {

let request: OpenAPIRuntime.Request
let baseURL: URL
let request: HTTPRequest
let httpBody: HTTPBody?

var body: some Property {
if let data = request.body {
Payload(data: data)
if let urlComponents {
if let host = urlComponents.host {
if let scheme = urlComponents.scheme {
BaseURL(.init(scheme), host: host)
} else {
BaseURL(host)
}
}

if !urlComponents.path.isEmpty {
Path(urlComponents.path)
}

if let queries = urlComponents.queryItems {
PropertyForEach(queries, id: \.self) { query in
Query(name: query.name, value: query.value)
}
}
}

AsyncProperty {
if let data = try await data {
Payload(data: data)
}
}

if let query = request.query {
Path(request.path + (query.hasPrefix("?") ? query : "?\(query)"))
} else {
Path(request.path)
RequestMethod(.init(request.method.rawValue))

PropertyForEach(request.headerFields.enumerated(), id: \.1) { (offset, header) in
CustomHeader(name: header.name.rawName, value: header.value)
.headerStrategy(offset == .zero ? .setting : .adding)
.headerSeparator(header.name == .cookie ? ";" : ",")
}
}

RequestMethod(.init(request.method.name))
private var urlComponents: URLComponents? {
URLComponents(string: baseURL.absoluteString).flatMap { baseComponents in
URLComponents(string: request.path ?? "").map {
var baseComponents = baseComponents
baseComponents.percentEncodedPath += $0.percentEncodedPath
baseComponents.percentEncodedQuery = $0.percentEncodedQuery
return baseComponents
}
}
}

let headers = HTTPHeaders(request.headerFields.map { ($0.name, $0.value) })
private var data: Data? {
get async throws {
guard let httpBody else {
return nil
}

PropertyForEach(headers.names, id: \.self) { name in
PropertyForEach((headers[name] ?? []).enumerated(), id: \.offset) { offset, value in
CustomHeader(name: name, value: value)
.headerStrategy(offset == .zero ? .setting : .adding)
var data = Data()
for try await bytes in httpBody {
data.append(contentsOf: bytes)
}
return data
}
}
}
54 changes: 31 additions & 23 deletions Sources/OpenAPIRequestDL/RequestDLClientTransport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import OpenAPIRuntime
import RequestDL
import Foundation
import HTTPTypes

/**
A `ClientTransport` that utilizes `RequestDL` to execute HTTP requests.
Expand Down Expand Up @@ -87,39 +88,46 @@ public struct RequestDLClientTransport: ClientTransport {
// MARK: - Public methods

public func send(
_ request: OpenAPIRuntime.Request,
_ request: HTTPRequest,
body: HTTPBody?,
baseURL: URL,
operationID: String
) async throws -> OpenAPIRuntime.Response {

let scheme = baseURL.scheme ?? "http"
let url = baseURL.absoluteString.replacingOccurrences(
of: scheme + "://",
with: ""
)
var components = url.split(separator: "/")
let baseURL = components.removeFirst()

) async throws -> (HTTPResponse, HTTPBody?) {
let response = try await task(AnyProperty(
PropertyGroup {
content

BaseURL(.init(scheme), host: String(baseURL))
PropertyForEach(components, id: \.self) {
Path($0)
}

OpenAPIRequest(request: request)
OpenAPIRequest(
baseURL: baseURL,
request: request,
httpBody: body
)
}
))
.result()

return .init(
statusCode: Int(response.head.status.code),
headerFields: response.head.headers.map {
.init(name: $0, value: $1)
},
body: response.payload
var headers = HTTPFields()
for header in response.head.headers {
if let name = HTTPField.Name(header.name) {
headers.append(HTTPField(
name: name,
value: header.value
))
}
}

return (
HTTPResponse(
status: HTTPResponse.Status(
integerLiteral: Int(response.head.status.code)
),
headerFields: headers
),
HTTPBody(
response.payload,
length: .known(Int64(response.payload.count)),
iterationBehavior: .multiple
)
)
}
}

0 comments on commit c051acf

Please sign in to comment.