Skip to content

Commit fa3ed15

Browse files
authored
Update README.md
1 parent 4b4c96d commit fa3ed15

File tree

1 file changed

+54
-6
lines changed

1 file changed

+54
-6
lines changed

README.md

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,57 @@
77
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.
88

99
## Usage
10-
- To get started, check out the [documentation](https://wei18.github.io/github-rest-api-swift-openapi/documentation/githubrestapiswiftopenapi/)
11-
12-
- Or refer to example: Get Users.
13-
https://github.com/Wei18/github-rest-api-swift-openapi/blob/46bd7a951cd6a2bda9a9d26d843d55bb12f769c3/Tests/UsersTests/UsersTests.swift#L8-L15
14-
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)"
36+
37+
let client = Client(
38+
serverURL: try Servers.server1(),
39+
transport: URLSessionTransport(),
40+
middlewares: [AuthenticationMiddleware(token: nil)]
41+
)
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+
}
59+
}
60+
```
1561
## Installation
1662

1763
### Swift Package Manager
@@ -31,7 +77,9 @@ dependencies: [
3177

3278
## Overview
3379

34-
[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. The Swift OpenAPI Generator is a Swift package plugin designed to generate code at build-time, ensuring it remains synchronized with the OpenAPI document.
80+
[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.
81+
82+
The [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.
3583

3684
Use [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).
3785

0 commit comments

Comments
 (0)