Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable all feature flags for 0.3.0 #296

Merged
merged 29 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
09b7fdb
[WIP] Adopt swift-http-types
czechboy0 Sep 4, 2023
85aa75f
Try streaming
czechboy0 Sep 4, 2023
2eb8cf2
Add more streaming examples
czechboy0 Sep 4, 2023
5cd2a8b
petstore consumer tests working again
czechboy0 Sep 5, 2023
7996f90
Add a streaming example
czechboy0 Sep 5, 2023
d0436f1
Add a server streaming example
czechboy0 Sep 5, 2023
463fd73
Add another server streaming example that uses the unfolding initiali…
czechboy0 Sep 5, 2023
25ebc93
Use Swift overloads directly
czechboy0 Sep 5, 2023
531e1e6
WIP
czechboy0 Sep 6, 2023
3e4ee23
Fix tests up
czechboy0 Sep 6, 2023
c45e971
Updates
czechboy0 Sep 7, 2023
d3737e0
Represent no responses as a nil HTTPBody in server transport and midd…
czechboy0 Sep 8, 2023
dc32180
Use the renamed method
czechboy0 Sep 9, 2023
fa5926f
Fixes
czechboy0 Sep 9, 2023
31545a1
Feedback: further cleanup of the HTTPBody API
czechboy0 Sep 12, 2023
d52e465
Remove unnecessary initializers
czechboy0 Sep 12, 2023
42596c2
Review feedback: make response body optional
czechboy0 Sep 13, 2023
f508302
Merge branch 'main' into hd-adopt-http-types
czechboy0 Sep 18, 2023
1e57593
Merge branch 'main' into hd-adopt-http-types
czechboy0 Sep 18, 2023
6b195be
WIP
czechboy0 Sep 25, 2023
66eb9ce
Merge remote-tracking branch 'apple/main' into hd-adopt-http-types
czechboy0 Sep 25, 2023
95141bb
WIP
czechboy0 Sep 25, 2023
0b766a4
Merge branch 'main' into hd-adopt-http-types
czechboy0 Sep 25, 2023
e06a278
Enable all feature flags for 0.3.0
czechboy0 Sep 25, 2023
b0f99dc
Stop using the generated SPI
czechboy0 Sep 26, 2023
74256ab
Merge branch 'hd-adopt-http-types' into hd-0.3.0-enable-feature-flags
czechboy0 Sep 27, 2023
423ca43
Adapt to removed utils in runtime
czechboy0 Sep 27, 2023
d99a80c
Merge branch 'hd-adopt-http-types' into hd-0.3.0-enable-feature-flags
czechboy0 Sep 27, 2023
7527e66
Merge branch 'main' into hd-0.3.0-enable-feature-flags
czechboy0 Oct 2, 2023
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
12 changes: 2 additions & 10 deletions Sources/_OpenAPIGeneratorCore/FeatureFlags.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,8 @@
/// 0.2 is tagged. (This is for pre-1.0 versioning, would be 1.0 and 2.0 after
/// 1.0 is released.)
public enum FeatureFlag: String, Hashable, Codable, CaseIterable, Sendable {

/// Support for `nullable` schemas.
///
/// A dedicated field in OpenAPI 3.0, a `null` value present in
/// the `types` array in OpenAPI 3.1.
case nullableSchemas

/// Support for `application/x-www-form-urlencoded` request bodies as
/// structured payloads.
case urlEncodedForm
// needs to be here for the enum to compile
case empty
}

