-
Notifications
You must be signed in to change notification settings - Fork 0
/
generator.go
43 lines (37 loc) · 1.25 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
package client
import (
"fmt"
"github.com/specgen-io/specgen/v2/goven/generator"
"github.com/specgen-io/specgen/v2/goven/spec"
"github.com/specgen-io/specgen/v2/goven/typescript/validations"
)
type ClientGenerator interface {
ApiClient(api *spec.Api) *generator.CodeFile
ErrorResponses(httpErrors *spec.HttpErrors) *generator.CodeFile
}
type Generator struct {
validations.Validation
CommonGenerator
ClientGenerator
Modules *Modules
}
func NewClientGenerator(client, validationName string, modules *Modules) *Generator {
validation := validations.New(validationName, &(modules.Modules))
commonGenerator := CommonGenerator{modules, validation}
var clientGenerator ClientGenerator = nil
switch client {
case Axios:
clientGenerator = &AxiosGenerator{modules, validation, commonGenerator}
case NodeFetch:
clientGenerator = &FetchGenerator{modules, true, validation, commonGenerator}
case BrowserFetch:
clientGenerator = &FetchGenerator{modules, false, validation, commonGenerator}
default:
panic(fmt.Sprintf("Unknown client: %s", client))
}
return &Generator{validation, commonGenerator, clientGenerator, modules}
}
var Axios = "axios"
var NodeFetch = "node-fetch"
var BrowserFetch = "browser-fetch"
var Clients = []string{Axios, NodeFetch, BrowserFetch}