diff --git a/Sources/swift-openapi-generator/Documentation.docc/Articles/Manually-invoking-the-generator-CLI.md b/Sources/swift-openapi-generator/Documentation.docc/Articles/Manually-invoking-the-generator-CLI.md index d85d02ba..5a40720b 100644 --- a/Sources/swift-openapi-generator/Documentation.docc/Articles/Manually-invoking-the-generator-CLI.md +++ b/Sources/swift-openapi-generator/Documentation.docc/Articles/Manually-invoking-the-generator-CLI.md @@ -49,9 +49,9 @@ As an alternative to invoking the CLI manually, you can also use the package com Set up the `openapi.yaml` and `openapi-generator-config.yaml` files the same way as you would for the build plugin, and then run: ```console -% swift package plugin generate-code-from-openapi --target GreetingServiceClient +% swift package plugin generate-code-from-openapi --target HelloWorldURLSessionClient ``` -This will generate files into the `GreetingServiceClient` target's Sources directory, in a directory called GeneratedSources, which you can then check into your repository. +This will generate files into the `HelloWorldURLSessionClient` target's Sources directory, in a directory called `GeneratedSources`, which you can then check into your repository. You can also invoke the command from the Xcode UI by control-clicking on a target in the Project Navigator, and selecting the command. diff --git a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/Adding-openapi-and-swagger-ui-endpoints.tutorial b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/Adding-openapi-and-swagger-ui-endpoints.tutorial index 536c3e44..f6cbef00 100644 --- a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/Adding-openapi-and-swagger-ui-endpoints.tutorial +++ b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/Adding-openapi-and-swagger-ui-endpoints.tutorial @@ -7,8 +7,8 @@ Additionally, you can host an HTML page that renders the OpenAPI document as interactive documentation that you can use from the browser, for example using [swagger-ui](https://github.com/swagger-api/swagger-ui). In this tutorial we'll add both endpoints to our Vapor server. - - > Tip: The [OpenAPIEndpointsServer example package](https://github.com/apple/swift-openapi-generator/tree/main/Examples/OpenAPIEndpointsServer) contains the configured Vapor server, in case you want to see the result of this tutorial. + + > Tip: The [swagger-ui-endpoint-example package](https://github.com/apple/swift-openapi-generator/tree/main/Examples/swagger-ui-endpoint-example) contains the result of this tutorial, in case you're looking for a working example. } @Section(title: "Add an /openapi.yaml endpoint") { @@ -17,7 +17,7 @@ @Steps { @Step { - Create a `Public/` directory for serving static content. + In the server package, create a `Public/` directory for serving static content. @Code(name: "console", file: server-openapi-endpoints.console.0.txt, reset: true) } @@ -44,11 +44,11 @@ } } @Section(title: "Add a Swagger UI endpoint") { - Now we'll add a static `openapi.html` page that serves Swagger UI and add a redirect to this page from `/` for discoverability. + Now we'll add a static `openapi.html` page that serves Swagger UI and add a redirect to this page from `/openapi` for discoverability. @Steps { @Step { - Create the file `Public/openapi.html` with the swagger-ui JavaScript. + Create the file `Public/openapi.html` with the HTML contents as shown on the right. By placing it in the public directory, it is already reachable at `/openapi.html`. diff --git a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/ClientSwiftPM.tutorial b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/ClientSwiftPM.tutorial index 53f9da6e..734920f3 100644 --- a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/ClientSwiftPM.tutorial +++ b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/ClientSwiftPM.tutorial @@ -14,11 +14,13 @@ The API for the service is defined using OpenAPI and you'll create a Swift client for this service, from scratch! Your Swift package will make use of the Swift OpenAPI Generator plugin to generate the code you'll use to call this API. + + > Tip: The [hello-world-urlsession-client-example package](https://github.com/apple/swift-openapi-generator/tree/main/Examples/hello-world-urlsession-client-example) contains the result of this tutorial, in case you're looking for a working example. } @Section(title: "(Optional) Downloading and running the server locally for testing") { - In the next section of the guide we will create a client for this service. In order to execute requests, you can download the example server implementation and run it locally. + In the next section of the guide we will create a client for this service. In order to execute requests, you can download an example server implementation and run it locally. @Steps { @Step { @@ -164,4 +166,21 @@ } } } + + @Section(title: "Unwrapping the response using the shorthand API") { + If you don't need to handle all the response codes and content types, you can also use the shorthand API on the response and body enums, providing you with throwing getters for unwrapping each value. + + These conveniences will throw an error if the received response or content type doesn't match the one you're requesting. + + @Steps { + @Step { + Remove the switch statement and replace it with chained access to the `ok` response, to its `body`, to the `json` content type of the body, and finally to the `message` property of the received greeting. + @Code(name: "main.swift", file: client.main.7.swift, previousFile: client.main.6.swift) + } + @Step { + You can now compile and run the executable again and see the response in the console. + @Code(name: "console", file: client.console.4.0.txt) + } + } + } } diff --git a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/ClientXcode.tutorial b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/ClientXcode.tutorial index a1fea028..7e7d81ab 100644 --- a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/ClientXcode.tutorial +++ b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/ClientXcode.tutorial @@ -14,11 +14,15 @@ The API for the service is defined using OpenAPI and you'll create a Swift client for this service, from scratch! Your Xcode project will make use of the Swift OpenAPI Generator plugin to generate the code you'll use to call this API from your existing app. + + Note: If you don't already have an existing app project, first create a new SwiftUI-based iOS app Xcode project before continuing. + + > Tip: The [HelloWorldiOSClientAppExample package](https://github.com/apple/swift-openapi-generator/tree/main/Examples/HelloWorldiOSClientAppExample) contains the result of this tutorial, in case you're looking for a working example. } @Section(title: "(Optional) Downloading and running the server locally for testing") { - In the next section of the guide we will create a client for this service. In order to execute requests, you can download the example server implementation and run it locally. + In the next section of the guide we will create a client for this service. In order to execute requests, you can download an example server implementation and run it locally. @Steps { @Step { @@ -35,7 +39,7 @@ } } } - + @Section(title: "Configuring your target to use the Swift OpenAPI Generator plugin") { Let's extend this app to call our `GreetingService` API. @@ -63,25 +67,23 @@ @Step { With the configuration files in place, we will add the following three package dependencies: the build plugin, the Runtime library, and a concrete client transport that uses URLSession to send HTTP requests. - Select the project in the Project Navigator again, select the project in the Project Editor, and go to Package Dependencies. + Select the project in the Project Navigator, select the project in the Project Editor, and go to Package Dependencies. } @Step { Under Packages, click the plus button to add a new package dependency. } @Step { Find the `swift-openapi-generator` package in an existing collection, or type in the full URL to the search field at the top: `https://github.com/apple/swift-openapi-generator`. - - Change the dependency rule to `Up to Next Minor Version`. } @Step { - Since the package provides a build plugin that we will integrate later, do not check any products on the next Choose Package Products screen. + Since the package provides a build plugin that we will integrate later, make sure that on the Choose Package Products screen, the "Add to Target" value is "None" for all products listed. Click Add Package. } @Step { Repeat the same steps two more times, with the packages `https://github.com/apple/swift-openapi-runtime` and `https://github.com/apple/swift-openapi-urlsession`. - This time, do check the library products to be added to the **GreetingServiceClient target**. Note, this might not be the default target Xcode offers to add the libraries to. + This time, ensure the library products are added to the **GreetingServiceClient target**. Note, this might not be the default target Xcode offers to add the libraries to. } @Step { To finish configuring the build plugin in your target, navigate to the Build Phases tab of the GreetingServiceClient in the Project Editor, and expand the Run Build Tool Plug-ins section. @@ -110,7 +112,7 @@ @Code(name: "GreetingClient.swift", file: client.xcode.0.swift, reset: true) } @Step { - Define a new struct called `GreetingClient` with an initializer and an empty method that will fetch cats using the generated client. + Define a new struct called `GreetingClient` with an initializer and an empty method that will fetch the greeting using the generated client. @Code(name: "GreetingClient.swift", file: client.xcode.1.swift) } @@ -145,6 +147,13 @@ @Code(name: "GreetingClient.swift", file: client.xcode.6.swift) } + @Step { + Alternatively, if you don't need to handle all the responses and content types exhaustively, you can use the shorthand API to unwrap the received body value. + + Note that if the actual received response or content type is different to your requested one, the unwrapping getters will thrown an error. + + @Code(name: "GreetingClient.swift", file: client.xcode.6.2.swift) + } @Step { Finally, in your app target, integrate the client to fetch the personalized greeting, for example to show it in the UI. diff --git a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/ServerSwiftPM.tutorial b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/ServerSwiftPM.tutorial index 6c86155f..917e12ce 100644 --- a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/ServerSwiftPM.tutorial +++ b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/ServerSwiftPM.tutorial @@ -15,6 +15,8 @@ The API for the service is defined using OpenAPI and you'll create a Swift server for this service, from scratch! Your Swift package will make use of the Swift OpenAPI Generator plugin to generate the code you'll use to implement this API. + + > Tip: The [hello-world-vapor-server-example package](https://github.com/apple/swift-openapi-generator/tree/main/Examples/hello-world-vapor-server-example) contains the result of this tutorial, in case you're looking for a working example. } @Section(title: "Creating a new Swift package") { diff --git a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.Package.1.swift b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.Package.1.swift index 582937d0..f92bb26c 100644 --- a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.Package.1.swift +++ b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.Package.1.swift @@ -3,12 +3,7 @@ import PackageDescription let package = Package( name: "GreetingServiceClient", - platforms: [ - .macOS(.v10_15), - .iOS(.v13), - .tvOS(.v13), - .watchOS(.v6), - ], + platforms: [.macOS(.v10_15), .iOS(.v13), .tvOS(.v13), .watchOS(.v6), .visionOS(.v1)], targets: [ .executableTarget( name: "GreetingServiceClient" diff --git a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.Package.2.swift b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.Package.2.swift index 6b6aa0c6..0e5c53dc 100644 --- a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.Package.2.swift +++ b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.Package.2.swift @@ -3,12 +3,7 @@ import PackageDescription let package = Package( name: "GreetingServiceClient", - platforms: [ - .macOS(.v10_15), - .iOS(.v13), - .tvOS(.v13), - .watchOS(.v6), - ], + platforms: [.macOS(.v10_15), .iOS(.v13), .tvOS(.v13), .watchOS(.v6), .visionOS(.v1)], dependencies: [ .package(url: "https://github.com/apple/swift-openapi-generator", exact: "1.0.0-alpha.1"), .package(url: "https://github.com/apple/swift-openapi-runtime", exact: "1.0.0-alpha.1"), diff --git a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.Package.3.swift b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.Package.3.swift index 604589fb..1eff2261 100644 --- a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.Package.3.swift +++ b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.Package.3.swift @@ -3,12 +3,7 @@ import PackageDescription let package = Package( name: "GreetingServiceClient", - platforms: [ - .macOS(.v10_15), - .iOS(.v13), - .tvOS(.v13), - .watchOS(.v6), - ], + platforms: [.macOS(.v10_15), .iOS(.v13), .tvOS(.v13), .watchOS(.v6), .visionOS(.v1)], dependencies: [ .package(url: "https://github.com/apple/swift-openapi-generator", exact: "1.0.0-alpha.1"), .package(url: "https://github.com/apple/swift-openapi-runtime", exact: "1.0.0-alpha.1"), @@ -18,10 +13,7 @@ let package = Package( .executableTarget( name: "GreetingServiceClient", plugins: [ - .plugin( - name: "OpenAPIGenerator", - package: "swift-openapi-generator" - ) + .plugin(name: "OpenAPIGenerator", package: "swift-openapi-generator"), ] ) ] diff --git a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.Package.4.swift b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.Package.4.swift index 85228d70..55f74c81 100644 --- a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.Package.4.swift +++ b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.Package.4.swift @@ -3,12 +3,7 @@ import PackageDescription let package = Package( name: "GreetingServiceClient", - platforms: [ - .macOS(.v10_15), - .iOS(.v13), - .tvOS(.v13), - .watchOS(.v6), - ], + platforms: [.macOS(.v10_15), .iOS(.v13), .tvOS(.v13), .watchOS(.v6), .visionOS(.v1)], dependencies: [ .package(url: "https://github.com/apple/swift-openapi-generator", exact: "1.0.0-alpha.1"), .package(url: "https://github.com/apple/swift-openapi-runtime", exact: "1.0.0-alpha.1"), @@ -18,20 +13,11 @@ let package = Package( .executableTarget( name: "GreetingServiceClient", dependencies: [ - .product( - name: "OpenAPIRuntime", - package: "swift-openapi-runtime" - ), - .product( - name: "OpenAPIURLSession", - package: "swift-openapi-urlsession" - ), + .product(name: "OpenAPIRuntime", package: "swift-openapi-runtime"), + .product(name: "OpenAPIURLSession", package: "swift-openapi-urlsession"), ], plugins: [ - .plugin( - name: "OpenAPIGenerator", - package: "swift-openapi-generator" - ) + .plugin(name: "OpenAPIGenerator", package: "swift-openapi-generator"), ] ) ] diff --git a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.Package.5.swift b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.Package.5.swift index 85228d70..55f74c81 100644 --- a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.Package.5.swift +++ b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.Package.5.swift @@ -3,12 +3,7 @@ import PackageDescription let package = Package( name: "GreetingServiceClient", - platforms: [ - .macOS(.v10_15), - .iOS(.v13), - .tvOS(.v13), - .watchOS(.v6), - ], + platforms: [.macOS(.v10_15), .iOS(.v13), .tvOS(.v13), .watchOS(.v6), .visionOS(.v1)], dependencies: [ .package(url: "https://github.com/apple/swift-openapi-generator", exact: "1.0.0-alpha.1"), .package(url: "https://github.com/apple/swift-openapi-runtime", exact: "1.0.0-alpha.1"), @@ -18,20 +13,11 @@ let package = Package( .executableTarget( name: "GreetingServiceClient", dependencies: [ - .product( - name: "OpenAPIRuntime", - package: "swift-openapi-runtime" - ), - .product( - name: "OpenAPIURLSession", - package: "swift-openapi-urlsession" - ), + .product(name: "OpenAPIRuntime", package: "swift-openapi-runtime"), + .product(name: "OpenAPIURLSession", package: "swift-openapi-urlsession"), ], plugins: [ - .plugin( - name: "OpenAPIGenerator", - package: "swift-openapi-generator" - ) + .plugin(name: "OpenAPIGenerator", package: "swift-openapi-generator"), ] ) ] diff --git a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.console.1.0.txt b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.console.1.0.txt index 5ddd2e9d..16eb02db 100644 --- a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.console.1.0.txt +++ b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.console.1.0.txt @@ -1,2 +1,2 @@ % git clone https://github.com/apple/swift-openapi-generator -% cd swift-openapi-generator/Examples/GreetingService +% cd swift-openapi-generator/Examples/hello-world-vapor-server-example diff --git a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.console.1.1.txt b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.console.1.1.txt index 3e7b4cdc..112b9a8e 100644 --- a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.console.1.1.txt +++ b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.console.1.1.txt @@ -1,7 +1,7 @@ % git clone https://github.com/apple/swift-openapi-generator -% cd swift-openapi-generator/Examples/GreetingService +% cd swift-openapi-generator/Examples/hello-world-vapor-server-example -% swift run GreetingService +% swift run HelloWorldVaporServer .. Build complete! (37.91s) -2023-06-01T10:36:58+0200 notice codes.vapor.application : [Vapor] Server starting on http://127.0.0.1:8080 +2023-12-12T09:06:32+0100 notice codes.vapor.application : [Vapor] Server starting on http://127.0.0.1:8080 diff --git a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.console.1.2.txt b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.console.1.2.txt index a0a71dac..bdd97c3d 100644 --- a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.console.1.2.txt +++ b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.console.1.2.txt @@ -1,10 +1,10 @@ % git clone https://github.com/apple/swift-openapi-generator -% cd swift-openapi-generator/Examples/GreetingService +% cd swift-openapi-generator/Examples/hello-world-vapor-server-example -% swift run GreetingService +% swift run HelloWorldVaporServer .. Build complete! (37.91s) -2023-06-01T10:36:58+0200 notice codes.vapor.application : [Vapor] Server starting on http://127.0.0.1:8080 +2023-12-12T09:06:32+0100 notice codes.vapor.application : [Vapor] Server starting on http://127.0.0.1:8080 % curl 'localhost:8080/api/greet?name=Jane' { diff --git a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.main.0.swift b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.main.0.swift index f7cf60e1..44e20d5a 100644 --- a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.main.0.swift +++ b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.main.0.swift @@ -1 +1,4 @@ +// The Swift Programming Language +// https://docs.swift.org/swift-book + print("Hello, world!") diff --git a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.main.3.swift b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.main.3.swift index 43db3703..36acbcba 100644 --- a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.main.3.swift +++ b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.main.3.swift @@ -6,9 +6,5 @@ let client = Client( transport: URLSessionTransport() ) -let response = try await client.getGreeting( - .init( - query: .init(name: "CLI") - ) -) +let response = try await client.getGreeting(query: .init(name: "CLI")) print(response) diff --git a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.main.4.swift b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.main.4.swift index ffc42cea..1cb79a1b 100644 --- a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.main.4.swift +++ b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.main.4.swift @@ -6,11 +6,7 @@ let client = Client( transport: URLSessionTransport() ) -let response = try await client.getGreeting( - .init( - query: .init(name: "CLI") - ) -) +let response = try await client.getGreeting(query: .init(name: "CLI")) switch response { case .ok(let okResponse): print(okResponse) diff --git a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.main.5.swift b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.main.5.swift index a3bbdcaf..082116fc 100644 --- a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.main.5.swift +++ b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.main.5.swift @@ -6,11 +6,7 @@ let client = Client( transport: URLSessionTransport() ) -let response = try await client.getGreeting( - .init( - query: .init(name: "CLI") - ) -) +let response = try await client.getGreeting(query: .init(name: "CLI")) switch response { case .ok(let okResponse): print(okResponse) diff --git a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.main.6.swift b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.main.6.swift index 4b718279..7da6993b 100644 --- a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.main.6.swift +++ b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.main.6.swift @@ -6,11 +6,7 @@ let client = Client( transport: URLSessionTransport() ) -let response = try await client.getGreeting( - .init( - query: .init(name: "CLI") - ) -) +let response = try await client.getGreeting(query: .init(name: "CLI")) switch response { case .ok(let okResponse): switch okResponse.body { diff --git a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.main.7.swift b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.main.7.swift new file mode 100644 index 00000000..9b13e4e8 --- /dev/null +++ b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.main.7.swift @@ -0,0 +1,10 @@ +import OpenAPIRuntime +import OpenAPIURLSession + +let client = Client( + serverURL: try Servers.server2(), + transport: URLSessionTransport() +) + +let response = try await client.getGreeting(query: .init(name: "CLI")) +print(try response.ok.body.json.message) diff --git a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.openapi.2.yaml b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.openapi.2.yaml index 4408f4b1..1678ad56 100644 --- a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.openapi.2.yaml +++ b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.openapi.2.yaml @@ -12,12 +12,12 @@ paths: get: operationId: getGreeting parameters: - - name: name - required: false - in: query - description: The name used in the returned greeting. - schema: - type: string + - name: name + required: false + in: query + description: The name used in the returned greeting. + schema: + type: string responses: '200': description: A success response with a greeting. diff --git a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.openapi.yaml b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.openapi.yaml index c1e493c0..b7662156 100644 --- a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.openapi.yaml +++ b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.openapi.yaml @@ -10,12 +10,12 @@ paths: get: operationId: getGreeting parameters: - - name: name - required: false - in: query - description: The name used in the returned greeting. - schema: - type: string + - name: name + required: false + in: query + description: The name used in the returned greeting. + schema: + type: string responses: '200': description: A success response with a greeting. diff --git a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.xcode.3.swift b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.xcode.3.swift index 8991ae18..721e2049 100644 --- a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.xcode.3.swift +++ b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.xcode.3.swift @@ -9,10 +9,6 @@ public struct GreetingClient { serverURL: try Servers.server2(), transport: URLSessionTransport() ) - let response = try await client.getGreeting( - .init( - query: .init(name: name) - ) - ) + let response = try await client.getGreeting(query: .init(name: name)) } } diff --git a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.xcode.4.swift b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.xcode.4.swift index 7658f014..384f0eb2 100644 --- a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.xcode.4.swift +++ b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.xcode.4.swift @@ -9,11 +9,7 @@ public struct GreetingClient { serverURL: try Servers.server2(), transport: URLSessionTransport() ) - let response = try await client.getGreeting( - .init( - query: .init(name: name) - ) - ) + let response = try await client.getGreeting(query: .init(name: name)) switch response { case .ok(let okResponse): print(okResponse) diff --git a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.xcode.5.swift b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.xcode.5.swift index 4c133f3d..da9d9511 100644 --- a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.xcode.5.swift +++ b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.xcode.5.swift @@ -9,11 +9,7 @@ public struct GreetingClient { serverURL: try Servers.server2(), transport: URLSessionTransport() ) - let response = try await client.getGreeting( - .init( - query: .init(name: name) - ) - ) + let response = try await client.getGreeting(query: .init(name: name)) switch response { case .ok(let okResponse): print(okResponse) diff --git a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.xcode.6.2.swift b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.xcode.6.2.swift new file mode 100644 index 00000000..33c14bd3 --- /dev/null +++ b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.xcode.6.2.swift @@ -0,0 +1,15 @@ +import OpenAPIURLSession + +public struct GreetingClient { + + public init() {} + + public func getGreeting(name: String?) async throws -> String { + let client = Client( + serverURL: try Servers.server2(), + transport: URLSessionTransport() + ) + let response = try await client.getGreeting(query: .init(name: name)) + return try response.ok.body.json.message + } +} diff --git a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.xcode.6.swift b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.xcode.6.swift index aae71d6e..5bd073eb 100644 --- a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.xcode.6.swift +++ b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.xcode.6.swift @@ -9,11 +9,7 @@ public struct GreetingClient { serverURL: try Servers.server2(), transport: URLSessionTransport() ) - let response = try await client.getGreeting( - .init( - query: .init(name: name) - ) - ) + let response = try await client.getGreeting(query: .init(name: name)) switch response { case .ok(let okResponse): switch okResponse.body { diff --git a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/server.Package.3.swift b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/server.Package.3.swift index 5067493a..6ccab19f 100644 --- a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/server.Package.3.swift +++ b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/server.Package.3.swift @@ -16,10 +16,7 @@ let package = Package( .executableTarget( name: "GreetingService", plugins: [ - .plugin( - name: "OpenAPIGenerator", - package: "swift-openapi-generator" - ) + .plugin(name: "OpenAPIGenerator", package: "swift-openapi-generator"), ] ) ] diff --git a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/server.Package.4.swift b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/server.Package.4.swift index 8ac0751d..fceb1624 100644 --- a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/server.Package.4.swift +++ b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/server.Package.4.swift @@ -16,24 +16,12 @@ let package = Package( .executableTarget( name: "GreetingService", dependencies: [ - .product( - name: "OpenAPIRuntime", - package: "swift-openapi-runtime" - ), - .product( - name: "OpenAPIVapor", - package: "swift-openapi-vapor" - ), - .product( - name: "Vapor", - package: "vapor" - ), + .product(name: "OpenAPIRuntime", package: "swift-openapi-runtime"), + .product(name: "OpenAPIVapor", package: "swift-openapi-vapor"), + .product(name: "Vapor", package: "vapor"), ], plugins: [ - .plugin( - name: "OpenAPIGenerator", - package: "swift-openapi-generator" - ) + .plugin(name: "OpenAPIGenerator", package: "swift-openapi-generator"), ] ) ] diff --git a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/server.Package.5.swift b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/server.Package.5.swift index 8ac0751d..fceb1624 100644 --- a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/server.Package.5.swift +++ b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/server.Package.5.swift @@ -16,24 +16,12 @@ let package = Package( .executableTarget( name: "GreetingService", dependencies: [ - .product( - name: "OpenAPIRuntime", - package: "swift-openapi-runtime" - ), - .product( - name: "OpenAPIVapor", - package: "swift-openapi-vapor" - ), - .product( - name: "Vapor", - package: "vapor" - ), + .product(name: "OpenAPIRuntime", package: "swift-openapi-runtime"), + .product(name: "OpenAPIVapor", package: "swift-openapi-vapor"), + .product(name: "Vapor", package: "vapor"), ], plugins: [ - .plugin( - name: "OpenAPIGenerator", - package: "swift-openapi-generator" - ) + .plugin(name: "OpenAPIGenerator", package: "swift-openapi-generator"), ] ) ] diff --git a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/server.openapi.0.yaml b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/server.openapi.0.yaml index c1e493c0..b7662156 100644 --- a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/server.openapi.0.yaml +++ b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/server.openapi.0.yaml @@ -10,12 +10,12 @@ paths: get: operationId: getGreeting parameters: - - name: name - required: false - in: query - description: The name used in the returned greeting. - schema: - type: string + - name: name + required: false + in: query + description: The name used in the returned greeting. + schema: + type: string responses: '200': description: A success response with a greeting. diff --git a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/server.openapi.1.yaml b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/server.openapi.1.yaml index 6490845b..440fdc49 100644 --- a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/server.openapi.1.yaml +++ b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/server.openapi.1.yaml @@ -10,12 +10,12 @@ paths: get: operationId: getGreeting parameters: - - name: name - required: false - in: query - description: The name used in the returned greeting. - schema: - type: string + - name: name + required: false + in: query + description: The name used in the returned greeting. + schema: + type: string responses: '200': description: A success response with a greeting.