60 lines
1.2 KiB
Go
60 lines
1.2 KiB
Go
package encode // import "udico.de/uditaren/opier/encode"
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"udico.de/opier/openapi"
|
|
"unicode"
|
|
)
|
|
|
|
type Encoder struct {
|
|
Package string
|
|
api *openapi.OpenAPI
|
|
}
|
|
|
|
func NewEncoder(pkg string, api *openapi.OpenAPI) *Encoder {
|
|
return &Encoder{
|
|
Package: pkg,
|
|
api: api,
|
|
}
|
|
}
|
|
|
|
// make
|
|
func NormalizeName(aName string) string {
|
|
tRet := &strings.Builder{}
|
|
capitalizeNext := true
|
|
for _, rune := range aName {
|
|
if capitalizeNext {
|
|
tRet.WriteRune(unicode.ToUpper(rune))
|
|
capitalizeNext = false
|
|
} else {
|
|
if rune == '-' {
|
|
capitalizeNext = true
|
|
} else {
|
|
tRet.WriteRune(rune)
|
|
}
|
|
}
|
|
}
|
|
return tRet.String()
|
|
}
|
|
|
|
|
|
func (e Encoder) GeneratedHeader() string {
|
|
return`/***********************************************
|
|
*** This is a GENERATED file - Do not edit! ***
|
|
***********************************************/
|
|
|
|
`
|
|
}
|
|
|
|
func Comment(aComment string, indent int) string {
|
|
tBuf := &strings.Builder{}
|
|
tComment := strings.TrimSpace(aComment)
|
|
tInd := strings.Repeat(" ", indent)
|
|
if tComment != "" {
|
|
tCommentLines := strings.Split(tComment, "\n")
|
|
for _, tCommentLine := range tCommentLines {
|
|
tBuf.WriteString(fmt.Sprintf("%v// %v\n", tInd, tCommentLine))
|
|
}
|
|
}
|
|
return tBuf.String()
|
|
} |