Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

entoas: doesnt respect custom spec; fixed that #471

Merged
merged 1 commit into from
Apr 2, 2023
Merged
Changes from all commits
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
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