Skip to content

Commit

Permalink
Cleanup generated code
Browse files Browse the repository at this point in the history
  • Loading branch information
monstermunchkin committed Nov 27, 2024
1 parent d577c4b commit a999d8b
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 133 deletions.
12 changes: 9 additions & 3 deletions http/jsonapi/generator/generate_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -597,9 +597,16 @@ func (g *Generator) buildHandler(method string, op *openapi3.Operation, pattern

g.Add(auth)
// set tracing context

ctxStmt := jen.Id("r").Dot("Context").Call()

if auth != nil {
ctxStmt = jen.Id("ctx")
}

g.Line().Comment("Trace the service function handler execution")
g.Id("span").Op(":=").Qual(pkgSentry, "StartSpan").Call(
jen.Id("r").Dot("Context").Call(), jen.Lit("http.server"), jen.Qual(pkgSentry, "WithDescription").Call(jen.Lit(handler)))
ctxStmt, jen.Lit("http.server"), jen.Qual(pkgSentry, "WithDescription").Call(jen.Lit(handler)))
g.Defer().Id("span").Dot("Finish").Call()
g.Line().Empty()

Expand All @@ -626,7 +633,7 @@ func (g *Generator) buildHandler(method string, op *openapi3.Operation, pattern

// request
g.Id("request").Op(":=").Id(route.requestType).
Block(jen.Id("Request").Op(":").Id("r").Dot("WithContext").Call(jen.Id("ctx")).Op(","))
Block(jen.Id("Request").Op(":").Id("r").Op(","))

// vars in case parameters are given
g.Line().Comment("Scan and validate incoming request parameters")
Expand Down Expand Up @@ -773,7 +780,6 @@ func generateAuthorization(op *openapi3.Operation, secSchemes map[string]*openap
return nil, err
}

r.Line().Id("r").Op("=").Id("r.WithContext").Call(jen.Id("ctx"))
return r, nil
}

Expand Down
8 changes: 4 additions & 4 deletions http/jsonapi/generator/internal/articles/open-api_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions http/jsonapi/generator/internal/fueling/open-api_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 10 additions & 12 deletions http/jsonapi/generator/internal/pay/open-api_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a999d8b

Please sign in to comment.