-
Notifications
You must be signed in to change notification settings - Fork 0
/
implementation.go
34 lines (31 loc) · 1.18 KB
/
implementation.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
package service
import (
"github.com/specgen-io/specgen/v2/goven/generator"
"github.com/specgen-io/specgen/v2/goven/kotlin/writer"
"github.com/specgen-io/specgen/v2/goven/spec"
)
func (g *Generator) ServicesImplementations(version *spec.Version) []generator.CodeFile {
files := []generator.CodeFile{}
for _, api := range version.Http.Apis {
files = append(files, *g.serviceImplementation(&api))
}
return files
}
func (g *Generator) serviceImplementation(api *spec.Api) *generator.CodeFile {
w := writer.New(g.Packages.ServicesImpl(api.InHttp.InVersion), serviceImplName(api))
annotationImport, annotation := g.ServiceImplAnnotation(api)
w.Imports.Add(annotationImport)
w.Imports.PackageStar(g.Packages.Models(api.InHttp.InVersion))
w.Imports.PackageStar(g.Packages.ServicesApi(api))
w.Imports.Add(g.Types.Imports()...)
w.EmptyLine()
w.Line(`@%s`, annotation)
w.Line(`class [[.ClassName]] : %s {`, serviceInterfaceName(api))
for _, operation := range api.Operations {
w.Line(` override fun %s {`, operationSignature(g.Types, &operation))
w.Line(` throw UnsupportedOperationException("Implementation has not added yet")`)
w.Line(` }`)
}
w.Line(`}`)
return w.ToCodeFile()
}