Skip to content

Commit

Permalink
Merge pull request #1444 from microsoft/feature/swift
Browse files Browse the repository at this point in the history
swift support
  • Loading branch information
baywet authored Mar 30, 2022
2 parents 9885251 + c0e5f9a commit fb71842
Show file tree
Hide file tree
Showing 52 changed files with 1,053 additions and 44 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/abstractions-swift.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Swift abstractions

on:
workflow_dispatch:
push:
branches: [ main ]
paths: ['abstractions/swift/**', '.github/workflows/**']
pull_request:
paths: ['abstractions/swift/**', '.github/workflows/**']

jobs:
build:
runs-on: ubuntu-latest
env:
relativePath: ./abstractions/swift
steps:
- uses: actions/checkout@v3
- uses: fwal/setup-swift@v1
with:
swift-version: '5.6.0'
- name: Build SDK project
run: swift build
working-directory: ${{ env.relativePath }}
- name: Run unit tests
run: swift test
working-directory: ${{ env.relativePath }}
19 changes: 19 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,25 @@
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": "Launch Swift",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/src/kiota/bin/Debug/net6.0/kiota.dll",
"args": ["--openapi",
"https://raw.githubusercontent.com/microsoftgraph/msgraph-sdk-powershell/dev/openApiDocs/v1.0/Mail.yml",
"--language",
"swift",
"-o",
"${workspaceFolder}/samples/msgraph-mail/Swiftconsoleapp/Sources/Swiftconsoleapp",
"-n",
"Swiftconsoleapp",
"-co" ],
"cwd": "${workspaceFolder}/src/kiota",
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Adds support for 204 no content in generation and CSharp/Java/Go/TypeScript request adapters. #1410
- Added support for 204 no content in generation and CSharp/Java/Go/TypeScript request adapters. #1410
- Added a draft swift generation implementation. #1444

