Skip to content

Commit

Permalink
entoas: doesnt respect custom spec; fixed that (#471)
Browse files Browse the repository at this point in the history
  • Loading branch information
thmeitz authored Apr 2, 2023
1 parent bb1039b commit 4dd99ff
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions entoas/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,18 +157,25 @@ func Spec(spec *ogen.Spec) ExtensionOption {
// generator returns a gen.Hook that creates a Spec for the given gen.Graph.
func (ex *Extension) generate(next gen.Generator) gen.Generator {
return gen.GenerateFunc(func(g *gen.Graph) error {
var spec *ogen.Spec
// Let ent create all the files.
if err := next.Generate(g); err != nil {
return err
}
// Spec stub to fill.
spec := ogen.NewSpec().
SetOpenAPI("3.0.3").
SetInfo(ogen.NewInfo().
SetTitle("Ent Schema API").
SetDescription("This is an auto generated API description made out of an Ent schema definition").
SetVersion("0.1.0"),
)

if ex.spec != nil && len(ex.spec.OpenAPI) > 0 && len(ex.spec.Info.Title) > 0 && len(ex.spec.Info.Version) > 0 {
spec = ex.spec
} else {
// Spec stub to fill.
spec = ogen.NewSpec().
SetOpenAPI("3.0.3").
SetInfo(ogen.NewInfo().
SetTitle("Ent Schema API").
SetDescription("This is an auto generated API description made out of an Ent schema definition").
SetVersion("0.1.0"),
)
}

// Run the generator.
if err := generate(g, spec); err != nil {
return err
Expand Down

0 comments on commit 4dd99ff

Please sign in to comment.