ProductPromotion
Logo

Swift

made by https://0x3d.site

GitHub - Wei18/github-rest-api-swift-openapi: Scheduled generated GitHub's REST API Swift code from OpenAPI specification.
Scheduled generated GitHub's REST API Swift code from OpenAPI specification. - Wei18/github-rest-api-swift-openapi
Visit Site

GitHub - Wei18/github-rest-api-swift-openapi: Scheduled generated GitHub's REST API Swift code from OpenAPI specification.

GitHub - Wei18/github-rest-api-swift-openapi: Scheduled generated GitHub's REST API Swift code from OpenAPI specification.

GitHub's REST API Swift Language Code

This Swift code generator is built upon the Swift OpenAPI Generator and leverages the OpenAPI description for GitHub's REST API. The goal is to automate the creation of Swift language code, providing developers with a seamless way to interact with GitHub's REST API.

Usage

For example you can import these frameworks to fetch github users, or see reference UsersTests.swift.

import GitHubRestAPIUsers
import OpenAPIRuntime
import OpenAPIURLSession

let client = Client(serverURL: try Servers.server1(), transport: URLSessionTransport()) 
let users = try await client.users_sol_list().ok.body.json 
import GitHubRestAPIActions
import GitHubRestAPIActivity
import GitHubRestAPIApps
import GitHubRestAPIBilling
import GitHubRestAPIChecks
import GitHubRestAPIClassroom
import GitHubRestAPICode_Scanning
import GitHubRestAPICodes_Of_Conduct
import GitHubRestAPICodespaces
import GitHubRestAPICopilot
import GitHubRestAPIDependabot
import GitHubRestAPIDependency_Graph
import GitHubRestAPIDesktop
import GitHubRestAPIEmojis
import GitHubRestAPIGists
import GitHubRestAPIGit
import GitHubRestAPIGitignore
import GitHubRestAPIInteractions
import GitHubRestAPIIssues
import GitHubRestAPILicenses
import GitHubRestAPIMarkdown
import GitHubRestAPIMerge_Queue
import GitHubRestAPIMeta
import GitHubRestAPIMigrations
import GitHubRestAPIOidc
import GitHubRestAPIOrgs
import GitHubRestAPIPackages
import GitHubRestAPIProjects
import GitHubRestAPIPulls
import GitHubRestAPIRate_Limit
import GitHubRestAPIReactions
import GitHubRestAPIRepos
import GitHubRestAPISearch
import GitHubRestAPISecret_Scanning
import GitHubRestAPISecurity_Advisories
import GitHubRestAPITeams
import GitHubRestAPIUsers

The tutorial show you the following example or refer below.

// Usage.swift
// -
import Foundation
import GitHubRestAPIIssues
import OpenAPIRuntime
import OpenAPIURLSession
import HTTPTypes

struct GitHubRestAPIIssuesExtension {

    let owner: String

    let repo: String

    /// The issue number or pull number.
    let number: Int

    /// Update the comment if the anchor is found; otherwise, create it.
    func comment(anchor: String, body: String) async throws {
        let hidingContent = "<!-- Comment anchor: \(anchor) -->"
        let newBody = "\(body)\n\n\(hidingContent)"

        let client = Client(
            serverURL: try Servers.server1(),
            transport: URLSessionTransport(),
            middlewares: [AuthenticationMiddleware(token: nil)]
        )

        let comments = try await client.issues_sol_list_hyphen_comments(
            path: .init(owner: owner, repo: repo, issue_number: number)
        ).ok.body.json

        if let comment = comments.first(where: { $0.body?.contains(hidingContent) == true }) {
            _ = try await client.issues_sol_update_hyphen_comment(
                path: .init(owner: owner, repo: repo, comment_id: Components.Parameters.comment_hyphen_id(comment.id)),
                body: .json(.init(body: newBody))
            )
        } else {
            _ = try await client.issues_sol_create_hyphen_comment(
                path: .init(owner: owner, repo: repo, issue_number: number),
                body: .json(.init(body: newBody))
            )
        }
    }
}
import Foundation
import GitHubRestAPIUsers
import OpenAPIRuntime
import OpenAPIURLSession
import HTTPTypes

/// Example: ProcessInfo.processInfo.environment["GITHUB_TOKEN"] ?? ""
let token: String = "***"

let client = Client(
    serverURL: try Servers.server1(),
    transport: URLSessionTransport(),
    middlewares: [AuthenticationMiddleware(token: token)]
)

/// Injects an authorization header to every request.
struct AuthenticationMiddleware: ClientMiddleware {

    private let token: String

    init(token: String) {
        self.token = token
    }
    private var header: [String: String] { ["Authorization": "Bearer \(token)" ] }

    func intercept(
        _ request: HTTPRequest,
        body: HTTPBody?,
        baseURL: URL,
        operationID: String,
        next: @Sendable (HTTPRequest, HTTPBody?, URL) async throws -> (HTTPResponse, HTTPBody?)
    ) async throws -> (HTTPResponse, HTTPBody?) {
        var request = request
        request.headerFields.append(HTTPField(name: .authorization, value: "Bearer \(token)"))
        return try await next(request, body, baseURL)
    }

}

Installation

Swift Package Manager

The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler.

Once you have your Swift package set up, adding github-rest-api-swift-openapi as a dependency is as easy as adding it to the dependencies value of your Package.swift.

// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.

dependencies: [
    .package(url: "https://github.com/wei18/github-rest-api-swift-openapi.git", from: "1.0.0"),
]

Overview

OpenAPI serves as a standardized way to document HTTP services. It allows developers to automate workflows, such as generating code for making HTTP requests or implementing API servers.

The Swift OpenAPI Generator is a Swift package plugin designed to generate code at build-time, ensuring it remains synchronized with the OpenAPI document.

Use Submodules to clone github/rest-api-description and then split openapi tags into multiple modules (Swift Package Products).

Motivation

Wanna use Swift as the development language to create some convenient and user-friendly GitHub Actions.

Contributions

Contributions are welcome! If you encounter issues or have suggestions for improvements, feel free to open an issue or submit a pull request.

This repository is automatically kept up to date with the submodule github/rest-api-description.

If you've identified a mismatch between GitHub API's Swift code and these descriptions, or found an issue with the format of a schema, please open an issue to github/rest-api-description or open an issue to apple/swift-openapi-generator.

More Resources
to explore the angular.

mail [email protected] to add your project or resources here ๐Ÿ”ฅ.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here ๐Ÿ”.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory