Skip to content

Commit

Permalink
Additional 'case' blocks cannot appear after the 'default' block of a…
Browse files Browse the repository at this point in the history
… 'switch' (#212)
  • Loading branch information
dpasirst authored Aug 20, 2023
1 parent 3ffeaba commit a0333f6
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ extension ClientFileTranslator {
) throws -> Expression {
var cases: [SwitchCaseDescription] =
try description
.operation
.responseOutcomes
.map { outcome in
try translateResponseOutcomeInClient(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,4 +317,17 @@ extension OperationDescription {
var containsDefaultResponse: Bool {
operation.responses.contains(key: .default)
}

/// Returns the operation.responseOutcomes while ensuring if a `.default`
/// responseOutcome is present, then it is the last element in the returned array
var responseOutcomes: [OpenAPI.Operation.ResponseOutcome] {
var outcomes = operation.responseOutcomes
// if .default is present and not already last
if let index = outcomes.firstIndex(where: { $0.status == .default }), index != (outcomes.count - 1) {
//then we move it to be last
let defaultResp = outcomes.remove(at: index)
outcomes.append(defaultResp)
}
return outcomes
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ extension FileTranslator {
) throws -> [ContentType] {
let contentTypes =
try description
.operation
.responseOutcomes
.flatMap { outcome in
let response = try outcome.response.resolve(in: components)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ extension ServerFileTranslator {
func translateServerSerializer(_ description: OperationDescription) throws -> Expression {
var cases: [SwitchCaseDescription] =
try description
.operation
.responseOutcomes
.map { outcome in
try translateResponseOutcomeInServer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ extension TypesFileTranslator {

let documentedOutcomes =
try description
.operation
.responseOutcomes
.map { outcome in
try translateResponseOutcomeInTypes(
Expand Down

0 comments on commit a0333f6

Please sign in to comment.