Skip to content

Apply the same .swift-format as the generator repo #68

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

Merged
merged 2 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 6 additions & 3 deletions .swift-format
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
"lineLength" : 120,
"maximumBlankLines" : 1,
"prioritizeKeepingFunctionOutputTogether" : false,
"respectsExistingLineBreaks" : true,
"respectsExistingLineBreaks" : false,
"rules" : {
"AllPublicDeclarationsHaveDocumentation" : true,
"AlwaysUseLowerCamelCase" : false,
"AlwaysUseLiteralForEmptyCollectionInit" : true,
"AmbiguousTrailingClosureOverload" : true,
"BeginDocumentationCommentWithOneLineSummary" : false,
"DoNotUseSemicolons" : true,
Expand All @@ -38,16 +39,18 @@
"NoLeadingUnderscores" : false,
"NoParensAroundConditions" : true,
"NoVoidReturnOnFunctionSignature" : true,
"OmitExplicitReturns" : true,
"OneCasePerLine" : true,
"OneVariableDeclarationPerLine" : true,
"OnlyOneTrailingClosureArgument" : true,
"OrderedImports" : false,
"ReplaceForEachWithForLoop" : true,
"ReturnVoidInsteadOfEmptyTuple" : true,
"UseEarlyExits" : true,
"UseEarlyExits" : false,
"UseLetInEveryBoundCaseVariable" : false,
"UseShorthandTypeNames" : true,
"UseSingleLinePropertyGetter" : false,
"UseSynthesizedInitializer" : false,
"UseSynthesizedInitializer" : true,
"UseTripleSlashForDocumentationComments" : true,
"UseWhereClausesInForLoops" : false,
"ValidateDocumentationComments" : true
Expand Down
38 changes: 9 additions & 29 deletions Sources/OpenAPIRuntime/Base/Acceptable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ public struct QualityValue: Sendable, Hashable {

/// Returns a Boolean value indicating whether the quality value is
/// at its default value 1.0.
public var isDefault: Bool {
thousands == 1000
}
public var isDefault: Bool { thousands == 1000 }

/// Creates a new quality value from the provided floating-point number.
///
Expand All @@ -46,26 +44,20 @@ public struct QualityValue: Sendable, Hashable {
}

/// The value represented as a floating-point number between 0.0 and 1.0, inclusive.
public var doubleValue: Double {
Double(thousands) / 1000
}
public var doubleValue: Double { Double(thousands) / 1000 }
}

extension QualityValue: RawRepresentable {
/// Creates a new `QualityValue` instance from a raw string value.
///
/// - Parameter rawValue: A string representing the quality value.
public init?(rawValue: String) {
guard let doubleValue = Double(rawValue) else {
return nil
}
guard let doubleValue = Double(rawValue) else { return nil }
self.init(doubleValue: doubleValue)
}

/// The raw string representation of the `QualityValue`.
public var rawValue: String {
String(format: "%0.3f", doubleValue)
}
public var rawValue: String { String(format: "%0.3f", doubleValue) }
}

extension QualityValue: ExpressibleByIntegerLiteral {
Expand All @@ -86,18 +78,14 @@ extension QualityValue: ExpressibleByFloatLiteral {
/// Creates a new `QualityValue` instance from a floating-point literal value.
///
/// - Parameter value: A floating-point literal value representing the quality value.
public init(floatLiteral value: Double) {
self.init(doubleValue: value)
}
public init(floatLiteral value: Double) { self.init(doubleValue: value) }
}

extension Array {

/// Returns the default values for the acceptable type.
public static func defaultValues<T: AcceptableProtocol>() -> [AcceptHeaderContentType<T>]
where Element == AcceptHeaderContentType<T> {
T.allCases.map { .init(contentType: $0) }
}
where Element == AcceptHeaderContentType<T> { T.allCases.map { .init(contentType: $0) } }
}

/// A wrapper of an individual content type in the accept header.
Expand Down Expand Up @@ -129,9 +117,7 @@ public struct AcceptHeaderContentType<ContentType: AcceptableProtocol>: Sendable

/// Returns the default set of acceptable content types for this type, in
/// the order specified in the OpenAPI document.
public static var defaultValues: [Self] {
ContentType.allCases.map { .init(contentType: $0) }
}
public static var defaultValues: [Self] { ContentType.allCases.map { .init(contentType: $0) } }
}

extension AcceptHeaderContentType: RawRepresentable {
Expand Down Expand Up @@ -161,18 +147,12 @@ extension AcceptHeaderContentType: RawRepresentable {
}

/// The raw representation of the content negotiation as a MIME type string.
public var rawValue: String {
contentType.rawValue + (quality.isDefault ? "" : "; q=\(quality.rawValue)")
}
public var rawValue: String { contentType.rawValue + (quality.isDefault ? "" : "; q=\(quality.rawValue)") }
}

extension Array {

/// Returns the array sorted by the quality value, highest quality first.
public func sortedByQuality<T: AcceptableProtocol>() -> [AcceptHeaderContentType<T>]
where Element == AcceptHeaderContentType<T> {
sorted { a, b in
a.quality.doubleValue > b.quality.doubleValue
}
}
where Element == AcceptHeaderContentType<T> { sorted { a, b in a.quality.doubleValue > b.quality.doubleValue } }
}
4 changes: 1 addition & 3 deletions Sources/OpenAPIRuntime/Base/Base64EncodedData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ public struct Base64EncodedData: Sendable, Hashable {

/// Initializes an instance of ``Base64EncodedData`` wrapping the provided slice of bytes.
/// - Parameter data: The underlying bytes to wrap.
public init(data: ArraySlice<UInt8>) {
self.data = data
}
public init(data: ArraySlice<UInt8>) { self.data = data }
}

extension Base64EncodedData: Codable {
Expand Down
62 changes: 15 additions & 47 deletions Sources/OpenAPIRuntime/Base/CopyOnWriteBox.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,46 +16,31 @@
///
/// It also enables recursive types by introducing a "box" into the cycle, which
/// allows the owning type to have a finite size.
@_spi(Generated)
public struct CopyOnWriteBox<Wrapped> {
@_spi(Generated) public struct CopyOnWriteBox<Wrapped> {

/// The reference type storage for the box.
@usableFromInline
internal final class Storage {
@usableFromInline internal final class Storage {

/// The stored value.
@usableFromInline
var value: Wrapped
@usableFromInline var value: Wrapped

/// Creates a new storage with the provided initial value.
/// - Parameter value: The initial value to store in the box.
@inlinable
init(value: Wrapped) {
self.value = value
}
@inlinable init(value: Wrapped) { self.value = value }
}

/// The internal storage of the box.
@usableFromInline
internal var storage: Storage
@usableFromInline internal var storage: Storage

/// Creates a new box.
/// - Parameter value: The value to store in the box.
@inlinable
public init(value: Wrapped) {
self.storage = .init(value: value)
}
@inlinable public init(value: Wrapped) { self.storage = .init(value: value) }

/// The stored value whose accessors enforce copy-on-write semantics.
@inlinable
public var value: Wrapped {
get {
storage.value
}
@inlinable public var value: Wrapped {
get { storage.value }
_modify {
if !isKnownUniquelyReferenced(&storage) {
storage = Storage(value: storage.value)
}
if !isKnownUniquelyReferenced(&storage) { storage = Storage(value: storage.value) }
yield &storage.value
}
}
Expand All @@ -73,10 +58,7 @@ extension CopyOnWriteBox: Encodable where Wrapped: Encodable {
///
/// - Parameter encoder: The encoder to write data to.
/// - Throws: On an encoding error.
@inlinable
public func encode(to encoder: any Encoder) throws {
try value.encode(to: encoder)
}
@inlinable public func encode(to encoder: any Encoder) throws { try value.encode(to: encoder) }
}

extension CopyOnWriteBox: Decodable where Wrapped: Decodable {
Expand All @@ -88,8 +70,7 @@ extension CopyOnWriteBox: Decodable where Wrapped: Decodable {
///
/// - Parameter decoder: The decoder to read data from.
/// - Throws: On a decoding error.
@inlinable
public init(from decoder: any Decoder) throws {
@inlinable public init(from decoder: any Decoder) throws {
let value = try Wrapped(from: decoder)
self.init(value: value)
}
Expand All @@ -106,11 +87,7 @@ extension CopyOnWriteBox: Equatable where Wrapped: Equatable {
/// - lhs: A value to compare.
/// - rhs: Another value to compare.
/// - Returns: A Boolean value indicating whether the values are equal.
@inlinable
public static func == (
lhs: CopyOnWriteBox<Wrapped>,
rhs: CopyOnWriteBox<Wrapped>
) -> Bool {
@inlinable public static func == (lhs: CopyOnWriteBox<Wrapped>, rhs: CopyOnWriteBox<Wrapped>) -> Bool {
lhs.value == rhs.value
}
}
Expand All @@ -132,10 +109,7 @@ extension CopyOnWriteBox: Hashable where Wrapped: Hashable {
///
/// - Parameter hasher: The hasher to use when combining the components
/// of this instance.
@inlinable
public func hash(into hasher: inout Hasher) {
hasher.combine(value)
}
@inlinable public func hash(into hasher: inout Hasher) { hasher.combine(value) }
}

extension CopyOnWriteBox: CustomStringConvertible where Wrapped: CustomStringConvertible {
Expand Down Expand Up @@ -163,10 +137,7 @@ extension CopyOnWriteBox: CustomStringConvertible where Wrapped: CustomStringCon
///
/// The conversion of `p` to a string in the assignment to `s` uses the
/// `Point` type's `description` property.
@inlinable
public var description: String {
value.description
}
@inlinable public var description: String { value.description }
}

extension CopyOnWriteBox: CustomDebugStringConvertible where Wrapped: CustomDebugStringConvertible {
Expand Down Expand Up @@ -194,10 +165,7 @@ extension CopyOnWriteBox: CustomDebugStringConvertible where Wrapped: CustomDebu
///
/// The conversion of `p` to a string in the assignment to `s` uses the
/// `Point` type's `debugDescription` property.
@inlinable
public var debugDescription: String {
value.debugDescription
}
@inlinable public var debugDescription: String { value.debugDescription }
}

extension CopyOnWriteBox: @unchecked Sendable where Wrapped: Sendable {}
Loading