Skip to content

Commit 0f813d6

Browse files
authored
Enable all feature flags for 0.3.0 (#296)
Enable all feature flags for 0.3.0 ### Motivation 0.3.0 is an API-breaking version, so let's take the opportunity to enable all feature flags and delete them. ### Modifications Deleted all feature flags, all the staged behavior is now enabled by default. ### Result Simplified codebase again, we only support the new behavior. ### Test Plan Adapted tests as well. Reviewed by: simonjbeaumont Builds: ✔︎ pull request validation (5.8) - Build finished. ✔︎ pull request validation (5.9) - Build finished. ✔︎ pull request validation (compatibility test) - Build finished. ✔︎ pull request validation (docc test) - Build finished. ✔︎ pull request validation (nightly) - Build finished. ✔︎ pull request validation (soundness) - Build finished. ✖︎ pull request validation (integration test) - Build finished. #296
1 parent b65592a commit 0f813d6

File tree

7 files changed

+10
-111
lines changed

7 files changed

+10
-111
lines changed

Sources/_OpenAPIGeneratorCore/FeatureFlags.swift

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,8 @@
2626
/// 0.2 is tagged. (This is for pre-1.0 versioning, would be 1.0 and 2.0 after
2727
/// 1.0 is released.)
2828
public enum FeatureFlag: String, Hashable, Codable, CaseIterable, Sendable {
29-
30-
/// Support for `nullable` schemas.
31-
///
32-
/// A dedicated field in OpenAPI 3.0, a `null` value present in
33-
/// the `types` array in OpenAPI 3.1.
34-
case nullableSchemas
35-
36-
/// Support for `application/x-www-form-urlencoded` request bodies as
37-
/// structured payloads.
38-
case urlEncodedForm
29+
// needs to be here for the enum to compile
30+
case empty
3931
}
4032

4133
/// A set of enabled feature flags.

Sources/_OpenAPIGeneratorCore/Translator/Content/ContentInspector.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,15 +231,14 @@ extension FileTranslator {
231231
schema: contentValue.schema
232232
)
233233
}
234-
let urlEncodedFormsSupported = config.featureFlags.contains(.urlEncodedForm)
235-
if urlEncodedFormsSupported && contentKey.isUrlEncodedForm {
234+
if contentKey.isUrlEncodedForm {
236235
let contentType = ContentType(contentKey.typeAndSubtype)
237236
return .init(
238237
contentType: contentType,
239238
schema: contentValue.schema
240239
)
241240
}
242-
if !excludeBinary, contentKey.isBinary || !urlEncodedFormsSupported {
241+
if !excludeBinary, contentKey.isBinary {
243242
let contentType = contentKey.asGeneratorContentType
244243
return .init(
245244
contentType: contentType,

Sources/_OpenAPIGeneratorCore/Translator/FileTranslator+FeatureFlags.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,4 @@ import OpenAPIKit
1515

1616
extension FileTranslator {
1717
// Add helpers for reading feature flags below.
18-
19-
/// A Boolean value indicating whether the `nullable` field on schemas
20-
/// should be taken into account.
21-
var supportNullableSchemas: Bool {
22-
config.featureFlags.contains(.nullableSchemas)
23-
}
2418
}

Sources/_OpenAPIGeneratorCore/Translator/TypeAssignment/TypeAssigner.swift

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ struct TypeAssigner {
4545
/// safe to be used as a Swift identifier.
4646
var asSwiftSafeName: (String) -> String
4747

48-
/// A Boolean value indicating whether the `nullable` field on schemas
49-
/// should be taken into account.
50-
var supportNullableSchemas: Bool
51-
5248
/// Returns a type name for an OpenAPI-named component type.
5349
///
5450
/// A component type is any type in `#/components` in the OpenAPI document.
@@ -261,8 +257,7 @@ struct TypeAssigner {
261257
// creating a new inline type.
262258
if let referenceableType =
263259
try TypeMatcher(
264-
asSwiftSafeName: asSwiftSafeName,
265-
supportNullableSchemas: supportNullableSchemas
260+
asSwiftSafeName: asSwiftSafeName
266261
)
267262
.tryMatchReferenceableType(for: schema)
268263
{
@@ -460,16 +455,14 @@ extension FileTranslator {
460455
/// A configured type assigner.
461456
var typeAssigner: TypeAssigner {
462457
TypeAssigner(
463-
asSwiftSafeName: swiftSafeName,
464-
supportNullableSchemas: supportNullableSchemas
458+
asSwiftSafeName: swiftSafeName
465459
)
466460
}
467461

468462
/// A configured type matcher.
469463
var typeMatcher: TypeMatcher {
470464
TypeMatcher(
471-
asSwiftSafeName: swiftSafeName,
472-
supportNullableSchemas: supportNullableSchemas
465+
asSwiftSafeName: swiftSafeName
473466
)
474467
}
475468
}

Sources/_OpenAPIGeneratorCore/Translator/TypeAssignment/TypeMatcher.swift

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ struct TypeMatcher {
2020
/// safe to be used as a Swift identifier.
2121
var asSwiftSafeName: (String) -> String
2222

23-
/// A Boolean value indicating whether the `nullable` field on schemas
24-
/// should be taken into account.
25-
var supportNullableSchemas: Bool
26-
2723
/// Returns the type name of a built-in type that matches the specified
2824
/// schema.
2925
///
@@ -83,8 +79,7 @@ struct TypeMatcher {
8379
return nil
8480
}
8581
return try TypeAssigner(
86-
asSwiftSafeName: asSwiftSafeName,
87-
supportNullableSchemas: supportNullableSchemas
82+
asSwiftSafeName: asSwiftSafeName
8883
)
8984
.typeName(for: ref).asUsage
9085
},
@@ -95,7 +90,7 @@ struct TypeMatcher {
9590
TypeName.arrayContainer.asUsage
9691
}
9792
)?
98-
.withOptional(!schema.required || (supportNullableSchemas && schema.nullable))
93+
.withOptional(!schema.required || schema.nullable)
9994
}
10095

10196
/// Returns a Boolean value that indicates whether the schema

Tests/OpenAPIGeneratorReferenceTests/FileBasedReferenceTests.swift

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,7 @@ class FileBasedReferenceTests: XCTestCase {
4545
}
4646

4747
func testPetstore() throws {
48-
try _test(
49-
referenceProject: .init(name: .petstore),
50-
featureFlags: [
51-
.urlEncodedForm
52-
]
53-
)
48+
try _test(referenceProject: .init(name: .petstore))
5449
}
5550

5651
// MARK: - Private

Tests/OpenAPIGeneratorReferenceTests/SnippetBasedReferenceTests.swift

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -103,53 +103,6 @@ final class SnippetBasedReferenceTests: XCTestCase {
103103

104104
func testComponentsSchemasNullableStringProperty() throws {
105105
try self.assertSchemasTranslation(
106-
"""
107-
schemas:
108-
MyObj:
109-
type: object
110-
properties:
111-
fooOptional:
112-
type: string
113-
fooRequired:
114-
type: string
115-
fooOptionalNullable:
116-
type: [string, null]
117-
fooRequiredNullable:
118-
type: [string, null]
119-
required:
120-
- fooRequired
121-
- fooRequiredNullable
122-
""",
123-
"""
124-
public enum Schemas {
125-
public struct MyObj: Codable, Hashable, Sendable {
126-
public var fooOptional: Swift.String?
127-
public var fooRequired: Swift.String
128-
public var fooOptionalNullable: Swift.String?
129-
public var fooRequiredNullable: Swift.String
130-
public init(
131-
fooOptional: Swift.String? = nil,
132-
fooRequired: Swift.String,
133-
fooOptionalNullable: Swift.String? = nil,
134-
fooRequiredNullable: Swift.String
135-
) {
136-
self.fooOptional = fooOptional
137-
self.fooRequired = fooRequired
138-
self.fooOptionalNullable = fooOptionalNullable
139-
self.fooRequiredNullable = fooRequiredNullable
140-
}
141-
public enum CodingKeys: String, CodingKey {
142-
case fooOptional
143-
case fooRequired
144-
case fooOptionalNullable
145-
case fooRequiredNullable
146-
}
147-
}
148-
}
149-
"""
150-
)
151-
try self.assertSchemasTranslation(
152-
featureFlags: [.nullableSchemas],
153106
"""
154107
schemas:
155108
MyObj:
@@ -1160,28 +1113,6 @@ final class SnippetBasedReferenceTests: XCTestCase {
11601113

11611114
func testComponentsRequestBodiesInline_urlEncodedForm() throws {
11621115
try self.assertRequestBodiesTranslation(
1163-
"""
1164-
requestBodies:
1165-
MyRequestBody:
1166-
content:
1167-
application/x-www-form-urlencoded:
1168-
schema:
1169-
type: object
1170-
properties:
1171-
foo:
1172-
type: string
1173-
required: [foo]
1174-
""",
1175-
"""
1176-
public enum RequestBodies {
1177-
@frozen public enum MyRequestBody: Sendable, Hashable {
1178-
case urlEncodedForm(OpenAPIRuntime.HTTPBody)
1179-
}
1180-
}
1181-
"""
1182-
)
1183-
try self.assertRequestBodiesTranslation(
1184-
featureFlags: [.urlEncodedForm],
11851116
"""
11861117
requestBodies:
11871118
MyRequestBody:

0 commit comments

Comments
 (0)