Skip to content

Commit e8d5ae9

Browse files
authored
Prepare 0.2.0 release (API breaking changes) (#218)
Prepare 0.2.0 release (API breaking changes) ### Motivation It's time to release an API-breaking version and delete all the deprecated code. Requires that we first release 0.2.0 of the runtime library. ### Modifications Deleted all the deprecated code, removed all the feature flags and This is a breaking change, so the integration test will fail until we land this and then the corresponding generator changes. ### Result Removed a bunch of code! ### Test Plan Let's let CI check everything except for the integration test. Reviewed by: gjcairo Builds: ✔︎ pull request validation (soundness) - Build finished. ✖︎ pull request validation (5.8) - Build finished. ✖︎ pull request validation (5.9) - Build finished. ✖︎ pull request validation (docc test) - Build finished. ✖︎ pull request validation (integration test) - Build finished. ✖︎ pull request validation (nightly) - Build finished. #218
1 parent 7ddef95 commit e8d5ae9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+706
-4488
lines changed

IntegrationTest/Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ let package = Package(
3232
)
3333
],
3434
dependencies: [
35-
.package(url: "https://github.com/apple/swift-openapi-generator", .upToNextMinor(from: "0.1.0")),
36-
.package(url: "https://github.com/apple/swift-openapi-runtime", .upToNextMinor(from: "0.1.0")),
35+
.package(url: "https://github.com/apple/swift-openapi-generator", .upToNextMinor(from: "0.2.0")),
36+
.package(url: "https://github.com/apple/swift-openapi-runtime", .upToNextMinor(from: "0.2.0")),
3737
],
3838
targets: [
3939
.target(

Package.swift

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ let package = Package(
8080
// Tests-only: Runtime library linked by generated code, and also
8181
// helps keep the runtime library new enough to work with the generated
8282
// code.
83-
.package(url: "https://github.com/apple/swift-openapi-runtime", .upToNextMinor(from: "0.1.11")),
83+
.package(url: "https://github.com/apple/swift-openapi-runtime", .upToNextMinor(from: "0.2.0")),
8484

8585
// Build and preview docs
8686
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
@@ -147,18 +147,6 @@ let package = Package(
147147
swiftSettings: swiftSettings
148148
),
149149

150-
// PetstoreConsumerTestsFFMultipleContentTypes
151-
// Builds and tests the reference code from GeneratorReferenceTests
152-
// to ensure it actually works correctly at runtime.
153-
// Enabled feature flag: multipleContentTypes
154-
.testTarget(
155-
name: "PetstoreConsumerTestsFFMultipleContentTypes",
156-
dependencies: [
157-
"PetstoreConsumerTestCore"
158-
],
159-
swiftSettings: swiftSettings
160-
),
161-
162150
// Generator CLI
163151
.executableTarget(
164152
name: "swift-openapi-generator",

Sources/_OpenAPIGeneratorCore/FeatureFlags.swift

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,9 @@
2727
/// 1.0 is released.)
2828
public enum FeatureFlag: String, Hashable, Codable, CaseIterable {
2929

30-
/// Multiple request and response body content types.
31-
///
32-
/// Tracking issues:
33-
/// - https://github.com/apple/swift-openapi-generator/issues/6
34-
/// - https://github.com/apple/swift-openapi-generator/issues/7
35-
case multipleContentTypes
36-
37-
/// SOAR-0001 Improved OpenAPI -> Swift name mapping
38-
///
39-
/// Tracking issues:
40-
/// - https://github.com/apple/swift-openapi-generator/pull/95
41-
case proposal0001
42-
43-
/// Stricted input OpenAPI document validation.
44-
///
45-
/// Check for structural issues and detect cycles proactively.
46-
case strictOpenAPIValidation
47-
48-
/// Removed the generation of an undocumented case in enums/oneOfs.
49-
///
50-
/// Tracking issue:
51-
/// - https://github.com/apple/swift-openapi-generator/issues/204
52-
case closedEnumsAndOneOfs
30+
/// Has to be here until we add more feature flags, otherwise the enum
31+
/// doesn't compile.
32+
case empty
5333
}
5434

5535
/// A set of enabled feature flags.

Sources/_OpenAPIGeneratorCore/Parser/validateDoc.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
/// - config: The generator config.
1919
/// - Throws: An error if a fatal issue is found.
2020
func validateDoc(_ doc: ParsedOpenAPIRepresentation, config: Config) throws -> [Diagnostic] {
21-
guard config.featureFlags.contains(.strictOpenAPIValidation) else {
22-
return []
23-
}
2421
// Run OpenAPIKit's built-in validation.
2522
// Pass `false` to `strict`, however, because we don't
2623
// want to turn schema loading warnings into errors.

Sources/_OpenAPIGeneratorCore/Translator/CommonTranslations/SwiftSafeNames.swift

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -19,57 +19,12 @@ extension FileTranslator {
1919
///
2020
/// - Parameter string: The string to convert to be safe for Swift.
2121
func swiftSafeName(for string: String) -> String {
22-
guard config.featureFlags.contains(.proposal0001) else {
23-
return string.safeForSwiftCode
24-
}
25-
return string.proposedSafeForSwiftCode
22+
string.safeForSwiftCode
2623
}
2724
}
2825

2926
fileprivate extension String {
3027

31-
/// Returns a string sanitized to be usable as a Swift identifier.
32-
///
33-
/// For example, the string `$nake` would be returned as `_nake`, because
34-
/// the dollar sign is not a valid character in a Swift identifier.
35-
///
36-
/// In addition to replacing illegal characters with an underscores, also
37-
/// ensures that the identifier starts with a letter and not a number.
38-
var safeForSwiftCode: String {
39-
guard !isEmpty else {
40-
return "_empty"
41-
}
42-
43-
// Only allow [a-zA-Z][a-zA-Z0-9_]*
44-
// This is bad, is there something like percent encoding functionality but for general "allowed chars only"?
45-
46-
let firstCharSet: CharacterSet = .letters
47-
let numbers: CharacterSet = .decimalDigits
48-
let otherCharSet: CharacterSet = .alphanumerics.union(.init(charactersIn: "_"))
49-
50-
var sanitizedScalars: [Unicode.Scalar] = []
51-
for (index, scalar) in unicodeScalars.enumerated() {
52-
let allowedSet = index == 0 ? firstCharSet : otherCharSet
53-
let outScalar: Unicode.Scalar
54-
if allowedSet.contains(scalar) {
55-
outScalar = scalar
56-
} else if index == 0 && numbers.contains(scalar) {
57-
sanitizedScalars.append("_")
58-
outScalar = scalar
59-
} else {
60-
outScalar = "_"
61-
}
62-
sanitizedScalars.append(outScalar)
63-
}
64-
65-
let validString = String(UnicodeScalarView(sanitizedScalars))
66-
67-
guard Self.keywords.contains(validString) else {
68-
return validString
69-
}
70-
return "_\(validString)"
71-
}
72-
7328
/// Returns a string sanitized to be usable as a Swift identifier.
7429
///
7530
/// See the proposal SOAR-0001 for details.
@@ -81,7 +36,7 @@ fileprivate extension String {
8136
///
8237
/// In addition to replacing illegal characters, it also
8338
/// ensures that the identifier starts with a letter and not a number.
84-
var proposedSafeForSwiftCode: String {
39+
var safeForSwiftCode: String {
8540
guard !isEmpty else {
8641
return "_empty"
8742
}

Sources/_OpenAPIGeneratorCore/Translator/CommonTranslations/translateAllAnyOneOf.swift

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,9 @@ extension FileTranslator {
207207

208208
let caseNames = cases.map(\.0)
209209

210-
let undocumentedType: TypeName
211210
let codingKeysDecls: [Declaration]
212211
let decoder: Declaration
213212
if let discriminator {
214-
undocumentedType = .objectContainer
215213
let originalName = discriminator.propertyName
216214
let swiftName = swiftSafeName(for: originalName)
217215
codingKeysDecls = [
@@ -232,33 +230,12 @@ extension FileTranslator {
232230
cases: cases.map { ($0.0, $0.1!) }
233231
)
234232
} else {
235-
undocumentedType = .valueContainer
236233
codingKeysDecls = []
237234
decoder = translateOneOfWithoutDiscriminatorDecoder(
238235
caseNames: caseNames
239236
)
240237
}
241238

242-
let generateUndocumentedCase = shouldGenerateUndocumentedCaseForEnumsAndOneOfs
243-
244-
let otherCases: [Declaration]
245-
if generateUndocumentedCase {
246-
let undocumentedCase: Declaration = .commentable(
247-
.doc("Parsed a case that was not defined in the OpenAPI document."),
248-
.enumCase(
249-
name: Constants.OneOf.undocumentedCaseName,
250-
kind: .nameWithAssociatedValues([
251-
.init(type: undocumentedType.fullyQualifiedSwiftName)
252-
])
253-
)
254-
)
255-
otherCases = [
256-
undocumentedCase
257-
]
258-
} else {
259-
otherCases = []
260-
}
261-
262239
let encoder = translateOneOfEncoder(caseNames: caseNames)
263240

264241
let comment: Comment? =
@@ -269,7 +246,7 @@ extension FileTranslator {
269246
accessModifier: config.access,
270247
name: typeName.shortSwiftName,
271248
conformances: Constants.ObjectStruct.conformances,
272-
members: caseDecls + otherCases + codingKeysDecls + [
249+
members: caseDecls + codingKeysDecls + [
273250
decoder,
274251
encoder,
275252
]

Sources/_OpenAPIGeneratorCore/Translator/CommonTranslations/translateCodable.swift

Lines changed: 21 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -339,61 +339,11 @@ extension FileTranslator {
339339
)
340340
}
341341

342-
let generateUndocumentedCase = shouldGenerateUndocumentedCaseForEnumsAndOneOfs
343-
let otherExprs: [CodeBlock]
344-
if generateUndocumentedCase {
345-
otherExprs = [
346-
.declaration(
347-
.variable(
348-
kind: .let,
349-
left: "container",
350-
right: .try(
351-
.identifier("decoder")
352-
.dot("singleValueContainer")
353-
.call([])
354-
)
355-
)
356-
),
357-
.declaration(
358-
.variable(
359-
kind: .let,
360-
left: "value",
361-
right: .try(
362-
.identifier("container")
363-
.dot("decode")
364-
.call([
365-
.init(
366-
label: nil,
367-
expression:
368-
.identifier(
369-
TypeName
370-
.valueContainer
371-
.fullyQualifiedSwiftName
372-
)
373-
.dot("self")
374-
)
375-
])
376-
)
377-
)
378-
),
379-
.expression(
380-
.assignment(
381-
left: .identifier("self"),
382-
right: .dot(Constants.OneOf.undocumentedCaseName)
383-
.call([
384-
.init(label: nil, expression: .identifier("value"))
385-
])
386-
)
387-
),
388-
]
389-
} else {
390-
otherExprs = [
391-
.expression(
392-
translateOneOfDecoderThrowOnUnknownExpr()
393-
)
394-
]
395-
}
396-
342+
let otherExprs: [CodeBlock] = [
343+
.expression(
344+
translateOneOfDecoderThrowOnUnknownExpr()
345+
)
346+
]
397347
return decoderInitializer(
398348
body: (assignExprs).map { .expression($0) } + otherExprs
399349
)
@@ -447,60 +397,11 @@ extension FileTranslator {
447397
]
448398
)
449399
}
450-
let generateUndocumentedCase = shouldGenerateUndocumentedCaseForEnumsAndOneOfs
451-
let otherExprs: [CodeBlock]
452-
if generateUndocumentedCase {
453-
otherExprs = [
454-
.declaration(
455-
.variable(
456-
kind: .let,
457-
left: "container",
458-
right: .try(
459-
.identifier("decoder")
460-
.dot("singleValueContainer")
461-
.call([])
462-
)
463-
)
464-
),
465-
.declaration(
466-
.variable(
467-
kind: .let,
468-
left: "value",
469-
right: .try(
470-
.identifier("container")
471-
.dot("decode")
472-
.call([
473-
.init(
474-
label: nil,
475-
expression:
476-
.identifier(
477-
TypeName
478-
.objectContainer
479-
.fullyQualifiedSwiftName
480-
)
481-
.dot("self")
482-
)
483-
])
484-
)
485-
)
486-
),
487-
.expression(
488-
.assignment(
489-
left: .identifier("self"),
490-
right: .dot(Constants.OneOf.undocumentedCaseName)
491-
.call([
492-
.init(label: nil, expression: .identifier("value"))
493-
])
494-
)
495-
),
496-
]
497-
} else {
498-
otherExprs = [
499-
.expression(
500-
translateOneOfDecoderThrowOnUnknownExpr()
501-
)
502-
]
503-
}
400+
let otherExprs: [CodeBlock] = [
401+
.expression(
402+
translateOneOfDecoderThrowOnUnknownExpr()
403+
)
404+
]
504405
let body: [CodeBlock] = [
505406
.declaration(.decoderContainerOfKeysVar()),
506407
.declaration(
@@ -546,27 +447,19 @@ extension FileTranslator {
546447
func translateOneOfEncoder(
547448
caseNames: [String]
548449
) -> Declaration {
549-
let generateUndocumentedCase = shouldGenerateUndocumentedCaseForEnumsAndOneOfs
550-
let otherCaseNames: [String]
551-
if generateUndocumentedCase {
552-
otherCaseNames = [Constants.OneOf.undocumentedCaseName]
553-
} else {
554-
otherCaseNames = []
555-
}
556450
let switchExpr: Expression = .switch(
557451
switchedExpression: .identifier("self"),
558-
cases: (caseNames + otherCaseNames)
559-
.map { caseName in
560-
.init(
561-
kind: .case(.dot(caseName), ["value"]),
562-
body: [
563-
.expression(
564-
.identifier("value")
565-
.encodeExpr()
566-
)
567-
]
568-
)
569-
}
452+
cases: caseNames.map { caseName in
453+
.init(
454+
kind: .case(.dot(caseName), ["value"]),
455+
body: [
456+
.expression(
457+
.identifier("value")
458+
.encodeExpr()
459+
)
460+
]
461+
)
462+
}
570463
)
571464
return encoderFunction(body: [.expression(switchExpr)])
572465
}

0 commit comments

Comments
 (0)