@@ -87,43 +87,42 @@ extension TypesFileTranslator {
8787 staticMemberDecl = nil
8888 }
8989
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+
90120 let throwingGetterDesc = VariableDescription (
91121 accessModifier: config. access,
92122 kind: . var,
93123 left: . identifierPattern( enumCaseName) ,
94124 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) ) ] ,
127126 getterEffects: [ . throws]
128127 )
129128 let throwingGetterComment = Comment . doc (
0 commit comments