-
Notifications
You must be signed in to change notification settings - Fork 116
/
Package.swift
153 lines (136 loc) · 5.77 KB
/
Package.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// swift-tools-version:5.9
//===----------------------------------------------------------------------===//
//
// 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 Foundation
import PackageDescription
// General Swift-settings for all targets.
var swiftSettings: [SwiftSetting] = [
// https://github.com/apple/swift-evolution/blob/main/proposals/0335-existential-any.md
// Require `any` for existential types.
.enableUpcomingFeature("ExistentialAny")
]
// Strict concurrency is enabled in CI; use this environment variable to enable it locally.
if ProcessInfo.processInfo.environment["SWIFT_OPENAPI_STRICT_CONCURRENCY"].flatMap(Bool.init) ?? false {
swiftSettings.append(contentsOf: [
.define("SWIFT_OPENAPI_STRICT_CONCURRENCY"), .enableExperimentalFeature("StrictConcurrency"),
])
}
let package = Package(
name: "swift-openapi-generator",
platforms: [
.macOS(.v10_15),
// The platforms below are not currently supported for running
// the generator itself. We include them here to allow the generator
// to emit a more descriptive compiler error.
.iOS(.v13), .tvOS(.v13), .watchOS(.v6), .visionOS(.v1),
],
products: [
.executable(name: "swift-openapi-generator", targets: ["swift-openapi-generator"]),
.plugin(name: "OpenAPIGenerator", targets: ["OpenAPIGenerator"]),
.plugin(name: "OpenAPIGeneratorCommand", targets: ["OpenAPIGeneratorCommand"]),
.library(name: "_OpenAPIGeneratorCore", targets: ["_OpenAPIGeneratorCore"]),
],
dependencies: [
// General algorithms
.package(url: "https://github.com/apple/swift-algorithms", from: "1.2.0"),
// Read OpenAPI documents
.package(url: "https://github.com/mattpolzin/OpenAPIKit", from: "3.3.0"),
.package(url: "https://github.com/jpsim/Yams", "4.0.0"..<"6.0.0"),
// CLI Tool
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.3.0"),
// Tests-only: Runtime library linked by generated code, and also
// helps keep the runtime library new enough to work with the generated
// code.
.package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.3.2"),
.package(url: "https://github.com/apple/swift-http-types", from: "1.0.2"),
],
targets: [
// Generator Core
.target(
name: "_OpenAPIGeneratorCore",
dependencies: [
.product(name: "OpenAPIKit", package: "OpenAPIKit"),
.product(name: "OpenAPIKit30", package: "OpenAPIKit"),
.product(name: "OpenAPIKitCompat", package: "OpenAPIKit"),
.product(name: "Algorithms", package: "swift-algorithms"), .product(name: "Yams", package: "Yams"),
],
swiftSettings: swiftSettings
),
// Generator Core Tests
.testTarget(
name: "OpenAPIGeneratorCoreTests",
dependencies: ["_OpenAPIGeneratorCore"],
swiftSettings: swiftSettings
),
// GeneratorReferenceTests
.testTarget(
name: "OpenAPIGeneratorReferenceTests",
dependencies: ["_OpenAPIGeneratorCore"],
resources: [.copy("Resources")],
swiftSettings: swiftSettings
),
// Common types for concrete PetstoreConsumer*Tests test targets.
.target(
name: "PetstoreConsumerTestCore",
dependencies: [
.product(name: "OpenAPIRuntime", package: "swift-openapi-runtime"),
.product(name: "HTTPTypes", package: "swift-http-types"),
],
swiftSettings: swiftSettings
),
// PetstoreConsumerTests
// Builds and tests the reference code from GeneratorReferenceTests
// to ensure it actually works correctly at runtime.
.testTarget(
name: "PetstoreConsumerTests",
dependencies: ["PetstoreConsumerTestCore"],
swiftSettings: swiftSettings
),
// Test Target for swift-openapi-generator
.testTarget(
name: "OpenAPIGeneratorTests",
dependencies: [
"swift-openapi-generator", .product(name: "ArgumentParser", package: "swift-argument-parser"),
],
resources: [.copy("Resources")],
swiftSettings: swiftSettings
),
// Generator CLI
.executableTarget(
name: "swift-openapi-generator",
dependencies: [
"_OpenAPIGeneratorCore", .product(name: "ArgumentParser", package: "swift-argument-parser"),
],
swiftSettings: swiftSettings
),
// Build Plugin
.plugin(name: "OpenAPIGenerator", capability: .buildTool(), dependencies: ["swift-openapi-generator"]),
// Command Plugin
.plugin(
name: "OpenAPIGeneratorCommand",
capability: .command(
intent: .custom(
verb: "generate-code-from-openapi",
description: "Generate Swift code from an OpenAPI document."
),
permissions: [
.writeToPackageDirectory(
reason: "To write the generated Swift files back into the source directory of the package."
)
]
),
dependencies: ["swift-openapi-generator"]
),
]
)