Skip to content

sidekick: generate a Swift method for each api.Method #5130

@coryan

Description

@coryan

We want to generate relatively simple methods at first. Ignore detailed errors, retry loops, pagination, LROs, multiple HTTP bindings, multiple query parameters, complex bodies, or anything else. We want something to start building from.

This is a good start for publicca-v1:

  public func CreateExternalAccountKey(req: CreateExternalAccountKeyRequest) async throws -> ExternalAccountKey {
    let query = [
      URLQueryItem(name: "$alt", value: "json")
    ]
    var request = try await self.inner.Request(path: "/v1/\(req.parent)/externalAccountKeys", query: query)
    request.httpMethod = "POST"
    if let body = req.externalAccountKey {
      request.setValue("application/json", forHTTPHeaderField: "Content-Type")
      request.httpBody = try JSONEncoder().encode(body)
    }
    let (data, response) = try await self.inner.data(for: request)
    if !(200..<300).contains(response.statusCode) {
      throw RequestError.http(HTTPDetails(
        http_status_code: response.statusCode,
        headers: [:],
        payload: data,
      ))
    }
    let decodedResponse = try JSONDecoder().decode(ExternalAccountKey.self, from: data)
    return decodedResponse
  }

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions