Skip to content

Commit a0333f6

Browse files
authored
Additional 'case' blocks cannot appear after the 'default' block of a 'switch' (#212)
1 parent 3ffeaba commit a0333f6

File tree

5 files changed

+13
-4
lines changed

5 files changed

+13
-4
lines changed

Sources/_OpenAPIGeneratorCore/Translator/ClientTranslator/translateClientMethod.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ extension ClientFileTranslator {
123123
) throws -> Expression {
124124
var cases: [SwitchCaseDescription] =
125125
try description
126-
.operation
127126
.responseOutcomes
128127
.map { outcome in
129128
try translateResponseOutcomeInClient(

Sources/_OpenAPIGeneratorCore/Translator/Operations/OperationDescription.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,4 +317,17 @@ extension OperationDescription {
317317
var containsDefaultResponse: Bool {
318318
operation.responses.contains(key: .default)
319319
}
320+
321+
/// Returns the operation.responseOutcomes while ensuring if a `.default`
322+
/// responseOutcome is present, then it is the last element in the returned array
323+
var responseOutcomes: [OpenAPI.Operation.ResponseOutcome] {
324+
var outcomes = operation.responseOutcomes
325+
// if .default is present and not already last
326+
if let index = outcomes.firstIndex(where: { $0.status == .default }), index != (outcomes.count - 1) {
327+
//then we move it to be last
328+
let defaultResp = outcomes.remove(at: index)
329+
outcomes.append(defaultResp)
330+
}
331+
return outcomes
332+
}
320333
}

Sources/_OpenAPIGeneratorCore/Translator/Responses/acceptHeaderContentTypes.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ extension FileTranslator {
2727
) throws -> [ContentType] {
2828
let contentTypes =
2929
try description
30-
.operation
3130
.responseOutcomes
3231
.flatMap { outcome in
3332
let response = try outcome.response.resolve(in: components)

Sources/_OpenAPIGeneratorCore/Translator/ServerTranslator/translateServerMethod.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ extension ServerFileTranslator {
119119
func translateServerSerializer(_ description: OperationDescription) throws -> Expression {
120120
var cases: [SwitchCaseDescription] =
121121
try description
122-
.operation
123122
.responseOutcomes
124123
.map { outcome in
125124
try translateResponseOutcomeInServer(

Sources/_OpenAPIGeneratorCore/Translator/TypesTranslator/translateOperations.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ extension TypesFileTranslator {
123123

124124
let documentedOutcomes =
125125
try description
126-
.operation
127126
.responseOutcomes
128127
.map { outcome in
129128
try translateResponseOutcomeInTypes(

0 commit comments

Comments
 (0)