### Changed

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ The following table provides an overview of the languages supported by Kiota and
| Ruby | [](https://github.com/microsoft/kiota/projects/6) | [](./abstractions/ruby) | [JSON](./serialization/ruby/json/microsoft_kiota_serialization), [❌ TEXT](https://github.com/microsoft/kiota/issues/1049) | [Anonymous](./abstractions/ruby/microsoft_kiota_abstractions/lib/microsoft_kiota_abstractions/authentication/anonymous_authentication_provider.rb), [❌ Azure](https://github.com/microsoft/kiota/issues/421) | [](./http/ruby/nethttp/microsoft_kiota_nethttplibrary)| [link](https://microsoft.github.io/kiota/get-started/ruby) |
| TypeScript/JavaScript | [](https://github.com/microsoft/kiota/projects/2) | [](https://github.com/microsoft/kiota-typescript/tree/main/packages/abstractions) | [JSON](https://github.com/microsoft/kiota-typescript/tree/main/packages/serialization/json), [TEXT](https://github.com/microsoft/kiota-typescript/tree/main/packages/serialization/text) | [Anonymous](https://github.com/microsoft/kiota-typescript/blob/main/packages/abstractions/src/authentication/anonymousAuthenticationProvider.ts), [Azure](https://github.com/microsoft/kiota-typescript/tree/main/packages/authentication/azure) | [](https://github.com/microsoft/kiota-typescript/tree/main/packages/http/fetch) | [link](https://microsoft.github.io/kiota/get-started/typescript) |
| Shell | [](https://github.com/microsoft/kiota/projects/10) | [](./abstractions/dotnet), [](./cli/commonc) | [JSON](./serialization/dotnet/json), [TEXT](./serialization/dotnet/text) | [Anonymous](./abstractions/dotnet/src/authentication/AnonymousAuthenticationProvider.cs), [Azure](./authentication/dotnet/azure) | [](./http/dotnet/httpclient) | [link](https://microsoft.github.io/kiota/get-started/dotnet) |
| Swift | [](https://github.com/microsoft/kiota/issues/1449) | [](./abstractions/swift) | [❌ JSON](https://github.com/microsoft/kiota/issues/1451), [❌ TEXT](https://github.com/microsoft/kiota/issues/1452) | [Anonymous](./abstractions/swift/Source/MicrosoftKiotaAbstractions/Authentication/AnonymousAuthenticationProvider.swift), [❌ Azure](https://github.com/microsoft/kiota/issues/1453) | [](https://github.com/microsoft/kiota/issues/1454)| |

> Legend: ✔ -> in preview, ❌ -> not started, ▶ -> in progress.
Expand Down
9 changes: 9 additions & 0 deletions abstractions/swift/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.DS_Store
/.build
/Packages
/*.xcodeproj
xcuserdata/
DerivedData/
.swiftpm/config/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
20 changes: 20 additions & 0 deletions abstractions/swift/MicrosoftKiotaAbstractions.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Pod::Spec.new do |s|
s.name = "MicrosoftKiotaAbstractions"
s.version = "1.0.0"
s.summary = "MicrosoftKiotaAbstractions provides the base infrastructure for the Kiota-generated SDKs to function.
It defines multiple concepts related to abstract HTTP requests, serialization, and authentication.
These concepts can then be implemented independently without tying the SDKs to any specific implementation.
Kiota also provides default implementations for these concepts."
s.homepage = "https://github.com/microsoft/kiota"
s.license = { :type => "MIT" }
s.authors = { "Microsoft" => "[email protected]" }

s.requires_arc = true
s.swift_version = "5.0"
s.osx.deployment_target = "10.9"
s.ios.deployment_target = "9.0"
s.watchos.deployment_target = "3.0"
s.tvos.deployment_target = "9.0"
s.source = { :git => "https://github.com/microsoft/kiota.git", :tag => s.version }
s.source_files = "Source/*.swift"
end

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions abstractions/swift/Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"object": {
"pins": [
{
"package": "PathKit",
"repositoryURL": "https://github.com/kylef/PathKit.git",
"state": {
"branch": null,
"revision": "3bfd2737b700b9a36565a8c94f4ad2b050a5e574",
"version": "1.0.1"
}
},
{
"package": "Spectre",
"repositoryURL": "https://github.com/kylef/Spectre.git",
"state": {
"branch": null,
"revision": "26cc5e9ae0947092c7139ef7ba612e34646086c7",
"version": "0.10.1"
}
},
{
"package": "URITemplate",
"repositoryURL": "https://github.com/kylef/URITemplate.swift.git",
"state": {
"branch": null,
"revision": "a309673fdf86e4919a0250730e461ac533a03b3a",
"version": "3.0.1"
}
}
]
},
"version": 1
}
17 changes: 17 additions & 0 deletions abstractions/swift/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// swift-tools-version:5.0
import PackageDescription

let package = Package(
name: "MicrosoftKiotaAbstractions",
products: [
.library(name: "MicrosoftKiotaAbstractions", targets: ["MicrosoftKiotaAbstractions"])
],
dependencies: [
.package(url: "https://github.com/kylef/URITemplate.swift.git", from: "3.0.0")
],
targets: [
.target(name: "MicrosoftKiotaAbstractions", dependencies: ["URITemplate"]),
.testTarget(name: "MicrosoftKiotaAbstractionsTests", dependencies: ["MicrosoftKiotaAbstractions"])
],
swiftLanguageVersions: [.v5]
)
23 changes: 23 additions & 0 deletions abstractions/swift/Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Uncomment the next line to define a global platform for your project
platform :ios, '9.0'

target 'MicrosoftKiotaAbstractions' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!

# Pods for MicrosoftKiotaAbstractions
pod 'URITemplate'

target 'MicrosoftKiotaAbstractionsTests' do
# Pods for testing
end

end

target 'MicrosoftKiotaAbstractionsPackageDescription' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!

# Pods for MicrosoftKiotaAbstractionsPackageDescription

end
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
public class ApiClientBuilder {
private init() {

}
private static let defaultSerializationWriterFactoryInstanceIntl = SerializationWriterFactoryRegistry()
public static var defaultSerializationWriterFactoryInstance: SerializationWriterFactory {
get {
return defaultSerializationWriterFactoryInstanceIntl
}
}
public static func registerDefaultSerializer(metaFactory: () -> SerializationWriterFactory) {
let factory = metaFactory()
if let contentType = try? factory.getValidContentType() {
if contentType != "" {
defaultSerializationWriterFactoryInstanceIntl.contentTypeAssociatedFactories[contentType] = factory
}
}
}
private static let defaultParseNodeFactoryInstanceIntl = ParseNodeFactoryRegistry()
public static var defaultParseNodeFactoryInstance: ParseNodeFactory {
get {
return defaultParseNodeFactoryInstanceIntl
}
}
public static func registerDefaultParser(metaFactory: () -> ParseNodeFactory) {
let factory = metaFactory()
if let contentType = try? factory.getValidContentType() {
if contentType != "" {
defaultParseNodeFactoryInstanceIntl.contentTypeAssociatedFactories[contentType] = factory
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public enum ApiError: Error {
case unknownError(String, Any? = nil)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Foundation

public protocol AccessTokenProvider {
func getAuthenticationToken(url: URL) async throws -> String?
var allowedHostsValidator: AllowedHostsValidator { get }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import Foundation
public class AllowedHostsValidator {
private var validHostsIntl = Set<String>()
public init(validHosts: [String]) {
self.validHosts = validHosts;
}
public var validHosts: [String] { get {
return Array(validHostsIntl)

} set (validHosts) {
self.validHostsIntl = Set(validHosts.map { $0.lowercased() })
}}
public func isUrlHostValid(url: URL) -> Bool {
if let host = url.host {
return validHostsIntl.contains(host.lowercased())
}
return false
}
}
public let isSchemeHttps = { (url: URL) -> Bool in
if let scheme = url.scheme {
return scheme.lowercased() == "https"
}
return false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class AnonymousAuthenticationProvider : AuthenticationProvider {
public func authenticateRequest(request: RequestInformation) async throws {
// Do nothing
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public protocol AuthenticationProvider {
func authenticateRequest(request: RequestInformation) async throws
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
public class BaseBearerAuthenticationProvider : AuthenticationProvider {
public init (accessTokenProvider: AccessTokenProvider) {
accessTokenProviderIntl = accessTokenProvider
}
private var accessTokenProviderIntl: AccessTokenProvider
public var accessTokenProvider: AccessTokenProvider {
get {
return accessTokenProviderIntl
}
}
public let authorizationHeaderKey = "Authorization"
public let authorizationHeaderValuePrefix = "Bearer "
public func authenticateRequest(request: RequestInformation) async throws {
if request.headers[authorizationHeaderKey] == nil {
let url = try request.getUri()
let tokenResult = try? await accessTokenProvider.getAuthenticationToken(url: url)
if let token = tokenResult {
request.headers[authorizationHeaderKey] = authorizationHeaderValuePrefix + token
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
public enum HttpMethod {
case get
case post
case patch
case delete
case options
case connect
case put
case trace
case head
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
public typealias ErrorMappings = [String:ParsableFactory]
public typealias ResponseHandler<DeserializationType> = (Any, ErrorMappings) async throws -> DeserializationType
public protocol RequestAdapter {
func send<T:Parsable>(request: RequestInformation, ctor: ParsableFactory, responseHandler: ResponseHandler<T>?, errorMappings: ErrorMappings?) async throws -> T?
func sendCollection<T:Parsable>(request: RequestInformation, ctor: ParsableFactory, responseHandler: ResponseHandler<T>?, errorMappings: ErrorMappings?) async throws -> [T]?
func sendPrimitive<T>(request: RequestInformation, responseHandler: ResponseHandler<T>?, errorMappings: ErrorMappings?) async throws -> T?
func sendNoContent(request: RequestInformation, responseHandler: ResponseHandler<Void>?, errorMappings: ErrorMappings?) async throws -> Void
func enableBackingStore() throws
var baseUrl: String { get set }
var serializationWriterFactory: SerializationWriterFactory { get }
}
Loading

0 comments on commit fb71842

Please sign in to comment.