-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathentc.go
54 lines (45 loc) · 1.14 KB
/
entc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//go:build ignore
// +build ignore
package main
import (
"log"
"os"
"entgo.io/ent/entc"
"entgo.io/ent/entc/gen"
"github.com/ogen-go/ent2ogen"
"github.com/ogen-go/ogen"
ogengen "github.com/ogen-go/ogen/gen"
ogengenfs "github.com/ogen-go/ogen/gen/genfs"
)
func main() {
f, err := os.ReadFile("../_openapi/openapi.yml")
if err != nil {
log.Fatalf("reading openapi schema: %v", err)
}
spec, err := ogen.Parse(f)
if err != nil {
log.Fatalf("parsing openapi schema: %v", err)
}
g, err := ogengen.NewGenerator(spec, ogengen.Options{})
if err != nil {
log.Fatalf("creating ogen generator: %v", err)
}
if err := g.WriteSource(ogengenfs.FormattedSource{
Format: true,
Root: "../api",
}, "api"); err != nil {
log.Fatalf("generating ogen sources: %v", err)
}
ex, err := ent2ogen.NewExtension(ent2ogen.ExtensionConfig{
API: g.API(),
Types: g.Types(),
OgenPackage: "github.com/ogen-go/ent2ogen/example/api",
})
if err != nil {
log.Fatalf("creating ent2ogen extension: %v", err)
}
err = entc.Generate("./schema", &gen.Config{}, entc.Extensions(ex))
if err != nil {
log.Fatalf("running ent codegen: %v", err)
}
}