bump(github.com/go-openapi/spec): 7abd5745472fff5eb3685386d5fb8bf38683154d
This commit is contained in:
1
vendor/github.com/go-openapi/swag/.drone.sec
generated
vendored
1
vendor/github.com/go-openapi/swag/.drone.sec
generated
vendored
@@ -1 +0,0 @@
|
||||
eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkExMjhHQ00ifQ.darMHuSYnLhsknrnqjdXLGcyEJ5kM13yQbLGi2UWcKXpddHvPT3dMCnP5y7e27c76R2HFnvr56BqDMI-x0zyuQtjYKzSFUGjOcEhOH3OL1Hxu-Cm2z2443BS8asXNA3sEveAGQvG68jffm7CvtEtMo57wBpggI7UHbfIdLMK47s1EDpC4xanjiS1BJe5NC_Ikf0jfa6vf18oggbjxuoqSEvSNVdNRyZwG_npFaZFJzvdtehTG7GqunWjGiqBb81qNcEdzSdIZW7A_Esv4U-nOL5gGr55E9jKhv3bX4Z9ygGcSrJ3NCgR_3zRhYKkPEAOXIqQKfL6-h82BY--cHq9uw.NHL3X-1tjb8a8zF7.eRmLvOG32e7260K8rkI-HmUGG5Gb6Hu-obKKxBqHd-vVzsKnwTVJavLWktPqlXGMsnDt7MimSysNqsWemMUEviW2p3godnvjOOXTDb-RAtQ-39rvxnZ2bN8qwUVFrdiKTZD06l60yTeLW7L1psyLj50NxklFObhkpUcK5uukxLXT1SzGM9aY6_3dzW4HU9pZGQrIH1pj1UzvWIjz7iIzE1a37DHBN-FiYSASsw01v1SSIFr34gwlGcqzGfJBonffVrM4ordm3IiVm50Zvr25DrmYTKrQpJRB-KOvYxBNYDzjCaanHDyWGUGN44FUx38azHHEVBTaiOM7xwPeyCc-xTTv8WXGnL1xrhL3M_jNuwnbAjzL9X_li7KUSeYajwhGihdMZaHLYaqxh3NNnbPfYhR6sBxu8vaT1Sc4eE84QC4dV4OaAglPvrPdWL-DC7OYQyoPU8u9ggwUQHpFUzJyD549T_Tlgn-2Cw7kTe41VonH9HkoXGANDGtQCGTqTIEeFQJ3MDDucf5VteFP8_SJPfyJYxpStFt5U1AuULV9sXmpGQL_-GGFXowd0X0bHxFeo_eu1vm-oTqQQNbKRnyt5V3n4U9jhOUGnnIBy3JOG3DA2YhVJsHdlLZ9vaDpFYcxts4.SqYfES30FqVSufGbPZ6YXA
|
32
vendor/github.com/go-openapi/swag/.drone.yml
generated
vendored
32
vendor/github.com/go-openapi/swag/.drone.yml
generated
vendored
@@ -1,32 +0,0 @@
|
||||
clone:
|
||||
path: github.com/go-openapi/swag
|
||||
|
||||
matrix:
|
||||
GO_VERSION:
|
||||
- "1.6"
|
||||
|
||||
build:
|
||||
integration:
|
||||
image: golang:$$GO_VERSION
|
||||
pull: true
|
||||
commands:
|
||||
- go get -u github.com/stretchr/testify
|
||||
- go get -u github.com/mailru/easyjson
|
||||
- go test -race
|
||||
- go test -v -cover -coverprofile=coverage.out -covermode=count ./...
|
||||
|
||||
notify:
|
||||
slack:
|
||||
channel: bots
|
||||
webhook_url: $$SLACK_URL
|
||||
username: drone
|
||||
|
||||
publish:
|
||||
coverage:
|
||||
server: https://coverage.vmware.run
|
||||
token: $$GITHUB_TOKEN
|
||||
# threshold: 70
|
||||
# must_increase: true
|
||||
when:
|
||||
matrix:
|
||||
GO_VERSION: "1.6"
|
26
vendor/github.com/go-openapi/swag/.editorconfig
generated
vendored
Normal file
26
vendor/github.com/go-openapi/swag/.editorconfig
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
# top-most EditorConfig file
|
||||
root = true
|
||||
|
||||
# Unix-style newlines with a newline ending every file
|
||||
[*]
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
# Set default charset
|
||||
[*.{js,py,go,scala,rb,java,html,css,less,sass,md}]
|
||||
charset = utf-8
|
||||
|
||||
# Tab indentation (no size specified)
|
||||
[*.go]
|
||||
indent_style = tab
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
# Matches the exact files either package.json or .travis.yml
|
||||
[{package.json,.travis.yml}]
|
||||
indent_style = space
|
||||
indent_size = 2
|
13
vendor/github.com/go-openapi/swag/.pullapprove.yml
generated
vendored
13
vendor/github.com/go-openapi/swag/.pullapprove.yml
generated
vendored
@@ -1,13 +0,0 @@
|
||||
approve_by_comment: true
|
||||
approve_regex: '^(:shipit:|:\+1:|\+1|LGTM|lgtm|Approved)'
|
||||
reject_regex: ^[Rr]ejected
|
||||
reset_on_push: false
|
||||
reviewers:
|
||||
members:
|
||||
- casualjim
|
||||
- chancez
|
||||
- frapposelli
|
||||
- vburenin
|
||||
- pytlesk4
|
||||
name: pullapprove
|
||||
required: 1
|
14
vendor/github.com/go-openapi/swag/.travis.yml
generated
vendored
Normal file
14
vendor/github.com/go-openapi/swag/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
language: go
|
||||
go:
|
||||
- 1.8
|
||||
install:
|
||||
- go get -u github.com/stretchr/testify
|
||||
- go get -u github.com/mailru/easyjson
|
||||
- go get -u gopkg.in/yaml.v2
|
||||
script:
|
||||
- go test -v -race -cover -coverprofile=coverage.txt -covermode=atomic ./...
|
||||
after_success:
|
||||
- bash <(curl -s https://codecov.io/bash)
|
||||
notifications:
|
||||
slack:
|
||||
secure: QUWvCkBBK09GF7YtEvHHVt70JOkdlNBG0nIKu/5qc4/nW5HP8I2w0SEf/XR2je0eED1Qe3L/AfMCWwrEj+IUZc3l4v+ju8X8R3Lomhme0Eb0jd1MTMCuPcBT47YCj0M7RON7vXtbFfm1hFJ/jLe5+9FXz0hpXsR24PJc5ZIi/ogNwkaPqG4BmndzecpSh0vc2FJPZUD9LT0I09REY/vXR0oQAalLkW0asGD5taHZTUZq/kBpsNxaAFrLM23i4mUcf33M5fjLpvx5LRICrX/57XpBrDh2TooBU6Qj3CgoY0uPRYUmSNxbVx1czNzl2JtEpb5yjoxfVPQeg0BvQM00G8LJINISR+ohrjhkZmAqchDupAX+yFrxTtORa78CtnIL6z/aTNlgwwVD8kvL/1pFA/JWYmKDmz93mV/+6wubGzNSQCstzjkFA4/iZEKewKUoRIAi/fxyscP6L/rCpmY/4llZZvrnyTqVbt6URWpopUpH4rwYqreXAtJxJsfBJIeSmUIiDIOMGkCTvyTEW3fWGmGoqWtSHLoaWDyAIGb7azb+KvfpWtEcoPFWfSWU+LGee0A/YsUhBl7ADB9A0CJEuR8q4BPpKpfLwPKSiKSAXL7zDkyjExyhtgqbSl2jS+rKIHOZNL8JkCcTP2MKMVd563C5rC5FMKqu3S9m2b6380E=
|
2
vendor/github.com/go-openapi/swag/BUILD
generated
vendored
2
vendor/github.com/go-openapi/swag/BUILD
generated
vendored
@@ -10,11 +10,13 @@ go_library(
|
||||
"net.go",
|
||||
"path.go",
|
||||
"util.go",
|
||||
"yaml.go",
|
||||
],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//vendor/github.com/mailru/easyjson/jlexer:go_default_library",
|
||||
"//vendor/github.com/mailru/easyjson/jwriter:go_default_library",
|
||||
"//vendor/gopkg.in/yaml.v2:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
|
2
vendor/github.com/go-openapi/swag/README.md
generated
vendored
2
vendor/github.com/go-openapi/swag/README.md
generated
vendored
@@ -1,4 +1,4 @@
|
||||
# Swag [](https://ci.vmware.run/go-openapi/swag) [](https://coverage.vmware.run/go-openapi/swag) [](https://slackin.goswagger.io)
|
||||
# Swag [](https://travis-ci.org/go-openapi/swag) [](https://codecov.io/gh/go-openapi/swag) [](https://slackin.goswagger.io)
|
||||
|
||||
[](https://raw.githubusercontent.com/go-openapi/swag/master/LICENSE) [](http://godoc.org/github.com/go-openapi/swag)
|
||||
|
||||
|
2
vendor/github.com/go-openapi/swag/convert.go
generated
vendored
2
vendor/github.com/go-openapi/swag/convert.go
generated
vendored
@@ -159,7 +159,7 @@ func FormatInt16(value int16) string {
|
||||
|
||||
// FormatInt32 turns an int32 into a string
|
||||
func FormatInt32(value int32) string {
|
||||
return strconv.FormatInt(int64(value), 10)
|
||||
return strconv.Itoa(int(value))
|
||||
}
|
||||
|
||||
// FormatInt64 turns an int64 into a string
|
||||
|
47
vendor/github.com/go-openapi/swag/json.go
generated
vendored
47
vendor/github.com/go-openapi/swag/json.go
generated
vendored
@@ -17,6 +17,7 @@ package swag
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"log"
|
||||
"reflect"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -110,28 +111,40 @@ func ConcatJSON(blobs ...[]byte) []byte {
|
||||
|
||||
if len(b) < 3 { // yep empty but also the last one, so closing this thing
|
||||
if i == last && a > 0 {
|
||||
buf.WriteByte(closing)
|
||||
if err := buf.WriteByte(closing); err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
idx = 0
|
||||
if a > 0 { // we need to join with a comma for everything beyond the first non-empty item
|
||||
buf.WriteByte(comma)
|
||||
if err := buf.WriteByte(comma); err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
idx = 1 // this is not the first or the last so we want to drop the leading bracket
|
||||
}
|
||||
|
||||
if i != last { // not the last one, strip brackets
|
||||
buf.Write(b[idx : len(b)-1])
|
||||
if _, err := buf.Write(b[idx : len(b)-1]); err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
} else { // last one, strip only the leading bracket
|
||||
buf.Write(b[idx:])
|
||||
if _, err := buf.Write(b[idx:]); err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
}
|
||||
a++
|
||||
}
|
||||
// somehow it ended up being empty, so provide a default value
|
||||
if buf.Len() == 0 {
|
||||
buf.WriteByte(opening)
|
||||
buf.WriteByte(closing)
|
||||
if err := buf.WriteByte(opening); err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
if err := buf.WriteByte(closing); err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
}
|
||||
return buf.Bytes()
|
||||
}
|
||||
@@ -139,15 +152,23 @@ func ConcatJSON(blobs ...[]byte) []byte {
|
||||
// ToDynamicJSON turns an object into a properly JSON typed structure
|
||||
func ToDynamicJSON(data interface{}) interface{} {
|
||||
// TODO: convert straight to a json typed map (mergo + iterate?)
|
||||
b, _ := json.Marshal(data)
|
||||
b, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
var res interface{}
|
||||
json.Unmarshal(b, &res)
|
||||
if err := json.Unmarshal(b, &res); err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// FromDynamicJSON turns an object into a properly JSON typed structure
|
||||
func FromDynamicJSON(data, target interface{}) error {
|
||||
b, _ := json.Marshal(data)
|
||||
b, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
return json.Unmarshal(b, target)
|
||||
}
|
||||
|
||||
@@ -216,6 +237,8 @@ func newNameIndex(tpe reflect.Type) nameIndex {
|
||||
|
||||
// GetJSONNames gets all the json property names for a type
|
||||
func (n *NameProvider) GetJSONNames(subject interface{}) []string {
|
||||
n.lock.Lock()
|
||||
defer n.lock.Unlock()
|
||||
tpe := reflect.Indirect(reflect.ValueOf(subject)).Type()
|
||||
names, ok := n.index[tpe]
|
||||
if !ok {
|
||||
@@ -237,6 +260,8 @@ func (n *NameProvider) GetJSONName(subject interface{}, name string) (string, bo
|
||||
|
||||
// GetJSONNameForType gets the json name for a go property name on a given type
|
||||
func (n *NameProvider) GetJSONNameForType(tpe reflect.Type, name string) (string, bool) {
|
||||
n.lock.Lock()
|
||||
defer n.lock.Unlock()
|
||||
names, ok := n.index[tpe]
|
||||
if !ok {
|
||||
names = n.makeNameIndex(tpe)
|
||||
@@ -246,8 +271,6 @@ func (n *NameProvider) GetJSONNameForType(tpe reflect.Type, name string) (string
|
||||
}
|
||||
|
||||
func (n *NameProvider) makeNameIndex(tpe reflect.Type) nameIndex {
|
||||
n.lock.Lock()
|
||||
defer n.lock.Unlock()
|
||||
names := newNameIndex(tpe)
|
||||
n.index[tpe] = names
|
||||
return names
|
||||
@@ -261,6 +284,8 @@ func (n *NameProvider) GetGoName(subject interface{}, name string) (string, bool
|
||||
|
||||
// GetGoNameForType gets the go name for a given type for a json property name
|
||||
func (n *NameProvider) GetGoNameForType(tpe reflect.Type, name string) (string, bool) {
|
||||
n.lock.Lock()
|
||||
defer n.lock.Unlock()
|
||||
names, ok := n.index[tpe]
|
||||
if !ok {
|
||||
names = n.makeNameIndex(tpe)
|
||||
|
49
vendor/github.com/go-openapi/swag/loading.go
generated
vendored
49
vendor/github.com/go-openapi/swag/loading.go
generated
vendored
@@ -17,13 +17,25 @@ package swag
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// LoadHTTPTimeout the default timeout for load requests
|
||||
var LoadHTTPTimeout = 30 * time.Second
|
||||
|
||||
// LoadFromFileOrHTTP loads the bytes from a file or a remote http server based on the path passed in
|
||||
func LoadFromFileOrHTTP(path string) ([]byte, error) {
|
||||
return LoadStrategy(path, ioutil.ReadFile, loadHTTPBytes)(path)
|
||||
return LoadStrategy(path, ioutil.ReadFile, loadHTTPBytes(LoadHTTPTimeout))(path)
|
||||
}
|
||||
|
||||
// LoadFromFileOrHTTPWithTimeout loads the bytes from a file or a remote http server based on the path passed in
|
||||
// timeout arg allows for per request overriding of the request timeout
|
||||
func LoadFromFileOrHTTPWithTimeout(path string, timeout time.Duration) ([]byte, error) {
|
||||
return LoadStrategy(path, ioutil.ReadFile, loadHTTPBytes(timeout))(path)
|
||||
}
|
||||
|
||||
// LoadStrategy returns a loader function for a given path or uri
|
||||
@@ -31,19 +43,32 @@ func LoadStrategy(path string, local, remote func(string) ([]byte, error)) func(
|
||||
if strings.HasPrefix(path, "http") {
|
||||
return remote
|
||||
}
|
||||
return local
|
||||
return func(pth string) ([]byte, error) { return local(filepath.FromSlash(pth)) }
|
||||
}
|
||||
|
||||
func loadHTTPBytes(path string) ([]byte, error) {
|
||||
resp, err := http.Get(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
func loadHTTPBytes(timeout time.Duration) func(path string) ([]byte, error) {
|
||||
return func(path string) ([]byte, error) {
|
||||
client := &http.Client{Timeout: timeout}
|
||||
req, err := http.NewRequest("GET", path, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := client.Do(req)
|
||||
defer func() {
|
||||
if resp != nil {
|
||||
if e := resp.Body.Close(); e != nil {
|
||||
log.Println(e)
|
||||
}
|
||||
}
|
||||
}()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return nil, fmt.Errorf("could not access document at %q [%s] ", path, resp.Status)
|
||||
}
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return nil, fmt.Errorf("could not access document at %q [%s] ", path, resp.Status)
|
||||
}
|
||||
|
||||
return ioutil.ReadAll(resp.Body)
|
||||
return ioutil.ReadAll(resp.Body)
|
||||
}
|
||||
}
|
||||
|
3
vendor/github.com/go-openapi/swag/path.go
generated
vendored
3
vendor/github.com/go-openapi/swag/path.go
generated
vendored
@@ -47,6 +47,9 @@ func FindInGoSearchPath(pkg string) string {
|
||||
// FullGoSearchPath gets the search paths for finding packages
|
||||
func FullGoSearchPath() string {
|
||||
allPaths := os.Getenv(GOPATHKey)
|
||||
if allPaths == "" {
|
||||
allPaths = filepath.Join(os.Getenv("HOME"), "go")
|
||||
}
|
||||
if allPaths != "" {
|
||||
allPaths = strings.Join([]string{allPaths, runtime.GOROOT()}, ":")
|
||||
} else {
|
||||
|
26
vendor/github.com/go-openapi/swag/util.go
generated
vendored
26
vendor/github.com/go-openapi/swag/util.go
generated
vendored
@@ -20,10 +20,12 @@ import (
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
// Taken from https://github.com/golang/lint/blob/1fab560e16097e5b69afb66eb93aab843ef77845/lint.go#L663-L698
|
||||
// Taken from https://github.com/golang/lint/blob/3390df4df2787994aea98de825b964ac7944b817/lint.go#L732-L769
|
||||
var commonInitialisms = map[string]bool{
|
||||
"ACL": true,
|
||||
"API": true,
|
||||
"ASCII": true,
|
||||
"CPU": true,
|
||||
@@ -44,19 +46,21 @@ var commonInitialisms = map[string]bool{
|
||||
"RPC": true,
|
||||
"SLA": true,
|
||||
"SMTP": true,
|
||||
"SQL": true,
|
||||
"SSH": true,
|
||||
"TCP": true,
|
||||
"TLS": true,
|
||||
"TTL": true,
|
||||
"UDP": true,
|
||||
"UUID": true,
|
||||
"UID": true,
|
||||
"UI": true,
|
||||
"UID": true,
|
||||
"UUID": true,
|
||||
"URI": true,
|
||||
"URL": true,
|
||||
"UTF8": true,
|
||||
"VM": true,
|
||||
"XML": true,
|
||||
"XMPP": true,
|
||||
"XSRF": true,
|
||||
"XSS": true,
|
||||
}
|
||||
@@ -246,6 +250,9 @@ func ToJSONName(name string) string {
|
||||
// ToVarName camelcases a name which can be underscored or pascal cased
|
||||
func ToVarName(name string) string {
|
||||
res := ToGoName(name)
|
||||
if _, ok := commonInitialisms[res]; ok {
|
||||
return lower(res)
|
||||
}
|
||||
if len(res) <= 1 {
|
||||
return lower(res)
|
||||
}
|
||||
@@ -263,7 +270,18 @@ func ToGoName(name string) string {
|
||||
}
|
||||
out = append(out, uw)
|
||||
}
|
||||
return strings.Join(out, "")
|
||||
|
||||
result := strings.Join(out, "")
|
||||
if len(result) > 0 {
|
||||
ud := upper(result[:1])
|
||||
ru := []rune(ud)
|
||||
if unicode.IsUpper(ru[0]) {
|
||||
result = ud + result[1:]
|
||||
} else {
|
||||
result = "X" + ud + result[1:]
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// ContainsStringsCI searches a slice of strings for a case-insensitive match
|
||||
|
215
vendor/github.com/go-openapi/swag/yaml.go
generated
vendored
Normal file
215
vendor/github.com/go-openapi/swag/yaml.go
generated
vendored
Normal file
@@ -0,0 +1,215 @@
|
||||
// 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 (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
|
||||
"github.com/mailru/easyjson/jlexer"
|
||||
"github.com/mailru/easyjson/jwriter"
|
||||
|
||||
yaml "gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
// YAMLMatcher matches yaml
|
||||
func YAMLMatcher(path string) bool {
|
||||
ext := filepath.Ext(path)
|
||||
return ext == ".yaml" || ext == ".yml"
|
||||
}
|
||||
|
||||
// YAMLToJSON converts YAML unmarshaled data into json compatible data
|
||||
func YAMLToJSON(data interface{}) (json.RawMessage, error) {
|
||||
jm, err := transformData(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
b, err := WriteJSON(jm)
|
||||
return json.RawMessage(b), err
|
||||
}
|
||||
|
||||
func BytesToYAMLDoc(data []byte) (interface{}, error) {
|
||||
var canary map[interface{}]interface{} // validate this is an object and not a different type
|
||||
if err := yaml.Unmarshal(data, &canary); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var document yaml.MapSlice // preserve order that is present in the document
|
||||
if err := yaml.Unmarshal(data, &document); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return document, nil
|
||||
}
|
||||
|
||||
type JSONMapSlice []JSONMapItem
|
||||
|
||||
func (s JSONMapSlice) MarshalJSON() ([]byte, error) {
|
||||
w := &jwriter.Writer{Flags: jwriter.NilMapAsEmpty | jwriter.NilSliceAsEmpty}
|
||||
s.MarshalEasyJSON(w)
|
||||
return w.BuildBytes()
|
||||
}
|
||||
|
||||
func (s JSONMapSlice) MarshalEasyJSON(w *jwriter.Writer) {
|
||||
w.RawByte('{')
|
||||
|
||||
ln := len(s)
|
||||
last := ln - 1
|
||||
for i := 0; i < ln; i++ {
|
||||
s[i].MarshalEasyJSON(w)
|
||||
if i != last { // last item
|
||||
w.RawByte(',')
|
||||
}
|
||||
}
|
||||
|
||||
w.RawByte('}')
|
||||
}
|
||||
|
||||
func (s *JSONMapSlice) UnmarshalJSON(data []byte) error {
|
||||
l := jlexer.Lexer{Data: data}
|
||||
s.UnmarshalEasyJSON(&l)
|
||||
return l.Error()
|
||||
}
|
||||
func (s *JSONMapSlice) UnmarshalEasyJSON(in *jlexer.Lexer) {
|
||||
if in.IsNull() {
|
||||
in.Skip()
|
||||
return
|
||||
}
|
||||
|
||||
var result JSONMapSlice
|
||||
in.Delim('{')
|
||||
for !in.IsDelim('}') {
|
||||
var mi JSONMapItem
|
||||
mi.UnmarshalEasyJSON(in)
|
||||
result = append(result, mi)
|
||||
}
|
||||
*s = result
|
||||
}
|
||||
|
||||
type JSONMapItem struct {
|
||||
Key string
|
||||
Value interface{}
|
||||
}
|
||||
|
||||
func (s JSONMapItem) MarshalJSON() ([]byte, error) {
|
||||
w := &jwriter.Writer{Flags: jwriter.NilMapAsEmpty | jwriter.NilSliceAsEmpty}
|
||||
s.MarshalEasyJSON(w)
|
||||
return w.BuildBytes()
|
||||
}
|
||||
|
||||
func (s JSONMapItem) MarshalEasyJSON(w *jwriter.Writer) {
|
||||
w.String(s.Key)
|
||||
w.RawByte(':')
|
||||
w.Raw(WriteJSON(s.Value))
|
||||
}
|
||||
|
||||
func (s *JSONMapItem) UnmarshalEasyJSON(in *jlexer.Lexer) {
|
||||
key := in.UnsafeString()
|
||||
in.WantColon()
|
||||
value := in.Interface()
|
||||
in.WantComma()
|
||||
s.Key = key
|
||||
s.Value = value
|
||||
}
|
||||
func (s *JSONMapItem) UnmarshalJSON(data []byte) error {
|
||||
l := jlexer.Lexer{Data: data}
|
||||
s.UnmarshalEasyJSON(&l)
|
||||
return l.Error()
|
||||
}
|
||||
|
||||
func transformData(input interface{}) (out interface{}, err error) {
|
||||
switch in := input.(type) {
|
||||
case yaml.MapSlice:
|
||||
|
||||
o := make(JSONMapSlice, len(in))
|
||||
for i, mi := range in {
|
||||
var nmi JSONMapItem
|
||||
switch k := mi.Key.(type) {
|
||||
case string:
|
||||
nmi.Key = k
|
||||
case int:
|
||||
nmi.Key = strconv.Itoa(k)
|
||||
default:
|
||||
return nil, fmt.Errorf("types don't match expect map key string or int got: %T", mi.Key)
|
||||
}
|
||||
|
||||
v, err := transformData(mi.Value)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
nmi.Value = v
|
||||
o[i] = nmi
|
||||
}
|
||||
return o, nil
|
||||
case map[interface{}]interface{}:
|
||||
o := make(JSONMapSlice, 0, len(in))
|
||||
for ke, va := range in {
|
||||
var nmi JSONMapItem
|
||||
switch k := ke.(type) {
|
||||
case string:
|
||||
nmi.Key = k
|
||||
case int:
|
||||
nmi.Key = strconv.Itoa(k)
|
||||
default:
|
||||
return nil, fmt.Errorf("types don't match expect map key string or int got: %T", ke)
|
||||
}
|
||||
|
||||
v, err := transformData(va)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
nmi.Value = v
|
||||
o = append(o, nmi)
|
||||
}
|
||||
return o, nil
|
||||
case []interface{}:
|
||||
len1 := len(in)
|
||||
o := make([]interface{}, len1)
|
||||
for i := 0; i < len1; i++ {
|
||||
o[i], err = transformData(in[i])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return o, nil
|
||||
}
|
||||
return input, nil
|
||||
}
|
||||
|
||||
// YAMLDoc loads a yaml document from either http or a file and converts it to json
|
||||
func YAMLDoc(path string) (json.RawMessage, error) {
|
||||
yamlDoc, err := YAMLData(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
data, err := YAMLToJSON(yamlDoc)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return json.RawMessage(data), nil
|
||||
}
|
||||
|
||||
// YAMLData loads a yaml document from either http or a file
|
||||
func YAMLData(path string) (interface{}, error) {
|
||||
data, err := LoadFromFileOrHTTP(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return BytesToYAMLDoc(data)
|
||||
}
|
Reference in New Issue
Block a user