Skip to content

Commit 9ed8313

Browse files
Disable default traits for swift-openapi-runtime dependency (#878)
Disables the default traits for the `openapi-runtime`, to make sure that other packages depending on the generator can actually disable the traits if they want to. --------- Co-authored-by: Si Beaumont <simonjbeaumont@gmail.com>
1 parent 1c47554 commit 9ed8313

5 files changed

Lines changed: 177 additions & 3 deletions

File tree

.licenseignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ CONTRIBUTORS.txt
1111
LICENSE.txt
1212
NOTICE.txt
1313
Package.swift
14+
Package@swift-*.swift
1415
Package.resolved
1516
README.md
1617
SECURITY.md
@@ -21,6 +22,7 @@ docker/*
2122
**/*.docc/*
2223
**/.gitignore
2324
**/Package.swift
25+
**/Package@-*.swift
2426
**/Package.resolved
2527
**/README.md
2628
**/openapi.yaml

.swiftformatignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ Examples/**/Generated/*
44
Examples/**/GeneratedSources/*
55
Examples/streaming-chatgpt-proxy/**
66
**Package.swift
7+
**Package@-*.swift
8+
**Package@swift-*.swift

Package.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.10
1+
// swift-tools-version:6.1
22
//===----------------------------------------------------------------------===//
33
//
44
// This source file is part of the SwiftOpenAPIGenerator open source project
@@ -20,6 +20,7 @@ var swiftSettings: [SwiftSetting] = [
2020
// https://github.com/apple/swift-evolution/blob/main/proposals/0335-existential-any.md
2121
// Require `any` for existential types.
2222
.enableUpcomingFeature("ExistentialAny"), .enableExperimentalFeature("StrictConcurrency=complete"),
23+
.swiftLanguageMode(.v5),
2324
]
2425

2526
let package = Package(
@@ -54,7 +55,7 @@ let package = Package(
5455
// Tests-only: Runtime library linked by generated code, and also
5556
// helps keep the runtime library new enough to work with the generated
5657
// code.
57-
.package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.8.2"),
58+
.package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.11.0", traits: []),
5859
.package(url: "https://github.com/apple/swift-http-types", from: "1.0.2"),
5960
],
6061
targets: [

Package@swift-5.10.swift

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
// swift-tools-version:5.10
2+
//===----------------------------------------------------------------------===//
3+
//
4+
// This source file is part of the SwiftOpenAPIGenerator open source project
5+
//
6+
// Copyright (c) 2023 Apple Inc. and the SwiftOpenAPIGenerator project authors
7+
// Licensed under Apache License v2.0
8+
//
9+
// See LICENSE.txt for license information
10+
// See CONTRIBUTORS.txt for the list of SwiftOpenAPIGenerator project authors
11+
//
12+
// SPDX-License-Identifier: Apache-2.0
13+
//
14+
//===----------------------------------------------------------------------===//
15+
import Foundation
16+
import PackageDescription
17+
18+
// General Swift-settings for all targets.
19+
var swiftSettings: [SwiftSetting] = [
20+
// https://github.com/apple/swift-evolution/blob/main/proposals/0335-existential-any.md
21+
// Require `any` for existential types.
22+
.enableUpcomingFeature("ExistentialAny"), .enableExperimentalFeature("StrictConcurrency=complete"),
23+
]
24+
25+
let package = Package(
26+
name: "swift-openapi-generator",
27+
platforms: [
28+
.macOS(.v10_15),
29+
30+
// The platforms below are not currently supported for running
31+
// the generator itself. We include them here to allow the generator
32+
// to emit a more descriptive compiler error.
33+
.iOS(.v13), .tvOS(.v13), .watchOS(.v6), .visionOS(.v1),
34+
],
35+
products: [
36+
.executable(name: "swift-openapi-generator", targets: ["swift-openapi-generator"]),
37+
.plugin(name: "OpenAPIGenerator", targets: ["OpenAPIGenerator"]),
38+
.plugin(name: "OpenAPIGeneratorCommand", targets: ["OpenAPIGeneratorCommand"]),
39+
.library(name: "_OpenAPIGeneratorCore", targets: ["_OpenAPIGeneratorCore"]),
40+
],
41+
dependencies: [
42+
43+
// General algorithms
44+
.package(url: "https://github.com/apple/swift-algorithms", from: "1.2.0"),
45+
.package(url: "https://github.com/apple/swift-collections", from: "1.1.4"),
46+
47+
// Read OpenAPI documents
48+
.package(url: "https://github.com/mattpolzin/OpenAPIKit", from: "3.9.0"),
49+
.package(url: "https://github.com/jpsim/Yams", "4.0.0"..<"7.0.0"),
50+
51+
// CLI Tool
52+
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.3.0"),
53+
54+
// Tests-only: Runtime library linked by generated code, and also
55+
// helps keep the runtime library new enough to work with the generated
56+
// code.
57+
.package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.11.0"),
58+
.package(url: "https://github.com/apple/swift-http-types", from: "1.0.2"),
59+
],
60+
targets: [
61+
62+
// Generator Core
63+
.target(
64+
name: "_OpenAPIGeneratorCore",
65+
dependencies: [
66+
.product(name: "OpenAPIKit", package: "OpenAPIKit"),
67+
.product(name: "OpenAPIKit30", package: "OpenAPIKit"),
68+
.product(name: "OpenAPIKitCompat", package: "OpenAPIKit"),
69+
.product(name: "Algorithms", package: "swift-algorithms"),
70+
.product(name: "OrderedCollections", package: "swift-collections"),
71+
.product(name: "Yams", package: "Yams"),
72+
],
73+
swiftSettings: swiftSettings
74+
),
75+
76+
// Generator Core Tests
77+
.testTarget(
78+
name: "OpenAPIGeneratorCoreTests",
79+
dependencies: ["_OpenAPIGeneratorCore"],
80+
swiftSettings: swiftSettings
81+
),
82+
83+
// GeneratorReferenceTests
84+
.testTarget(
85+
name: "OpenAPIGeneratorReferenceTests",
86+
dependencies: ["_OpenAPIGeneratorCore"],
87+
resources: [.copy("Resources")],
88+
swiftSettings: swiftSettings
89+
),
90+
91+
// Common types for concrete PetstoreConsumer*Tests test targets.
92+
.target(
93+
name: "PetstoreConsumerTestCore",
94+
dependencies: [
95+
.product(name: "OpenAPIRuntime", package: "swift-openapi-runtime"),
96+
.product(name: "HTTPTypes", package: "swift-http-types"),
97+
],
98+
swiftSettings: swiftSettings
99+
),
100+
101+
// PetstoreConsumerTests
102+
// Builds and tests the reference code from GeneratorReferenceTests
103+
// to ensure it actually works correctly at runtime.
104+
.testTarget(
105+
name: "PetstoreConsumerTests",
106+
dependencies: ["PetstoreConsumerTestCore"],
107+
swiftSettings: swiftSettings
108+
),
109+
110+
// Test Target for swift-openapi-generator
111+
.testTarget(
112+
name: "OpenAPIGeneratorTests",
113+
dependencies: [
114+
"_OpenAPIGeneratorCore",
115+
// Everything except windows: https://github.com/swiftlang/swift-package-manager/issues/6367
116+
.target(
117+
name: "swift-openapi-generator",
118+
condition: .when(platforms: [.android, .linux, .macOS, .openbsd, .wasi, .custom("freebsd")])
119+
), .product(name: "ArgumentParser", package: "swift-argument-parser"),
120+
],
121+
resources: [.copy("Resources")],
122+
swiftSettings: swiftSettings
123+
),
124+
125+
// Generator CLI
126+
.executableTarget(
127+
name: "swift-openapi-generator",
128+
dependencies: [
129+
"_OpenAPIGeneratorCore", .product(name: "ArgumentParser", package: "swift-argument-parser"),
130+
],
131+
swiftSettings: swiftSettings
132+
),
133+
134+
// Build Plugin
135+
.plugin(name: "OpenAPIGenerator", capability: .buildTool(), dependencies: ["swift-openapi-generator"]),
136+
137+
// Command Plugin
138+
.plugin(
139+
name: "OpenAPIGeneratorCommand",
140+
capability: .command(
141+
intent: .custom(
142+
verb: "generate-code-from-openapi",
143+
description: "Generate Swift code from an OpenAPI document."
144+
),
145+
permissions: [
146+
.writeToPackageDirectory(
147+
reason: "To write the generated Swift files back into the source directory of the package."
148+
)
149+
]
150+
),
151+
dependencies: ["swift-openapi-generator"]
152+
),
153+
]
154+
)
155+
156+
// --- STANDARD CROSS-REPO SETTINGS DO NOT EDIT --- //
157+
for target in package.targets {
158+
switch target.type {
159+
case .regular, .test, .executable:
160+
var settings = target.swiftSettings ?? []
161+
// https://github.com/swiftlang/swift-evolution/blob/main/proposals/0444-member-import-visibility.md
162+
settings.append(.enableUpcomingFeature("MemberImportVisibility"))
163+
target.swiftSettings = settings
164+
case .macro, .plugin, .system, .binary: () // not applicable
165+
@unknown default: () // we don't know what to do here, do nothing
166+
}
167+
}// --- END: STANDARD CROSS-REPO SETTINGS DO NOT EDIT --- //

Plugins/PluginsShared/PluginError.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ struct FileError: Swift.Error, Equatable, CustomStringConvertible, LocalizedErro
7777
/// File wasn't found.
7878
case noFilesFound
7979
/// More than 1 file found.
80-
case multipleFilesFound(files: [Path])
80+
case multipleFilesFound(files: [String])
81+
82+
static func multipleFilesFound(files: [Path]) -> Self { .multipleFilesFound(files: files.map(\.description)) }
8183

8284
/// The error is definitely due to misconfiguration of a target.
8385
var isMisconfigurationError: Bool {

0 commit comments

Comments
 (0)