@@ -87,43 +87,42 @@ extension TypesFileTranslator {
87
87
staticMemberDecl = nil
88
88
}
89
89
90
+ var throwingGetterCases : [ SwitchCaseDescription ] = [
91
+ SwitchCaseDescription (
92
+ kind: . case(
93
+ . dot( responseKind. identifier) ,
94
+ responseKind. wantsStatusCode ? [ " _ " , " response " ] : [ " response " ]
95
+ ) ,
96
+ body: [ . expression( . return( . identifierPattern( " response " ) ) ) ]
97
+ )
98
+ ]
99
+ if !operation. containsDefaultResponse || operation. responseOutcomes. count > 1 {
100
+ throwingGetterCases. append (
101
+ SwitchCaseDescription (
102
+ kind: . default,
103
+ body: [
104
+ . expression(
105
+ . try (
106
+ . identifierPattern( " throwUnexpectedResponseStatus " )
107
+ . call ( [
108
+ . init(
109
+ label: " expectedStatus " ,
110
+ expression: . literal( . string( responseKind. prettyName) )
111
+ ) , . init( label: " response " , expression: . identifierPattern( " self " ) ) ,
112
+ ] )
113
+ )
114
+ )
115
+ ]
116
+ )
117
+ )
118
+ }
119
+
90
120
let throwingGetterDesc = VariableDescription (
91
121
accessModifier: config. access,
92
122
kind: . var,
93
123
left: . identifierPattern( enumCaseName) ,
94
124
type: . init( responseStructTypeName) ,
95
- getter: [
96
- . expression(
97
- . switch(
98
- switchedExpression: . identifierPattern( " self " ) ,
99
- cases: [
100
- SwitchCaseDescription (
101
- kind: . case(
102
- . dot( responseKind. identifier) ,
103
- responseKind. wantsStatusCode ? [ " _ " , " response " ] : [ " response " ]
104
- ) ,
105
- body: [ . expression( . return( . identifierPattern( " response " ) ) ) ]
106
- ) ,
107
- SwitchCaseDescription (
108
- kind: . default,
109
- body: [
110
- . expression(
111
- . try (
112
- . identifierPattern( " throwUnexpectedResponseStatus " )
113
- . call ( [
114
- . init(
115
- label: " expectedStatus " ,
116
- expression: . literal( . string( responseKind. prettyName) )
117
- ) , . init( label: " response " , expression: . identifierPattern( " self " ) ) ,
118
- ] )
119
- )
120
- )
121
- ]
122
- ) ,
123
- ]
124
- )
125
- )
126
- ] ,
125
+ getter: [ . expression( . switch( switchedExpression: . identifierPattern( " self " ) , cases: throwingGetterCases) ) ] ,
127
126
getterEffects: [ . throws]
128
127
)
129
128
let throwingGetterComment = Comment . doc (
0 commit comments