Skip to content

Commit 42ad540

Browse files
authored
Merge branch 'master' into fix.golang.object.to.interface
2 parents 24f90fb + 5728ed3 commit 42ad540

23 files changed

+1583
-0
lines changed

.github/workflows/test-framework-java.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ on:
1818
jobName:
1919
description: 'job name'
2020
required: true
21+
buildCommands:
22+
description: 'build commands for generated code'
23+
required: true
2124

2225
jobs:
2326

@@ -137,6 +140,7 @@ jobs:
137140
with:
138141
path: generated/${{ env.JOB_NAME }}
139142
job-name: ${{ env.JOB_NAME }}
143+
build-commands: ${{ env.BUILD_COMMANDS }}
140144
- id: outcome
141145
run: |
142146
echo "::set-output name=build_outcome::${{ steps.build.outcome }}"
@@ -156,3 +160,4 @@ jobs:
156160
JOB_NAME: ${{ github.event.inputs.jobName }}
157161
OPTIONS: ${{ github.event.inputs.options }}
158162
SPEC_URL: ${{ github.event.inputs.specUrl }}
163+
BUILD_COMMANDS: ${{ github.event.inputs.buildCommands }}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// APIHelper.swift
2+
//
3+
// Generated by swagger-codegen
4+
// https://github.com/swagger-api/swagger-codegen
5+
//
6+
7+
import Foundation
8+
9+
public struct APIHelper {
10+
public static func rejectNil(_ source: [String:Any?]) -> [String:Any]? {
11+
let destination = source.reduce(into: [String: Any]()) { (result, item) in
12+
if let value = item.value {
13+
result[item.key] = value
14+
}
15+
}
16+
17+
if destination.isEmpty {
18+
return nil
19+
}
20+
return destination
21+
}
22+
23+
public static func rejectNilHeaders(_ source: [String:Any?]) -> [String:String] {
24+
return source.reduce(into: [String: String]()) { (result, item) in
25+
if let collection = item.value as? Array<Any?> {
26+
result[item.key] = collection.filter({ $0 != nil }).map{ "\($0!)" }.joined(separator: ",")
27+
} else if let value: Any = item.value {
28+
result[item.key] = "\(value)"
29+
}
30+
}
31+
}
32+
33+
public static func convertBoolToString(_ source: [String: Any]?) -> [String:Any]? {
34+
guard let source = source else {
35+
return nil
36+
}
37+
38+
return source.reduce(into: [String: Any](), { (result, item) in
39+
switch item.value {
40+
case let x as Bool:
41+
result[item.key] = x.description
42+
default:
43+
result[item.key] = item.value
44+
}
45+
})
46+
}
47+
48+
49+
public static func mapValuesToQueryItems(_ source: [String:Any?]) -> [URLQueryItem]? {
50+
let destination = source.filter({ $0.value != nil}).reduce(into: [URLQueryItem]()) { (result, item) in
51+
if let collection = item.value as? Array<Any?> {
52+
let value = collection.filter({ $0 != nil }).map({"\($0!)"}).joined(separator: ",")
53+
result.append(URLQueryItem(name: item.key, value: value))
54+
} else if let value = item.value {
55+
result.append(URLQueryItem(name: item.key, value: "\(value)"))
56+
}
57+
}
58+
59+
if destination.isEmpty {
60+
return nil
61+
}
62+
return destination
63+
}
64+
}
65+
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// APIs.swift
2+
//
3+
// Generated by swagger-codegen
4+
// https://github.com/swagger-api/swagger-codegen
5+
//
6+
7+
import Foundation
8+
9+
open class {{projectName}}API {
10+
public static var basePath = "{{{basePath}}}"
11+
public static var credential: URLCredential?
12+
public static var customHeaders: [String:String] = [:]
13+
public static var requestBuilderFactory: RequestBuilderFactory = AlamofireRequestBuilderFactory()
14+
}
15+
16+
open class RequestBuilder<T> {
17+
var credential: URLCredential?
18+
var headers: [String:String]
19+
public let parameters: [String:Any]?
20+
public let isBody: Bool
21+
public let method: String
22+
public let URLString: String
23+
24+
/// Optional block to obtain a reference to the request's progress instance when available.
25+
public var onProgressReady: ((Progress) -> ())?
26+
27+
required public init(method: String, URLString: String, parameters: [String:Any]?, isBody: Bool, headers: [String:String] = [:]) {
28+
self.method = method
29+
self.URLString = URLString
30+
self.parameters = parameters
31+
self.isBody = isBody
32+
self.headers = headers
33+
34+
addHeaders({{projectName}}API.customHeaders)
35+
}
36+
37+
open func addHeaders(_ aHeaders:[String:String]) {
38+
for (header, value) in aHeaders {
39+
headers[header] = value
40+
}
41+
}
42+
43+
open func execute(_ completion: @escaping (_ response: Response<T>?, _ error: Error?) -> Void) { }
44+
45+
public func addHeader(name: String, value: String) -> Self {
46+
if !value.isEmpty {
47+
headers[name] = value
48+
}
49+
return self
50+
}
51+
52+
open func addCredential() -> Self {
53+
self.credential = {{projectName}}API.credential
54+
return self
55+
}
56+
}
57+
58+
public protocol RequestBuilderFactory {
59+
func getNonDecodableBuilder<T>() -> RequestBuilder<T>.Type
60+
func getBuilder<T:Decodable>() -> RequestBuilder<T>.Type
61+
}

0 commit comments

Comments
 (0)