postmanlabs / postmanlabs/postman-code-generators

Code Generator for Swift Async/Await

Open
#633 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

codegen
Dominant language
JavaScript
Stars
1k
Forks
381
PR merge metrics
No merged PRs in 30d

Description

Is your feature request related to a problem? Please describe.
It's not related to a problem

Describe the solution you'd like
In the Swift Codegen for URLSession the template is given a "closure" based approach. The language has moved away from 1+ years now. I would like to update the template

Additional context

Previously
import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif

var semaphore = DispatchSemaphore (value: 0)

var request = URLRequest(url: URL(string: "https://test-websvcs.nm.org/BusAdmin/Services/WebAPI/NMEmployeeMiddleTier/NMConnectAdmin/CurrentDate")!,timeoutInterval: Double.infinity)
request.httpMethod = "GET"

let task = URLSession.shared.dataTask(with: request) { data, response, error in 
  guard let data = data else {
    print(String(describing: error))
    semaphore.signal()
    return
  }
  print(String(data: data, encoding: .utf8)!)
  semaphore.signal()
}

task.resume()
semaphore.wait()

Now

import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif

var request = URLRequest(url: URL(string: "https://test-websvcs.nm.org/BusAdmin/Services/WebAPI/NMEmployeeMiddleTier/NMConnectAdmin/CurrentDate")!,timeoutInterval: Double.infinity)
request.httpMethod = "GET"

let (data, response) = try await URLSession.shared.data(from: request)

guard let data = data else {
  print(String(describing: error))
  return
}

print(String(data: data, encoding: .utf8)!)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No file or test is named. Start by locating the Swift Codegen template for URLSession and compare its generated closure-based example with the requested async/await form; done means generated Swift code uses async/await without the semaphore and completion-handler pattern.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.