mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 10:33:35 +00:00
Migrate from snapClient.VolumesnapshotV1alpha1Client to
snapClient.SnapshotV1alpha1Client and also update kube dependency Signed-off-by: Humble Chirammal <hchiramm@redhat.com>
This commit is contained in:
committed by
mergify[bot]
parent
3bc6771df8
commit
22ff5c0911
7
vendor/github.com/go-openapi/spec/items.go
generated
vendored
7
vendor/github.com/go-openapi/spec/items.go
generated
vendored
@ -29,6 +29,7 @@ const (
|
||||
// SimpleSchema describe swagger simple schemas for parameters and headers
|
||||
type SimpleSchema struct {
|
||||
Type string `json:"type,omitempty"`
|
||||
Nullable bool `json:"nullable,omitempty"`
|
||||
Format string `json:"format,omitempty"`
|
||||
Items *Items `json:"items,omitempty"`
|
||||
CollectionFormat string `json:"collectionFormat,omitempty"`
|
||||
@ -91,6 +92,12 @@ func (i *Items) Typed(tpe, format string) *Items {
|
||||
return i
|
||||
}
|
||||
|
||||
// AsNullable flags this schema as nullable.
|
||||
func (i *Items) AsNullable() *Items {
|
||||
i.Nullable = true
|
||||
return i
|
||||
}
|
||||
|
||||
// CollectionOf a fluent builder method for an array item
|
||||
func (i *Items) CollectionOf(items *Items, format string) *Items {
|
||||
i.Type = jsonArray
|
||||
|
7
vendor/github.com/go-openapi/spec/schema.go
generated
vendored
7
vendor/github.com/go-openapi/spec/schema.go
generated
vendored
@ -163,6 +163,7 @@ type SchemaProps struct {
|
||||
Schema SchemaURL `json:"-"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Type StringOrArray `json:"type,omitempty"`
|
||||
Nullable bool `json:"nullable,omitempty"`
|
||||
Format string `json:"format,omitempty"`
|
||||
Title string `json:"title,omitempty"`
|
||||
Default interface{} `json:"default,omitempty"`
|
||||
@ -302,6 +303,12 @@ func (s *Schema) AddType(tpe, format string) *Schema {
|
||||
return s
|
||||
}
|
||||
|
||||
// AsNullable flags this schema as nullable.
|
||||
func (s *Schema) AsNullable() *Schema {
|
||||
s.Nullable = true
|
||||
return s
|
||||
}
|
||||
|
||||
// CollectionOf a fluent builder method for an array parameter
|
||||
func (s *Schema) CollectionOf(items Schema) *Schema {
|
||||
s.Type = []string{jsonArray}
|
||||
|
124
vendor/github.com/go-openapi/spec/swagger.go
generated
vendored
124
vendor/github.com/go-openapi/spec/swagger.go
generated
vendored
@ -15,6 +15,8 @@
|
||||
package spec
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/gob"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strconv"
|
||||
@ -68,6 +70,36 @@ func (s *Swagger) UnmarshalJSON(data []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GobEncode provides a safe gob encoder for Swagger, including extensions
|
||||
func (s Swagger) GobEncode() ([]byte, error) {
|
||||
var b bytes.Buffer
|
||||
raw := struct {
|
||||
Props SwaggerProps
|
||||
Ext VendorExtensible
|
||||
}{
|
||||
Props: s.SwaggerProps,
|
||||
Ext: s.VendorExtensible,
|
||||
}
|
||||
err := gob.NewEncoder(&b).Encode(raw)
|
||||
return b.Bytes(), err
|
||||
}
|
||||
|
||||
// GobDecode provides a safe gob decoder for Swagger, including extensions
|
||||
func (s *Swagger) GobDecode(b []byte) error {
|
||||
var raw struct {
|
||||
Props SwaggerProps
|
||||
Ext VendorExtensible
|
||||
}
|
||||
buf := bytes.NewBuffer(b)
|
||||
err := gob.NewDecoder(buf).Decode(&raw)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
s.SwaggerProps = raw.Props
|
||||
s.VendorExtensible = raw.Ext
|
||||
return nil
|
||||
}
|
||||
|
||||
// SwaggerProps captures the top-level properties of an Api specification
|
||||
//
|
||||
// NOTE: validation rules
|
||||
@ -93,6 +125,98 @@ type SwaggerProps struct {
|
||||
ExternalDocs *ExternalDocumentation `json:"externalDocs,omitempty"`
|
||||
}
|
||||
|
||||
type swaggerPropsAlias SwaggerProps
|
||||
|
||||
type gobSwaggerPropsAlias struct {
|
||||
Security []map[string]struct {
|
||||
List []string
|
||||
Pad bool
|
||||
}
|
||||
Alias *swaggerPropsAlias
|
||||
SecurityIsEmpty bool
|
||||
}
|
||||
|
||||
// GobEncode provides a safe gob encoder for SwaggerProps, including empty security requirements
|
||||
func (o SwaggerProps) GobEncode() ([]byte, error) {
|
||||
raw := gobSwaggerPropsAlias{
|
||||
Alias: (*swaggerPropsAlias)(&o),
|
||||
}
|
||||
|
||||
var b bytes.Buffer
|
||||
if o.Security == nil {
|
||||
// nil security requirement
|
||||
err := gob.NewEncoder(&b).Encode(raw)
|
||||
return b.Bytes(), err
|
||||
}
|
||||
|
||||
if len(o.Security) == 0 {
|
||||
// empty, but non-nil security requirement
|
||||
raw.SecurityIsEmpty = true
|
||||
raw.Alias.Security = nil
|
||||
err := gob.NewEncoder(&b).Encode(raw)
|
||||
return b.Bytes(), err
|
||||
}
|
||||
|
||||
raw.Security = make([]map[string]struct {
|
||||
List []string
|
||||
Pad bool
|
||||
}, 0, len(o.Security))
|
||||
for _, req := range o.Security {
|
||||
v := make(map[string]struct {
|
||||
List []string
|
||||
Pad bool
|
||||
}, len(req))
|
||||
for k, val := range req {
|
||||
v[k] = struct {
|
||||
List []string
|
||||
Pad bool
|
||||
}{
|
||||
List: val,
|
||||
}
|
||||
}
|
||||
raw.Security = append(raw.Security, v)
|
||||
}
|
||||
|
||||
err := gob.NewEncoder(&b).Encode(raw)
|
||||
return b.Bytes(), err
|
||||
}
|
||||
|
||||
// GobDecode provides a safe gob decoder for SwaggerProps, including empty security requirements
|
||||
func (o *SwaggerProps) GobDecode(b []byte) error {
|
||||
var raw gobSwaggerPropsAlias
|
||||
|
||||
buf := bytes.NewBuffer(b)
|
||||
err := gob.NewDecoder(buf).Decode(&raw)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if raw.Alias == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
switch {
|
||||
case raw.SecurityIsEmpty:
|
||||
// empty, but non-nil security requirement
|
||||
raw.Alias.Security = []map[string][]string{}
|
||||
case len(raw.Alias.Security) == 0:
|
||||
// nil security requirement
|
||||
raw.Alias.Security = nil
|
||||
default:
|
||||
raw.Alias.Security = make([]map[string][]string, 0, len(raw.Security))
|
||||
for _, req := range raw.Security {
|
||||
v := make(map[string][]string, len(req))
|
||||
for k, val := range req {
|
||||
v[k] = make([]string, 0, len(val.List))
|
||||
v[k] = append(v[k], val.List...)
|
||||
}
|
||||
raw.Alias.Security = append(raw.Alias.Security, v)
|
||||
}
|
||||
}
|
||||
|
||||
*o = *(*SwaggerProps)(raw.Alias)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Dependencies represent a dependencies property
|
||||
type Dependencies map[string]SchemaOrStringArray
|
||||
|
||||
|
1
vendor/github.com/go-openapi/swag/doc.go
generated
vendored
1
vendor/github.com/go-openapi/swag/doc.go
generated
vendored
@ -27,7 +27,6 @@ You may also use it standalone for your projects.
|
||||
|
||||
This repo has only few dependencies outside of the standard library:
|
||||
|
||||
* JSON utilities depend on github.com/mailru/easyjson
|
||||
* YAML utilities depend on gopkg.in/yaml.v2
|
||||
*/
|
||||
package swag
|
||||
|
87
vendor/github.com/go-openapi/swag/name_lexem.go
generated
vendored
Normal file
87
vendor/github.com/go-openapi/swag/name_lexem.go
generated
vendored
Normal file
@ -0,0 +1,87 @@
|
||||
// Copyright 2015 go-swagger maintainers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package swag
|
||||
|
||||
import "unicode"
|
||||
|
||||
type (
|
||||
nameLexem interface {
|
||||
GetUnsafeGoName() string
|
||||
GetOriginal() string
|
||||
IsInitialism() bool
|
||||
}
|
||||
|
||||
initialismNameLexem struct {
|
||||
original string
|
||||
matchedInitialism string
|
||||
}
|
||||
|
||||
casualNameLexem struct {
|
||||
original string
|
||||
}
|
||||
)
|
||||
|
||||
func newInitialismNameLexem(original, matchedInitialism string) *initialismNameLexem {
|
||||
return &initialismNameLexem{
|
||||
original: original,
|
||||
matchedInitialism: matchedInitialism,
|
||||
}
|
||||
}
|
||||
|
||||
func newCasualNameLexem(original string) *casualNameLexem {
|
||||
return &casualNameLexem{
|
||||
original: original,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *initialismNameLexem) GetUnsafeGoName() string {
|
||||
return l.matchedInitialism
|
||||
}
|
||||
|
||||
func (l *casualNameLexem) GetUnsafeGoName() string {
|
||||
var first rune
|
||||
var rest string
|
||||
for i, orig := range l.original {
|
||||
if i == 0 {
|
||||
first = orig
|
||||
continue
|
||||
}
|
||||
if i > 0 {
|
||||
rest = l.original[i:]
|
||||
break
|
||||
}
|
||||
}
|
||||
if len(l.original) > 1 {
|
||||
return string(unicode.ToUpper(first)) + lower(rest)
|
||||
}
|
||||
|
||||
return l.original
|
||||
}
|
||||
|
||||
func (l *initialismNameLexem) GetOriginal() string {
|
||||
return l.original
|
||||
}
|
||||
|
||||
func (l *casualNameLexem) GetOriginal() string {
|
||||
return l.original
|
||||
}
|
||||
|
||||
func (l *initialismNameLexem) IsInitialism() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (l *casualNameLexem) IsInitialism() bool {
|
||||
return false
|
||||
}
|
262
vendor/github.com/go-openapi/swag/split.go
generated
vendored
Normal file
262
vendor/github.com/go-openapi/swag/split.go
generated
vendored
Normal file
@ -0,0 +1,262 @@
|
||||
// Copyright 2015 go-swagger maintainers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package swag
|
||||
|
||||
import (
|
||||
"unicode"
|
||||
)
|
||||
|
||||
var nameReplaceTable = map[rune]string{
|
||||
'@': "At ",
|
||||
'&': "And ",
|
||||
'|': "Pipe ",
|
||||
'$': "Dollar ",
|
||||
'!': "Bang ",
|
||||
'-': "",
|
||||
'_': "",
|
||||
}
|
||||
|
||||
type (
|
||||
splitter struct {
|
||||
postSplitInitialismCheck bool
|
||||
initialisms []string
|
||||
}
|
||||
|
||||
splitterOption func(*splitter) *splitter
|
||||
)
|
||||
|
||||
// split calls the splitter; splitter provides more control and post options
|
||||
func split(str string) []string {
|
||||
lexems := newSplitter().split(str)
|
||||
result := make([]string, 0, len(lexems))
|
||||
|
||||
for _, lexem := range lexems {
|
||||
result = append(result, lexem.GetOriginal())
|
||||
}
|
||||
|
||||
return result
|
||||
|
||||
}
|
||||
|
||||
func (s *splitter) split(str string) []nameLexem {
|
||||
return s.toNameLexems(str)
|
||||
}
|
||||
|
||||
func newSplitter(options ...splitterOption) *splitter {
|
||||
splitter := &splitter{
|
||||
postSplitInitialismCheck: false,
|
||||
initialisms: initialisms,
|
||||
}
|
||||
|
||||
for _, option := range options {
|
||||
splitter = option(splitter)
|
||||
}
|
||||
|
||||
return splitter
|
||||
}
|
||||
|
||||
// withPostSplitInitialismCheck allows to catch initialisms after main split process
|
||||
func withPostSplitInitialismCheck(s *splitter) *splitter {
|
||||
s.postSplitInitialismCheck = true
|
||||
return s
|
||||
}
|
||||
|
||||
type (
|
||||
initialismMatch struct {
|
||||
start, end int
|
||||
body []rune
|
||||
complete bool
|
||||
}
|
||||
initialismMatches []*initialismMatch
|
||||
)
|
||||
|
||||
func (s *splitter) toNameLexems(name string) []nameLexem {
|
||||
nameRunes := []rune(name)
|
||||
matches := s.gatherInitialismMatches(nameRunes)
|
||||
return s.mapMatchesToNameLexems(nameRunes, matches)
|
||||
}
|
||||
|
||||
func (s *splitter) gatherInitialismMatches(nameRunes []rune) initialismMatches {
|
||||
matches := make(initialismMatches, 0)
|
||||
|
||||
for currentRunePosition, currentRune := range nameRunes {
|
||||
newMatches := make(initialismMatches, 0, len(matches))
|
||||
|
||||
// check current initialism matches
|
||||
for _, match := range matches {
|
||||
if keepCompleteMatch := match.complete; keepCompleteMatch {
|
||||
newMatches = append(newMatches, match)
|
||||
continue
|
||||
}
|
||||
|
||||
// drop failed match
|
||||
currentMatchRune := match.body[currentRunePosition-match.start]
|
||||
if !s.initialismRuneEqual(currentMatchRune, currentRune) {
|
||||
continue
|
||||
}
|
||||
|
||||
// try to complete ongoing match
|
||||
if currentRunePosition-match.start == len(match.body)-1 {
|
||||
// we are close; the next step is to check the symbol ahead
|
||||
// if it is a small letter, then it is not the end of match
|
||||
// but beginning of the next word
|
||||
|
||||
if currentRunePosition < len(nameRunes)-1 {
|
||||
nextRune := nameRunes[currentRunePosition+1]
|
||||
if newWord := unicode.IsLower(nextRune); newWord {
|
||||
// oh ok, it was the start of a new word
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
match.complete = true
|
||||
match.end = currentRunePosition
|
||||
}
|
||||
|
||||
newMatches = append(newMatches, match)
|
||||
}
|
||||
|
||||
// check for new initialism matches
|
||||
for _, initialism := range s.initialisms {
|
||||
initialismRunes := []rune(initialism)
|
||||
if s.initialismRuneEqual(initialismRunes[0], currentRune) {
|
||||
newMatches = append(newMatches, &initialismMatch{
|
||||
start: currentRunePosition,
|
||||
body: initialismRunes,
|
||||
complete: false,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
matches = newMatches
|
||||
}
|
||||
|
||||
return matches
|
||||
}
|
||||
|
||||
func (s *splitter) mapMatchesToNameLexems(nameRunes []rune, matches initialismMatches) []nameLexem {
|
||||
nameLexems := make([]nameLexem, 0)
|
||||
|
||||
var lastAcceptedMatch *initialismMatch
|
||||
for _, match := range matches {
|
||||
if !match.complete {
|
||||
continue
|
||||
}
|
||||
|
||||
if firstMatch := lastAcceptedMatch == nil; firstMatch {
|
||||
nameLexems = append(nameLexems, s.breakCasualString(nameRunes[:match.start])...)
|
||||
nameLexems = append(nameLexems, s.breakInitialism(string(match.body)))
|
||||
|
||||
lastAcceptedMatch = match
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
if overlappedMatch := match.start <= lastAcceptedMatch.end; overlappedMatch {
|
||||
continue
|
||||
}
|
||||
|
||||
middle := nameRunes[lastAcceptedMatch.end+1 : match.start]
|
||||
nameLexems = append(nameLexems, s.breakCasualString(middle)...)
|
||||
nameLexems = append(nameLexems, s.breakInitialism(string(match.body)))
|
||||
|
||||
lastAcceptedMatch = match
|
||||
}
|
||||
|
||||
// we have not found any accepted matches
|
||||
if lastAcceptedMatch == nil {
|
||||
return s.breakCasualString(nameRunes)
|
||||
}
|
||||
|
||||
if lastAcceptedMatch.end+1 != len(nameRunes) {
|
||||
rest := nameRunes[lastAcceptedMatch.end+1:]
|
||||
nameLexems = append(nameLexems, s.breakCasualString(rest)...)
|
||||
}
|
||||
|
||||
return nameLexems
|
||||
}
|
||||
|
||||
func (s *splitter) initialismRuneEqual(a, b rune) bool {
|
||||
return a == b
|
||||
}
|
||||
|
||||
func (s *splitter) breakInitialism(original string) nameLexem {
|
||||
return newInitialismNameLexem(original, original)
|
||||
}
|
||||
|
||||
func (s *splitter) breakCasualString(str []rune) []nameLexem {
|
||||
segments := make([]nameLexem, 0)
|
||||
currentSegment := ""
|
||||
|
||||
addCasualNameLexem := func(original string) {
|
||||
segments = append(segments, newCasualNameLexem(original))
|
||||
}
|
||||
|
||||
addInitialismNameLexem := func(original, match string) {
|
||||
segments = append(segments, newInitialismNameLexem(original, match))
|
||||
}
|
||||
|
||||
addNameLexem := func(original string) {
|
||||
if s.postSplitInitialismCheck {
|
||||
for _, initialism := range s.initialisms {
|
||||
if upper(initialism) == upper(original) {
|
||||
addInitialismNameLexem(original, initialism)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
addCasualNameLexem(original)
|
||||
}
|
||||
|
||||
for _, rn := range string(str) {
|
||||
if replace, found := nameReplaceTable[rn]; found {
|
||||
if currentSegment != "" {
|
||||
addNameLexem(currentSegment)
|
||||
currentSegment = ""
|
||||
}
|
||||
|
||||
if replace != "" {
|
||||
addNameLexem(replace)
|
||||
}
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
if !unicode.In(rn, unicode.L, unicode.M, unicode.N, unicode.Pc) {
|
||||
if currentSegment != "" {
|
||||
addNameLexem(currentSegment)
|
||||
currentSegment = ""
|
||||
}
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
if unicode.IsUpper(rn) {
|
||||
if currentSegment != "" {
|
||||
addNameLexem(currentSegment)
|
||||
}
|
||||
currentSegment = ""
|
||||
}
|
||||
|
||||
currentSegment += string(rn)
|
||||
}
|
||||
|
||||
if currentSegment != "" {
|
||||
addNameLexem(currentSegment)
|
||||
}
|
||||
|
||||
return segments
|
||||
}
|
92
vendor/github.com/go-openapi/swag/util.go
generated
vendored
92
vendor/github.com/go-openapi/swag/util.go
generated
vendored
@ -15,11 +15,8 @@
|
||||
package swag
|
||||
|
||||
import (
|
||||
"math"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"strings"
|
||||
"sync"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
@ -29,16 +26,8 @@ var commonInitialisms *indexOfInitialisms
|
||||
// initialisms is a slice of sorted initialisms
|
||||
var initialisms []string
|
||||
|
||||
var once sync.Once
|
||||
|
||||
var isInitialism func(string) bool
|
||||
|
||||
var (
|
||||
splitRex1 *regexp.Regexp
|
||||
splitRex2 *regexp.Regexp
|
||||
splitReplacer *strings.Replacer
|
||||
)
|
||||
|
||||
func init() {
|
||||
// Taken from https://github.com/golang/lint/blob/3390df4df2787994aea98de825b964ac7944b817/lint.go#L732-L769
|
||||
var configuredInitialisms = map[string]bool{
|
||||
@ -55,6 +44,8 @@ func init() {
|
||||
"HTTP": true,
|
||||
"ID": true,
|
||||
"IP": true,
|
||||
"IPv4": true,
|
||||
"IPv6": true,
|
||||
"JSON": true,
|
||||
"LHS": true,
|
||||
"OAI": true,
|
||||
@ -85,15 +76,12 @@ func init() {
|
||||
|
||||
// a thread-safe index of initialisms
|
||||
commonInitialisms = newIndexOfInitialisms().load(configuredInitialisms)
|
||||
initialisms = commonInitialisms.sorted()
|
||||
|
||||
// a test function
|
||||
isInitialism = commonInitialisms.isInitialism
|
||||
}
|
||||
|
||||
func ensureSorted() {
|
||||
initialisms = commonInitialisms.sorted()
|
||||
}
|
||||
|
||||
const (
|
||||
//collectionFormatComma = "csv"
|
||||
collectionFormatSpace = "ssv"
|
||||
@ -175,40 +163,6 @@ func (s byInitialism) Less(i, j int) bool {
|
||||
return strings.Compare(s[i], s[j]) > 0
|
||||
}
|
||||
|
||||
// Prepares strings by splitting by caps, spaces, dashes, and underscore
|
||||
func split(str string) []string {
|
||||
// check if consecutive single char things make up an initialism
|
||||
once.Do(func() {
|
||||
splitRex1 = regexp.MustCompile(`(\p{Lu})`)
|
||||
splitRex2 = regexp.MustCompile(`(\pL|\pM|\pN|\p{Pc})+`)
|
||||
splitReplacer = strings.NewReplacer(
|
||||
"@", "At ",
|
||||
"&", "And ",
|
||||
"|", "Pipe ",
|
||||
"$", "Dollar ",
|
||||
"!", "Bang ",
|
||||
"-", " ",
|
||||
"_", " ",
|
||||
)
|
||||
ensureSorted()
|
||||
})
|
||||
|
||||
str = trim(str)
|
||||
|
||||
// Convert dash and underscore to spaces
|
||||
str = splitReplacer.Replace(str)
|
||||
|
||||
// Split when uppercase is found (needed for Snake)
|
||||
str = splitRex1.ReplaceAllString(str, " $1")
|
||||
|
||||
for _, k := range initialisms {
|
||||
str = strings.Replace(str, splitRex1.ReplaceAllString(k, " $1"), " "+k, -1)
|
||||
}
|
||||
// Get the final list of words
|
||||
//words = rex2.FindAllString(str, -1)
|
||||
return splitRex2.FindAllString(str, -1)
|
||||
}
|
||||
|
||||
// Removes leading whitespaces
|
||||
func trim(str string) string {
|
||||
return strings.Trim(str, " ")
|
||||
@ -261,30 +215,31 @@ func ToCommandName(name string) string {
|
||||
|
||||
// ToHumanNameLower represents a code name as a human series of words
|
||||
func ToHumanNameLower(name string) string {
|
||||
in := split(name)
|
||||
in := newSplitter(withPostSplitInitialismCheck).split(name)
|
||||
out := make([]string, 0, len(in))
|
||||
|
||||
for _, w := range in {
|
||||
if !isInitialism(upper(w)) {
|
||||
out = append(out, lower(w))
|
||||
if !w.IsInitialism() {
|
||||
out = append(out, lower(w.GetOriginal()))
|
||||
} else {
|
||||
out = append(out, w)
|
||||
out = append(out, w.GetOriginal())
|
||||
}
|
||||
}
|
||||
|
||||
return strings.Join(out, " ")
|
||||
}
|
||||
|
||||
// ToHumanNameTitle represents a code name as a human series of words with the first letters titleized
|
||||
func ToHumanNameTitle(name string) string {
|
||||
in := split(name)
|
||||
out := make([]string, 0, len(in))
|
||||
in := newSplitter(withPostSplitInitialismCheck).split(name)
|
||||
|
||||
out := make([]string, 0, len(in))
|
||||
for _, w := range in {
|
||||
uw := upper(w)
|
||||
if !isInitialism(uw) {
|
||||
out = append(out, Camelize(w))
|
||||
original := w.GetOriginal()
|
||||
if !w.IsInitialism() {
|
||||
out = append(out, Camelize(original))
|
||||
} else {
|
||||
out = append(out, w)
|
||||
out = append(out, original)
|
||||
}
|
||||
}
|
||||
return strings.Join(out, " ")
|
||||
@ -319,24 +274,25 @@ func ToVarName(name string) string {
|
||||
|
||||
// ToGoName translates a swagger name which can be underscored or camel cased to a name that golint likes
|
||||
func ToGoName(name string) string {
|
||||
in := split(name)
|
||||
out := make([]string, 0, len(in))
|
||||
lexems := newSplitter(withPostSplitInitialismCheck).split(name)
|
||||
|
||||
for _, w := range in {
|
||||
uw := upper(w)
|
||||
mod := int(math.Min(float64(len(uw)), 2))
|
||||
if !isInitialism(uw) && !isInitialism(uw[:len(uw)-mod]) {
|
||||
uw = Camelize(w)
|
||||
result := ""
|
||||
for _, lexem := range lexems {
|
||||
goName := lexem.GetUnsafeGoName()
|
||||
|
||||
// to support old behavior
|
||||
if lexem.IsInitialism() {
|
||||
goName = upper(goName)
|
||||
}
|
||||
out = append(out, uw)
|
||||
result += goName
|
||||
}
|
||||
|
||||
result := strings.Join(out, "")
|
||||
if len(result) > 0 {
|
||||
if !unicode.IsUpper([]rune(result)[0]) {
|
||||
result = "X" + result
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user