-
Notifications
You must be signed in to change notification settings - Fork 0
/
generator.go
51 lines (45 loc) · 1.19 KB
/
generator.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
package client
import (
"fmt"
"github.com/specgen-io/specgen/v2/goven/generator"
"github.com/specgen-io/specgen/v2/goven/kotlin/models"
"github.com/specgen-io/specgen/v2/goven/kotlin/types"
"github.com/specgen-io/specgen/v2/goven/spec"
)
type ClientGenerator interface {
Clients(version *spec.Version) []generator.CodeFile
Utils() []generator.CodeFile
Exceptions(errors *spec.ErrorResponses) []generator.CodeFile
}
type Generator struct {
ClientGenerator
models.Generator
Jsonlib string
Types *types.Types
Packages *Packages
}
func NewGenerator(jsonlib, client string, packages *Packages) *Generator {
types := models.NewTypes(jsonlib)
models := models.NewGenerator(jsonlib, &(packages.Packages))
var clientGenerator ClientGenerator = nil
switch client {
case OkHttp:
clientGenerator = NewOkHttpGenerator(types, models, packages)
break
case Micronaut:
clientGenerator = NewMicronautGenerator(types, models, packages)
break
case MicronautDecl:
clientGenerator = NewMicronautDeclGenerator(types, models, packages)
break
default:
panic(fmt.Sprintf(`Unsupported client: %s`, client))
}
return &Generator{
clientGenerator,
models,
jsonlib,
types,
packages,
}
}