/// A set of enabled feature flags.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,15 +231,14 @@ extension FileTranslator {
schema: contentValue.schema
)
}
let urlEncodedFormsSupported = config.featureFlags.contains(.urlEncodedForm)
if urlEncodedFormsSupported && contentKey.isUrlEncodedForm {
if contentKey.isUrlEncodedForm {
let contentType = ContentType(contentKey.typeAndSubtype)
return .init(
contentType: contentType,
schema: contentValue.schema
)
}
if !excludeBinary, contentKey.isBinary || !urlEncodedFormsSupported {
if !excludeBinary, contentKey.isBinary {
let contentType = contentKey.asGeneratorContentType
return .init(
contentType: contentType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,4 @@ import OpenAPIKit

extension FileTranslator {
// Add helpers for reading feature flags below.

/// A Boolean value indicating whether the `nullable` field on schemas
/// should be taken into account.
var supportNullableSchemas: Bool {
config.featureFlags.contains(.nullableSchemas)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ struct TypeAssigner {
/// safe to be used as a Swift identifier.
var asSwiftSafeName: (String) -> String

/// A Boolean value indicating whether the `nullable` field on schemas
/// should be taken into account.
var supportNullableSchemas: Bool

/// Returns a type name for an OpenAPI-named component type.
///
/// A component type is any type in `#/components` in the OpenAPI document.
Expand Down Expand Up @@ -261,8 +257,7 @@ struct TypeAssigner {
// creating a new inline type.
if let referenceableType =
try TypeMatcher(
asSwiftSafeName: asSwiftSafeName,
supportNullableSchemas: supportNullableSchemas
asSwiftSafeName: asSwiftSafeName
)
.tryMatchReferenceableType(for: schema)
{
Expand Down Expand Up @@ -460,16 +455,14 @@ extension FileTranslator {
/// A configured type assigner.
var typeAssigner: TypeAssigner {
TypeAssigner(
asSwiftSafeName: swiftSafeName,
supportNullableSchemas: supportNullableSchemas
asSwiftSafeName: swiftSafeName
)
}

/// A configured type matcher.
var typeMatcher: TypeMatcher {
TypeMatcher(
asSwiftSafeName: swiftSafeName,
supportNullableSchemas: supportNullableSchemas
asSwiftSafeName: swiftSafeName
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ struct TypeMatcher {
/// safe to be used as a Swift identifier.
var asSwiftSafeName: (String) -> String

/// A Boolean value indicating whether the `nullable` field on schemas
/// should be taken into account.
var supportNullableSchemas: Bool

/// Returns the type name of a built-in type that matches the specified
/// schema.
///
Expand Down Expand Up @@ -83,8 +79,7 @@ struct TypeMatcher {
return nil
}
return try TypeAssigner(
asSwiftSafeName: asSwiftSafeName,
supportNullableSchemas: supportNullableSchemas
asSwiftSafeName: asSwiftSafeName
)
.typeName(for: ref).asUsage
},
Expand All @@ -95,7 +90,7 @@ struct TypeMatcher {
TypeName.arrayContainer.asUsage
}
)?
.withOptional(!schema.required || (supportNullableSchemas && schema.nullable))
.withOptional(!schema.required || schema.nullable)
}

/// Returns a Boolean value that indicates whether the schema
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,7 @@ class FileBasedReferenceTests: XCTestCase {
}

func testPetstore() throws {
try _test(
referenceProject: .init(name: .petstore),
featureFlags: [
.urlEncodedForm
]
)
try _test(referenceProject: .init(name: .petstore))
}

// MARK: - Private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,53 +103,6 @@ final class SnippetBasedReferenceTests: XCTestCase {

func testComponentsSchemasNullableStringProperty() throws {
try self.assertSchemasTranslation(
"""
schemas:
MyObj:
type: object
properties:
fooOptional:
type: string
fooRequired:
type: string
fooOptionalNullable:
type: [string, null]
fooRequiredNullable:
type: [string, null]
required:
- fooRequired
- fooRequiredNullable
""",
"""
public enum Schemas {
public struct MyObj: Codable, Hashable, Sendable {
public var fooOptional: Swift.String?
public var fooRequired: Swift.String
public var fooOptionalNullable: Swift.String?
public var fooRequiredNullable: Swift.String
public init(
fooOptional: Swift.String? = nil,
fooRequired: Swift.String,
fooOptionalNullable: Swift.String? = nil,
fooRequiredNullable: Swift.String
) {
self.fooOptional = fooOptional
self.fooRequired = fooRequired
self.fooOptionalNullable = fooOptionalNullable
self.fooRequiredNullable = fooRequiredNullable
}
public enum CodingKeys: String, CodingKey {
case fooOptional
case fooRequired
case fooOptionalNullable
case fooRequiredNullable
}
}
}
"""
)
try self.assertSchemasTranslation(
featureFlags: [.nullableSchemas],
"""
schemas:
MyObj:
Expand Down Expand Up @@ -1160,28 +1113,6 @@ final class SnippetBasedReferenceTests: XCTestCase {

func testComponentsRequestBodiesInline_urlEncodedForm() throws {
try self.assertRequestBodiesTranslation(
"""
requestBodies:
MyRequestBody:
content:
application/x-www-form-urlencoded:
schema:
type: object
properties:
foo:
type: string
required: [foo]
""",
"""
public enum RequestBodies {
@frozen public enum MyRequestBody: Sendable, Hashable {
case urlEncodedForm(OpenAPIRuntime.HTTPBody)
}
}
"""
)
try self.assertRequestBodiesTranslation(
featureFlags: [.urlEncodedForm],
"""
requestBodies:
MyRequestBody:
Expand Down