Skip to content

Commit d4da561

Browse files
committed
fix(codegen): lint issues
1 parent e1a1624 commit d4da561

File tree

2 files changed

+26
-36
lines changed

2 files changed

+26
-36
lines changed

codegen/pkg/generator/names.go

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -98,28 +98,3 @@ func phpEnumCaseName(value string) string {
9898

9999
return value
100100
}
101-
102-
func isServiceLocalSchemaName(name string) bool {
103-
name = strings.TrimSpace(name)
104-
if name == "" {
105-
return false
106-
}
107-
108-
suffixes := []string{
109-
"Request",
110-
"RequestBody",
111-
"Response",
112-
"ResponseBody",
113-
"Params",
114-
"Param",
115-
"Parameters",
116-
}
117-
118-
for _, suffix := range suffixes {
119-
if strings.HasSuffix(name, suffix) {
120-
return true
121-
}
122-
}
123-
124-
return false
125-
}

codegen/pkg/generator/operations.go

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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

313310
func (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

Comments
 (0)