Skip to content

Commit

Permalink
Add Swift Open Api generated methods
Browse files Browse the repository at this point in the history
  • Loading branch information
aromanov91 committed Sep 24, 2023
1 parent 68929c5 commit fef55de
Show file tree
Hide file tree
Showing 10 changed files with 455 additions and 164 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ DerivedData/
.swiftpm/config/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
/Package.resolved
48 changes: 24 additions & 24 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/hmlongco/Factory.git",
"state" : {
"revision" : "bf4e0ab7cfc45a921856d9ca196d834b7abf15a0",
"version" : "2.1.5"
"revision" : "061b3afe0358a0da7ce568f8272c847910be3dd7",
"version" : "2.2.0"
}
},
{
"identity" : "openapikit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/mattpolzin/OpenAPIKit.git",
"state" : {
"revision" : "84f6702500fb00476d74420c1a0df64cddd3993e",
"version" : "3.0.0-alpha.7"
"revision" : "beca680cef9ea622d39b42187baa9ce77b89865a",
"version" : "3.0.0-beta.5"
}
},
{
"identity" : "oversizecore",
"kind" : "remoteSourceControl",
"location" : "https://github.com/oversizedev/OversizeCore.git",
"state" : {
"revision" : "a248ebced6edae54b75d0e19d6f9d121be9e0810",
"version" : "1.4.0"
"revision" : "988deea848fb80612858b8a0036b51e919064abf",
"version" : "1.8.1"
}
},
{
Expand All @@ -41,17 +41,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/oversizedev/OversizeServices.git",
"state" : {
"revision" : "247aac3a109da879b1b57ab5661ca08998ba0e27",
"version" : "1.6.0"
"revision" : "2553d37f66d1e619a36410c3d63afc7ad3b99976",
"version" : "1.8.2"
}
},
{
"identity" : "oversizeui",
"kind" : "remoteSourceControl",
"location" : "https://github.com/oversizedev/OversizeUI.git",
"state" : {
"revision" : "c7a305332c81c3be2ce34d7d928f79d43b50be74",
"version" : "3.0.6"
"revision" : "89a07072b2def7ba9948c532f0259f1dfb60f97e",
"version" : "3.2.0"
}
},
{
Expand All @@ -68,8 +68,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-argument-parser.git",
"state" : {
"revision" : "fee6933f37fde9a5e12a1e4aeaa93fe60116ff2a",
"version" : "1.2.2"
"revision" : "8f4d2753f0e4778c76d5f05ad16c74f707390531",
"version" : "1.2.3"
}
},
{
Expand All @@ -95,26 +95,26 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-openapi-generator",
"state" : {
"revision" : "1c07b5d805dec7f0e12d402d3da3413d59309bb6",
"version" : "0.1.3"
"revision" : "7da0f96bba4f40bec50273723e586c77f6323d6b",
"version" : "0.2.2"
}
},
{
"identity" : "swift-openapi-runtime",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-openapi-runtime",
"state" : {
"revision" : "e81f70f2a8b445224dc6b97d0c31ed0d190e04de",
"version" : "0.1.4"
"revision" : "5f7e7ee6862fcda793d16d8b5bf8d204503f161f",
"version" : "0.2.3"
}
},
{
"identity" : "swift-openapi-urlsession",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-openapi-urlsession",
"state" : {
"revision" : "12cece2055fa3dbd20729eaf561a12af7b6fca7a",
"version" : "0.1.1"
"revision" : "8d34af5db44be4825749259dbb38e5e11a4c48da",
"version" : "0.2.2"
}
},
{
Expand All @@ -131,26 +131,26 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-system.git",
"state" : {
"revision" : "836bc4557b74fe6d2660218d56e3ce96aff76574",
"version" : "1.1.1"
"revision" : "025bcb1165deab2e20d4eaba79967ce73013f496",
"version" : "1.2.1"
}
},
{
"identity" : "swift-tools-support-core",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-tools-support-core.git",
"state" : {
"revision" : "93784c59434dbca8e8a9e4b700d0d6d94551da6a",
"version" : "0.5.2"
"revision" : "3b13e439a341bbbfe0f710c7d1be37221745ef1a",
"version" : "0.6.1"
}
},
{
"identity" : "yams",
"kind" : "remoteSourceControl",
"location" : "https://github.com/jpsim/Yams.git",
"state" : {
"revision" : "9ff1cc9327586db4e0c8f46f064b6a82ec1566fa",
"version" : "4.0.6"
"revision" : "0d9ee7ea8c4ebd4a489ad7a73d5c6cad55d6fed3",
"version" : "5.0.6"
}
}
],
Expand Down
53 changes: 26 additions & 27 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
// swift-tools-version: 5.8
// The swift-tools-version declares the minimum version of Swift required to build this package.

private extension PackageDescription.Target.Dependency {
static let openAPIRuntime: Self = .product(name: "OpenAPIRuntime", package: "swift-openapi-runtime")
static let openAPIURLSession: Self = .product(name: "OpenAPIURLSession", package: "swift-openapi-urlsession")
static let factory: Self = .product(name: "Factory", package: "Factory")
static let oversizeServices: Self = .product(name: "OversizeServices", package: "OversizeServices")
}

