-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterface.go
More file actions
37 lines (27 loc) · 888 Bytes
/
interface.go
File metadata and controls
37 lines (27 loc) · 888 Bytes
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
package main
import (
"github.com/godknowsiamgood/oapi3gen/spec"
"strings"
"text/template"
)
type Server interface {
TemplateFunctions() template.FuncMap
OperationParameterTags(param spec.Parameter) string
FieldTags(context string, name string, field spec.Schema, parent spec.Schema) string
}
type DefaultServer struct{}
func (s DefaultServer) OperationParameterTags(_ spec.Parameter) string {
return ""
}
func (s DefaultServer) TemplateFunctions() template.FuncMap {
return nil
}
func (s DefaultServer) FieldTags(context string, name string, field spec.Schema, parent spec.Schema) string {
tags := strings.Builder{}
tags.WriteString("`json:\"" + name)
if parent.IsFieldOptional(name) && context != spec.PropertiesContextParameters && context != spec.PropertiesContextRequestBody {
tags.WriteString(",omitempty")
}
tags.WriteString("\"`")
return tags.String()
}