Skip to content

Commit

Permalink
[Runtime] Add headerFields and body to UndocumentedPayload (#90)
Browse files Browse the repository at this point in the history
### Motivation

The runtime changes for
apple/swift-openapi-generator#299.

### Modifications

Added `headerFields` and `body` properties to `UndocumentedPayload`,
allowing adopters to access the full request information when an
undocumented response is returned.

### Result

Easier access to the raw payload when an undocumented response is
returned.

### Test Plan

These are just the runtime changes, tested together with generated
changes.
  • Loading branch information
czechboy0 committed Dec 15, 2023
1 parent bc1023f commit fd101c3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
//
//===----------------------------------------------------------------------===//

import HTTPTypes

/// A payload value used by undocumented operation responses.
///
/// Each operation's `Output` enum type needs to exhaustively
Expand All @@ -20,6 +22,19 @@
/// `undocumented` enum case is used when such a status code is
/// detected.
public struct UndocumentedPayload: Sendable, Hashable {
/// Creates a new payload.
public init() {}

/// The header fields contained in the response.
public var headerFields: HTTPFields

/// The body stream of this part, if present.
public var body: HTTPBody?

/// Creates a new part.
/// - Parameters:
/// - headerFields: The header fields contained in the response.
/// - body: The body stream of this part, if present.
public init(headerFields: HTTPFields = [:], body: HTTPBody? = nil) {
self.headerFields = headerFields
self.body = body
}
}
7 changes: 7 additions & 0 deletions Sources/OpenAPIRuntime/Deprecated/Deprecated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,10 @@ import Foundation
import HTTPTypes

// MARK: - Functionality to be removed in the future

extension UndocumentedPayload {
/// Creates a new payload.
@available(*, deprecated, renamed: "init(headerFields:body:)") @_disfavoredOverload public init() {
self.init(headerFields: [:], body: nil)
}
}

0 comments on commit fd101c3

Please sign in to comment.