Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,39 @@ extension TypesFileTranslator {
staticMemberDecl = nil
}

let isSingleCaseOutput = operation.containsDefaultResponse && operation.responseOutcomes.count == 1

var throwingGetterCases: [SwitchCaseDescription] = [
SwitchCaseDescription(
kind: .case(
.dot(responseKind.identifier),
responseKind.wantsStatusCode ? ["_", "response"] : ["response"]
),
body: [.expression(.return(.identifierPattern("response")))]
)
]
if !isSingleCaseOutput {
throwingGetterCases.append(
SwitchCaseDescription(
kind: .default,
body: [
.expression(
.try(
.identifierPattern("throwUnexpectedResponseStatus")
.call([
.init(
label: "expectedStatus",
expression: .literal(.string(responseKind.prettyName))
),
.init(label: "response", expression: .identifierPattern("self")),
])
)
)
]
)
)
}

let throwingGetterDesc = VariableDescription(
accessModifier: config.access,
kind: .var,
Expand All @@ -96,31 +129,7 @@ extension TypesFileTranslator {
.expression(
.switch(
switchedExpression: .identifierPattern("self"),
cases: [
SwitchCaseDescription(
kind: .case(
.dot(responseKind.identifier),
responseKind.wantsStatusCode ? ["_", "response"] : ["response"]
),
body: [.expression(.return(.identifierPattern("response")))]
),
SwitchCaseDescription(
kind: .default,
body: [
.expression(
.try(
.identifierPattern("throwUnexpectedResponseStatus")
.call([
.init(
label: "expectedStatus",
expression: .literal(.string(responseKind.prettyName))
), .init(label: "response", expression: .identifierPattern("self")),
])
)
)
]
),
]
cases: throwingGetterCases
)
)
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3416,11 +3416,6 @@ final class SnippetBasedReferenceTests: XCTestCase {
switch self {
case let .`default`(_, response):
return response
default:
try throwUnexpectedResponseStatus(
expectedStatus: "default",
response: self
)
}
}
}
Expand Down
Loading