Skip to content

Commit

Permalink
add methods order
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Kisler <admin@dkisler.com>
  • Loading branch information
kislerdm committed Sep 28, 2024
1 parent 1e1991b commit 8d11799
Show file tree
Hide file tree
Showing 3 changed files with 1,227 additions and 1,218 deletions.
15 changes: 12 additions & 3 deletions generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ func extractSpecs(spec openAPISpec, orderedEndpointRoutes []string) (templateInp
m := generateModels(spec)
endpoints := generateEndpointsImplementationMethods(spec, orderedEndpointRoutes)

var endpointNames = make([]string, 0, len(endpoints))
for k, _ := range endpoints {
endpointNames = append(endpointNames, k)
}
slices.Sort(endpointNames)

endpointsStr := make([]string, len(endpoints))
endpointsTestStr := make([]string, 0, len(endpoints))
models := models{}
Expand Down Expand Up @@ -449,7 +455,8 @@ func extractSpecs(spec openAPISpec, orderedEndpointRoutes []string) (templateInp
},
}

for i, s := range endpoints {
for i, name := range endpointNames {
s := endpoints[name]
endpointsStr[i] = s.generateMethodImplementation()
if !skipTest(s.Route) {
endpointsTestStr = append(endpointsTestStr, s.generateMethodImplementationTest())
Expand Down Expand Up @@ -1326,6 +1333,7 @@ func (m model) generateCodeEnum() string {
children[i] = c
i++
}
slices.Sort(children)

for _, child := range children {
enumOption := strings.ToUpper(child[:1]) + child[1:]
Expand Down Expand Up @@ -1374,7 +1382,7 @@ func implementationNameFromID(s string) string {

func generateEndpointsImplementationMethods(
o openAPISpec, orderedEndpoints []string,
) (endpoints []endpointImplementation) {
) (endpoints map[string]endpointImplementation) {
const suffixResponseObject = "RespObj"
const suffixRequestObject = "ReqObj"

Expand All @@ -1387,6 +1395,7 @@ func generateEndpointsImplementationMethods(
http.MethodDelete,
}

endpoints = make(map[string]endpointImplementation)
for _, route := range orderedEndpoints {
p := o.Paths.Find(route)
if p == nil {
Expand Down Expand Up @@ -1454,7 +1463,7 @@ func generateEndpointsImplementationMethods(
}
}

endpoints = append(endpoints, e)
endpoints[e.Name] = e
}
}
return
Expand Down
Loading

0 comments on commit 8d11799

Please sign in to comment.