|
7 | 7 | This 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 bindings, providing developers with a seamless way to interact with GitHub's REST API. |
8 | 8 |
|
9 | 9 | ## Usage |
10 | | -- Example: How to get users. |
11 | | - https://github.com/Wei18/github-rest-api-swift-openapi/blob/46bd7a951cd6a2bda9a9d26d843d55bb12f769c3/Tests/UsersTests/UsersTests.swift#L8-L15 |
12 | | - |
13 | | -- Example: Enhance issues comment API |
14 | | - ```swift |
15 | | - // Usage.swift |
16 | | - // - |
17 | | - import Foundation |
18 | | - import GitHubRestAPIIssues |
19 | | - import OpenAPIRuntime |
20 | | - import OpenAPIURLSession |
21 | | - import HTTPTypes |
22 | | - |
23 | | - struct GitHubRestAPIIssuesExtension { |
24 | | - |
25 | | - let owner: String |
26 | | - |
27 | | - let repo: String |
28 | | - |
29 | | - /// The issue number or pull number. |
30 | | - let number: Int |
31 | | - |
32 | | - /// Update the comment if the anchor is found; otherwise, create it. |
33 | | - func comment(anchor: String, body: String) async throws { |
34 | | - let hidingContent = "<!-- Comment anchor: \(anchor) -->" |
35 | | - let newBody = "\(body)\n\n\(hidingContent)" |
| 10 | +For 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). |
| 11 | +```swift |
| 12 | +import GitHubRestAPIUsers |
| 13 | +import OpenAPIRuntime |
| 14 | +import OpenAPIURLSession |
| 15 | + |
| 16 | +let client = Client(serverURL: try Servers.server1(), transport: URLSessionTransport()) |
| 17 | +let users = try await client.users_sol_list().ok.body.json |
| 18 | +``` |
| 19 | + |
| 20 | + |
| 21 | +<details> |
| 22 | +<summary>Full Supported Framworks</summary> |
36 | 23 |
|
37 | | - let client = Client( |
38 | | - serverURL: try Servers.server1(), |
39 | | - transport: URLSessionTransport(), |
40 | | - middlewares: [AuthenticationMiddleware(token: nil)] |
| 24 | +```swift |
| 25 | +import GitHubRestAPIActions |
| 26 | +import GitHubRestAPIActivity |
| 27 | +import GitHubRestAPIApps |
| 28 | +import GitHubRestAPIBilling |
| 29 | +import GitHubRestAPIChecks |
| 30 | +import GitHubRestAPIClassroom |
| 31 | +import GitHubRestAPICode_Scanning |
| 32 | +import GitHubRestAPICodes_Of_Conduct |
| 33 | +import GitHubRestAPICodespaces |
| 34 | +import GitHubRestAPICopilot |
| 35 | +import GitHubRestAPIDependabot |
| 36 | +import GitHubRestAPIDependency_Graph |
| 37 | +import GitHubRestAPIDesktop |
| 38 | +import GitHubRestAPIEmojis |
| 39 | +import GitHubRestAPIGists |
| 40 | +import GitHubRestAPIGit |
| 41 | +import GitHubRestAPIGitignore |
| 42 | +import GitHubRestAPIInteractions |
| 43 | +import GitHubRestAPIIssues |
| 44 | +import GitHubRestAPILicenses |
| 45 | +import GitHubRestAPIMarkdown |
| 46 | +import GitHubRestAPIMerge_Queue |
| 47 | +import GitHubRestAPIMeta |
| 48 | +import GitHubRestAPIMigrations |
| 49 | +import GitHubRestAPIOidc |
| 50 | +import GitHubRestAPIOrgs |
| 51 | +import GitHubRestAPIPackages |
| 52 | +import GitHubRestAPIProjects |
| 53 | +import GitHubRestAPIPulls |
| 54 | +import GitHubRestAPIRate_Limit |
| 55 | +import GitHubRestAPIReactions |
| 56 | +import GitHubRestAPIRepos |
| 57 | +import GitHubRestAPISearch |
| 58 | +import GitHubRestAPISecret_Scanning |
| 59 | +import GitHubRestAPISecurity_Advisories |
| 60 | +import GitHubRestAPITeams |
| 61 | +import GitHubRestAPIUsers |
| 62 | +``` |
| 63 | +</details> |
| 64 | + |
| 65 | +<details> |
| 66 | +<summary>Example of code for enhanced issues comment API</summary> |
| 67 | + |
| 68 | +```swift |
| 69 | +// Usage.swift |
| 70 | +// - |
| 71 | +import Foundation |
| 72 | +import GitHubRestAPIIssues |
| 73 | +import OpenAPIRuntime |
| 74 | +import OpenAPIURLSession |
| 75 | +import HTTPTypes |
| 76 | + |
| 77 | +struct GitHubRestAPIIssuesExtension { |
| 78 | + |
| 79 | + let owner: String |
| 80 | + |
| 81 | + let repo: String |
| 82 | + |
| 83 | + /// The issue number or pull number. |
| 84 | + let number: Int |
| 85 | + |
| 86 | + /// Update the comment if the anchor is found; otherwise, create it. |
| 87 | + func comment(anchor: String, body: String) async throws { |
| 88 | + let hidingContent = "<!-- Comment anchor: \(anchor) -->" |
| 89 | + let newBody = "\(body)\n\n\(hidingContent)" |
| 90 | + |
| 91 | + let client = Client( |
| 92 | + serverURL: try Servers.server1(), |
| 93 | + transport: URLSessionTransport(), |
| 94 | + middlewares: [AuthenticationMiddleware(token: nil)] |
| 95 | + ) |
| 96 | + |
| 97 | + let comments = try await client.issues_sol_list_hyphen_comments( |
| 98 | + path: .init(owner: owner, repo: repo, issue_number: number) |
| 99 | + ).ok.body.json |
| 100 | + |
| 101 | + if let comment = comments.first(where: { $0.body?.contains(hidingContent) == true }) { |
| 102 | + _ = try await client.issues_sol_update_hyphen_comment( |
| 103 | + path: .init(owner: owner, repo: repo, comment_id: Components.Parameters.comment_hyphen_id(comment.id)), |
| 104 | + body: .json(.init(body: newBody)) |
| 105 | + ) |
| 106 | + } else { |
| 107 | + _ = try await client.issues_sol_create_hyphen_comment( |
| 108 | + path: .init(owner: owner, repo: repo, issue_number: number), |
| 109 | + body: .json(.init(body: newBody)) |
41 | 110 | ) |
42 | | - |
43 | | - let comments = try await client.issues_sol_list_hyphen_comments( |
44 | | - path: .init(owner: owner, repo: repo, issue_number: number) |
45 | | - ).ok.body.json |
46 | | - |
47 | | - if let comment = comments.first(where: { $0.body?.contains(hidingContent) == true }) { |
48 | | - _ = try await client.issues_sol_update_hyphen_comment( |
49 | | - path: .init(owner: owner, repo: repo, comment_id: Components.Parameters.comment_hyphen_id(comment.id)), |
50 | | - body: .json(.init(body: newBody)) |
51 | | - ) |
52 | | - } else { |
53 | | - _ = try await client.issues_sol_create_hyphen_comment( |
54 | | - path: .init(owner: owner, repo: repo, issue_number: number), |
55 | | - body: .json(.init(body: newBody)) |
56 | | - ) |
57 | | - } |
58 | 111 | } |
59 | 112 | } |
60 | | - ``` |
| 113 | +} |
| 114 | +``` |
| 115 | +</details> |
| 116 | + |
61 | 117 | ## Installation |
62 | 118 |
|
63 | 119 | ### Swift Package Manager |
|
0 commit comments