Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Cleanup generated code
  • Loading branch information
monstermunchkin committed Nov 27, 2024
commit b7380cecf1022d4d424c00a4bbabd5a95c60578b
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