Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 3 additions & 16 deletions Examples/GreetingService/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ let package = Package(
.macOS(.v13)
],
dependencies: [
.package(url: "https://github.com/apple/swift-openapi-generator", .upToNextMinor(from: "0.3.0")),
.package(url: "https://github.com/apple/swift-openapi-runtime", .upToNextMinor(from: "0.3.0")),
.package(url: "https://github.com/apple/swift-openapi-urlsession", .upToNextMinor(from: "0.3.0")),
.package(url: "https://github.com/swift-server/swift-openapi-vapor", .upToNextMinor(from: "0.3.0")),
.package(url: "https://github.com/apple/swift-openapi-generator", .upToNextMinor(from: "0.2.0")),
.package(url: "https://github.com/apple/swift-openapi-runtime", .upToNextMinor(from: "0.2.0")),
.package(url: "https://github.com/swift-server/swift-openapi-vapor", .upToNextMinor(from: "0.2.0")),
.package(url: "https://github.com/vapor/vapor", from: "4.76.0"),
],
targets: [
Expand All @@ -38,18 +37,6 @@ let package = Package(
.plugin(name: "OpenAPIGenerator", package: "swift-openapi-generator")
]
),

.executableTarget(
name: "GreetingServiceClient",
dependencies: [
.product(name: "OpenAPIRuntime", package: "swift-openapi-runtime"),
.product(name: "OpenAPIURLSession", package: "swift-openapi-urlsession"),
],
plugins: [
.plugin(name: "OpenAPIGenerator", package: "swift-openapi-generator")
]
),

.testTarget(
name: "GreetingServiceMockTests",
dependencies: [
Expand Down

This file was deleted.

34 changes: 34 additions & 0 deletions Examples/GreetingService/Sources/GreetingService/openapi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
openapi: '3.0.3'
info:
title: GreetingService
version: 1.0.0
servers:
- url: https://example.com/api
description: Example
paths:
/greet:
get:
operationId: getGreeting
parameters:
- name: name
required: false
in: query
description: A name used in the returned greeting.
schema:
type: string
responses:
'200':
description: A success response with a greeting.
content:
application/json:
schema:
$ref: '#/components/schemas/Greeting'
components:
schemas:
Greeting:
type: object
properties:
message:
type: string
required:
- message

This file was deleted.

11 changes: 11 additions & 0 deletions Examples/GreetingServiceClient/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.DS_Store
.build
/Packages
/*.xcodeproj
xcuserdata/
DerivedData/
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.vscode
/Package.resolved
.ci/
.docc-build/
41 changes: 41 additions & 0 deletions Examples/GreetingServiceClient/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// swift-tools-version:5.8
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftOpenAPIGenerator open source project
//
// Copyright (c) 2023 Apple Inc. and the SwiftOpenAPIGenerator project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of SwiftOpenAPIGenerator project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
import PackageDescription

let package = Package(
name: "GreetingService",
platforms: [
.macOS(.v13)
],
dependencies: [
// TODO: When swift-openapi-generator is tagged with 0.3.0, stop depending on main.
// .package(url: "https://github.com/apple/swift-openapi-generator", .upToNextMinor(from: "0.3.0"),
.package(url: "https://github.com/apple/swift-openapi-generator", branch: "main"),
.package(url: "https://github.com/apple/swift-openapi-runtime", .upToNextMinor(from: "0.3.0")),
.package(url: "https://github.com/apple/swift-openapi-urlsession", .upToNextMinor(from: "0.3.0")),
],
targets: [
.executableTarget(
name: "GreetingServiceClient",
dependencies: [
.product(name: "OpenAPIRuntime", package: "swift-openapi-runtime"),
.product(name: "OpenAPIURLSession", package: "swift-openapi-urlsession"),
],
plugins: [
.plugin(name: "OpenAPIGenerator", package: "swift-openapi-generator")
]
)
]
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftOpenAPIGenerator open source project
//
// Copyright (c) 2023 Apple Inc. and the SwiftOpenAPIGenerator project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of SwiftOpenAPIGenerator project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
import GreetingService

// Mock operates on value types, and requires no concrete client or server transport.
struct MockGreetingService: APIProtocol {
func getGreeting(
_ input: Operations.getGreeting.Input
) async throws -> Operations.getGreeting.Output {
let name = input.query.name ?? "<unknown>"
return .ok(.init(body: .json(.init(message: "(mock) Hello, \(name)"))))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftOpenAPIGenerator open source project
//
// Copyright (c) 2023 Apple Inc. and the SwiftOpenAPIGenerator project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of SwiftOpenAPIGenerator project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
import XCTest
@testable import GreetingService

final class GreetingServiceMockTests: XCTestCase {
func testWithMock() async throws {
let client: APIProtocol = MockGreetingService()
let response = try await client.getGreeting(.init(query: .init(name: "Jane")))
XCTAssertEqual(response, .ok(.init(body: .json(.init(message: "(mock) Hello, Jane")))))
}
}