private extension PackageDescription.Target.PluginUsage {
static let openAPIGenerator: Self = .plugin(name: "OpenAPIGenerator", package: "swift-openapi-generator")
}

import PackageDescription

let package = Package(
Expand All @@ -9,43 +20,31 @@ let package = Package(
.macOS(.v12), .iOS(.v15), .tvOS(.v15), .watchOS(.v8),
],
products: [
.executable(name: "OversizeNetwork", targets: ["OversizeNetwork"]),
.library(
name: "OversizeNetwork",
targets: ["OversizeNetwork"]
),
],
dependencies: [
.package(url: "https://github.com/apple/swift-openapi-generator", .upToNextMinor(from: "0.1.0")),
.package(url: "https://github.com/apple/swift-openapi-runtime", .upToNextMinor(from: "0.1.0")),
.package(url: "https://github.com/apple/swift-openapi-urlsession", .upToNextMinor(from: "0.1.0")),
.package(url: "https://github.com/apple/swift-openapi-generator", .upToNextMinor(from: "0.2.0")),
.package(url: "https://github.com/apple/swift-openapi-runtime", .upToNextMinor(from: "0.2.0")),
.package(url: "https://github.com/apple/swift-openapi-urlsession", .upToNextMinor(from: "0.2.0")),
.package(url: "https://github.com/hmlongco/Factory.git", .upToNextMajor(from: "2.1.3")),
.package(url: "https://github.com/oversizedev/OversizeServices.git", .upToNextMajor(from: "1.4.0")),
],
targets: [
.executableTarget(
.target(
name: "OversizeNetwork",
dependencies: [
.product(
name: "OpenAPIRuntime",
package: "swift-openapi-runtime"
),
.product(
name: "OpenAPIURLSession",
package: "swift-openapi-urlsession"
),
.product(
name: "Factory",
package: "Factory"
),
.product(
name: "OversizeServices",
package: "OversizeServices"
),
.openAPIRuntime,
.openAPIURLSession,
.factory,
.oversizeServices,
],
path: "Sources",
path: "./Sources/OversizeNetwork/Repositories",
plugins: [
.plugin(
name: "OpenAPIGenerator",
package: "swift-openapi-generator"
)
.openAPIGenerator,
]
)
),
]
)
38 changes: 0 additions & 38 deletions Sources/OversizeNetwork/NetworkService.swift

This file was deleted.

91 changes: 91 additions & 0 deletions Sources/OversizeNetwork/Repositories/NetworkService.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
//
// Copyright © 2023 Alexander Romanov
// NetworkService.swift, created on 30.06.2023
//
import OpenAPIURLSession
import OversizeServices

public struct NetworkService {
let client = Client(
serverURL: try! Servers.server1(),
transport: URLSessionTransport()
)

public init() {}

public func fetchApps() async -> Result<[Components.Schemas.AppShort], AppError> {
do {
let response = try await client.fetchApps(.init())
switch response {
case let .ok(okResponse):
switch okResponse.body {
case let .json(apps):
return .success(apps)
}
case .undocumented:
return .failure(.network(type: .unexpectedStatusCode))
case .notFound:
return .failure(.network(type: .invalidURL))
}
} catch {
return .failure(.network(type: .unknown))
}
}

public func fetchInfo() async -> Result<Components.Schemas.Info, AppError> {
do {
let response = try await client.fetchInfo(.init())
switch response {
case let .ok(okResponse):
switch okResponse.body {
case let .json(info):
return .success(info)
}
case .undocumented:
return .failure(.network(type: .unexpectedStatusCode))
case .notFound:
return .failure(.network(type: .invalidURL))
}
} catch {
return .failure(.network(type: .unknown))
}
}

public func fetchAppById(appId: String) async -> Result<Components.Schemas.AppDetail, AppError> {
do {
let response = try await client.fetchAppById(.init(path: .init(appId: appId)))
switch response {
case let .ok(okResponse):
switch okResponse.body {
case let .json(info):
return .success(info)
}
case .undocumented:
return .failure(.network(type: .unexpectedStatusCode))
case .notFound:
return .failure(.network(type: .invalidURL))
}
} catch {
return .failure(.network(type: .unknown))
}
}

public func fetchAds() async -> Result<[Components.Schemas.Ad], AppError> {
do {
let response = try await client.fetchAds(.init())
switch response {
case let .ok(okResponse):
switch okResponse.body {
case let .json(ads):
return .success(ads)
}
case .undocumented:
return .failure(.network(type: .unexpectedStatusCode))
case .notFound:
return .failure(.network(type: .invalidURL))
}
} catch {
return .failure(.network(type: .unknown))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@

import Factory
import Foundation
import OversizeServices

public extension Container {
var networkService: Factory<NetworkService> {
self { NetworkService() }
}
}

File renamed without changes.
Loading

0 comments on commit fef55de

Please sign in to comment.