|
| 1 | +// Generated by swift-openapi-generator, do not modify. |
| 2 | +@_spi(Generated) import OpenAPIRuntime |
| 3 | +#if os(Linux) |
| 4 | +@preconcurrency import struct Foundation.URL |
| 5 | +@preconcurrency import struct Foundation.Data |
| 6 | +@preconcurrency import struct Foundation.Date |
| 7 | +#else |
| 8 | +import struct Foundation.URL |
| 9 | +import struct Foundation.Data |
| 10 | +import struct Foundation.Date |
| 11 | +#endif |
| 12 | +import HTTPTypes |
| 13 | +/// GitHub's v3 REST API. |
| 14 | +public struct Client: APIProtocol { |
| 15 | + /// The underlying HTTP client. |
| 16 | + private let client: UniversalClient |
| 17 | + /// Creates a new client. |
| 18 | + /// - Parameters: |
| 19 | + /// - serverURL: The server URL that the client connects to. Any server |
| 20 | + /// URLs defined in the OpenAPI document are available as static methods |
| 21 | + /// on the ``Servers`` type. |
| 22 | + /// - configuration: A set of configuration values for the client. |
| 23 | + /// - transport: A transport that performs HTTP operations. |
| 24 | + /// - middlewares: A list of middlewares to call before the transport. |
| 25 | + public init( |
| 26 | + serverURL: Foundation.URL, |
| 27 | + configuration: Configuration = .init(), |
| 28 | + transport: any ClientTransport, |
| 29 | + middlewares: [any ClientMiddleware] = [] |
| 30 | + ) { |
| 31 | + self.client = .init( |
| 32 | + serverURL: serverURL, |
| 33 | + configuration: configuration, |
| 34 | + transport: transport, |
| 35 | + middlewares: middlewares |
| 36 | + ) |
| 37 | + } |
| 38 | + private var converter: Converter { |
| 39 | + client.converter |
| 40 | + } |
| 41 | + /// Revoke a list of credentials |
| 42 | + /// |
| 43 | + /// Submit a list of credentials to be revoked. This endpoint is intended to revoke credentials the caller does not own and may have found exposed on GitHub.com or elsewhere. It can also be used for credentials associated with an old user account that you no longer have access to. Credential owners will be notified of the revocation. |
| 44 | + /// |
| 45 | + /// This endpoint currently accepts the following credential types: |
| 46 | + /// - Personal access tokens (classic) |
| 47 | + /// - Fine-grained personal access tokens |
| 48 | + /// |
| 49 | + /// Revoked credentials may impact users on GitHub Free, Pro, & Team and GitHub Enterprise Cloud, and GitHub Enterprise Cloud with Enterprise Managed Users. |
| 50 | + /// GitHub cannot reactivate any credentials that have been revoked; new credentials will need to be generated. |
| 51 | + /// |
| 52 | + /// To prevent abuse, this API is limited to only 60 unauthenticated requests per hour and a max of 1000 tokens per API request. |
| 53 | + /// |
| 54 | + /// > [!NOTE] |
| 55 | + /// > Any authenticated requests will return a 403. |
| 56 | + /// |
| 57 | + /// - Remark: HTTP `POST /credentials/revoke`. |
| 58 | + /// - Remark: Generated from `#/paths//credentials/revoke/post(credentials/revoke)`. |
| 59 | + public func credentialsRevoke(_ input: Operations.CredentialsRevoke.Input) async throws -> Operations.CredentialsRevoke.Output { |
| 60 | + try await client.send( |
| 61 | + input: input, |
| 62 | + forOperation: Operations.CredentialsRevoke.id, |
| 63 | + serializer: { input in |
| 64 | + let path = try converter.renderedPath( |
| 65 | + template: "/credentials/revoke", |
| 66 | + parameters: [] |
| 67 | + ) |
| 68 | + var request: HTTPTypes.HTTPRequest = .init( |
| 69 | + soar_path: path, |
| 70 | + method: .post |
| 71 | + ) |
| 72 | + suppressMutabilityWarning(&request) |
| 73 | + converter.setAcceptHeader( |
| 74 | + in: &request.headerFields, |
| 75 | + contentTypes: input.headers.accept |
| 76 | + ) |
| 77 | + let body: OpenAPIRuntime.HTTPBody? |
| 78 | + switch input.body { |
| 79 | + case let .json(value): |
| 80 | + body = try converter.setRequiredRequestBodyAsJSON( |
| 81 | + value, |
| 82 | + headerFields: &request.headerFields, |
| 83 | + contentType: "application/json; charset=utf-8" |
| 84 | + ) |
| 85 | + } |
| 86 | + return (request, body) |
| 87 | + }, |
| 88 | + deserializer: { response, responseBody in |
| 89 | + switch response.status.code { |
| 90 | + case 202: |
| 91 | + let contentType = converter.extractContentTypeIfPresent(in: response.headerFields) |
| 92 | + let body: Components.Responses.Accepted.Body |
| 93 | + let chosenContentType = try converter.bestContentType( |
| 94 | + received: contentType, |
| 95 | + options: [ |
| 96 | + "application/json" |
| 97 | + ] |
| 98 | + ) |
| 99 | + switch chosenContentType { |
| 100 | + case "application/json": |
| 101 | + body = try await converter.getResponseBodyAsJSON( |
| 102 | + OpenAPIRuntime.OpenAPIObjectContainer.self, |
| 103 | + from: responseBody, |
| 104 | + transforming: { value in |
| 105 | + .json(value) |
| 106 | + } |
| 107 | + ) |
| 108 | + default: |
| 109 | + preconditionFailure("bestContentType chose an invalid content type.") |
| 110 | + } |
| 111 | + return .accepted(.init(body: body)) |
| 112 | + case 422: |
| 113 | + let contentType = converter.extractContentTypeIfPresent(in: response.headerFields) |
| 114 | + let body: Components.Responses.ValidationFailedSimple.Body |
| 115 | + let chosenContentType = try converter.bestContentType( |
| 116 | + received: contentType, |
| 117 | + options: [ |
| 118 | + "application/json" |
| 119 | + ] |
| 120 | + ) |
| 121 | + switch chosenContentType { |
| 122 | + case "application/json": |
| 123 | + body = try await converter.getResponseBodyAsJSON( |
| 124 | + Components.Schemas.ValidationErrorSimple.self, |
| 125 | + from: responseBody, |
| 126 | + transforming: { value in |
| 127 | + .json(value) |
| 128 | + } |
| 129 | + ) |
| 130 | + default: |
| 131 | + preconditionFailure("bestContentType chose an invalid content type.") |
| 132 | + } |
| 133 | + return .unprocessableContent(.init(body: body)) |
| 134 | + case 500: |
| 135 | + let contentType = converter.extractContentTypeIfPresent(in: response.headerFields) |
| 136 | + let body: Components.Responses.InternalError.Body |
| 137 | + let chosenContentType = try converter.bestContentType( |
| 138 | + received: contentType, |
| 139 | + options: [ |
| 140 | + "application/json" |
| 141 | + ] |
| 142 | + ) |
| 143 | + switch chosenContentType { |
| 144 | + case "application/json": |
| 145 | + body = try await converter.getResponseBodyAsJSON( |
| 146 | + Components.Schemas.BasicError.self, |
| 147 | + from: responseBody, |
| 148 | + transforming: { value in |
| 149 | + .json(value) |
| 150 | + } |
| 151 | + ) |
| 152 | + default: |
| 153 | + preconditionFailure("bestContentType chose an invalid content type.") |
| 154 | + } |
| 155 | + return .internalServerError(.init(body: body)) |
| 156 | + default: |
| 157 | + return .undocumented( |
| 158 | + statusCode: response.status.code, |
| 159 | + .init( |
| 160 | + headerFields: response.headerFields, |
| 161 | + body: responseBody |
| 162 | + ) |
| 163 | + ) |
| 164 | + } |
| 165 | + } |
| 166 | + ) |
| 167 | + } |
| 168 | +} |
0 commit comments