Skip to main content

curl2swift

curl2swift is a command line tool for transforming a cURL request to Swift code. It takes a cURL and generates code for the request, the request's response mapping and a test.

Note that the generated code is not yet intended for general usage, because it depends on some code that is specific to the project for which this tool was initially designed.

TODOs

  • Implement template configuration and customization.
  • Try out various cURLs to add handling for unexpected arguments.
  • Add configuration options for specifying output file.
  • Enable path param specification (e.g. using {...} to denote a path param placeholder.)

USAGE

  1. Copy a cURL into the clipboard.
  2. Call curl2swift and pass a request name and (optional) description, e.g. curl2swift TestRequest "Call test request".
  3. Processed request template is printed out with a promt if user wants to copy it.
  4. Processed test template is printed out with the same promt.

OUTPUT EXAMPLE

After step 3:

/// Add docs
class TestRequest: RequestSpecBuilder {

    
    struct Response: Codable {
        let login : String?
        let id : Int?
        let nodeNode : String?
        let avatarAvatar : String?
        let gravatarGravatar : String?
        let url : String?
        let htmlHtml : String?
        let followersFollowers : String?
        let followingFollowing : String?
        let gistsGists : String?
        let starredStarred : String?
        let subscriptionsSubscriptions : String?
        let organizationsOrganizations : String?
        let reposRepos : String?
        let eventsEvents : String?
        let receivedReceived : String?
        let type : String?
        let siteSite : Bool?
        let name : String?
        let company : String?
        let blog : String?
        let location : String?
        let email : String?
        let hireable : String?
        let bio : String?
        let twitterTwitter : String?
        let publicPublic : Int?
        let publicPublic : Int?
        let followers : Int?
        let following : Int?
        let createdCreated : String?
        let updatedUpdated : String?

        enum CodingKeys: String, CodingKey {
            case login = "login"
            case id = "id"
            case nodeNode = "node_id"
            case avatarAvatar = "avatar_url"
            case gravatarGravatar = "gravatar_id"
            case url = "url"
            case htmlHtml = "html_url"
            case followersFollowers = "followers_url"
            case followingFollowing = "following_url"
            case gistsGists = "gists_url"
            case starredStarred = "starred_url"
            case subscriptionsSubscriptions = "subscriptions_url"
            case organizationsOrganizations = "organizations_url"
            case reposRepos = "repos_url"
            case eventsEvents = "events_url"
            case receivedReceived = "received_events_url"
            case type = "type"
            case siteSite = "site_admin"
            case name = "name"
            case company = "company"
            case blog = "blog"
            case location = "location"
            case email = "email"
            case hireable = "hireable"
            case bio = "bio"
            case twitterTwitter = "twitter_username"
            case publicPublic = "public_repos"
            case publicPublic = "public_gists"
            case followers = "followers"
            case following = "following"
            case createdCreated = "created_at"
            case updatedUpdated = "updated_at"
        }
    }


    required init(baseURL: String = "",
                  path: String = "",
                  method: HTTPMethod = .get,
                  headers: [String: String] = [:],
                  params: [String: String] = [:]) {
        super.init(baseURL: baseURL, path: path, method: method, headers: headers, params: params)
        set(.path("/users/defunkt"))
        set(.method(.get))
    }
}

extension TestRequest {
}


- - - - - - - - - - - - 
END OF GENERATED OUTPUT
- - - - - - - - - - - - 

Copy output to clipboard? [y/n]

Note that the extension contains setters for headers and body paramaeters, if the request has any.

After step 4:

- - - - - - - - 
GENERATED TEST:
- - - - - - - - 

    func testTestRequest() {
        let expectation = XCTestExpectation(description: "waiting for reponse")
        TestRequest()
            .set(.baseURL("https://api.github.com"))
            .set(.path("/users/defunkt"))
            .makeRxRequest()
            .mapTo(TestRequest.Response.self)
            .do(onSuccess: { _ in expectation.fulfill() })
            .discardableSubscribe()
        wait(for: [expectation], timeout: 10)
    }


- - - - - - - - - - - - 
END OF GENERATED OUTPUT
- - - - - - - - - - - - 

Copy to clipboard? [y/n]

Metadata

Release files for curl2swift 0.4.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for curl2swift 0.4.4
File Size Uploaded Provenance Actions
curl2swift-0.4.4.tar.gz 22.3 kB Without provenance Details for curl2swift-0.4.4.tar.gz

Release files / curl2swift-0.4.4.tar.gz

Download URL curl2swift-0.4.4.tar.gz
Size 22.3 kB
Tags Source
SHA-256 checksum
How to use checksums
c6cf6db84376443f8e68b40c06e19d8f25dcb61eac21b4f9809287e9a1556421
BLAKE2b-256 checksum
How to use checksums
e3f2e4ede083440a0e0ee981bfa8dab3c4f84aad84db3dda7bade3508072cc5b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.6

Security for curl2swift 0.4.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page