@@ -191,7 +191,7 @@ func (g *Generator) buildOperation(method, path string, op *v3.Operation, params
191191 BodySchema : bodySchema ,
192192 BodyRequired : bodyRequired ,
193193 Deprecated : deprecated ,
194- Responses : g .collectOperationResponses (op , operationID ),
194+ Responses : g .collectOperationResponses (op , operationID , method , path ),
195195 }, nil
196196}
197197
@@ -200,10 +200,7 @@ func (g *Generator) resolveOperationBody(op *v3.Operation) (string, string, bool
200200 return "" , "" , false , nil
201201 }
202202
203- required := false
204- if op .RequestBody .Required != nil && * op .RequestBody .Required {
205- required = true
206- }
203+ required := op .RequestBody .Required != nil && * op .RequestBody .Required
207204
208205 var schema * base.SchemaProxy
209206 if op .RequestBody .Content != nil {
@@ -247,15 +244,15 @@ func (op *operation) methodName() string {
247244 return strcase .ToLowerCamel (op .ID )
248245}
249246
250- func (g * Generator ) collectOperationResponses (op * v3.Operation , operationID string ) []* operationResponse {
247+ func (g * Generator ) collectOperationResponses (op * v3.Operation , operationID string , method string , path string ) []* operationResponse {
251248 if op == nil || op .Responses == nil || op .Responses .Codes .Len () == 0 {
252249 return nil
253250 }
254251
255252 responses := make ([]* operationResponse , 0 , op .Responses .Codes .Len ())
256253
257254 for status , response := range op .Responses .Codes .FromOldest () {
258- respType := g .responseTypeForResponse (response , "SumUp\\ Services" , operationID , status )
255+ respType := g .responseTypeForResponse (response , "SumUp\\ Services" , operationID , status , method , path )
259256 if respType == nil {
260257 continue
261258 }
@@ -275,7 +272,7 @@ func (g *Generator) collectOperationResponses(op *v3.Operation, operationID stri
275272 return responses
276273}
277274
278- func (g * Generator ) responseTypeForResponse (resp * v3.Response , currentNamespace string , operationID string , statusCode string ) * responseType {
275+ func (g * Generator ) responseTypeForResponse (resp * v3.Response , currentNamespace string , operationID string , statusCode string , method string , path string ) * responseType {
279276 if resp == nil {
280277 return & responseType {Kind : responseTypeVoid }
281278 }
@@ -307,7 +304,7 @@ func (g *Generator) responseTypeForResponse(resp *v3.Response, currentNamespace
307304 return & responseType {Kind : responseTypeVoid }
308305 }
309306
310- return g .buildResponseType (schema , currentNamespace , inlineResponseClassName (operationID , statusCode ))
307+ return g .buildResponseType (schema , currentNamespace , inlineResponseClassName (operationID , statusCode , method , path ))
311308}
312309
313310func (g * Generator ) buildResponseType (schema * base.SchemaProxy , currentNamespace string , inlineBaseName string ) * responseType {
@@ -407,12 +404,30 @@ func (g *Generator) buildResponseTypeFromSpec(spec *base.Schema, currentNamespac
407404 return & responseType {Kind : responseTypeMixed }
408405}
409406
410- func inlineResponseClassName (operationID string , statusCode string ) string {
407+ func inlineResponseClassName (operationID string , statusCode string , method string , path string ) string {
411408 if operationID == "" {
412409 return ""
413410 }
414411
415- base := strcase .ToCamel (operationID ) + "Response"
412+ pathPart := ""
413+ if path != "" {
414+ replacer := strings .NewReplacer ("/" , "_" , "{" , "" , "}" , "" , "-" , "_" , "." , "_" )
415+ pathPart = strcase .ToCamel (replacer .Replace (strings .Trim (path , "/" )))
416+ }
417+
418+ methodPart := ""
419+ if method != "" {
420+ methodPart = strcase .ToCamel (strings .ToLower (method ))
421+ }
422+
423+ base := strcase .ToCamel (operationID )
424+ if pathPart != "" {
425+ base += pathPart
426+ }
427+ if methodPart != "" {
428+ base += methodPart
429+ }
430+ base += "Response"
416431 if statusCode != "" && statusCode != "200" {
417432 base += statusCode
418433 }
0 commit comments