Swift OpenAPI Runtime

repository·main·Indexed 42 days ago

https://github.com/apple/swift-openapi-runtime

Provides common abstractions and helper functions required by code generated by the Swift OpenAPI Generator. It defines core protocols for pluggable client/server transports and middlewares, including ClientTransport, ClientMiddleware, ServerTransport, and ServerMiddleware.

Tokens
544
Snippets
2
Records
3
Agent score
5%

What's inside Swift OpenAPI Runtime

  1. Implement custom transports and middlewares

    main

    The Swift OpenAPI Generator produces code designed for pluggable layers. You can extend the functionality of your generated client or server by implementing types that adopt one of the following protocols provided by the runtime library:

    Client-side extensions

    • ClientTransport: Define how requests are actually sent over the network.
    • ClientMiddleware: Implement logic that intercepts or modifies client requests and responses (e.g., logging, authentication, or retries).

    Server-side extensions

    • ServerTransport: Define how the server receives incoming requests.
    • ServerMiddleware: Implement logic that intercepts or modifies incoming server requests and outgoing responses.
  2. Install OpenAPIRuntime via Swift Package Manager

    main

    To use the abstractions and helper functions required by code generated by the Swift OpenAPI Generator, add swift-openapi-runtime as a dependency in your Package.swift file.

    // Add the package dependency
    .package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.0.0"),
    
    // Add the product to your target
    .target(name: "MyTarget", dependencies: [
        .product(name: "OpenAPIRuntime", package: "swift-openapi-runtime"),
    ]),
  3. Install Swift OpenAPI Runtime

    main

    To use the runtime with your project, add swift-openapi-runtime as a package dependency in your Package.swift and then include the OpenAPIRuntime product in your target's dependencies.

    // Add the package dependency
    .package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.0.0"),
    
    // Add the product to your target
    .target(name: "MyTarget", dependencies: [
        .product(name: "OpenAPIRuntime", package: "swift-openapi-runtime"),
    ]),