{"id":13523095,"url":"https://github.com/Wei18/github-rest-api-swift-openapi","last_synced_at":"2025-04-01T00:30:54.659Z","repository":{"id":214871374,"uuid":"737089529","full_name":"Wei18/github-rest-api-swift-openapi","owner":"Wei18","description":"Scheduled generated GitHub's REST API Swift code from OpenAPI specification.","archived":false,"fork":false,"pushed_at":"2024-10-28T22:02:29.000Z","size":265091,"stargazers_count":13,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-30T17:24:44.897Z","etag":null,"topics":["api","docc","github-actions","github-api","githubapi","oas3","openapi","rest-api","swift","swiftpackage"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Wei18.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-12-29T19:33:57.000Z","updated_at":"2024-10-28T22:02:34.000Z","dependencies_parsed_at":"2024-10-22T06:41:57.904Z","dependency_job_id":null,"html_url":"https://github.com/Wei18/github-rest-api-swift-openapi","commit_stats":null,"previous_names":["wei18/github-rest-api-swift-openapi"],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Wei18%2Fgithub-rest-api-swift-openapi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Wei18%2Fgithub-rest-api-swift-openapi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Wei18%2Fgithub-rest-api-swift-openapi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Wei18%2Fgithub-rest-api-swift-openapi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Wei18","download_url":"https://codeload.github.com/Wei18/github-rest-api-swift-openapi/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222688173,"owners_count":17023297,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","docc","github-actions","github-api","githubapi","oas3","openapi","rest-api","swift","swiftpackage"],"created_at":"2024-08-01T06:00:55.430Z","updated_at":"2024-11-02T07:31:17.826Z","avatar_url":"https://github.com/Wei18.png","language":"Swift","readme":"# GitHub's REST API Swift Language Code\n[![](https://img.shields.io/badge/docc-read_documentation-blue)](https://swiftpackageindex.com/wei18/github-rest-api-swift-openapi/documentation)\n[![](https://img.shields.io/github/v/release/wei18/github-rest-api-swift-openapi)](https://github.com/wei18/github-rest-api-swift-openapi/releases)\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fwei18%2Fgithub-rest-api-swift-openapi%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/wei18/github-rest-api-swift-openapi)\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fwei18%2Fgithub-rest-api-swift-openapi%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/wei18/github-rest-api-swift-openapi)\n\n\nThis Swift code generator is built upon the [Swift OpenAPI Generator](https://github.com/apple/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.\n\n## Usage\nFor example you can import these frameworks to fetch github users, or see reference [UsersTests.swift](https://github.com/Wei18/github-rest-api-swift-openapi/blob/46bd7a951cd6a2bda9a9d26d843d55bb12f769c3/Tests/UsersTests/UsersTests.swift#L8-L15).\n```swift\nimport GitHubRestAPIUsers\nimport OpenAPIRuntime\nimport OpenAPIURLSession\n\nlet client = Client(serverURL: try Servers.server1(), transport: URLSessionTransport()) \nlet users = try await client.users_sol_list().ok.body.json \n```\n\n\u003cdetails\u003e\n\u003csummary\u003eFull Supported Framworks\u003c/summary\u003e\n    \n```swift\nimport GitHubRestAPIActions\nimport GitHubRestAPIActivity\nimport GitHubRestAPIApps\nimport GitHubRestAPIBilling\nimport GitHubRestAPIChecks\nimport GitHubRestAPIClassroom\nimport GitHubRestAPICode_Scanning\nimport GitHubRestAPICodes_Of_Conduct\nimport GitHubRestAPICodespaces\nimport GitHubRestAPICopilot\nimport GitHubRestAPIDependabot\nimport GitHubRestAPIDependency_Graph\nimport GitHubRestAPIDesktop\nimport GitHubRestAPIEmojis\nimport GitHubRestAPIGists\nimport GitHubRestAPIGit\nimport GitHubRestAPIGitignore\nimport GitHubRestAPIInteractions\nimport GitHubRestAPIIssues\nimport GitHubRestAPILicenses\nimport GitHubRestAPIMarkdown\nimport GitHubRestAPIMerge_Queue\nimport GitHubRestAPIMeta\nimport GitHubRestAPIMigrations\nimport GitHubRestAPIOidc\nimport GitHubRestAPIOrgs\nimport GitHubRestAPIPackages\nimport GitHubRestAPIProjects\nimport GitHubRestAPIPulls\nimport GitHubRestAPIRate_Limit\nimport GitHubRestAPIReactions\nimport GitHubRestAPIRepos\nimport GitHubRestAPISearch\nimport GitHubRestAPISecret_Scanning\nimport GitHubRestAPISecurity_Advisories\nimport GitHubRestAPITeams\nimport GitHubRestAPIUsers\n```\n\u003c/details\u003e\n\nThe [tutorial](https://swiftpackageindex.com/wei18/github-rest-api-swift-openapi/tutorial/use-github-restapi-issues) show you the following example or refer below.\n\n\u003cdetails\u003e\n\u003csummary\u003eExample of code for enhanced issues comment API\u003c/summary\u003e\n\n```swift\n// Usage.swift\n// -\nimport Foundation\nimport GitHubRestAPIIssues\nimport OpenAPIRuntime\nimport OpenAPIURLSession\nimport HTTPTypes\n\nstruct GitHubRestAPIIssuesExtension {\n\n    let owner: String\n\n    let repo: String\n\n    /// The issue number or pull number.\n    let number: Int\n\n    /// Update the comment if the anchor is found; otherwise, create it.\n    func comment(anchor: String, body: String) async throws {\n        let hidingContent = \"\u003c!-- Comment anchor: \\(anchor) --\u003e\"\n        let newBody = \"\\(body)\\n\\n\\(hidingContent)\"\n\n        let client = Client(\n            serverURL: try Servers.server1(),\n            transport: URLSessionTransport(),\n            middlewares: [AuthenticationMiddleware(token: nil)]\n        )\n\n        let comments = try await client.issues_sol_list_hyphen_comments(\n            path: .init(owner: owner, repo: repo, issue_number: number)\n        ).ok.body.json\n\n        if let comment = comments.first(where: { $0.body?.contains(hidingContent) == true }) {\n            _ = try await client.issues_sol_update_hyphen_comment(\n                path: .init(owner: owner, repo: repo, comment_id: Components.Parameters.comment_hyphen_id(comment.id)),\n                body: .json(.init(body: newBody))\n            )\n        } else {\n            _ = try await client.issues_sol_create_hyphen_comment(\n                path: .init(owner: owner, repo: repo, issue_number: number),\n                body: .json(.init(body: newBody))\n            )\n        }\n    }\n}\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eExample of code for the `GITHUB_TOKEN` to authenticate.\u003c/summary\u003e\n    \n```swift\nimport Foundation\nimport GitHubRestAPIUsers\nimport OpenAPIRuntime\nimport OpenAPIURLSession\nimport HTTPTypes\n\n/// Example: ProcessInfo.processInfo.environment[\"GITHUB_TOKEN\"] ?? \"\"\nlet token: String = \"***\"\n\nlet client = Client(\n    serverURL: try Servers.server1(),\n    transport: URLSessionTransport(),\n    middlewares: [AuthenticationMiddleware(token: token)]\n)\n\n/// Injects an authorization header to every request.\nstruct AuthenticationMiddleware: ClientMiddleware {\n\n    private let token: String\n\n    init(token: String) {\n        self.token = token\n    }\n    private var header: [String: String] { [\"Authorization\": \"Bearer \\(token)\" ] }\n\n    func intercept(\n        _ request: HTTPRequest,\n        body: HTTPBody?,\n        baseURL: URL,\n        operationID: String,\n        next: @Sendable (HTTPRequest, HTTPBody?, URL) async throws -\u003e (HTTPResponse, HTTPBody?)\n    ) async throws -\u003e (HTTPResponse, HTTPBody?) {\n        var request = request\n        request.headerFields.append(HTTPField(name: .authorization, value: \"Bearer \\(token)\"))\n        return try await next(request, body, baseURL)\n    }\n\n}\n```\n\u003c/details\u003e\n\n## Installation\n\n### Swift Package Manager\n\nThe [Swift Package Manager](https://swift.org/package-manager/) is a tool for automating the distribution of Swift code and is integrated into the `swift` compiler.\n\nOnce 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`.\n\n```swift\n// swift-tools-version: 5.9\n// The swift-tools-version declares the minimum version of Swift required to build this package.\n\ndependencies: [\n    .package(url: \"https://github.com/wei18/github-rest-api-swift-openapi.git\", from: \"1.0.0\"),\n]\n```\n\n## Overview\n\n[OpenAPI](https://www.openapis.org/) 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. \n\nThe [Swift OpenAPI Generator](https://github.com/apple/swift-openapi-generator) is a Swift package plugin designed to generate code at build-time, ensuring it remains synchronized with the OpenAPI document.\n\nUse [Submodules](https://git-scm.com/book/en/v2/Git-Tools-Submodules) to clone [github/rest-api-description](https://github.com/github/rest-api-description) and then split openapi tags into multiple modules (Swift Package Products).\n\n# Motivation\n\nWanna use Swift as the development language to create some convenient and user-friendly GitHub Actions.\n\n# Contributions\n\nContributions are welcome! If you encounter issues or have suggestions for improvements, feel free to open an issue or submit a pull request.\n\nThis repository is automatically kept up to date with the submodule [github/rest-api-description](https://github.com/github/rest-api-description).\n\nIf 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](https://github.com/github/rest-api-description/issues/new?template=schema-inaccuracy.md) or [open an issue to apple/swift-openapi-generator](https://github.com/apple/swift-openapi-generator/issues).\n","funding_links":[],"categories":["Libs"],"sub_categories":["API"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FWei18%2Fgithub-rest-api-swift-openapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FWei18%2Fgithub-rest-api-swift-openapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FWei18%2Fgithub-rest-api-swift-openapi/lists"}