diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json
index 34854614..37c4c552 100644
--- a/Godeps/Godeps.json
+++ b/Godeps/Godeps.json
@@ -40,23 +40,23 @@
},
{
"ImportPath": "github.com/coreos/go-oidc/http",
- "Rev": "be73733bb8cc830d0205609b95d125215f8e9c70"
+ "Rev": "a4973d9a4225417aecf5d450a9522f00c1f7130f"
},
{
"ImportPath": "github.com/coreos/go-oidc/jose",
- "Rev": "be73733bb8cc830d0205609b95d125215f8e9c70"
+ "Rev": "a4973d9a4225417aecf5d450a9522f00c1f7130f"
},
{
"ImportPath": "github.com/coreos/go-oidc/key",
- "Rev": "be73733bb8cc830d0205609b95d125215f8e9c70"
+ "Rev": "a4973d9a4225417aecf5d450a9522f00c1f7130f"
},
{
"ImportPath": "github.com/coreos/go-oidc/oauth2",
- "Rev": "be73733bb8cc830d0205609b95d125215f8e9c70"
+ "Rev": "a4973d9a4225417aecf5d450a9522f00c1f7130f"
},
{
"ImportPath": "github.com/coreos/go-oidc/oidc",
- "Rev": "be73733bb8cc830d0205609b95d125215f8e9c70"
+ "Rev": "a4973d9a4225417aecf5d450a9522f00c1f7130f"
},
{
"ImportPath": "github.com/coreos/pkg/health",
@@ -154,21 +154,33 @@
"ImportPath": "github.com/golang/protobuf/ptypes/timestamp",
"Rev": "4bd1920723d7b7c925de087aa32e2187708897f7"
},
+ {
+ "ImportPath": "github.com/google/btree",
+ "Rev": "7d79101e329e5a3adf994758c578dab82b90c017"
+ },
{
"ImportPath": "github.com/google/gofuzz",
"Rev": "44d81051d367757e1c7c6a5a86423ece9afcf63c"
},
{
"ImportPath": "github.com/googleapis/gnostic/OpenAPIv2",
- "Rev": "68f4ded48ba9414dab2ae69b3f0d69971da73aa5"
+ "Rev": "0c5108395e2debce0d731cf0287ddf7242066aba"
},
{
"ImportPath": "github.com/googleapis/gnostic/compiler",
- "Rev": "68f4ded48ba9414dab2ae69b3f0d69971da73aa5"
+ "Rev": "0c5108395e2debce0d731cf0287ddf7242066aba"
},
{
"ImportPath": "github.com/googleapis/gnostic/extensions",
- "Rev": "68f4ded48ba9414dab2ae69b3f0d69971da73aa5"
+ "Rev": "0c5108395e2debce0d731cf0287ddf7242066aba"
+ },
+ {
+ "ImportPath": "github.com/gregjones/httpcache",
+ "Rev": "787624de3eb7bd915c329cba748687a3b22666a6"
+ },
+ {
+ "ImportPath": "github.com/gregjones/httpcache/diskcache",
+ "Rev": "787624de3eb7bd915c329cba748687a3b22666a6"
},
{
"ImportPath": "github.com/hashicorp/golang-lru",
@@ -206,6 +218,10 @@
"ImportPath": "github.com/mailru/easyjson/jwriter",
"Rev": "d5b7844b561a7bc640052f1b935f7b800330d7e0"
},
+ {
+ "ImportPath": "github.com/peterbourgon/diskv",
+ "Rev": "5dfcb07a075adbaaa4094cddfd160b1e1c77a043"
+ },
{
"ImportPath": "github.com/pmezard/go-difflib/difflib",
"Rev": "d8ed2627bdf02c080bf22230dbb337003b7aba2d"
diff --git a/rest/config.go b/rest/config.go
index dca7333d..627a9cc9 100644
--- a/rest/config.go
+++ b/rest/config.go
@@ -71,6 +71,10 @@ type Config struct {
// TODO: demonstrate an OAuth2 compatible client.
BearerToken string
+ // CacheDir is the directory where we'll store HTTP cached responses.
+ // If set to empty string, no caching mechanism will be used.
+ CacheDir string
+
// Impersonate is the configuration that RESTClient will use for impersonation.
Impersonate ImpersonationConfig
diff --git a/rest/config_test.go b/rest/config_test.go
index f04135a4..f20ed722 100644
--- a/rest/config_test.go
+++ b/rest/config_test.go
@@ -249,6 +249,7 @@ func TestAnonymousConfig(t *testing.T) {
expected.BearerToken = ""
expected.Username = ""
expected.Password = ""
+ expected.CacheDir = ""
expected.AuthProvider = nil
expected.AuthConfigPersister = nil
expected.TLSClientConfig.CertData = nil
diff --git a/rest/transport.go b/rest/transport.go
index ba43752b..4c5b1648 100644
--- a/rest/transport.go
+++ b/rest/transport.go
@@ -89,6 +89,7 @@ func (c *Config) TransportConfig() (*transport.Config, error) {
},
Username: c.Username,
Password: c.Password,
+ CacheDir: c.CacheDir,
BearerToken: c.BearerToken,
Impersonate: transport.ImpersonationConfig{
UserName: c.Impersonate.UserName,
diff --git a/tools/clientcmd/client_config.go b/tools/clientcmd/client_config.go
index a8698af2..9646c6b7 100644
--- a/tools/clientcmd/client_config.go
+++ b/tools/clientcmd/client_config.go
@@ -22,6 +22,7 @@ import (
"io/ioutil"
"net/url"
"os"
+ "path/filepath"
"strings"
"github.com/golang/glog"
@@ -31,16 +32,19 @@ import (
restclient "k8s.io/client-go/rest"
clientauth "k8s.io/client-go/tools/auth"
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
+ "k8s.io/client-go/util/homedir"
)
var (
// ClusterDefaults has the same behavior as the old EnvVar and DefaultCluster fields
// DEPRECATED will be replaced
ClusterDefaults = clientcmdapi.Cluster{Server: getDefaultServer()}
+ cacheDirDefault = filepath.Join(homedir.HomeDir(), ".kube", "http-cache")
// DefaultClientConfig represents the legacy behavior of this package for defaulting
// DEPRECATED will be replace
DefaultClientConfig = DirectClientConfig{*clientcmdapi.NewConfig(), "", &ConfigOverrides{
ClusterDefaults: ClusterDefaults,
+ CacheDir: cacheDirDefault,
}, nil, NewDefaultClientConfigLoadingRules(), promptedCredentials{}}
)
@@ -131,6 +135,7 @@ func (config *DirectClientConfig) ClientConfig() (*restclient.Config, error) {
clientConfig := &restclient.Config{}
clientConfig.Host = configClusterInfo.Server
+ clientConfig.CacheDir = config.overrides.CacheDir
if len(config.overrides.Timeout) > 0 {
timeout, err := ParseTimeout(config.overrides.Timeout)
diff --git a/tools/clientcmd/overrides.go b/tools/clientcmd/overrides.go
index 963ac8fa..25ab1ea1 100644
--- a/tools/clientcmd/overrides.go
+++ b/tools/clientcmd/overrides.go
@@ -17,11 +17,13 @@ limitations under the License.
package clientcmd
import (
+ "path/filepath"
"strconv"
"github.com/spf13/pflag"
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
+ "k8s.io/client-go/util/homedir"
)
// ConfigOverrides holds values that should override whatever information is pulled from the actual Config object. You can't
@@ -34,6 +36,7 @@ type ConfigOverrides struct {
Context clientcmdapi.Context
CurrentContext string
Timeout string
+ CacheDir string
}
// ConfigOverrideFlags holds the flag names to be used for binding command line flags. Notice that this structure tightly
@@ -44,6 +47,7 @@ type ConfigOverrideFlags struct {
ContextOverrideFlags ContextOverrideFlags
CurrentContext FlagInfo
Timeout FlagInfo
+ CacheDir FlagInfo
}
// AuthOverrideFlags holds the flag names to be used for binding command line flags for AuthInfo objects
@@ -146,10 +150,12 @@ const (
FlagUsername = "username"
FlagPassword = "password"
FlagTimeout = "request-timeout"
+ FlagCacheDir = "cachedir"
)
// RecommendedConfigOverrideFlags is a convenience method to return recommended flag names prefixed with a string of your choosing
func RecommendedConfigOverrideFlags(prefix string) ConfigOverrideFlags {
+ defaultCacheDir := filepath.Join(homedir.HomeDir(), ".kube", "http-cache")
return ConfigOverrideFlags{
AuthOverrideFlags: RecommendedAuthOverrideFlags(prefix),
ClusterOverrideFlags: RecommendedClusterOverrideFlags(prefix),
@@ -157,6 +163,7 @@ func RecommendedConfigOverrideFlags(prefix string) ConfigOverrideFlags {
CurrentContext: FlagInfo{prefix + FlagContext, "", "", "The name of the kubeconfig context to use"},
Timeout: FlagInfo{prefix + FlagTimeout, "", "0", "The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests."},
+ CacheDir: FlagInfo{prefix + FlagCacheDir, "", defaultCacheDir, "Path to http-cache directory"},
}
}
@@ -198,6 +205,7 @@ func BindOverrideFlags(overrides *ConfigOverrides, flags *pflag.FlagSet, flagNam
BindContextFlags(&overrides.Context, flags, flagNames.ContextOverrideFlags)
flagNames.CurrentContext.BindStringFlag(flags, &overrides.CurrentContext)
flagNames.Timeout.BindStringFlag(flags, &overrides.Timeout)
+ flagNames.CacheDir.BindStringFlag(flags, &overrides.CacheDir)
}
// BindAuthInfoFlags is a convenience method to bind the specified flags to their associated variables
diff --git a/transport/BUILD b/transport/BUILD
index 1a54f483..c17299d5 100644
--- a/transport/BUILD
+++ b/transport/BUILD
@@ -30,6 +30,9 @@ go_library(
tags = ["automanaged"],
deps = [
"//vendor/github.com/golang/glog:go_default_library",
+ "//vendor/github.com/gregjones/httpcache:go_default_library",
+ "//vendor/github.com/gregjones/httpcache/diskcache:go_default_library",
+ "//vendor/github.com/peterbourgon/diskv:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/net:go_default_library",
],
)
diff --git a/transport/config.go b/transport/config.go
index 820594ba..e34d6e8c 100644
--- a/transport/config.go
+++ b/transport/config.go
@@ -34,6 +34,10 @@ type Config struct {
// Bearer token for authentication
BearerToken string
+ // CacheDir is the directory where we'll store HTTP cached responses.
+ // If set to empty string, no caching mechanism will be used.
+ CacheDir string
+
// Impersonate is the config that this Config will impersonate using
Impersonate ImpersonationConfig
diff --git a/transport/round_trippers.go b/transport/round_trippers.go
index c728b187..2394c42c 100644
--- a/transport/round_trippers.go
+++ b/transport/round_trippers.go
@@ -23,6 +23,9 @@ import (
"time"
"github.com/golang/glog"
+ "github.com/gregjones/httpcache"
+ "github.com/gregjones/httpcache/diskcache"
+ "github.com/peterbourgon/diskv"
utilnet "k8s.io/apimachinery/pkg/util/net"
)
@@ -56,6 +59,9 @@ func HTTPWrappersForConfig(config *Config, rt http.RoundTripper) (http.RoundTrip
len(config.Impersonate.Extra) > 0 {
rt = NewImpersonatingRoundTripper(config.Impersonate, rt)
}
+ if len(config.CacheDir) > 0 {
+ rt = NewCacheRoundTripper(config.CacheDir, rt)
+ }
return rt, nil
}
@@ -87,6 +93,17 @@ type authProxyRoundTripper struct {
rt http.RoundTripper
}
+// NewCacheRoundTripper creates a roundtripper that reads the ETag on
+// response headers and send the If-None-Match header on subsequent
+// corresponding requests.
+func NewCacheRoundTripper(cacheDir string, rt http.RoundTripper) http.RoundTripper {
+ d := diskv.New(diskv.Options{BasePath: cacheDir})
+ t := httpcache.NewTransport(diskcache.NewWithDiskv(d))
+ t.Transport = rt
+
+ return t
+}
+
// NewAuthProxyRoundTripper provides a roundtripper which will add auth proxy fields to requests for
// authentication terminating proxy cases
// assuming you pull the user from the context:
diff --git a/transport/round_trippers_test.go b/transport/round_trippers_test.go
index d5ffc6bd..c1e30c3f 100644
--- a/transport/round_trippers_test.go
+++ b/transport/round_trippers_test.go
@@ -17,7 +17,11 @@ limitations under the License.
package transport
import (
+ "bytes"
+ "io/ioutil"
"net/http"
+ "net/url"
+ "os"
"reflect"
"strings"
"testing"
@@ -216,3 +220,60 @@ func TestAuthProxyRoundTripper(t *testing.T) {
}
}
}
+
+func TestCacheRoundTripper(t *testing.T) {
+ rt := &testRoundTripper{}
+ cacheDir, err := ioutil.TempDir("", "cache-rt")
+ defer os.RemoveAll(cacheDir)
+ if err != nil {
+ t.Fatal(err)
+ }
+ cache := NewCacheRoundTripper(cacheDir, rt)
+
+ // First call, caches the response
+ req := &http.Request{
+ Method: http.MethodGet,
+ URL: &url.URL{Host: "localhost"},
+ }
+ rt.Response = &http.Response{
+ Header: http.Header{"ETag": []string{`"123456"`}},
+ Body: ioutil.NopCloser(bytes.NewReader([]byte("Content"))),
+ StatusCode: http.StatusOK,
+ }
+ resp, err := cache.RoundTrip(req)
+ if err != nil {
+ t.Fatal(err)
+ }
+ content, err := ioutil.ReadAll(resp.Body)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if string(content) != "Content" {
+ t.Errorf(`Expected Body to be "Content", got %q`, string(content))
+ }
+
+ // Second call, returns cached response
+ req = &http.Request{
+ Method: http.MethodGet,
+ URL: &url.URL{Host: "localhost"},
+ }
+ rt.Response = &http.Response{
+ StatusCode: http.StatusNotModified,
+ Body: ioutil.NopCloser(bytes.NewReader([]byte("Other Content"))),
+ }
+
+ resp, err = cache.RoundTrip(req)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ // Read body and make sure we have the initial content
+ content, err = ioutil.ReadAll(resp.Body)
+ resp.Body.Close()
+ if err != nil {
+ t.Fatal(err)
+ }
+ if string(content) != "Content" {
+ t.Errorf("Invalid content read from cache %q", string(content))
+ }
+}
diff --git a/vendor/github.com/coreos/go-oidc/http/http.go b/vendor/github.com/coreos/go-oidc/http/http.go
index c3f51215..48717833 100644
--- a/vendor/github.com/coreos/go-oidc/http/http.go
+++ b/vendor/github.com/coreos/go-oidc/http/http.go
@@ -91,7 +91,12 @@ func expires(date, expires string) (time.Duration, bool, error) {
return 0, false, nil
}
- te, err := time.Parse(time.RFC1123, expires)
+ var te time.Time
+ var err error
+ if expires == "0" {
+ return 0, false, nil
+ }
+ te, err = time.Parse(time.RFC1123, expires)
if err != nil {
return 0, false, err
}
diff --git a/vendor/github.com/google/btree/.travis.yml b/vendor/github.com/google/btree/.travis.yml
new file mode 100644
index 00000000..4f2ee4d9
--- /dev/null
+++ b/vendor/github.com/google/btree/.travis.yml
@@ -0,0 +1 @@
+language: go
diff --git a/vendor/github.com/google/btree/LICENSE b/vendor/github.com/google/btree/LICENSE
new file mode 100644
index 00000000..d6456956
--- /dev/null
+++ b/vendor/github.com/google/btree/LICENSE
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ 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.
diff --git a/vendor/github.com/google/btree/README.md b/vendor/github.com/google/btree/README.md
new file mode 100644
index 00000000..6062a4da
--- /dev/null
+++ b/vendor/github.com/google/btree/README.md
@@ -0,0 +1,12 @@
+# BTree implementation for Go
+
+
+
+This package provides an in-memory B-Tree implementation for Go, useful as
+an ordered, mutable data structure.
+
+The API is based off of the wonderful
+http://godoc.org/github.com/petar/GoLLRB/llrb, and is meant to allow btree to
+act as a drop-in replacement for gollrb trees.
+
+See http://godoc.org/github.com/google/btree for documentation.
diff --git a/vendor/github.com/google/btree/btree.go b/vendor/github.com/google/btree/btree.go
new file mode 100644
index 00000000..fc5aaaa1
--- /dev/null
+++ b/vendor/github.com/google/btree/btree.go
@@ -0,0 +1,649 @@
+// Copyright 2014 Google Inc.
+//
+// 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 btree implements in-memory B-Trees of arbitrary degree.
+//
+// btree implements an in-memory B-Tree for use as an ordered data structure.
+// It is not meant for persistent storage solutions.
+//
+// It has a flatter structure than an equivalent red-black or other binary tree,
+// which in some cases yields better memory usage and/or performance.
+// See some discussion on the matter here:
+// http://google-opensource.blogspot.com/2013/01/c-containers-that-save-memory-and-time.html
+// Note, though, that this project is in no way related to the C++ B-Tree
+// implmentation written about there.
+//
+// Within this tree, each node contains a slice of items and a (possibly nil)
+// slice of children. For basic numeric values or raw structs, this can cause
+// efficiency differences when compared to equivalent C++ template code that
+// stores values in arrays within the node:
+// * Due to the overhead of storing values as interfaces (each
+// value needs to be stored as the value itself, then 2 words for the
+// interface pointing to that value and its type), resulting in higher
+// memory use.
+// * Since interfaces can point to values anywhere in memory, values are
+// most likely not stored in contiguous blocks, resulting in a higher
+// number of cache misses.
+// These issues don't tend to matter, though, when working with strings or other
+// heap-allocated structures, since C++-equivalent structures also must store
+// pointers and also distribute their values across the heap.
+//
+// This implementation is designed to be a drop-in replacement to gollrb.LLRB
+// trees, (http://github.com/petar/gollrb), an excellent and probably the most
+// widely used ordered tree implementation in the Go ecosystem currently.
+// Its functions, therefore, exactly mirror those of
+// llrb.LLRB where possible. Unlike gollrb, though, we currently don't
+// support storing multiple equivalent values or backwards iteration.
+package btree
+
+import (
+ "fmt"
+ "io"
+ "sort"
+ "strings"
+)
+
+// Item represents a single object in the tree.
+type Item interface {
+ // Less tests whether the current item is less than the given argument.
+ //
+ // This must provide a strict weak ordering.
+ // If !a.Less(b) && !b.Less(a), we treat this to mean a == b (i.e. we can only
+ // hold one of either a or b in the tree).
+ Less(than Item) bool
+}
+
+const (
+ DefaultFreeListSize = 32
+)
+
+// FreeList represents a free list of btree nodes. By default each
+// BTree has its own FreeList, but multiple BTrees can share the same
+// FreeList.
+// Two Btrees using the same freelist are not safe for concurrent write access.
+type FreeList struct {
+ freelist []*node
+}
+
+// NewFreeList creates a new free list.
+// size is the maximum size of the returned free list.
+func NewFreeList(size int) *FreeList {
+ return &FreeList{freelist: make([]*node, 0, size)}
+}
+
+func (f *FreeList) newNode() (n *node) {
+ index := len(f.freelist) - 1
+ if index < 0 {
+ return new(node)
+ }
+ f.freelist, n = f.freelist[:index], f.freelist[index]
+ return
+}
+
+func (f *FreeList) freeNode(n *node) {
+ if len(f.freelist) < cap(f.freelist) {
+ f.freelist = append(f.freelist, n)
+ }
+}
+
+// ItemIterator allows callers of Ascend* to iterate in-order over portions of
+// the tree. When this function returns false, iteration will stop and the
+// associated Ascend* function will immediately return.
+type ItemIterator func(i Item) bool
+
+// New creates a new B-Tree with the given degree.
+//
+// New(2), for example, will create a 2-3-4 tree (each node contains 1-3 items
+// and 2-4 children).
+func New(degree int) *BTree {
+ return NewWithFreeList(degree, NewFreeList(DefaultFreeListSize))
+}
+
+// NewWithFreeList creates a new B-Tree that uses the given node free list.
+func NewWithFreeList(degree int, f *FreeList) *BTree {
+ if degree <= 1 {
+ panic("bad degree")
+ }
+ return &BTree{
+ degree: degree,
+ freelist: f,
+ }
+}
+
+// items stores items in a node.
+type items []Item
+
+// insertAt inserts a value into the given index, pushing all subsequent values
+// forward.
+func (s *items) insertAt(index int, item Item) {
+ *s = append(*s, nil)
+ if index < len(*s) {
+ copy((*s)[index+1:], (*s)[index:])
+ }
+ (*s)[index] = item
+}
+
+// removeAt removes a value at a given index, pulling all subsequent values
+// back.
+func (s *items) removeAt(index int) Item {
+ item := (*s)[index]
+ (*s)[index] = nil
+ copy((*s)[index:], (*s)[index+1:])
+ *s = (*s)[:len(*s)-1]
+ return item
+}
+
+// pop removes and returns the last element in the list.
+func (s *items) pop() (out Item) {
+ index := len(*s) - 1
+ out = (*s)[index]
+ (*s)[index] = nil
+ *s = (*s)[:index]
+ return
+}
+
+// find returns the index where the given item should be inserted into this
+// list. 'found' is true if the item already exists in the list at the given
+// index.
+func (s items) find(item Item) (index int, found bool) {
+ i := sort.Search(len(s), func(i int) bool {
+ return item.Less(s[i])
+ })
+ if i > 0 && !s[i-1].Less(item) {
+ return i - 1, true
+ }
+ return i, false
+}
+
+// children stores child nodes in a node.
+type children []*node
+
+// insertAt inserts a value into the given index, pushing all subsequent values
+// forward.
+func (s *children) insertAt(index int, n *node) {
+ *s = append(*s, nil)
+ if index < len(*s) {
+ copy((*s)[index+1:], (*s)[index:])
+ }
+ (*s)[index] = n
+}
+
+// removeAt removes a value at a given index, pulling all subsequent values
+// back.
+func (s *children) removeAt(index int) *node {
+ n := (*s)[index]
+ (*s)[index] = nil
+ copy((*s)[index:], (*s)[index+1:])
+ *s = (*s)[:len(*s)-1]
+ return n
+}
+
+// pop removes and returns the last element in the list.
+func (s *children) pop() (out *node) {
+ index := len(*s) - 1
+ out = (*s)[index]
+ (*s)[index] = nil
+ *s = (*s)[:index]
+ return
+}
+
+// node is an internal node in a tree.
+//
+// It must at all times maintain the invariant that either
+// * len(children) == 0, len(items) unconstrained
+// * len(children) == len(items) + 1
+type node struct {
+ items items
+ children children
+ t *BTree
+}
+
+// split splits the given node at the given index. The current node shrinks,
+// and this function returns the item that existed at that index and a new node
+// containing all items/children after it.
+func (n *node) split(i int) (Item, *node) {
+ item := n.items[i]
+ next := n.t.newNode()
+ next.items = append(next.items, n.items[i+1:]...)
+ n.items = n.items[:i]
+ if len(n.children) > 0 {
+ next.children = append(next.children, n.children[i+1:]...)
+ n.children = n.children[:i+1]
+ }
+ return item, next
+}
+
+// maybeSplitChild checks if a child should be split, and if so splits it.
+// Returns whether or not a split occurred.
+func (n *node) maybeSplitChild(i, maxItems int) bool {
+ if len(n.children[i].items) < maxItems {
+ return false
+ }
+ first := n.children[i]
+ item, second := first.split(maxItems / 2)
+ n.items.insertAt(i, item)
+ n.children.insertAt(i+1, second)
+ return true
+}
+
+// insert inserts an item into the subtree rooted at this node, making sure
+// no nodes in the subtree exceed maxItems items. Should an equivalent item be
+// be found/replaced by insert, it will be returned.
+func (n *node) insert(item Item, maxItems int) Item {
+ i, found := n.items.find(item)
+ if found {
+ out := n.items[i]
+ n.items[i] = item
+ return out
+ }
+ if len(n.children) == 0 {
+ n.items.insertAt(i, item)
+ return nil
+ }
+ if n.maybeSplitChild(i, maxItems) {
+ inTree := n.items[i]
+ switch {
+ case item.Less(inTree):
+ // no change, we want first split node
+ case inTree.Less(item):
+ i++ // we want second split node
+ default:
+ out := n.items[i]
+ n.items[i] = item
+ return out
+ }
+ }
+ return n.children[i].insert(item, maxItems)
+}
+
+// get finds the given key in the subtree and returns it.
+func (n *node) get(key Item) Item {
+ i, found := n.items.find(key)
+ if found {
+ return n.items[i]
+ } else if len(n.children) > 0 {
+ return n.children[i].get(key)
+ }
+ return nil
+}
+
+// min returns the first item in the subtree.
+func min(n *node) Item {
+ if n == nil {
+ return nil
+ }
+ for len(n.children) > 0 {
+ n = n.children[0]
+ }
+ if len(n.items) == 0 {
+ return nil
+ }
+ return n.items[0]
+}
+
+// max returns the last item in the subtree.
+func max(n *node) Item {
+ if n == nil {
+ return nil
+ }
+ for len(n.children) > 0 {
+ n = n.children[len(n.children)-1]
+ }
+ if len(n.items) == 0 {
+ return nil
+ }
+ return n.items[len(n.items)-1]
+}
+
+// toRemove details what item to remove in a node.remove call.
+type toRemove int
+
+const (
+ removeItem toRemove = iota // removes the given item
+ removeMin // removes smallest item in the subtree
+ removeMax // removes largest item in the subtree
+)
+
+// remove removes an item from the subtree rooted at this node.
+func (n *node) remove(item Item, minItems int, typ toRemove) Item {
+ var i int
+ var found bool
+ switch typ {
+ case removeMax:
+ if len(n.children) == 0 {
+ return n.items.pop()
+ }
+ i = len(n.items)
+ case removeMin:
+ if len(n.children) == 0 {
+ return n.items.removeAt(0)
+ }
+ i = 0
+ case removeItem:
+ i, found = n.items.find(item)
+ if len(n.children) == 0 {
+ if found {
+ return n.items.removeAt(i)
+ }
+ return nil
+ }
+ default:
+ panic("invalid type")
+ }
+ // If we get to here, we have children.
+ child := n.children[i]
+ if len(child.items) <= minItems {
+ return n.growChildAndRemove(i, item, minItems, typ)
+ }
+ // Either we had enough items to begin with, or we've done some
+ // merging/stealing, because we've got enough now and we're ready to return
+ // stuff.
+ if found {
+ // The item exists at index 'i', and the child we've selected can give us a
+ // predecessor, since if we've gotten here it's got > minItems items in it.
+ out := n.items[i]
+ // We use our special-case 'remove' call with typ=maxItem to pull the
+ // predecessor of item i (the rightmost leaf of our immediate left child)
+ // and set it into where we pulled the item from.
+ n.items[i] = child.remove(nil, minItems, removeMax)
+ return out
+ }
+ // Final recursive call. Once we're here, we know that the item isn't in this
+ // node and that the child is big enough to remove from.
+ return child.remove(item, minItems, typ)
+}
+
+// growChildAndRemove grows child 'i' to make sure it's possible to remove an
+// item from it while keeping it at minItems, then calls remove to actually
+// remove it.
+//
+// Most documentation says we have to do two sets of special casing:
+// 1) item is in this node
+// 2) item is in child
+// In both cases, we need to handle the two subcases:
+// A) node has enough values that it can spare one
+// B) node doesn't have enough values
+// For the latter, we have to check:
+// a) left sibling has node to spare
+// b) right sibling has node to spare
+// c) we must merge
+// To simplify our code here, we handle cases #1 and #2 the same:
+// If a node doesn't have enough items, we make sure it does (using a,b,c).
+// We then simply redo our remove call, and the second time (regardless of
+// whether we're in case 1 or 2), we'll have enough items and can guarantee
+// that we hit case A.
+func (n *node) growChildAndRemove(i int, item Item, minItems int, typ toRemove) Item {
+ child := n.children[i]
+ if i > 0 && len(n.children[i-1].items) > minItems {
+ // Steal from left child
+ stealFrom := n.children[i-1]
+ stolenItem := stealFrom.items.pop()
+ child.items.insertAt(0, n.items[i-1])
+ n.items[i-1] = stolenItem
+ if len(stealFrom.children) > 0 {
+ child.children.insertAt(0, stealFrom.children.pop())
+ }
+ } else if i < len(n.items) && len(n.children[i+1].items) > minItems {
+ // steal from right child
+ stealFrom := n.children[i+1]
+ stolenItem := stealFrom.items.removeAt(0)
+ child.items = append(child.items, n.items[i])
+ n.items[i] = stolenItem
+ if len(stealFrom.children) > 0 {
+ child.children = append(child.children, stealFrom.children.removeAt(0))
+ }
+ } else {
+ if i >= len(n.items) {
+ i--
+ child = n.children[i]
+ }
+ // merge with right child
+ mergeItem := n.items.removeAt(i)
+ mergeChild := n.children.removeAt(i + 1)
+ child.items = append(child.items, mergeItem)
+ child.items = append(child.items, mergeChild.items...)
+ child.children = append(child.children, mergeChild.children...)
+ n.t.freeNode(mergeChild)
+ }
+ return n.remove(item, minItems, typ)
+}
+
+// iterate provides a simple method for iterating over elements in the tree.
+// It could probably use some work to be extra-efficient (it calls from() a
+// little more than it should), but it works pretty well for now.
+//
+// It requires that 'from' and 'to' both return true for values we should hit
+// with the iterator. It should also be the case that 'from' returns true for
+// values less than or equal to values 'to' returns true for, and 'to'
+// returns true for values greater than or equal to those that 'from'
+// does.
+func (n *node) iterate(from, to func(Item) bool, iter ItemIterator) bool {
+ for i, item := range n.items {
+ if !from(item) {
+ continue
+ }
+ if len(n.children) > 0 && !n.children[i].iterate(from, to, iter) {
+ return false
+ }
+ if !to(item) {
+ return false
+ }
+ if !iter(item) {
+ return false
+ }
+ }
+ if len(n.children) > 0 {
+ return n.children[len(n.children)-1].iterate(from, to, iter)
+ }
+ return true
+}
+
+// Used for testing/debugging purposes.
+func (n *node) print(w io.Writer, level int) {
+ fmt.Fprintf(w, "%sNODE:%v\n", strings.Repeat(" ", level), n.items)
+ for _, c := range n.children {
+ c.print(w, level+1)
+ }
+}
+
+// BTree is an implementation of a B-Tree.
+//
+// BTree stores Item instances in an ordered structure, allowing easy insertion,
+// removal, and iteration.
+//
+// Write operations are not safe for concurrent mutation by multiple
+// goroutines, but Read operations are.
+type BTree struct {
+ degree int
+ length int
+ root *node
+ freelist *FreeList
+}
+
+// maxItems returns the max number of items to allow per node.
+func (t *BTree) maxItems() int {
+ return t.degree*2 - 1
+}
+
+// minItems returns the min number of items to allow per node (ignored for the
+// root node).
+func (t *BTree) minItems() int {
+ return t.degree - 1
+}
+
+func (t *BTree) newNode() (n *node) {
+ n = t.freelist.newNode()
+ n.t = t
+ return
+}
+
+func (t *BTree) freeNode(n *node) {
+ for i := range n.items {
+ n.items[i] = nil // clear to allow GC
+ }
+ n.items = n.items[:0]
+ for i := range n.children {
+ n.children[i] = nil // clear to allow GC
+ }
+ n.children = n.children[:0]
+ n.t = nil // clear to allow GC
+ t.freelist.freeNode(n)
+}
+
+// ReplaceOrInsert adds the given item to the tree. If an item in the tree
+// already equals the given one, it is removed from the tree and returned.
+// Otherwise, nil is returned.
+//
+// nil cannot be added to the tree (will panic).
+func (t *BTree) ReplaceOrInsert(item Item) Item {
+ if item == nil {
+ panic("nil item being added to BTree")
+ }
+ if t.root == nil {
+ t.root = t.newNode()
+ t.root.items = append(t.root.items, item)
+ t.length++
+ return nil
+ } else if len(t.root.items) >= t.maxItems() {
+ item2, second := t.root.split(t.maxItems() / 2)
+ oldroot := t.root
+ t.root = t.newNode()
+ t.root.items = append(t.root.items, item2)
+ t.root.children = append(t.root.children, oldroot, second)
+ }
+ out := t.root.insert(item, t.maxItems())
+ if out == nil {
+ t.length++
+ }
+ return out
+}
+
+// Delete removes an item equal to the passed in item from the tree, returning
+// it. If no such item exists, returns nil.
+func (t *BTree) Delete(item Item) Item {
+ return t.deleteItem(item, removeItem)
+}
+
+// DeleteMin removes the smallest item in the tree and returns it.
+// If no such item exists, returns nil.
+func (t *BTree) DeleteMin() Item {
+ return t.deleteItem(nil, removeMin)
+}
+
+// DeleteMax removes the largest item in the tree and returns it.
+// If no such item exists, returns nil.
+func (t *BTree) DeleteMax() Item {
+ return t.deleteItem(nil, removeMax)
+}
+
+func (t *BTree) deleteItem(item Item, typ toRemove) Item {
+ if t.root == nil || len(t.root.items) == 0 {
+ return nil
+ }
+ out := t.root.remove(item, t.minItems(), typ)
+ if len(t.root.items) == 0 && len(t.root.children) > 0 {
+ oldroot := t.root
+ t.root = t.root.children[0]
+ t.freeNode(oldroot)
+ }
+ if out != nil {
+ t.length--
+ }
+ return out
+}
+
+// AscendRange calls the iterator for every value in the tree within the range
+// [greaterOrEqual, lessThan), until iterator returns false.
+func (t *BTree) AscendRange(greaterOrEqual, lessThan Item, iterator ItemIterator) {
+ if t.root == nil {
+ return
+ }
+ t.root.iterate(
+ func(a Item) bool { return !a.Less(greaterOrEqual) },
+ func(a Item) bool { return a.Less(lessThan) },
+ iterator)
+}
+
+// AscendLessThan calls the iterator for every value in the tree within the range
+// [first, pivot), until iterator returns false.
+func (t *BTree) AscendLessThan(pivot Item, iterator ItemIterator) {
+ if t.root == nil {
+ return
+ }
+ t.root.iterate(
+ func(a Item) bool { return true },
+ func(a Item) bool { return a.Less(pivot) },
+ iterator)
+}
+
+// AscendGreaterOrEqual calls the iterator for every value in the tree within
+// the range [pivot, last], until iterator returns false.
+func (t *BTree) AscendGreaterOrEqual(pivot Item, iterator ItemIterator) {
+ if t.root == nil {
+ return
+ }
+ t.root.iterate(
+ func(a Item) bool { return !a.Less(pivot) },
+ func(a Item) bool { return true },
+ iterator)
+}
+
+// Ascend calls the iterator for every value in the tree within the range
+// [first, last], until iterator returns false.
+func (t *BTree) Ascend(iterator ItemIterator) {
+ if t.root == nil {
+ return
+ }
+ t.root.iterate(
+ func(a Item) bool { return true },
+ func(a Item) bool { return true },
+ iterator)
+}
+
+// Get looks for the key item in the tree, returning it. It returns nil if
+// unable to find that item.
+func (t *BTree) Get(key Item) Item {
+ if t.root == nil {
+ return nil
+ }
+ return t.root.get(key)
+}
+
+// Min returns the smallest item in the tree, or nil if the tree is empty.
+func (t *BTree) Min() Item {
+ return min(t.root)
+}
+
+// Max returns the largest item in the tree, or nil if the tree is empty.
+func (t *BTree) Max() Item {
+ return max(t.root)
+}
+
+// Has returns true if the given key is in the tree.
+func (t *BTree) Has(key Item) bool {
+ return t.Get(key) != nil
+}
+
+// Len returns the number of items currently in the tree.
+func (t *BTree) Len() int {
+ return t.length
+}
+
+// Int implements the Item interface for integers.
+type Int int
+
+// Less returns true if int(a) < int(b).
+func (a Int) Less(b Item) bool {
+ return a < b.(Int)
+}
diff --git a/vendor/github.com/google/btree/btree_mem.go b/vendor/github.com/google/btree/btree_mem.go
new file mode 100644
index 00000000..cb95b7fa
--- /dev/null
+++ b/vendor/github.com/google/btree/btree_mem.go
@@ -0,0 +1,76 @@
+// Copyright 2014 Google Inc.
+//
+// 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.
+
+// +build ignore
+
+// This binary compares memory usage between btree and gollrb.
+package main
+
+import (
+ "flag"
+ "fmt"
+ "math/rand"
+ "runtime"
+ "time"
+
+ "github.com/google/btree"
+ "github.com/petar/GoLLRB/llrb"
+)
+
+var (
+ size = flag.Int("size", 1000000, "size of the tree to build")
+ degree = flag.Int("degree", 8, "degree of btree")
+ gollrb = flag.Bool("llrb", false, "use llrb instead of btree")
+)
+
+func main() {
+ flag.Parse()
+ vals := rand.Perm(*size)
+ var t, v interface{}
+ v = vals
+ var stats runtime.MemStats
+ for i := 0; i < 10; i++ {
+ runtime.GC()
+ }
+ fmt.Println("-------- BEFORE ----------")
+ runtime.ReadMemStats(&stats)
+ fmt.Printf("%+v\n", stats)
+ start := time.Now()
+ if *gollrb {
+ tr := llrb.New()
+ for _, v := range vals {
+ tr.ReplaceOrInsert(llrb.Int(v))
+ }
+ t = tr // keep it around
+ } else {
+ tr := btree.New(*degree)
+ for _, v := range vals {
+ tr.ReplaceOrInsert(btree.Int(v))
+ }
+ t = tr // keep it around
+ }
+ fmt.Printf("%v inserts in %v\n", *size, time.Since(start))
+ fmt.Println("-------- AFTER ----------")
+ runtime.ReadMemStats(&stats)
+ fmt.Printf("%+v\n", stats)
+ for i := 0; i < 10; i++ {
+ runtime.GC()
+ }
+ fmt.Println("-------- AFTER GC ----------")
+ runtime.ReadMemStats(&stats)
+ fmt.Printf("%+v\n", stats)
+ if t == v {
+ fmt.Println("to make sure vals and tree aren't GC'd")
+ }
+}
diff --git a/vendor/github.com/googleapis/gnostic/OpenAPIv2/OpenAPIv2.go b/vendor/github.com/googleapis/gnostic/OpenAPIv2/OpenAPIv2.go
index dc431e1e..0e32451a 100644
--- a/vendor/github.com/googleapis/gnostic/OpenAPIv2/OpenAPIv2.go
+++ b/vendor/github.com/googleapis/gnostic/OpenAPIv2/OpenAPIv2.go
@@ -20,13 +20,16 @@ import (
"fmt"
"github.com/googleapis/gnostic/compiler"
"gopkg.in/yaml.v2"
+ "regexp"
"strings"
)
+// Version returns the package name (and OpenAPI version).
func Version() string {
return "openapi_v2"
}
+// NewAdditionalPropertiesItem creates an object of type AdditionalPropertiesItem if possible, returning an error if not.
func NewAdditionalPropertiesItem(in interface{}, context *compiler.Context) (*AdditionalPropertiesItem, error) {
errors := make([]error, 0)
x := &AdditionalPropertiesItem{}
@@ -36,12 +39,12 @@ func NewAdditionalPropertiesItem(in interface{}, context *compiler.Context) (*Ad
m, ok := compiler.UnpackMap(in)
if ok {
// errors might be ok here, they mean we just don't have the right subtype
- t, matching_error := NewSchema(m, compiler.NewContext("schema", context))
- if matching_error == nil {
+ t, matchingError := NewSchema(m, compiler.NewContext("schema", context))
+ if matchingError == nil {
x.Oneof = &AdditionalPropertiesItem_Schema{Schema: t}
matched = true
} else {
- errors = append(errors, matching_error)
+ errors = append(errors, matchingError)
}
}
}
@@ -57,6 +60,7 @@ func NewAdditionalPropertiesItem(in interface{}, context *compiler.Context) (*Ad
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewAny creates an object of type Any if possible, returning an error if not.
func NewAny(in interface{}, context *compiler.Context) (*Any, error) {
errors := make([]error, 0)
x := &Any{}
@@ -65,6 +69,7 @@ func NewAny(in interface{}, context *compiler.Context) (*Any, error) {
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewApiKeySecurity creates an object of type ApiKeySecurity if possible, returning an error if not.
func NewApiKeySecurity(in interface{}, context *compiler.Context) (*ApiKeySecurity, error) {
errors := make([]error, 0)
x := &ApiKeySecurity{}
@@ -80,7 +85,7 @@ func NewApiKeySecurity(in interface{}, context *compiler.Context) (*ApiKeySecuri
errors = append(errors, compiler.NewError(context, message))
}
allowedKeys := []string{"description", "in", "name", "type"}
- allowedPatterns := []string{"^x-"}
+ allowedPatterns := []*regexp.Regexp{pattern0}
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
@@ -138,10 +143,10 @@ func NewApiKeySecurity(in interface{}, context *compiler.Context) (*ApiKeySecuri
// MAP: Any ^x-
x.VendorExtension = make([]*NamedAny, 0)
for _, item := range m {
- k, ok := item.Key.(string)
+ k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
- if compiler.PatternMatches("^x-", k) {
+ if strings.HasPrefix(k, "x-") {
pair := &NamedAny{}
pair.Name = k
result := &Any{}
@@ -169,6 +174,7 @@ func NewApiKeySecurity(in interface{}, context *compiler.Context) (*ApiKeySecuri
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewBasicAuthenticationSecurity creates an object of type BasicAuthenticationSecurity if possible, returning an error if not.
func NewBasicAuthenticationSecurity(in interface{}, context *compiler.Context) (*BasicAuthenticationSecurity, error) {
errors := make([]error, 0)
x := &BasicAuthenticationSecurity{}
@@ -184,7 +190,7 @@ func NewBasicAuthenticationSecurity(in interface{}, context *compiler.Context) (
errors = append(errors, compiler.NewError(context, message))
}
allowedKeys := []string{"description", "type"}
- allowedPatterns := []string{"^x-"}
+ allowedPatterns := []*regexp.Regexp{pattern0}
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
@@ -218,10 +224,10 @@ func NewBasicAuthenticationSecurity(in interface{}, context *compiler.Context) (
// MAP: Any ^x-
x.VendorExtension = make([]*NamedAny, 0)
for _, item := range m {
- k, ok := item.Key.(string)
+ k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
- if compiler.PatternMatches("^x-", k) {
+ if strings.HasPrefix(k, "x-") {
pair := &NamedAny{}
pair.Name = k
result := &Any{}
@@ -249,6 +255,7 @@ func NewBasicAuthenticationSecurity(in interface{}, context *compiler.Context) (
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewBodyParameter creates an object of type BodyParameter if possible, returning an error if not.
func NewBodyParameter(in interface{}, context *compiler.Context) (*BodyParameter, error) {
errors := make([]error, 0)
x := &BodyParameter{}
@@ -264,7 +271,7 @@ func NewBodyParameter(in interface{}, context *compiler.Context) (*BodyParameter
errors = append(errors, compiler.NewError(context, message))
}
allowedKeys := []string{"description", "in", "name", "required", "schema"}
- allowedPatterns := []string{"^x-"}
+ allowedPatterns := []*regexp.Regexp{pattern0}
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
@@ -325,10 +332,10 @@ func NewBodyParameter(in interface{}, context *compiler.Context) (*BodyParameter
// MAP: Any ^x-
x.VendorExtension = make([]*NamedAny, 0)
for _, item := range m {
- k, ok := item.Key.(string)
+ k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
- if compiler.PatternMatches("^x-", k) {
+ if strings.HasPrefix(k, "x-") {
pair := &NamedAny{}
pair.Name = k
result := &Any{}
@@ -356,6 +363,7 @@ func NewBodyParameter(in interface{}, context *compiler.Context) (*BodyParameter
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewContact creates an object of type Contact if possible, returning an error if not.
func NewContact(in interface{}, context *compiler.Context) (*Contact, error) {
errors := make([]error, 0)
x := &Contact{}
@@ -365,7 +373,7 @@ func NewContact(in interface{}, context *compiler.Context) (*Contact, error) {
errors = append(errors, compiler.NewError(context, message))
} else {
allowedKeys := []string{"email", "name", "url"}
- allowedPatterns := []string{"^x-"}
+ allowedPatterns := []*regexp.Regexp{pattern0}
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
@@ -402,10 +410,10 @@ func NewContact(in interface{}, context *compiler.Context) (*Contact, error) {
// MAP: Any ^x-
x.VendorExtension = make([]*NamedAny, 0)
for _, item := range m {
- k, ok := item.Key.(string)
+ k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
- if compiler.PatternMatches("^x-", k) {
+ if strings.HasPrefix(k, "x-") {
pair := &NamedAny{}
pair.Name = k
result := &Any{}
@@ -433,6 +441,7 @@ func NewContact(in interface{}, context *compiler.Context) (*Contact, error) {
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewDefault creates an object of type Default if possible, returning an error if not.
func NewDefault(in interface{}, context *compiler.Context) (*Default, error) {
errors := make([]error, 0)
x := &Default{}
@@ -445,7 +454,7 @@ func NewDefault(in interface{}, context *compiler.Context) (*Default, error) {
// MAP: Any
x.AdditionalProperties = make([]*NamedAny, 0)
for _, item := range m {
- k, ok := item.Key.(string)
+ k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
pair := &NamedAny{}
@@ -474,6 +483,7 @@ func NewDefault(in interface{}, context *compiler.Context) (*Default, error) {
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewDefinitions creates an object of type Definitions if possible, returning an error if not.
func NewDefinitions(in interface{}, context *compiler.Context) (*Definitions, error) {
errors := make([]error, 0)
x := &Definitions{}
@@ -486,7 +496,7 @@ func NewDefinitions(in interface{}, context *compiler.Context) (*Definitions, er
// MAP: Schema
x.AdditionalProperties = make([]*NamedSchema, 0)
for _, item := range m {
- k, ok := item.Key.(string)
+ k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
pair := &NamedSchema{}
@@ -503,6 +513,7 @@ func NewDefinitions(in interface{}, context *compiler.Context) (*Definitions, er
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewDocument creates an object of type Document if possible, returning an error if not.
func NewDocument(in interface{}, context *compiler.Context) (*Document, error) {
errors := make([]error, 0)
x := &Document{}
@@ -518,7 +529,7 @@ func NewDocument(in interface{}, context *compiler.Context) (*Document, error) {
errors = append(errors, compiler.NewError(context, message))
}
allowedKeys := []string{"basePath", "consumes", "definitions", "externalDocs", "host", "info", "parameters", "paths", "produces", "responses", "schemes", "security", "securityDefinitions", "swagger", "tags"}
- allowedPatterns := []string{"^x-"}
+ allowedPatterns := []*regexp.Regexp{pattern0}
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
@@ -695,10 +706,10 @@ func NewDocument(in interface{}, context *compiler.Context) (*Document, error) {
// MAP: Any ^x-
x.VendorExtension = make([]*NamedAny, 0)
for _, item := range m {
- k, ok := item.Key.(string)
+ k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
- if compiler.PatternMatches("^x-", k) {
+ if strings.HasPrefix(k, "x-") {
pair := &NamedAny{}
pair.Name = k
result := &Any{}
@@ -726,6 +737,7 @@ func NewDocument(in interface{}, context *compiler.Context) (*Document, error) {
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewExamples creates an object of type Examples if possible, returning an error if not.
func NewExamples(in interface{}, context *compiler.Context) (*Examples, error) {
errors := make([]error, 0)
x := &Examples{}
@@ -738,7 +750,7 @@ func NewExamples(in interface{}, context *compiler.Context) (*Examples, error) {
// MAP: Any
x.AdditionalProperties = make([]*NamedAny, 0)
for _, item := range m {
- k, ok := item.Key.(string)
+ k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
pair := &NamedAny{}
@@ -767,6 +779,7 @@ func NewExamples(in interface{}, context *compiler.Context) (*Examples, error) {
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewExternalDocs creates an object of type ExternalDocs if possible, returning an error if not.
func NewExternalDocs(in interface{}, context *compiler.Context) (*ExternalDocs, error) {
errors := make([]error, 0)
x := &ExternalDocs{}
@@ -782,7 +795,7 @@ func NewExternalDocs(in interface{}, context *compiler.Context) (*ExternalDocs,
errors = append(errors, compiler.NewError(context, message))
}
allowedKeys := []string{"description", "url"}
- allowedPatterns := []string{"^x-"}
+ allowedPatterns := []*regexp.Regexp{pattern0}
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
@@ -810,10 +823,10 @@ func NewExternalDocs(in interface{}, context *compiler.Context) (*ExternalDocs,
// MAP: Any ^x-
x.VendorExtension = make([]*NamedAny, 0)
for _, item := range m {
- k, ok := item.Key.(string)
+ k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
- if compiler.PatternMatches("^x-", k) {
+ if strings.HasPrefix(k, "x-") {
pair := &NamedAny{}
pair.Name = k
result := &Any{}
@@ -841,6 +854,7 @@ func NewExternalDocs(in interface{}, context *compiler.Context) (*ExternalDocs,
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewFileSchema creates an object of type FileSchema if possible, returning an error if not.
func NewFileSchema(in interface{}, context *compiler.Context) (*FileSchema, error) {
errors := make([]error, 0)
x := &FileSchema{}
@@ -856,7 +870,7 @@ func NewFileSchema(in interface{}, context *compiler.Context) (*FileSchema, erro
errors = append(errors, compiler.NewError(context, message))
}
allowedKeys := []string{"default", "description", "example", "externalDocs", "format", "readOnly", "required", "title", "type"}
- allowedPatterns := []string{"^x-"}
+ allowedPatterns := []*regexp.Regexp{pattern0}
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
@@ -955,10 +969,10 @@ func NewFileSchema(in interface{}, context *compiler.Context) (*FileSchema, erro
// MAP: Any ^x-
x.VendorExtension = make([]*NamedAny, 0)
for _, item := range m {
- k, ok := item.Key.(string)
+ k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
- if compiler.PatternMatches("^x-", k) {
+ if strings.HasPrefix(k, "x-") {
pair := &NamedAny{}
pair.Name = k
result := &Any{}
@@ -986,6 +1000,7 @@ func NewFileSchema(in interface{}, context *compiler.Context) (*FileSchema, erro
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewFormDataParameterSubSchema creates an object of type FormDataParameterSubSchema if possible, returning an error if not.
func NewFormDataParameterSubSchema(in interface{}, context *compiler.Context) (*FormDataParameterSubSchema, error) {
errors := make([]error, 0)
x := &FormDataParameterSubSchema{}
@@ -995,7 +1010,7 @@ func NewFormDataParameterSubSchema(in interface{}, context *compiler.Context) (*
errors = append(errors, compiler.NewError(context, message))
} else {
allowedKeys := []string{"allowEmptyValue", "collectionFormat", "default", "description", "enum", "exclusiveMaximum", "exclusiveMinimum", "format", "in", "items", "maxItems", "maxLength", "maximum", "minItems", "minLength", "minimum", "multipleOf", "name", "pattern", "required", "type", "uniqueItems"}
- allowedPatterns := []string{"^x-"}
+ allowedPatterns := []*regexp.Regexp{pattern0}
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
@@ -1278,10 +1293,10 @@ func NewFormDataParameterSubSchema(in interface{}, context *compiler.Context) (*
// MAP: Any ^x-
x.VendorExtension = make([]*NamedAny, 0)
for _, item := range m {
- k, ok := item.Key.(string)
+ k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
- if compiler.PatternMatches("^x-", k) {
+ if strings.HasPrefix(k, "x-") {
pair := &NamedAny{}
pair.Name = k
result := &Any{}
@@ -1309,6 +1324,7 @@ func NewFormDataParameterSubSchema(in interface{}, context *compiler.Context) (*
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewHeader creates an object of type Header if possible, returning an error if not.
func NewHeader(in interface{}, context *compiler.Context) (*Header, error) {
errors := make([]error, 0)
x := &Header{}
@@ -1324,7 +1340,7 @@ func NewHeader(in interface{}, context *compiler.Context) (*Header, error) {
errors = append(errors, compiler.NewError(context, message))
}
allowedKeys := []string{"collectionFormat", "default", "description", "enum", "exclusiveMaximum", "exclusiveMinimum", "format", "items", "maxItems", "maxLength", "maximum", "minItems", "minLength", "minimum", "multipleOf", "pattern", "type", "uniqueItems"}
- allowedPatterns := []string{"^x-"}
+ allowedPatterns := []*regexp.Regexp{pattern0}
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
@@ -1565,10 +1581,10 @@ func NewHeader(in interface{}, context *compiler.Context) (*Header, error) {
// MAP: Any ^x-
x.VendorExtension = make([]*NamedAny, 0)
for _, item := range m {
- k, ok := item.Key.(string)
+ k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
- if compiler.PatternMatches("^x-", k) {
+ if strings.HasPrefix(k, "x-") {
pair := &NamedAny{}
pair.Name = k
result := &Any{}
@@ -1596,6 +1612,7 @@ func NewHeader(in interface{}, context *compiler.Context) (*Header, error) {
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewHeaderParameterSubSchema creates an object of type HeaderParameterSubSchema if possible, returning an error if not.
func NewHeaderParameterSubSchema(in interface{}, context *compiler.Context) (*HeaderParameterSubSchema, error) {
errors := make([]error, 0)
x := &HeaderParameterSubSchema{}
@@ -1605,7 +1622,7 @@ func NewHeaderParameterSubSchema(in interface{}, context *compiler.Context) (*He
errors = append(errors, compiler.NewError(context, message))
} else {
allowedKeys := []string{"collectionFormat", "default", "description", "enum", "exclusiveMaximum", "exclusiveMinimum", "format", "in", "items", "maxItems", "maxLength", "maximum", "minItems", "minLength", "minimum", "multipleOf", "name", "pattern", "required", "type", "uniqueItems"}
- allowedPatterns := []string{"^x-"}
+ allowedPatterns := []*regexp.Regexp{pattern0}
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
@@ -1879,10 +1896,10 @@ func NewHeaderParameterSubSchema(in interface{}, context *compiler.Context) (*He
// MAP: Any ^x-
x.VendorExtension = make([]*NamedAny, 0)
for _, item := range m {
- k, ok := item.Key.(string)
+ k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
- if compiler.PatternMatches("^x-", k) {
+ if strings.HasPrefix(k, "x-") {
pair := &NamedAny{}
pair.Name = k
result := &Any{}
@@ -1910,6 +1927,7 @@ func NewHeaderParameterSubSchema(in interface{}, context *compiler.Context) (*He
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewHeaders creates an object of type Headers if possible, returning an error if not.
func NewHeaders(in interface{}, context *compiler.Context) (*Headers, error) {
errors := make([]error, 0)
x := &Headers{}
@@ -1922,7 +1940,7 @@ func NewHeaders(in interface{}, context *compiler.Context) (*Headers, error) {
// MAP: Header
x.AdditionalProperties = make([]*NamedHeader, 0)
for _, item := range m {
- k, ok := item.Key.(string)
+ k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
pair := &NamedHeader{}
@@ -1939,6 +1957,7 @@ func NewHeaders(in interface{}, context *compiler.Context) (*Headers, error) {
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewInfo creates an object of type Info if possible, returning an error if not.
func NewInfo(in interface{}, context *compiler.Context) (*Info, error) {
errors := make([]error, 0)
x := &Info{}
@@ -1954,7 +1973,7 @@ func NewInfo(in interface{}, context *compiler.Context) (*Info, error) {
errors = append(errors, compiler.NewError(context, message))
}
allowedKeys := []string{"contact", "description", "license", "termsOfService", "title", "version"}
- allowedPatterns := []string{"^x-"}
+ allowedPatterns := []*regexp.Regexp{pattern0}
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
@@ -2018,10 +2037,10 @@ func NewInfo(in interface{}, context *compiler.Context) (*Info, error) {
// MAP: Any ^x-
x.VendorExtension = make([]*NamedAny, 0)
for _, item := range m {
- k, ok := item.Key.(string)
+ k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
- if compiler.PatternMatches("^x-", k) {
+ if strings.HasPrefix(k, "x-") {
pair := &NamedAny{}
pair.Name = k
result := &Any{}
@@ -2049,6 +2068,7 @@ func NewInfo(in interface{}, context *compiler.Context) (*Info, error) {
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewItemsItem creates an object of type ItemsItem if possible, returning an error if not.
func NewItemsItem(in interface{}, context *compiler.Context) (*ItemsItem, error) {
errors := make([]error, 0)
x := &ItemsItem{}
@@ -2067,6 +2087,7 @@ func NewItemsItem(in interface{}, context *compiler.Context) (*ItemsItem, error)
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewJsonReference creates an object of type JsonReference if possible, returning an error if not.
func NewJsonReference(in interface{}, context *compiler.Context) (*JsonReference, error) {
errors := make([]error, 0)
x := &JsonReference{}
@@ -2082,7 +2103,7 @@ func NewJsonReference(in interface{}, context *compiler.Context) (*JsonReference
errors = append(errors, compiler.NewError(context, message))
}
allowedKeys := []string{"$ref", "description"}
- allowedPatterns := []string{}
+ var allowedPatterns []*regexp.Regexp
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
@@ -2110,6 +2131,7 @@ func NewJsonReference(in interface{}, context *compiler.Context) (*JsonReference
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewLicense creates an object of type License if possible, returning an error if not.
func NewLicense(in interface{}, context *compiler.Context) (*License, error) {
errors := make([]error, 0)
x := &License{}
@@ -2125,7 +2147,7 @@ func NewLicense(in interface{}, context *compiler.Context) (*License, error) {
errors = append(errors, compiler.NewError(context, message))
}
allowedKeys := []string{"name", "url"}
- allowedPatterns := []string{"^x-"}
+ allowedPatterns := []*regexp.Regexp{pattern0}
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
@@ -2153,10 +2175,10 @@ func NewLicense(in interface{}, context *compiler.Context) (*License, error) {
// MAP: Any ^x-
x.VendorExtension = make([]*NamedAny, 0)
for _, item := range m {
- k, ok := item.Key.(string)
+ k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
- if compiler.PatternMatches("^x-", k) {
+ if strings.HasPrefix(k, "x-") {
pair := &NamedAny{}
pair.Name = k
result := &Any{}
@@ -2184,6 +2206,7 @@ func NewLicense(in interface{}, context *compiler.Context) (*License, error) {
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewNamedAny creates an object of type NamedAny if possible, returning an error if not.
func NewNamedAny(in interface{}, context *compiler.Context) (*NamedAny, error) {
errors := make([]error, 0)
x := &NamedAny{}
@@ -2193,7 +2216,7 @@ func NewNamedAny(in interface{}, context *compiler.Context) (*NamedAny, error) {
errors = append(errors, compiler.NewError(context, message))
} else {
allowedKeys := []string{"name", "value"}
- allowedPatterns := []string{}
+ var allowedPatterns []*regexp.Regexp
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
@@ -2221,6 +2244,7 @@ func NewNamedAny(in interface{}, context *compiler.Context) (*NamedAny, error) {
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewNamedHeader creates an object of type NamedHeader if possible, returning an error if not.
func NewNamedHeader(in interface{}, context *compiler.Context) (*NamedHeader, error) {
errors := make([]error, 0)
x := &NamedHeader{}
@@ -2230,7 +2254,7 @@ func NewNamedHeader(in interface{}, context *compiler.Context) (*NamedHeader, er
errors = append(errors, compiler.NewError(context, message))
} else {
allowedKeys := []string{"name", "value"}
- allowedPatterns := []string{}
+ var allowedPatterns []*regexp.Regexp
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
@@ -2258,6 +2282,7 @@ func NewNamedHeader(in interface{}, context *compiler.Context) (*NamedHeader, er
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewNamedParameter creates an object of type NamedParameter if possible, returning an error if not.
func NewNamedParameter(in interface{}, context *compiler.Context) (*NamedParameter, error) {
errors := make([]error, 0)
x := &NamedParameter{}
@@ -2267,7 +2292,7 @@ func NewNamedParameter(in interface{}, context *compiler.Context) (*NamedParamet
errors = append(errors, compiler.NewError(context, message))
} else {
allowedKeys := []string{"name", "value"}
- allowedPatterns := []string{}
+ var allowedPatterns []*regexp.Regexp
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
@@ -2295,6 +2320,7 @@ func NewNamedParameter(in interface{}, context *compiler.Context) (*NamedParamet
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewNamedPathItem creates an object of type NamedPathItem if possible, returning an error if not.
func NewNamedPathItem(in interface{}, context *compiler.Context) (*NamedPathItem, error) {
errors := make([]error, 0)
x := &NamedPathItem{}
@@ -2304,7 +2330,7 @@ func NewNamedPathItem(in interface{}, context *compiler.Context) (*NamedPathItem
errors = append(errors, compiler.NewError(context, message))
} else {
allowedKeys := []string{"name", "value"}
- allowedPatterns := []string{}
+ var allowedPatterns []*regexp.Regexp
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
@@ -2332,6 +2358,7 @@ func NewNamedPathItem(in interface{}, context *compiler.Context) (*NamedPathItem
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewNamedResponse creates an object of type NamedResponse if possible, returning an error if not.
func NewNamedResponse(in interface{}, context *compiler.Context) (*NamedResponse, error) {
errors := make([]error, 0)
x := &NamedResponse{}
@@ -2341,7 +2368,7 @@ func NewNamedResponse(in interface{}, context *compiler.Context) (*NamedResponse
errors = append(errors, compiler.NewError(context, message))
} else {
allowedKeys := []string{"name", "value"}
- allowedPatterns := []string{}
+ var allowedPatterns []*regexp.Regexp
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
@@ -2369,6 +2396,7 @@ func NewNamedResponse(in interface{}, context *compiler.Context) (*NamedResponse
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewNamedResponseValue creates an object of type NamedResponseValue if possible, returning an error if not.
func NewNamedResponseValue(in interface{}, context *compiler.Context) (*NamedResponseValue, error) {
errors := make([]error, 0)
x := &NamedResponseValue{}
@@ -2378,7 +2406,7 @@ func NewNamedResponseValue(in interface{}, context *compiler.Context) (*NamedRes
errors = append(errors, compiler.NewError(context, message))
} else {
allowedKeys := []string{"name", "value"}
- allowedPatterns := []string{}
+ var allowedPatterns []*regexp.Regexp
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
@@ -2406,6 +2434,7 @@ func NewNamedResponseValue(in interface{}, context *compiler.Context) (*NamedRes
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewNamedSchema creates an object of type NamedSchema if possible, returning an error if not.
func NewNamedSchema(in interface{}, context *compiler.Context) (*NamedSchema, error) {
errors := make([]error, 0)
x := &NamedSchema{}
@@ -2415,7 +2444,7 @@ func NewNamedSchema(in interface{}, context *compiler.Context) (*NamedSchema, er
errors = append(errors, compiler.NewError(context, message))
} else {
allowedKeys := []string{"name", "value"}
- allowedPatterns := []string{}
+ var allowedPatterns []*regexp.Regexp
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
@@ -2443,6 +2472,7 @@ func NewNamedSchema(in interface{}, context *compiler.Context) (*NamedSchema, er
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewNamedSecurityDefinitionsItem creates an object of type NamedSecurityDefinitionsItem if possible, returning an error if not.
func NewNamedSecurityDefinitionsItem(in interface{}, context *compiler.Context) (*NamedSecurityDefinitionsItem, error) {
errors := make([]error, 0)
x := &NamedSecurityDefinitionsItem{}
@@ -2452,7 +2482,7 @@ func NewNamedSecurityDefinitionsItem(in interface{}, context *compiler.Context)
errors = append(errors, compiler.NewError(context, message))
} else {
allowedKeys := []string{"name", "value"}
- allowedPatterns := []string{}
+ var allowedPatterns []*regexp.Regexp
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
@@ -2480,6 +2510,7 @@ func NewNamedSecurityDefinitionsItem(in interface{}, context *compiler.Context)
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewNamedString creates an object of type NamedString if possible, returning an error if not.
func NewNamedString(in interface{}, context *compiler.Context) (*NamedString, error) {
errors := make([]error, 0)
x := &NamedString{}
@@ -2489,7 +2520,7 @@ func NewNamedString(in interface{}, context *compiler.Context) (*NamedString, er
errors = append(errors, compiler.NewError(context, message))
} else {
allowedKeys := []string{"name", "value"}
- allowedPatterns := []string{}
+ var allowedPatterns []*regexp.Regexp
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
@@ -2517,6 +2548,7 @@ func NewNamedString(in interface{}, context *compiler.Context) (*NamedString, er
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewNamedStringArray creates an object of type NamedStringArray if possible, returning an error if not.
func NewNamedStringArray(in interface{}, context *compiler.Context) (*NamedStringArray, error) {
errors := make([]error, 0)
x := &NamedStringArray{}
@@ -2526,7 +2558,7 @@ func NewNamedStringArray(in interface{}, context *compiler.Context) (*NamedStrin
errors = append(errors, compiler.NewError(context, message))
} else {
allowedKeys := []string{"name", "value"}
- allowedPatterns := []string{}
+ var allowedPatterns []*regexp.Regexp
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
@@ -2554,6 +2586,7 @@ func NewNamedStringArray(in interface{}, context *compiler.Context) (*NamedStrin
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewNonBodyParameter creates an object of type NonBodyParameter if possible, returning an error if not.
func NewNonBodyParameter(in interface{}, context *compiler.Context) (*NonBodyParameter, error) {
errors := make([]error, 0)
x := &NonBodyParameter{}
@@ -2572,45 +2605,45 @@ func NewNonBodyParameter(in interface{}, context *compiler.Context) (*NonBodyPar
// HeaderParameterSubSchema header_parameter_sub_schema = 1;
{
// errors might be ok here, they mean we just don't have the right subtype
- t, matching_error := NewHeaderParameterSubSchema(m, compiler.NewContext("headerParameterSubSchema", context))
- if matching_error == nil {
+ t, matchingError := NewHeaderParameterSubSchema(m, compiler.NewContext("headerParameterSubSchema", context))
+ if matchingError == nil {
x.Oneof = &NonBodyParameter_HeaderParameterSubSchema{HeaderParameterSubSchema: t}
matched = true
} else {
- errors = append(errors, matching_error)
+ errors = append(errors, matchingError)
}
}
// FormDataParameterSubSchema form_data_parameter_sub_schema = 2;
{
// errors might be ok here, they mean we just don't have the right subtype
- t, matching_error := NewFormDataParameterSubSchema(m, compiler.NewContext("formDataParameterSubSchema", context))
- if matching_error == nil {
+ t, matchingError := NewFormDataParameterSubSchema(m, compiler.NewContext("formDataParameterSubSchema", context))
+ if matchingError == nil {
x.Oneof = &NonBodyParameter_FormDataParameterSubSchema{FormDataParameterSubSchema: t}
matched = true
} else {
- errors = append(errors, matching_error)
+ errors = append(errors, matchingError)
}
}
// QueryParameterSubSchema query_parameter_sub_schema = 3;
{
// errors might be ok here, they mean we just don't have the right subtype
- t, matching_error := NewQueryParameterSubSchema(m, compiler.NewContext("queryParameterSubSchema", context))
- if matching_error == nil {
+ t, matchingError := NewQueryParameterSubSchema(m, compiler.NewContext("queryParameterSubSchema", context))
+ if matchingError == nil {
x.Oneof = &NonBodyParameter_QueryParameterSubSchema{QueryParameterSubSchema: t}
matched = true
} else {
- errors = append(errors, matching_error)
+ errors = append(errors, matchingError)
}
}
// PathParameterSubSchema path_parameter_sub_schema = 4;
{
// errors might be ok here, they mean we just don't have the right subtype
- t, matching_error := NewPathParameterSubSchema(m, compiler.NewContext("pathParameterSubSchema", context))
- if matching_error == nil {
+ t, matchingError := NewPathParameterSubSchema(m, compiler.NewContext("pathParameterSubSchema", context))
+ if matchingError == nil {
x.Oneof = &NonBodyParameter_PathParameterSubSchema{PathParameterSubSchema: t}
matched = true
} else {
- errors = append(errors, matching_error)
+ errors = append(errors, matchingError)
}
}
}
@@ -2621,6 +2654,7 @@ func NewNonBodyParameter(in interface{}, context *compiler.Context) (*NonBodyPar
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewOauth2AccessCodeSecurity creates an object of type Oauth2AccessCodeSecurity if possible, returning an error if not.
func NewOauth2AccessCodeSecurity(in interface{}, context *compiler.Context) (*Oauth2AccessCodeSecurity, error) {
errors := make([]error, 0)
x := &Oauth2AccessCodeSecurity{}
@@ -2636,7 +2670,7 @@ func NewOauth2AccessCodeSecurity(in interface{}, context *compiler.Context) (*Oa
errors = append(errors, compiler.NewError(context, message))
}
allowedKeys := []string{"authorizationUrl", "description", "flow", "scopes", "tokenUrl", "type"}
- allowedPatterns := []string{"^x-"}
+ allowedPatterns := []*regexp.Regexp{pattern0}
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
@@ -2712,10 +2746,10 @@ func NewOauth2AccessCodeSecurity(in interface{}, context *compiler.Context) (*Oa
// MAP: Any ^x-
x.VendorExtension = make([]*NamedAny, 0)
for _, item := range m {
- k, ok := item.Key.(string)
+ k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
- if compiler.PatternMatches("^x-", k) {
+ if strings.HasPrefix(k, "x-") {
pair := &NamedAny{}
pair.Name = k
result := &Any{}
@@ -2743,6 +2777,7 @@ func NewOauth2AccessCodeSecurity(in interface{}, context *compiler.Context) (*Oa
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewOauth2ApplicationSecurity creates an object of type Oauth2ApplicationSecurity if possible, returning an error if not.
func NewOauth2ApplicationSecurity(in interface{}, context *compiler.Context) (*Oauth2ApplicationSecurity, error) {
errors := make([]error, 0)
x := &Oauth2ApplicationSecurity{}
@@ -2758,7 +2793,7 @@ func NewOauth2ApplicationSecurity(in interface{}, context *compiler.Context) (*O
errors = append(errors, compiler.NewError(context, message))
}
allowedKeys := []string{"description", "flow", "scopes", "tokenUrl", "type"}
- allowedPatterns := []string{"^x-"}
+ allowedPatterns := []*regexp.Regexp{pattern0}
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
@@ -2825,10 +2860,10 @@ func NewOauth2ApplicationSecurity(in interface{}, context *compiler.Context) (*O
// MAP: Any ^x-
x.VendorExtension = make([]*NamedAny, 0)
for _, item := range m {
- k, ok := item.Key.(string)
+ k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
- if compiler.PatternMatches("^x-", k) {
+ if strings.HasPrefix(k, "x-") {
pair := &NamedAny{}
pair.Name = k
result := &Any{}
@@ -2856,6 +2891,7 @@ func NewOauth2ApplicationSecurity(in interface{}, context *compiler.Context) (*O
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewOauth2ImplicitSecurity creates an object of type Oauth2ImplicitSecurity if possible, returning an error if not.
func NewOauth2ImplicitSecurity(in interface{}, context *compiler.Context) (*Oauth2ImplicitSecurity, error) {
errors := make([]error, 0)
x := &Oauth2ImplicitSecurity{}
@@ -2871,7 +2907,7 @@ func NewOauth2ImplicitSecurity(in interface{}, context *compiler.Context) (*Oaut
errors = append(errors, compiler.NewError(context, message))
}
allowedKeys := []string{"authorizationUrl", "description", "flow", "scopes", "type"}
- allowedPatterns := []string{"^x-"}
+ allowedPatterns := []*regexp.Regexp{pattern0}
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
@@ -2938,10 +2974,10 @@ func NewOauth2ImplicitSecurity(in interface{}, context *compiler.Context) (*Oaut
// MAP: Any ^x-
x.VendorExtension = make([]*NamedAny, 0)
for _, item := range m {
- k, ok := item.Key.(string)
+ k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
- if compiler.PatternMatches("^x-", k) {
+ if strings.HasPrefix(k, "x-") {
pair := &NamedAny{}
pair.Name = k
result := &Any{}
@@ -2969,6 +3005,7 @@ func NewOauth2ImplicitSecurity(in interface{}, context *compiler.Context) (*Oaut
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewOauth2PasswordSecurity creates an object of type Oauth2PasswordSecurity if possible, returning an error if not.
func NewOauth2PasswordSecurity(in interface{}, context *compiler.Context) (*Oauth2PasswordSecurity, error) {
errors := make([]error, 0)
x := &Oauth2PasswordSecurity{}
@@ -2984,7 +3021,7 @@ func NewOauth2PasswordSecurity(in interface{}, context *compiler.Context) (*Oaut
errors = append(errors, compiler.NewError(context, message))
}
allowedKeys := []string{"description", "flow", "scopes", "tokenUrl", "type"}
- allowedPatterns := []string{"^x-"}
+ allowedPatterns := []*regexp.Regexp{pattern0}
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
@@ -3051,10 +3088,10 @@ func NewOauth2PasswordSecurity(in interface{}, context *compiler.Context) (*Oaut
// MAP: Any ^x-
x.VendorExtension = make([]*NamedAny, 0)
for _, item := range m {
- k, ok := item.Key.(string)
+ k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
- if compiler.PatternMatches("^x-", k) {
+ if strings.HasPrefix(k, "x-") {
pair := &NamedAny{}
pair.Name = k
result := &Any{}
@@ -3082,6 +3119,7 @@ func NewOauth2PasswordSecurity(in interface{}, context *compiler.Context) (*Oaut
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewOauth2Scopes creates an object of type Oauth2Scopes if possible, returning an error if not.
func NewOauth2Scopes(in interface{}, context *compiler.Context) (*Oauth2Scopes, error) {
errors := make([]error, 0)
x := &Oauth2Scopes{}
@@ -3094,7 +3132,7 @@ func NewOauth2Scopes(in interface{}, context *compiler.Context) (*Oauth2Scopes,
// MAP: string
x.AdditionalProperties = make([]*NamedString, 0)
for _, item := range m {
- k, ok := item.Key.(string)
+ k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
pair := &NamedString{}
@@ -3107,6 +3145,7 @@ func NewOauth2Scopes(in interface{}, context *compiler.Context) (*Oauth2Scopes,
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewOperation creates an object of type Operation if possible, returning an error if not.
func NewOperation(in interface{}, context *compiler.Context) (*Operation, error) {
errors := make([]error, 0)
x := &Operation{}
@@ -3122,7 +3161,7 @@ func NewOperation(in interface{}, context *compiler.Context) (*Operation, error)
errors = append(errors, compiler.NewError(context, message))
}
allowedKeys := []string{"consumes", "deprecated", "description", "externalDocs", "operationId", "parameters", "produces", "responses", "schemes", "security", "summary", "tags"}
- allowedPatterns := []string{"^x-"}
+ allowedPatterns := []*regexp.Regexp{pattern0}
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
@@ -3268,10 +3307,10 @@ func NewOperation(in interface{}, context *compiler.Context) (*Operation, error)
// MAP: Any ^x-
x.VendorExtension = make([]*NamedAny, 0)
for _, item := range m {
- k, ok := item.Key.(string)
+ k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
- if compiler.PatternMatches("^x-", k) {
+ if strings.HasPrefix(k, "x-") {
pair := &NamedAny{}
pair.Name = k
result := &Any{}
@@ -3299,6 +3338,7 @@ func NewOperation(in interface{}, context *compiler.Context) (*Operation, error)
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewParameter creates an object of type Parameter if possible, returning an error if not.
func NewParameter(in interface{}, context *compiler.Context) (*Parameter, error) {
errors := make([]error, 0)
x := &Parameter{}
@@ -3308,12 +3348,12 @@ func NewParameter(in interface{}, context *compiler.Context) (*Parameter, error)
m, ok := compiler.UnpackMap(in)
if ok {
// errors might be ok here, they mean we just don't have the right subtype
- t, matching_error := NewBodyParameter(m, compiler.NewContext("bodyParameter", context))
- if matching_error == nil {
+ t, matchingError := NewBodyParameter(m, compiler.NewContext("bodyParameter", context))
+ if matchingError == nil {
x.Oneof = &Parameter_BodyParameter{BodyParameter: t}
matched = true
} else {
- errors = append(errors, matching_error)
+ errors = append(errors, matchingError)
}
}
}
@@ -3322,12 +3362,12 @@ func NewParameter(in interface{}, context *compiler.Context) (*Parameter, error)
m, ok := compiler.UnpackMap(in)
if ok {
// errors might be ok here, they mean we just don't have the right subtype
- t, matching_error := NewNonBodyParameter(m, compiler.NewContext("nonBodyParameter", context))
- if matching_error == nil {
+ t, matchingError := NewNonBodyParameter(m, compiler.NewContext("nonBodyParameter", context))
+ if matchingError == nil {
x.Oneof = &Parameter_NonBodyParameter{NonBodyParameter: t}
matched = true
} else {
- errors = append(errors, matching_error)
+ errors = append(errors, matchingError)
}
}
}
@@ -3338,6 +3378,7 @@ func NewParameter(in interface{}, context *compiler.Context) (*Parameter, error)
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewParameterDefinitions creates an object of type ParameterDefinitions if possible, returning an error if not.
func NewParameterDefinitions(in interface{}, context *compiler.Context) (*ParameterDefinitions, error) {
errors := make([]error, 0)
x := &ParameterDefinitions{}
@@ -3350,7 +3391,7 @@ func NewParameterDefinitions(in interface{}, context *compiler.Context) (*Parame
// MAP: Parameter
x.AdditionalProperties = make([]*NamedParameter, 0)
for _, item := range m {
- k, ok := item.Key.(string)
+ k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
pair := &NamedParameter{}
@@ -3367,6 +3408,7 @@ func NewParameterDefinitions(in interface{}, context *compiler.Context) (*Parame
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewParametersItem creates an object of type ParametersItem if possible, returning an error if not.
func NewParametersItem(in interface{}, context *compiler.Context) (*ParametersItem, error) {
errors := make([]error, 0)
x := &ParametersItem{}
@@ -3376,12 +3418,12 @@ func NewParametersItem(in interface{}, context *compiler.Context) (*ParametersIt
m, ok := compiler.UnpackMap(in)
if ok {
// errors might be ok here, they mean we just don't have the right subtype
- t, matching_error := NewParameter(m, compiler.NewContext("parameter", context))
- if matching_error == nil {
+ t, matchingError := NewParameter(m, compiler.NewContext("parameter", context))
+ if matchingError == nil {
x.Oneof = &ParametersItem_Parameter{Parameter: t}
matched = true
} else {
- errors = append(errors, matching_error)
+ errors = append(errors, matchingError)
}
}
}
@@ -3390,12 +3432,12 @@ func NewParametersItem(in interface{}, context *compiler.Context) (*ParametersIt
m, ok := compiler.UnpackMap(in)
if ok {
// errors might be ok here, they mean we just don't have the right subtype
- t, matching_error := NewJsonReference(m, compiler.NewContext("jsonReference", context))
- if matching_error == nil {
+ t, matchingError := NewJsonReference(m, compiler.NewContext("jsonReference", context))
+ if matchingError == nil {
x.Oneof = &ParametersItem_JsonReference{JsonReference: t}
matched = true
} else {
- errors = append(errors, matching_error)
+ errors = append(errors, matchingError)
}
}
}
@@ -3406,6 +3448,7 @@ func NewParametersItem(in interface{}, context *compiler.Context) (*ParametersIt
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewPathItem creates an object of type PathItem if possible, returning an error if not.
func NewPathItem(in interface{}, context *compiler.Context) (*PathItem, error) {
errors := make([]error, 0)
x := &PathItem{}
@@ -3415,7 +3458,7 @@ func NewPathItem(in interface{}, context *compiler.Context) (*PathItem, error) {
errors = append(errors, compiler.NewError(context, message))
} else {
allowedKeys := []string{"$ref", "delete", "get", "head", "options", "parameters", "patch", "post", "put"}
- allowedPatterns := []string{"^x-"}
+ allowedPatterns := []*regexp.Regexp{pattern0}
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
@@ -3513,10 +3556,10 @@ func NewPathItem(in interface{}, context *compiler.Context) (*PathItem, error) {
// MAP: Any ^x-
x.VendorExtension = make([]*NamedAny, 0)
for _, item := range m {
- k, ok := item.Key.(string)
+ k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
- if compiler.PatternMatches("^x-", k) {
+ if strings.HasPrefix(k, "x-") {
pair := &NamedAny{}
pair.Name = k
result := &Any{}
@@ -3544,6 +3587,7 @@ func NewPathItem(in interface{}, context *compiler.Context) (*PathItem, error) {
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewPathParameterSubSchema creates an object of type PathParameterSubSchema if possible, returning an error if not.
func NewPathParameterSubSchema(in interface{}, context *compiler.Context) (*PathParameterSubSchema, error) {
errors := make([]error, 0)
x := &PathParameterSubSchema{}
@@ -3559,7 +3603,7 @@ func NewPathParameterSubSchema(in interface{}, context *compiler.Context) (*Path
errors = append(errors, compiler.NewError(context, message))
}
allowedKeys := []string{"collectionFormat", "default", "description", "enum", "exclusiveMaximum", "exclusiveMinimum", "format", "in", "items", "maxItems", "maxLength", "maximum", "minItems", "minLength", "minimum", "multipleOf", "name", "pattern", "required", "type", "uniqueItems"}
- allowedPatterns := []string{"^x-"}
+ allowedPatterns := []*regexp.Regexp{pattern0}
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
@@ -3833,10 +3877,10 @@ func NewPathParameterSubSchema(in interface{}, context *compiler.Context) (*Path
// MAP: Any ^x-
x.VendorExtension = make([]*NamedAny, 0)
for _, item := range m {
- k, ok := item.Key.(string)
+ k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
- if compiler.PatternMatches("^x-", k) {
+ if strings.HasPrefix(k, "x-") {
pair := &NamedAny{}
pair.Name = k
result := &Any{}
@@ -3864,6 +3908,7 @@ func NewPathParameterSubSchema(in interface{}, context *compiler.Context) (*Path
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewPaths creates an object of type Paths if possible, returning an error if not.
func NewPaths(in interface{}, context *compiler.Context) (*Paths, error) {
errors := make([]error, 0)
x := &Paths{}
@@ -3873,7 +3918,7 @@ func NewPaths(in interface{}, context *compiler.Context) (*Paths, error) {
errors = append(errors, compiler.NewError(context, message))
} else {
allowedKeys := []string{}
- allowedPatterns := []string{"^x-", "^/"}
+ allowedPatterns := []*regexp.Regexp{pattern0, pattern1}
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
@@ -3883,10 +3928,10 @@ func NewPaths(in interface{}, context *compiler.Context) (*Paths, error) {
// MAP: Any ^x-
x.VendorExtension = make([]*NamedAny, 0)
for _, item := range m {
- k, ok := item.Key.(string)
+ k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
- if compiler.PatternMatches("^x-", k) {
+ if strings.HasPrefix(k, "x-") {
pair := &NamedAny{}
pair.Name = k
result := &Any{}
@@ -3914,10 +3959,10 @@ func NewPaths(in interface{}, context *compiler.Context) (*Paths, error) {
// MAP: PathItem ^/
x.Path = make([]*NamedPathItem, 0)
for _, item := range m {
- k, ok := item.Key.(string)
+ k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
- if compiler.PatternMatches("^/", k) {
+ if strings.HasPrefix(k, "/") {
pair := &NamedPathItem{}
pair.Name = k
var err error
@@ -3933,6 +3978,7 @@ func NewPaths(in interface{}, context *compiler.Context) (*Paths, error) {
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewPrimitivesItems creates an object of type PrimitivesItems if possible, returning an error if not.
func NewPrimitivesItems(in interface{}, context *compiler.Context) (*PrimitivesItems, error) {
errors := make([]error, 0)
x := &PrimitivesItems{}
@@ -3942,7 +3988,7 @@ func NewPrimitivesItems(in interface{}, context *compiler.Context) (*PrimitivesI
errors = append(errors, compiler.NewError(context, message))
} else {
allowedKeys := []string{"collectionFormat", "default", "enum", "exclusiveMaximum", "exclusiveMinimum", "format", "items", "maxItems", "maxLength", "maximum", "minItems", "minLength", "minimum", "multipleOf", "pattern", "type", "uniqueItems"}
- allowedPatterns := []string{"^x-"}
+ allowedPatterns := []*regexp.Regexp{pattern0}
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
@@ -4174,10 +4220,10 @@ func NewPrimitivesItems(in interface{}, context *compiler.Context) (*PrimitivesI
// MAP: Any ^x-
x.VendorExtension = make([]*NamedAny, 0)
for _, item := range m {
- k, ok := item.Key.(string)
+ k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
- if compiler.PatternMatches("^x-", k) {
+ if strings.HasPrefix(k, "x-") {
pair := &NamedAny{}
pair.Name = k
result := &Any{}
@@ -4205,6 +4251,7 @@ func NewPrimitivesItems(in interface{}, context *compiler.Context) (*PrimitivesI
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewProperties creates an object of type Properties if possible, returning an error if not.
func NewProperties(in interface{}, context *compiler.Context) (*Properties, error) {
errors := make([]error, 0)
x := &Properties{}
@@ -4217,7 +4264,7 @@ func NewProperties(in interface{}, context *compiler.Context) (*Properties, erro
// MAP: Schema
x.AdditionalProperties = make([]*NamedSchema, 0)
for _, item := range m {
- k, ok := item.Key.(string)
+ k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
pair := &NamedSchema{}
@@ -4234,6 +4281,7 @@ func NewProperties(in interface{}, context *compiler.Context) (*Properties, erro
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewQueryParameterSubSchema creates an object of type QueryParameterSubSchema if possible, returning an error if not.
func NewQueryParameterSubSchema(in interface{}, context *compiler.Context) (*QueryParameterSubSchema, error) {
errors := make([]error, 0)
x := &QueryParameterSubSchema{}
@@ -4243,7 +4291,7 @@ func NewQueryParameterSubSchema(in interface{}, context *compiler.Context) (*Que
errors = append(errors, compiler.NewError(context, message))
} else {
allowedKeys := []string{"allowEmptyValue", "collectionFormat", "default", "description", "enum", "exclusiveMaximum", "exclusiveMinimum", "format", "in", "items", "maxItems", "maxLength", "maximum", "minItems", "minLength", "minimum", "multipleOf", "name", "pattern", "required", "type", "uniqueItems"}
- allowedPatterns := []string{"^x-"}
+ allowedPatterns := []*regexp.Regexp{pattern0}
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
@@ -4526,10 +4574,10 @@ func NewQueryParameterSubSchema(in interface{}, context *compiler.Context) (*Que
// MAP: Any ^x-
x.VendorExtension = make([]*NamedAny, 0)
for _, item := range m {
- k, ok := item.Key.(string)
+ k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
- if compiler.PatternMatches("^x-", k) {
+ if strings.HasPrefix(k, "x-") {
pair := &NamedAny{}
pair.Name = k
result := &Any{}
@@ -4557,6 +4605,7 @@ func NewQueryParameterSubSchema(in interface{}, context *compiler.Context) (*Que
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewResponse creates an object of type Response if possible, returning an error if not.
func NewResponse(in interface{}, context *compiler.Context) (*Response, error) {
errors := make([]error, 0)
x := &Response{}
@@ -4572,7 +4621,7 @@ func NewResponse(in interface{}, context *compiler.Context) (*Response, error) {
errors = append(errors, compiler.NewError(context, message))
}
allowedKeys := []string{"description", "examples", "headers", "schema"}
- allowedPatterns := []string{"^x-"}
+ allowedPatterns := []*regexp.Regexp{pattern0}
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
@@ -4618,10 +4667,10 @@ func NewResponse(in interface{}, context *compiler.Context) (*Response, error) {
// MAP: Any ^x-
x.VendorExtension = make([]*NamedAny, 0)
for _, item := range m {
- k, ok := item.Key.(string)
+ k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
- if compiler.PatternMatches("^x-", k) {
+ if strings.HasPrefix(k, "x-") {
pair := &NamedAny{}
pair.Name = k
result := &Any{}
@@ -4649,6 +4698,7 @@ func NewResponse(in interface{}, context *compiler.Context) (*Response, error) {
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewResponseDefinitions creates an object of type ResponseDefinitions if possible, returning an error if not.
func NewResponseDefinitions(in interface{}, context *compiler.Context) (*ResponseDefinitions, error) {
errors := make([]error, 0)
x := &ResponseDefinitions{}
@@ -4661,7 +4711,7 @@ func NewResponseDefinitions(in interface{}, context *compiler.Context) (*Respons
// MAP: Response
x.AdditionalProperties = make([]*NamedResponse, 0)
for _, item := range m {
- k, ok := item.Key.(string)
+ k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
pair := &NamedResponse{}
@@ -4678,6 +4728,7 @@ func NewResponseDefinitions(in interface{}, context *compiler.Context) (*Respons
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewResponseValue creates an object of type ResponseValue if possible, returning an error if not.
func NewResponseValue(in interface{}, context *compiler.Context) (*ResponseValue, error) {
errors := make([]error, 0)
x := &ResponseValue{}
@@ -4687,12 +4738,12 @@ func NewResponseValue(in interface{}, context *compiler.Context) (*ResponseValue
m, ok := compiler.UnpackMap(in)
if ok {
// errors might be ok here, they mean we just don't have the right subtype
- t, matching_error := NewResponse(m, compiler.NewContext("response", context))
- if matching_error == nil {
+ t, matchingError := NewResponse(m, compiler.NewContext("response", context))
+ if matchingError == nil {
x.Oneof = &ResponseValue_Response{Response: t}
matched = true
} else {
- errors = append(errors, matching_error)
+ errors = append(errors, matchingError)
}
}
}
@@ -4701,12 +4752,12 @@ func NewResponseValue(in interface{}, context *compiler.Context) (*ResponseValue
m, ok := compiler.UnpackMap(in)
if ok {
// errors might be ok here, they mean we just don't have the right subtype
- t, matching_error := NewJsonReference(m, compiler.NewContext("jsonReference", context))
- if matching_error == nil {
+ t, matchingError := NewJsonReference(m, compiler.NewContext("jsonReference", context))
+ if matchingError == nil {
x.Oneof = &ResponseValue_JsonReference{JsonReference: t}
matched = true
} else {
- errors = append(errors, matching_error)
+ errors = append(errors, matchingError)
}
}
}
@@ -4717,6 +4768,7 @@ func NewResponseValue(in interface{}, context *compiler.Context) (*ResponseValue
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewResponses creates an object of type Responses if possible, returning an error if not.
func NewResponses(in interface{}, context *compiler.Context) (*Responses, error) {
errors := make([]error, 0)
x := &Responses{}
@@ -4726,7 +4778,7 @@ func NewResponses(in interface{}, context *compiler.Context) (*Responses, error)
errors = append(errors, compiler.NewError(context, message))
} else {
allowedKeys := []string{}
- allowedPatterns := []string{"^([0-9]{3})$|^(default)$", "^x-"}
+ allowedPatterns := []*regexp.Regexp{pattern2, pattern0}
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
@@ -4736,10 +4788,10 @@ func NewResponses(in interface{}, context *compiler.Context) (*Responses, error)
// MAP: ResponseValue ^([0-9]{3})$|^(default)$
x.ResponseCode = make([]*NamedResponseValue, 0)
for _, item := range m {
- k, ok := item.Key.(string)
+ k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
- if compiler.PatternMatches("^([0-9]{3})$|^(default)$", k) {
+ if pattern2.MatchString(k) {
pair := &NamedResponseValue{}
pair.Name = k
var err error
@@ -4755,10 +4807,10 @@ func NewResponses(in interface{}, context *compiler.Context) (*Responses, error)
// MAP: Any ^x-
x.VendorExtension = make([]*NamedAny, 0)
for _, item := range m {
- k, ok := item.Key.(string)
+ k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
- if compiler.PatternMatches("^x-", k) {
+ if strings.HasPrefix(k, "x-") {
pair := &NamedAny{}
pair.Name = k
result := &Any{}
@@ -4786,6 +4838,7 @@ func NewResponses(in interface{}, context *compiler.Context) (*Responses, error)
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewSchema creates an object of type Schema if possible, returning an error if not.
func NewSchema(in interface{}, context *compiler.Context) (*Schema, error) {
errors := make([]error, 0)
x := &Schema{}
@@ -4795,7 +4848,7 @@ func NewSchema(in interface{}, context *compiler.Context) (*Schema, error) {
errors = append(errors, compiler.NewError(context, message))
} else {
allowedKeys := []string{"$ref", "additionalProperties", "allOf", "default", "description", "discriminator", "enum", "example", "exclusiveMaximum", "exclusiveMinimum", "externalDocs", "format", "items", "maxItems", "maxLength", "maxProperties", "maximum", "minItems", "minLength", "minProperties", "minimum", "multipleOf", "pattern", "properties", "readOnly", "required", "title", "type", "uniqueItems", "xml"}
- allowedPatterns := []string{"^x-"}
+ allowedPatterns := []*regexp.Regexp{pattern0}
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
@@ -5145,10 +5198,10 @@ func NewSchema(in interface{}, context *compiler.Context) (*Schema, error) {
// MAP: Any ^x-
x.VendorExtension = make([]*NamedAny, 0)
for _, item := range m {
- k, ok := item.Key.(string)
+ k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
- if compiler.PatternMatches("^x-", k) {
+ if strings.HasPrefix(k, "x-") {
pair := &NamedAny{}
pair.Name = k
result := &Any{}
@@ -5176,6 +5229,7 @@ func NewSchema(in interface{}, context *compiler.Context) (*Schema, error) {
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewSchemaItem creates an object of type SchemaItem if possible, returning an error if not.
func NewSchemaItem(in interface{}, context *compiler.Context) (*SchemaItem, error) {
errors := make([]error, 0)
x := &SchemaItem{}
@@ -5185,12 +5239,12 @@ func NewSchemaItem(in interface{}, context *compiler.Context) (*SchemaItem, erro
m, ok := compiler.UnpackMap(in)
if ok {
// errors might be ok here, they mean we just don't have the right subtype
- t, matching_error := NewSchema(m, compiler.NewContext("schema", context))
- if matching_error == nil {
+ t, matchingError := NewSchema(m, compiler.NewContext("schema", context))
+ if matchingError == nil {
x.Oneof = &SchemaItem_Schema{Schema: t}
matched = true
} else {
- errors = append(errors, matching_error)
+ errors = append(errors, matchingError)
}
}
}
@@ -5199,12 +5253,12 @@ func NewSchemaItem(in interface{}, context *compiler.Context) (*SchemaItem, erro
m, ok := compiler.UnpackMap(in)
if ok {
// errors might be ok here, they mean we just don't have the right subtype
- t, matching_error := NewFileSchema(m, compiler.NewContext("fileSchema", context))
- if matching_error == nil {
+ t, matchingError := NewFileSchema(m, compiler.NewContext("fileSchema", context))
+ if matchingError == nil {
x.Oneof = &SchemaItem_FileSchema{FileSchema: t}
matched = true
} else {
- errors = append(errors, matching_error)
+ errors = append(errors, matchingError)
}
}
}
@@ -5215,6 +5269,7 @@ func NewSchemaItem(in interface{}, context *compiler.Context) (*SchemaItem, erro
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewSecurityDefinitions creates an object of type SecurityDefinitions if possible, returning an error if not.
func NewSecurityDefinitions(in interface{}, context *compiler.Context) (*SecurityDefinitions, error) {
errors := make([]error, 0)
x := &SecurityDefinitions{}
@@ -5227,7 +5282,7 @@ func NewSecurityDefinitions(in interface{}, context *compiler.Context) (*Securit
// MAP: SecurityDefinitionsItem
x.AdditionalProperties = make([]*NamedSecurityDefinitionsItem, 0)
for _, item := range m {
- k, ok := item.Key.(string)
+ k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
pair := &NamedSecurityDefinitionsItem{}
@@ -5244,6 +5299,7 @@ func NewSecurityDefinitions(in interface{}, context *compiler.Context) (*Securit
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewSecurityDefinitionsItem creates an object of type SecurityDefinitionsItem if possible, returning an error if not.
func NewSecurityDefinitionsItem(in interface{}, context *compiler.Context) (*SecurityDefinitionsItem, error) {
errors := make([]error, 0)
x := &SecurityDefinitionsItem{}
@@ -5253,12 +5309,12 @@ func NewSecurityDefinitionsItem(in interface{}, context *compiler.Context) (*Sec
m, ok := compiler.UnpackMap(in)
if ok {
// errors might be ok here, they mean we just don't have the right subtype
- t, matching_error := NewBasicAuthenticationSecurity(m, compiler.NewContext("basicAuthenticationSecurity", context))
- if matching_error == nil {
+ t, matchingError := NewBasicAuthenticationSecurity(m, compiler.NewContext("basicAuthenticationSecurity", context))
+ if matchingError == nil {
x.Oneof = &SecurityDefinitionsItem_BasicAuthenticationSecurity{BasicAuthenticationSecurity: t}
matched = true
} else {
- errors = append(errors, matching_error)
+ errors = append(errors, matchingError)
}
}
}
@@ -5267,12 +5323,12 @@ func NewSecurityDefinitionsItem(in interface{}, context *compiler.Context) (*Sec
m, ok := compiler.UnpackMap(in)
if ok {
// errors might be ok here, they mean we just don't have the right subtype
- t, matching_error := NewApiKeySecurity(m, compiler.NewContext("apiKeySecurity", context))
- if matching_error == nil {
+ t, matchingError := NewApiKeySecurity(m, compiler.NewContext("apiKeySecurity", context))
+ if matchingError == nil {
x.Oneof = &SecurityDefinitionsItem_ApiKeySecurity{ApiKeySecurity: t}
matched = true
} else {
- errors = append(errors, matching_error)
+ errors = append(errors, matchingError)
}
}
}
@@ -5281,12 +5337,12 @@ func NewSecurityDefinitionsItem(in interface{}, context *compiler.Context) (*Sec
m, ok := compiler.UnpackMap(in)
if ok {
// errors might be ok here, they mean we just don't have the right subtype
- t, matching_error := NewOauth2ImplicitSecurity(m, compiler.NewContext("oauth2ImplicitSecurity", context))
- if matching_error == nil {
+ t, matchingError := NewOauth2ImplicitSecurity(m, compiler.NewContext("oauth2ImplicitSecurity", context))
+ if matchingError == nil {
x.Oneof = &SecurityDefinitionsItem_Oauth2ImplicitSecurity{Oauth2ImplicitSecurity: t}
matched = true
} else {
- errors = append(errors, matching_error)
+ errors = append(errors, matchingError)
}
}
}
@@ -5295,12 +5351,12 @@ func NewSecurityDefinitionsItem(in interface{}, context *compiler.Context) (*Sec
m, ok := compiler.UnpackMap(in)
if ok {
// errors might be ok here, they mean we just don't have the right subtype
- t, matching_error := NewOauth2PasswordSecurity(m, compiler.NewContext("oauth2PasswordSecurity", context))
- if matching_error == nil {
+ t, matchingError := NewOauth2PasswordSecurity(m, compiler.NewContext("oauth2PasswordSecurity", context))
+ if matchingError == nil {
x.Oneof = &SecurityDefinitionsItem_Oauth2PasswordSecurity{Oauth2PasswordSecurity: t}
matched = true
} else {
- errors = append(errors, matching_error)
+ errors = append(errors, matchingError)
}
}
}
@@ -5309,12 +5365,12 @@ func NewSecurityDefinitionsItem(in interface{}, context *compiler.Context) (*Sec
m, ok := compiler.UnpackMap(in)
if ok {
// errors might be ok here, they mean we just don't have the right subtype
- t, matching_error := NewOauth2ApplicationSecurity(m, compiler.NewContext("oauth2ApplicationSecurity", context))
- if matching_error == nil {
+ t, matchingError := NewOauth2ApplicationSecurity(m, compiler.NewContext("oauth2ApplicationSecurity", context))
+ if matchingError == nil {
x.Oneof = &SecurityDefinitionsItem_Oauth2ApplicationSecurity{Oauth2ApplicationSecurity: t}
matched = true
} else {
- errors = append(errors, matching_error)
+ errors = append(errors, matchingError)
}
}
}
@@ -5323,12 +5379,12 @@ func NewSecurityDefinitionsItem(in interface{}, context *compiler.Context) (*Sec
m, ok := compiler.UnpackMap(in)
if ok {
// errors might be ok here, they mean we just don't have the right subtype
- t, matching_error := NewOauth2AccessCodeSecurity(m, compiler.NewContext("oauth2AccessCodeSecurity", context))
- if matching_error == nil {
+ t, matchingError := NewOauth2AccessCodeSecurity(m, compiler.NewContext("oauth2AccessCodeSecurity", context))
+ if matchingError == nil {
x.Oneof = &SecurityDefinitionsItem_Oauth2AccessCodeSecurity{Oauth2AccessCodeSecurity: t}
matched = true
} else {
- errors = append(errors, matching_error)
+ errors = append(errors, matchingError)
}
}
}
@@ -5339,6 +5395,7 @@ func NewSecurityDefinitionsItem(in interface{}, context *compiler.Context) (*Sec
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewSecurityRequirement creates an object of type SecurityRequirement if possible, returning an error if not.
func NewSecurityRequirement(in interface{}, context *compiler.Context) (*SecurityRequirement, error) {
errors := make([]error, 0)
x := &SecurityRequirement{}
@@ -5351,7 +5408,7 @@ func NewSecurityRequirement(in interface{}, context *compiler.Context) (*Securit
// MAP: StringArray
x.AdditionalProperties = make([]*NamedStringArray, 0)
for _, item := range m {
- k, ok := item.Key.(string)
+ k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
pair := &NamedStringArray{}
@@ -5368,6 +5425,7 @@ func NewSecurityRequirement(in interface{}, context *compiler.Context) (*Securit
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewStringArray creates an object of type StringArray if possible, returning an error if not.
func NewStringArray(in interface{}, context *compiler.Context) (*StringArray, error) {
errors := make([]error, 0)
x := &StringArray{}
@@ -5384,6 +5442,7 @@ func NewStringArray(in interface{}, context *compiler.Context) (*StringArray, er
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewTag creates an object of type Tag if possible, returning an error if not.
func NewTag(in interface{}, context *compiler.Context) (*Tag, error) {
errors := make([]error, 0)
x := &Tag{}
@@ -5399,7 +5458,7 @@ func NewTag(in interface{}, context *compiler.Context) (*Tag, error) {
errors = append(errors, compiler.NewError(context, message))
}
allowedKeys := []string{"description", "externalDocs", "name"}
- allowedPatterns := []string{"^x-"}
+ allowedPatterns := []*regexp.Regexp{pattern0}
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
@@ -5436,10 +5495,10 @@ func NewTag(in interface{}, context *compiler.Context) (*Tag, error) {
// MAP: Any ^x-
x.VendorExtension = make([]*NamedAny, 0)
for _, item := range m {
- k, ok := item.Key.(string)
+ k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
- if compiler.PatternMatches("^x-", k) {
+ if strings.HasPrefix(k, "x-") {
pair := &NamedAny{}
pair.Name = k
result := &Any{}
@@ -5467,6 +5526,7 @@ func NewTag(in interface{}, context *compiler.Context) (*Tag, error) {
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewTypeItem creates an object of type TypeItem if possible, returning an error if not.
func NewTypeItem(in interface{}, context *compiler.Context) (*TypeItem, error) {
errors := make([]error, 0)
x := &TypeItem{}
@@ -5492,6 +5552,7 @@ func NewTypeItem(in interface{}, context *compiler.Context) (*TypeItem, error) {
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewVendorExtension creates an object of type VendorExtension if possible, returning an error if not.
func NewVendorExtension(in interface{}, context *compiler.Context) (*VendorExtension, error) {
errors := make([]error, 0)
x := &VendorExtension{}
@@ -5504,7 +5565,7 @@ func NewVendorExtension(in interface{}, context *compiler.Context) (*VendorExten
// MAP: Any
x.AdditionalProperties = make([]*NamedAny, 0)
for _, item := range m {
- k, ok := item.Key.(string)
+ k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
pair := &NamedAny{}
@@ -5533,6 +5594,7 @@ func NewVendorExtension(in interface{}, context *compiler.Context) (*VendorExten
return x, compiler.NewErrorGroupOrNil(errors)
}
+// NewXml creates an object of type Xml if possible, returning an error if not.
func NewXml(in interface{}, context *compiler.Context) (*Xml, error) {
errors := make([]error, 0)
x := &Xml{}
@@ -5542,7 +5604,7 @@ func NewXml(in interface{}, context *compiler.Context) (*Xml, error) {
errors = append(errors, compiler.NewError(context, message))
} else {
allowedKeys := []string{"attribute", "name", "namespace", "prefix", "wrapped"}
- allowedPatterns := []string{"^x-"}
+ allowedPatterns := []*regexp.Regexp{pattern0}
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
@@ -5597,10 +5659,10 @@ func NewXml(in interface{}, context *compiler.Context) (*Xml, error) {
// MAP: Any ^x-
x.VendorExtension = make([]*NamedAny, 0)
for _, item := range m {
- k, ok := item.Key.(string)
+ k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
- if compiler.PatternMatches("^x-", k) {
+ if strings.HasPrefix(k, "x-") {
pair := &NamedAny{}
pair.Name = k
result := &Any{}
@@ -5628,6 +5690,7 @@ func NewXml(in interface{}, context *compiler.Context) (*Xml, error) {
return x, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside AdditionalPropertiesItem objects.
func (m *AdditionalPropertiesItem) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
{
@@ -5642,11 +5705,13 @@ func (m *AdditionalPropertiesItem) ResolveReferences(root string) (interface{},
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside Any objects.
func (m *Any) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside ApiKeySecurity objects.
func (m *ApiKeySecurity) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
for _, item := range m.VendorExtension {
@@ -5660,6 +5725,7 @@ func (m *ApiKeySecurity) ResolveReferences(root string) (interface{}, error) {
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside BasicAuthenticationSecurity objects.
func (m *BasicAuthenticationSecurity) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
for _, item := range m.VendorExtension {
@@ -5673,6 +5739,7 @@ func (m *BasicAuthenticationSecurity) ResolveReferences(root string) (interface{
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside BodyParameter objects.
func (m *BodyParameter) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
if m.Schema != nil {
@@ -5692,6 +5759,7 @@ func (m *BodyParameter) ResolveReferences(root string) (interface{}, error) {
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside Contact objects.
func (m *Contact) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
for _, item := range m.VendorExtension {
@@ -5705,6 +5773,7 @@ func (m *Contact) ResolveReferences(root string) (interface{}, error) {
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside Default objects.
func (m *Default) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
for _, item := range m.AdditionalProperties {
@@ -5718,6 +5787,7 @@ func (m *Default) ResolveReferences(root string) (interface{}, error) {
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside Definitions objects.
func (m *Definitions) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
for _, item := range m.AdditionalProperties {
@@ -5731,6 +5801,7 @@ func (m *Definitions) ResolveReferences(root string) (interface{}, error) {
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside Document objects.
func (m *Document) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
if m.Info != nil {
@@ -5802,6 +5873,7 @@ func (m *Document) ResolveReferences(root string) (interface{}, error) {
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside Examples objects.
func (m *Examples) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
for _, item := range m.AdditionalProperties {
@@ -5815,6 +5887,7 @@ func (m *Examples) ResolveReferences(root string) (interface{}, error) {
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside ExternalDocs objects.
func (m *ExternalDocs) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
for _, item := range m.VendorExtension {
@@ -5828,6 +5901,7 @@ func (m *ExternalDocs) ResolveReferences(root string) (interface{}, error) {
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside FileSchema objects.
func (m *FileSchema) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
if m.Default != nil {
@@ -5859,6 +5933,7 @@ func (m *FileSchema) ResolveReferences(root string) (interface{}, error) {
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside FormDataParameterSubSchema objects.
func (m *FormDataParameterSubSchema) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
if m.Items != nil {
@@ -5892,6 +5967,7 @@ func (m *FormDataParameterSubSchema) ResolveReferences(root string) (interface{}
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside Header objects.
func (m *Header) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
if m.Items != nil {
@@ -5925,6 +6001,7 @@ func (m *Header) ResolveReferences(root string) (interface{}, error) {
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside HeaderParameterSubSchema objects.
func (m *HeaderParameterSubSchema) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
if m.Items != nil {
@@ -5958,6 +6035,7 @@ func (m *HeaderParameterSubSchema) ResolveReferences(root string) (interface{},
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside Headers objects.
func (m *Headers) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
for _, item := range m.AdditionalProperties {
@@ -5971,6 +6049,7 @@ func (m *Headers) ResolveReferences(root string) (interface{}, error) {
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside Info objects.
func (m *Info) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
if m.Contact != nil {
@@ -5996,6 +6075,7 @@ func (m *Info) ResolveReferences(root string) (interface{}, error) {
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside ItemsItem objects.
func (m *ItemsItem) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
for _, item := range m.Schema {
@@ -6009,6 +6089,7 @@ func (m *ItemsItem) ResolveReferences(root string) (interface{}, error) {
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside JsonReference objects.
func (m *JsonReference) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
if m.XRef != "" {
@@ -6028,6 +6109,7 @@ func (m *JsonReference) ResolveReferences(root string) (interface{}, error) {
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside License objects.
func (m *License) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
for _, item := range m.VendorExtension {
@@ -6041,6 +6123,7 @@ func (m *License) ResolveReferences(root string) (interface{}, error) {
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside NamedAny objects.
func (m *NamedAny) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
if m.Value != nil {
@@ -6052,6 +6135,7 @@ func (m *NamedAny) ResolveReferences(root string) (interface{}, error) {
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside NamedHeader objects.
func (m *NamedHeader) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
if m.Value != nil {
@@ -6063,6 +6147,7 @@ func (m *NamedHeader) ResolveReferences(root string) (interface{}, error) {
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside NamedParameter objects.
func (m *NamedParameter) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
if m.Value != nil {
@@ -6074,6 +6159,7 @@ func (m *NamedParameter) ResolveReferences(root string) (interface{}, error) {
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside NamedPathItem objects.
func (m *NamedPathItem) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
if m.Value != nil {
@@ -6085,6 +6171,7 @@ func (m *NamedPathItem) ResolveReferences(root string) (interface{}, error) {
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside NamedResponse objects.
func (m *NamedResponse) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
if m.Value != nil {
@@ -6096,6 +6183,7 @@ func (m *NamedResponse) ResolveReferences(root string) (interface{}, error) {
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside NamedResponseValue objects.
func (m *NamedResponseValue) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
if m.Value != nil {
@@ -6107,6 +6195,7 @@ func (m *NamedResponseValue) ResolveReferences(root string) (interface{}, error)
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside NamedSchema objects.
func (m *NamedSchema) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
if m.Value != nil {
@@ -6118,6 +6207,7 @@ func (m *NamedSchema) ResolveReferences(root string) (interface{}, error) {
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside NamedSecurityDefinitionsItem objects.
func (m *NamedSecurityDefinitionsItem) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
if m.Value != nil {
@@ -6129,11 +6219,13 @@ func (m *NamedSecurityDefinitionsItem) ResolveReferences(root string) (interface
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside NamedString objects.
func (m *NamedString) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside NamedStringArray objects.
func (m *NamedStringArray) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
if m.Value != nil {
@@ -6145,6 +6237,7 @@ func (m *NamedStringArray) ResolveReferences(root string) (interface{}, error) {
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside NonBodyParameter objects.
func (m *NonBodyParameter) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
{
@@ -6186,6 +6279,7 @@ func (m *NonBodyParameter) ResolveReferences(root string) (interface{}, error) {
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside Oauth2AccessCodeSecurity objects.
func (m *Oauth2AccessCodeSecurity) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
if m.Scopes != nil {
@@ -6205,6 +6299,7 @@ func (m *Oauth2AccessCodeSecurity) ResolveReferences(root string) (interface{},
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside Oauth2ApplicationSecurity objects.
func (m *Oauth2ApplicationSecurity) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
if m.Scopes != nil {
@@ -6224,6 +6319,7 @@ func (m *Oauth2ApplicationSecurity) ResolveReferences(root string) (interface{},
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside Oauth2ImplicitSecurity objects.
func (m *Oauth2ImplicitSecurity) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
if m.Scopes != nil {
@@ -6243,6 +6339,7 @@ func (m *Oauth2ImplicitSecurity) ResolveReferences(root string) (interface{}, er
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside Oauth2PasswordSecurity objects.
func (m *Oauth2PasswordSecurity) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
if m.Scopes != nil {
@@ -6262,6 +6359,7 @@ func (m *Oauth2PasswordSecurity) ResolveReferences(root string) (interface{}, er
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside Oauth2Scopes objects.
func (m *Oauth2Scopes) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
for _, item := range m.AdditionalProperties {
@@ -6275,6 +6373,7 @@ func (m *Oauth2Scopes) ResolveReferences(root string) (interface{}, error) {
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside Operation objects.
func (m *Operation) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
if m.ExternalDocs != nil {
@@ -6316,6 +6415,7 @@ func (m *Operation) ResolveReferences(root string) (interface{}, error) {
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside Parameter objects.
func (m *Parameter) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
{
@@ -6339,6 +6439,7 @@ func (m *Parameter) ResolveReferences(root string) (interface{}, error) {
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside ParameterDefinitions objects.
func (m *ParameterDefinitions) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
for _, item := range m.AdditionalProperties {
@@ -6352,6 +6453,7 @@ func (m *ParameterDefinitions) ResolveReferences(root string) (interface{}, erro
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside ParametersItem objects.
func (m *ParametersItem) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
{
@@ -6383,6 +6485,7 @@ func (m *ParametersItem) ResolveReferences(root string) (interface{}, error) {
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside PathItem objects.
func (m *PathItem) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
if m.XRef != "" {
@@ -6460,6 +6563,7 @@ func (m *PathItem) ResolveReferences(root string) (interface{}, error) {
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside PathParameterSubSchema objects.
func (m *PathParameterSubSchema) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
if m.Items != nil {
@@ -6493,6 +6597,7 @@ func (m *PathParameterSubSchema) ResolveReferences(root string) (interface{}, er
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside Paths objects.
func (m *Paths) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
for _, item := range m.VendorExtension {
@@ -6514,6 +6619,7 @@ func (m *Paths) ResolveReferences(root string) (interface{}, error) {
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside PrimitivesItems objects.
func (m *PrimitivesItems) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
if m.Items != nil {
@@ -6547,6 +6653,7 @@ func (m *PrimitivesItems) ResolveReferences(root string) (interface{}, error) {
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside Properties objects.
func (m *Properties) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
for _, item := range m.AdditionalProperties {
@@ -6560,6 +6667,7 @@ func (m *Properties) ResolveReferences(root string) (interface{}, error) {
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside QueryParameterSubSchema objects.
func (m *QueryParameterSubSchema) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
if m.Items != nil {
@@ -6593,6 +6701,7 @@ func (m *QueryParameterSubSchema) ResolveReferences(root string) (interface{}, e
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside Response objects.
func (m *Response) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
if m.Schema != nil {
@@ -6624,6 +6733,7 @@ func (m *Response) ResolveReferences(root string) (interface{}, error) {
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside ResponseDefinitions objects.
func (m *ResponseDefinitions) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
for _, item := range m.AdditionalProperties {
@@ -6637,6 +6747,7 @@ func (m *ResponseDefinitions) ResolveReferences(root string) (interface{}, error
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside ResponseValue objects.
func (m *ResponseValue) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
{
@@ -6668,6 +6779,7 @@ func (m *ResponseValue) ResolveReferences(root string) (interface{}, error) {
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside Responses objects.
func (m *Responses) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
for _, item := range m.ResponseCode {
@@ -6689,6 +6801,7 @@ func (m *Responses) ResolveReferences(root string) (interface{}, error) {
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside Schema objects.
func (m *Schema) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
if m.XRef != "" {
@@ -6780,6 +6893,7 @@ func (m *Schema) ResolveReferences(root string) (interface{}, error) {
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside SchemaItem objects.
func (m *SchemaItem) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
{
@@ -6803,6 +6917,7 @@ func (m *SchemaItem) ResolveReferences(root string) (interface{}, error) {
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside SecurityDefinitions objects.
func (m *SecurityDefinitions) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
for _, item := range m.AdditionalProperties {
@@ -6816,6 +6931,7 @@ func (m *SecurityDefinitions) ResolveReferences(root string) (interface{}, error
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside SecurityDefinitionsItem objects.
func (m *SecurityDefinitionsItem) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
{
@@ -6875,6 +6991,7 @@ func (m *SecurityDefinitionsItem) ResolveReferences(root string) (interface{}, e
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside SecurityRequirement objects.
func (m *SecurityRequirement) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
for _, item := range m.AdditionalProperties {
@@ -6888,11 +7005,13 @@ func (m *SecurityRequirement) ResolveReferences(root string) (interface{}, error
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside StringArray objects.
func (m *StringArray) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside Tag objects.
func (m *Tag) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
if m.ExternalDocs != nil {
@@ -6912,11 +7031,13 @@ func (m *Tag) ResolveReferences(root string) (interface{}, error) {
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside TypeItem objects.
func (m *TypeItem) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside VendorExtension objects.
func (m *VendorExtension) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
for _, item := range m.AdditionalProperties {
@@ -6930,6 +7051,7 @@ func (m *VendorExtension) ResolveReferences(root string) (interface{}, error) {
return nil, compiler.NewErrorGroupOrNil(errors)
}
+// ResolveReferences resolves references found inside Xml objects.
func (m *Xml) ResolveReferences(root string) (interface{}, error) {
errors := make([]error, 0)
for _, item := range m.VendorExtension {
@@ -6942,3 +7064,1665 @@ func (m *Xml) ResolveReferences(root string) (interface{}, error) {
}
return nil, compiler.NewErrorGroupOrNil(errors)
}
+
+// ToRawInfo returns a description of AdditionalPropertiesItem suitable for JSON or YAML export.
+func (m *AdditionalPropertiesItem) ToRawInfo() interface{} {
+ // ONE OF WRAPPER
+ // AdditionalPropertiesItem
+ // {Name:schema Type:Schema StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ v0 := m.GetSchema()
+ if v0 != nil {
+ return v0.ToRawInfo()
+ }
+ // {Name:boolean Type:bool StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ if v1, ok := m.GetOneof().(*AdditionalPropertiesItem_Boolean); ok {
+ return v1.Boolean
+ }
+ return nil
+}
+
+// ToRawInfo returns a description of Any suitable for JSON or YAML export.
+func (m *Any) ToRawInfo() interface{} {
+ var err error
+ var info1 []yaml.MapSlice
+ err = yaml.Unmarshal([]byte(m.Yaml), &info1)
+ if err == nil {
+ return info1
+ }
+ var info2 yaml.MapSlice
+ err = yaml.Unmarshal([]byte(m.Yaml), &info2)
+ if err == nil {
+ return info2
+ }
+ var info3 interface{}
+ err = yaml.Unmarshal([]byte(m.Yaml), &info3)
+ if err == nil {
+ return info3
+ }
+ return nil
+}
+
+// ToRawInfo returns a description of ApiKeySecurity suitable for JSON or YAML export.
+func (m *ApiKeySecurity) ToRawInfo() interface{} {
+ info := yaml.MapSlice{}
+ if m.Type != "" {
+ info = append(info, yaml.MapItem{"type", m.Type})
+ }
+ if m.Name != "" {
+ info = append(info, yaml.MapItem{"name", m.Name})
+ }
+ if m.In != "" {
+ info = append(info, yaml.MapItem{"in", m.In})
+ }
+ if m.Description != "" {
+ info = append(info, yaml.MapItem{"description", m.Description})
+ }
+ if m.VendorExtension != nil {
+ for _, item := range m.VendorExtension {
+ info = append(info, yaml.MapItem{item.Name, item.Value.ToRawInfo()})
+ }
+ }
+ // &{Name:VendorExtension Type:NamedAny StringEnumValues:[] MapType:Any Repeated:true Pattern:^x- Implicit:true Description:}
+ return info
+}
+
+// ToRawInfo returns a description of BasicAuthenticationSecurity suitable for JSON or YAML export.
+func (m *BasicAuthenticationSecurity) ToRawInfo() interface{} {
+ info := yaml.MapSlice{}
+ if m.Type != "" {
+ info = append(info, yaml.MapItem{"type", m.Type})
+ }
+ if m.Description != "" {
+ info = append(info, yaml.MapItem{"description", m.Description})
+ }
+ if m.VendorExtension != nil {
+ for _, item := range m.VendorExtension {
+ info = append(info, yaml.MapItem{item.Name, item.Value.ToRawInfo()})
+ }
+ }
+ // &{Name:VendorExtension Type:NamedAny StringEnumValues:[] MapType:Any Repeated:true Pattern:^x- Implicit:true Description:}
+ return info
+}
+
+// ToRawInfo returns a description of BodyParameter suitable for JSON or YAML export.
+func (m *BodyParameter) ToRawInfo() interface{} {
+ info := yaml.MapSlice{}
+ if m.Description != "" {
+ info = append(info, yaml.MapItem{"description", m.Description})
+ }
+ if m.Name != "" {
+ info = append(info, yaml.MapItem{"name", m.Name})
+ }
+ if m.In != "" {
+ info = append(info, yaml.MapItem{"in", m.In})
+ }
+ if m.Required != false {
+ info = append(info, yaml.MapItem{"required", m.Required})
+ }
+ if m.Schema != nil {
+ info = append(info, yaml.MapItem{"schema", m.Schema.ToRawInfo()})
+ }
+ // &{Name:schema Type:Schema StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ if m.VendorExtension != nil {
+ for _, item := range m.VendorExtension {
+ info = append(info, yaml.MapItem{item.Name, item.Value.ToRawInfo()})
+ }
+ }
+ // &{Name:VendorExtension Type:NamedAny StringEnumValues:[] MapType:Any Repeated:true Pattern:^x- Implicit:true Description:}
+ return info
+}
+
+// ToRawInfo returns a description of Contact suitable for JSON or YAML export.
+func (m *Contact) ToRawInfo() interface{} {
+ info := yaml.MapSlice{}
+ if m.Name != "" {
+ info = append(info, yaml.MapItem{"name", m.Name})
+ }
+ if m.Url != "" {
+ info = append(info, yaml.MapItem{"url", m.Url})
+ }
+ if m.Email != "" {
+ info = append(info, yaml.MapItem{"email", m.Email})
+ }
+ if m.VendorExtension != nil {
+ for _, item := range m.VendorExtension {
+ info = append(info, yaml.MapItem{item.Name, item.Value.ToRawInfo()})
+ }
+ }
+ // &{Name:VendorExtension Type:NamedAny StringEnumValues:[] MapType:Any Repeated:true Pattern:^x- Implicit:true Description:}
+ return info
+}
+
+// ToRawInfo returns a description of Default suitable for JSON or YAML export.
+func (m *Default) ToRawInfo() interface{} {
+ info := yaml.MapSlice{}
+ if m.AdditionalProperties != nil {
+ for _, item := range m.AdditionalProperties {
+ info = append(info, yaml.MapItem{item.Name, item.Value.ToRawInfo()})
+ }
+ }
+ // &{Name:additionalProperties Type:NamedAny StringEnumValues:[] MapType:Any Repeated:true Pattern: Implicit:false Description:}
+ return info
+}
+
+// ToRawInfo returns a description of Definitions suitable for JSON or YAML export.
+func (m *Definitions) ToRawInfo() interface{} {
+ info := yaml.MapSlice{}
+ if m.AdditionalProperties != nil {
+ for _, item := range m.AdditionalProperties {
+ info = append(info, yaml.MapItem{item.Name, item.Value.ToRawInfo()})
+ }
+ }
+ // &{Name:additionalProperties Type:NamedSchema StringEnumValues:[] MapType:Schema Repeated:true Pattern: Implicit:true Description:}
+ return info
+}
+
+// ToRawInfo returns a description of Document suitable for JSON or YAML export.
+func (m *Document) ToRawInfo() interface{} {
+ info := yaml.MapSlice{}
+ if m.Swagger != "" {
+ info = append(info, yaml.MapItem{"swagger", m.Swagger})
+ }
+ if m.Info != nil {
+ info = append(info, yaml.MapItem{"info", m.Info.ToRawInfo()})
+ }
+ // &{Name:info Type:Info StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ if m.Host != "" {
+ info = append(info, yaml.MapItem{"host", m.Host})
+ }
+ if m.BasePath != "" {
+ info = append(info, yaml.MapItem{"basePath", m.BasePath})
+ }
+ if len(m.Schemes) != 0 {
+ info = append(info, yaml.MapItem{"schemes", m.Schemes})
+ }
+ if len(m.Consumes) != 0 {
+ info = append(info, yaml.MapItem{"consumes", m.Consumes})
+ }
+ if len(m.Produces) != 0 {
+ info = append(info, yaml.MapItem{"produces", m.Produces})
+ }
+ if m.Paths != nil {
+ info = append(info, yaml.MapItem{"paths", m.Paths.ToRawInfo()})
+ }
+ // &{Name:paths Type:Paths StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ if m.Definitions != nil {
+ info = append(info, yaml.MapItem{"definitions", m.Definitions.ToRawInfo()})
+ }
+ // &{Name:definitions Type:Definitions StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ if m.Parameters != nil {
+ info = append(info, yaml.MapItem{"parameters", m.Parameters.ToRawInfo()})
+ }
+ // &{Name:parameters Type:ParameterDefinitions StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ if m.Responses != nil {
+ info = append(info, yaml.MapItem{"responses", m.Responses.ToRawInfo()})
+ }
+ // &{Name:responses Type:ResponseDefinitions StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ if len(m.Security) != 0 {
+ items := make([]interface{}, 0)
+ for _, item := range m.Security {
+ items = append(items, item.ToRawInfo())
+ }
+ info = append(info, yaml.MapItem{"security", items})
+ }
+ // &{Name:security Type:SecurityRequirement StringEnumValues:[] MapType: Repeated:true Pattern: Implicit:false Description:}
+ if m.SecurityDefinitions != nil {
+ info = append(info, yaml.MapItem{"securityDefinitions", m.SecurityDefinitions.ToRawInfo()})
+ }
+ // &{Name:securityDefinitions Type:SecurityDefinitions StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ if len(m.Tags) != 0 {
+ items := make([]interface{}, 0)
+ for _, item := range m.Tags {
+ items = append(items, item.ToRawInfo())
+ }
+ info = append(info, yaml.MapItem{"tags", items})
+ }
+ // &{Name:tags Type:Tag StringEnumValues:[] MapType: Repeated:true Pattern: Implicit:false Description:}
+ if m.ExternalDocs != nil {
+ info = append(info, yaml.MapItem{"externalDocs", m.ExternalDocs.ToRawInfo()})
+ }
+ // &{Name:externalDocs Type:ExternalDocs StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ if m.VendorExtension != nil {
+ for _, item := range m.VendorExtension {
+ info = append(info, yaml.MapItem{item.Name, item.Value.ToRawInfo()})
+ }
+ }
+ // &{Name:VendorExtension Type:NamedAny StringEnumValues:[] MapType:Any Repeated:true Pattern:^x- Implicit:true Description:}
+ return info
+}
+
+// ToRawInfo returns a description of Examples suitable for JSON or YAML export.
+func (m *Examples) ToRawInfo() interface{} {
+ info := yaml.MapSlice{}
+ if m.AdditionalProperties != nil {
+ for _, item := range m.AdditionalProperties {
+ info = append(info, yaml.MapItem{item.Name, item.Value.ToRawInfo()})
+ }
+ }
+ // &{Name:additionalProperties Type:NamedAny StringEnumValues:[] MapType:Any Repeated:true Pattern: Implicit:true Description:}
+ return info
+}
+
+// ToRawInfo returns a description of ExternalDocs suitable for JSON or YAML export.
+func (m *ExternalDocs) ToRawInfo() interface{} {
+ info := yaml.MapSlice{}
+ if m.Description != "" {
+ info = append(info, yaml.MapItem{"description", m.Description})
+ }
+ if m.Url != "" {
+ info = append(info, yaml.MapItem{"url", m.Url})
+ }
+ if m.VendorExtension != nil {
+ for _, item := range m.VendorExtension {
+ info = append(info, yaml.MapItem{item.Name, item.Value.ToRawInfo()})
+ }
+ }
+ // &{Name:VendorExtension Type:NamedAny StringEnumValues:[] MapType:Any Repeated:true Pattern:^x- Implicit:true Description:}
+ return info
+}
+
+// ToRawInfo returns a description of FileSchema suitable for JSON or YAML export.
+func (m *FileSchema) ToRawInfo() interface{} {
+ info := yaml.MapSlice{}
+ if m.Format != "" {
+ info = append(info, yaml.MapItem{"format", m.Format})
+ }
+ if m.Title != "" {
+ info = append(info, yaml.MapItem{"title", m.Title})
+ }
+ if m.Description != "" {
+ info = append(info, yaml.MapItem{"description", m.Description})
+ }
+ if m.Default != nil {
+ info = append(info, yaml.MapItem{"default", m.Default.ToRawInfo()})
+ }
+ // &{Name:default Type:Any StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ if len(m.Required) != 0 {
+ info = append(info, yaml.MapItem{"required", m.Required})
+ }
+ if m.Type != "" {
+ info = append(info, yaml.MapItem{"type", m.Type})
+ }
+ if m.ReadOnly != false {
+ info = append(info, yaml.MapItem{"readOnly", m.ReadOnly})
+ }
+ if m.ExternalDocs != nil {
+ info = append(info, yaml.MapItem{"externalDocs", m.ExternalDocs.ToRawInfo()})
+ }
+ // &{Name:externalDocs Type:ExternalDocs StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ if m.Example != nil {
+ info = append(info, yaml.MapItem{"example", m.Example.ToRawInfo()})
+ }
+ // &{Name:example Type:Any StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ if m.VendorExtension != nil {
+ for _, item := range m.VendorExtension {
+ info = append(info, yaml.MapItem{item.Name, item.Value.ToRawInfo()})
+ }
+ }
+ // &{Name:VendorExtension Type:NamedAny StringEnumValues:[] MapType:Any Repeated:true Pattern:^x- Implicit:true Description:}
+ return info
+}
+
+// ToRawInfo returns a description of FormDataParameterSubSchema suitable for JSON or YAML export.
+func (m *FormDataParameterSubSchema) ToRawInfo() interface{} {
+ info := yaml.MapSlice{}
+ if m.Required != false {
+ info = append(info, yaml.MapItem{"required", m.Required})
+ }
+ if m.In != "" {
+ info = append(info, yaml.MapItem{"in", m.In})
+ }
+ if m.Description != "" {
+ info = append(info, yaml.MapItem{"description", m.Description})
+ }
+ if m.Name != "" {
+ info = append(info, yaml.MapItem{"name", m.Name})
+ }
+ if m.AllowEmptyValue != false {
+ info = append(info, yaml.MapItem{"allowEmptyValue", m.AllowEmptyValue})
+ }
+ if m.Type != "" {
+ info = append(info, yaml.MapItem{"type", m.Type})
+ }
+ if m.Format != "" {
+ info = append(info, yaml.MapItem{"format", m.Format})
+ }
+ if m.Items != nil {
+ info = append(info, yaml.MapItem{"items", m.Items.ToRawInfo()})
+ }
+ // &{Name:items Type:PrimitivesItems StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ if m.CollectionFormat != "" {
+ info = append(info, yaml.MapItem{"collectionFormat", m.CollectionFormat})
+ }
+ if m.Default != nil {
+ info = append(info, yaml.MapItem{"default", m.Default.ToRawInfo()})
+ }
+ // &{Name:default Type:Any StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ if m.Maximum != 0.0 {
+ info = append(info, yaml.MapItem{"maximum", m.Maximum})
+ }
+ if m.ExclusiveMaximum != false {
+ info = append(info, yaml.MapItem{"exclusiveMaximum", m.ExclusiveMaximum})
+ }
+ if m.Minimum != 0.0 {
+ info = append(info, yaml.MapItem{"minimum", m.Minimum})
+ }
+ if m.ExclusiveMinimum != false {
+ info = append(info, yaml.MapItem{"exclusiveMinimum", m.ExclusiveMinimum})
+ }
+ if m.MaxLength != 0 {
+ info = append(info, yaml.MapItem{"maxLength", m.MaxLength})
+ }
+ if m.MinLength != 0 {
+ info = append(info, yaml.MapItem{"minLength", m.MinLength})
+ }
+ if m.Pattern != "" {
+ info = append(info, yaml.MapItem{"pattern", m.Pattern})
+ }
+ if m.MaxItems != 0 {
+ info = append(info, yaml.MapItem{"maxItems", m.MaxItems})
+ }
+ if m.MinItems != 0 {
+ info = append(info, yaml.MapItem{"minItems", m.MinItems})
+ }
+ if m.UniqueItems != false {
+ info = append(info, yaml.MapItem{"uniqueItems", m.UniqueItems})
+ }
+ if len(m.Enum) != 0 {
+ items := make([]interface{}, 0)
+ for _, item := range m.Enum {
+ items = append(items, item.ToRawInfo())
+ }
+ info = append(info, yaml.MapItem{"enum", items})
+ }
+ // &{Name:enum Type:Any StringEnumValues:[] MapType: Repeated:true Pattern: Implicit:false Description:}
+ if m.MultipleOf != 0.0 {
+ info = append(info, yaml.MapItem{"multipleOf", m.MultipleOf})
+ }
+ if m.VendorExtension != nil {
+ for _, item := range m.VendorExtension {
+ info = append(info, yaml.MapItem{item.Name, item.Value.ToRawInfo()})
+ }
+ }
+ // &{Name:VendorExtension Type:NamedAny StringEnumValues:[] MapType:Any Repeated:true Pattern:^x- Implicit:true Description:}
+ return info
+}
+
+// ToRawInfo returns a description of Header suitable for JSON or YAML export.
+func (m *Header) ToRawInfo() interface{} {
+ info := yaml.MapSlice{}
+ if m.Type != "" {
+ info = append(info, yaml.MapItem{"type", m.Type})
+ }
+ if m.Format != "" {
+ info = append(info, yaml.MapItem{"format", m.Format})
+ }
+ if m.Items != nil {
+ info = append(info, yaml.MapItem{"items", m.Items.ToRawInfo()})
+ }
+ // &{Name:items Type:PrimitivesItems StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ if m.CollectionFormat != "" {
+ info = append(info, yaml.MapItem{"collectionFormat", m.CollectionFormat})
+ }
+ if m.Default != nil {
+ info = append(info, yaml.MapItem{"default", m.Default.ToRawInfo()})
+ }
+ // &{Name:default Type:Any StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ if m.Maximum != 0.0 {
+ info = append(info, yaml.MapItem{"maximum", m.Maximum})
+ }
+ if m.ExclusiveMaximum != false {
+ info = append(info, yaml.MapItem{"exclusiveMaximum", m.ExclusiveMaximum})
+ }
+ if m.Minimum != 0.0 {
+ info = append(info, yaml.MapItem{"minimum", m.Minimum})
+ }
+ if m.ExclusiveMinimum != false {
+ info = append(info, yaml.MapItem{"exclusiveMinimum", m.ExclusiveMinimum})
+ }
+ if m.MaxLength != 0 {
+ info = append(info, yaml.MapItem{"maxLength", m.MaxLength})
+ }
+ if m.MinLength != 0 {
+ info = append(info, yaml.MapItem{"minLength", m.MinLength})
+ }
+ if m.Pattern != "" {
+ info = append(info, yaml.MapItem{"pattern", m.Pattern})
+ }
+ if m.MaxItems != 0 {
+ info = append(info, yaml.MapItem{"maxItems", m.MaxItems})
+ }
+ if m.MinItems != 0 {
+ info = append(info, yaml.MapItem{"minItems", m.MinItems})
+ }
+ if m.UniqueItems != false {
+ info = append(info, yaml.MapItem{"uniqueItems", m.UniqueItems})
+ }
+ if len(m.Enum) != 0 {
+ items := make([]interface{}, 0)
+ for _, item := range m.Enum {
+ items = append(items, item.ToRawInfo())
+ }
+ info = append(info, yaml.MapItem{"enum", items})
+ }
+ // &{Name:enum Type:Any StringEnumValues:[] MapType: Repeated:true Pattern: Implicit:false Description:}
+ if m.MultipleOf != 0.0 {
+ info = append(info, yaml.MapItem{"multipleOf", m.MultipleOf})
+ }
+ if m.Description != "" {
+ info = append(info, yaml.MapItem{"description", m.Description})
+ }
+ if m.VendorExtension != nil {
+ for _, item := range m.VendorExtension {
+ info = append(info, yaml.MapItem{item.Name, item.Value.ToRawInfo()})
+ }
+ }
+ // &{Name:VendorExtension Type:NamedAny StringEnumValues:[] MapType:Any Repeated:true Pattern:^x- Implicit:true Description:}
+ return info
+}
+
+// ToRawInfo returns a description of HeaderParameterSubSchema suitable for JSON or YAML export.
+func (m *HeaderParameterSubSchema) ToRawInfo() interface{} {
+ info := yaml.MapSlice{}
+ if m.Required != false {
+ info = append(info, yaml.MapItem{"required", m.Required})
+ }
+ if m.In != "" {
+ info = append(info, yaml.MapItem{"in", m.In})
+ }
+ if m.Description != "" {
+ info = append(info, yaml.MapItem{"description", m.Description})
+ }
+ if m.Name != "" {
+ info = append(info, yaml.MapItem{"name", m.Name})
+ }
+ if m.Type != "" {
+ info = append(info, yaml.MapItem{"type", m.Type})
+ }
+ if m.Format != "" {
+ info = append(info, yaml.MapItem{"format", m.Format})
+ }
+ if m.Items != nil {
+ info = append(info, yaml.MapItem{"items", m.Items.ToRawInfo()})
+ }
+ // &{Name:items Type:PrimitivesItems StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ if m.CollectionFormat != "" {
+ info = append(info, yaml.MapItem{"collectionFormat", m.CollectionFormat})
+ }
+ if m.Default != nil {
+ info = append(info, yaml.MapItem{"default", m.Default.ToRawInfo()})
+ }
+ // &{Name:default Type:Any StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ if m.Maximum != 0.0 {
+ info = append(info, yaml.MapItem{"maximum", m.Maximum})
+ }
+ if m.ExclusiveMaximum != false {
+ info = append(info, yaml.MapItem{"exclusiveMaximum", m.ExclusiveMaximum})
+ }
+ if m.Minimum != 0.0 {
+ info = append(info, yaml.MapItem{"minimum", m.Minimum})
+ }
+ if m.ExclusiveMinimum != false {
+ info = append(info, yaml.MapItem{"exclusiveMinimum", m.ExclusiveMinimum})
+ }
+ if m.MaxLength != 0 {
+ info = append(info, yaml.MapItem{"maxLength", m.MaxLength})
+ }
+ if m.MinLength != 0 {
+ info = append(info, yaml.MapItem{"minLength", m.MinLength})
+ }
+ if m.Pattern != "" {
+ info = append(info, yaml.MapItem{"pattern", m.Pattern})
+ }
+ if m.MaxItems != 0 {
+ info = append(info, yaml.MapItem{"maxItems", m.MaxItems})
+ }
+ if m.MinItems != 0 {
+ info = append(info, yaml.MapItem{"minItems", m.MinItems})
+ }
+ if m.UniqueItems != false {
+ info = append(info, yaml.MapItem{"uniqueItems", m.UniqueItems})
+ }
+ if len(m.Enum) != 0 {
+ items := make([]interface{}, 0)
+ for _, item := range m.Enum {
+ items = append(items, item.ToRawInfo())
+ }
+ info = append(info, yaml.MapItem{"enum", items})
+ }
+ // &{Name:enum Type:Any StringEnumValues:[] MapType: Repeated:true Pattern: Implicit:false Description:}
+ if m.MultipleOf != 0.0 {
+ info = append(info, yaml.MapItem{"multipleOf", m.MultipleOf})
+ }
+ if m.VendorExtension != nil {
+ for _, item := range m.VendorExtension {
+ info = append(info, yaml.MapItem{item.Name, item.Value.ToRawInfo()})
+ }
+ }
+ // &{Name:VendorExtension Type:NamedAny StringEnumValues:[] MapType:Any Repeated:true Pattern:^x- Implicit:true Description:}
+ return info
+}
+
+// ToRawInfo returns a description of Headers suitable for JSON or YAML export.
+func (m *Headers) ToRawInfo() interface{} {
+ info := yaml.MapSlice{}
+ if m.AdditionalProperties != nil {
+ for _, item := range m.AdditionalProperties {
+ info = append(info, yaml.MapItem{item.Name, item.Value.ToRawInfo()})
+ }
+ }
+ // &{Name:additionalProperties Type:NamedHeader StringEnumValues:[] MapType:Header Repeated:true Pattern: Implicit:true Description:}
+ return info
+}
+
+// ToRawInfo returns a description of Info suitable for JSON or YAML export.
+func (m *Info) ToRawInfo() interface{} {
+ info := yaml.MapSlice{}
+ if m.Title != "" {
+ info = append(info, yaml.MapItem{"title", m.Title})
+ }
+ if m.Version != "" {
+ info = append(info, yaml.MapItem{"version", m.Version})
+ }
+ if m.Description != "" {
+ info = append(info, yaml.MapItem{"description", m.Description})
+ }
+ if m.TermsOfService != "" {
+ info = append(info, yaml.MapItem{"termsOfService", m.TermsOfService})
+ }
+ if m.Contact != nil {
+ info = append(info, yaml.MapItem{"contact", m.Contact.ToRawInfo()})
+ }
+ // &{Name:contact Type:Contact StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ if m.License != nil {
+ info = append(info, yaml.MapItem{"license", m.License.ToRawInfo()})
+ }
+ // &{Name:license Type:License StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ if m.VendorExtension != nil {
+ for _, item := range m.VendorExtension {
+ info = append(info, yaml.MapItem{item.Name, item.Value.ToRawInfo()})
+ }
+ }
+ // &{Name:VendorExtension Type:NamedAny StringEnumValues:[] MapType:Any Repeated:true Pattern:^x- Implicit:true Description:}
+ return info
+}
+
+// ToRawInfo returns a description of ItemsItem suitable for JSON or YAML export.
+func (m *ItemsItem) ToRawInfo() interface{} {
+ info := yaml.MapSlice{}
+ if len(m.Schema) != 0 {
+ items := make([]interface{}, 0)
+ for _, item := range m.Schema {
+ items = append(items, item.ToRawInfo())
+ }
+ info = append(info, yaml.MapItem{"schema", items})
+ }
+ // &{Name:schema Type:Schema StringEnumValues:[] MapType: Repeated:true Pattern: Implicit:false Description:}
+ return info
+}
+
+// ToRawInfo returns a description of JsonReference suitable for JSON or YAML export.
+func (m *JsonReference) ToRawInfo() interface{} {
+ info := yaml.MapSlice{}
+ if m.XRef != "" {
+ info = append(info, yaml.MapItem{"$ref", m.XRef})
+ }
+ if m.Description != "" {
+ info = append(info, yaml.MapItem{"description", m.Description})
+ }
+ return info
+}
+
+// ToRawInfo returns a description of License suitable for JSON or YAML export.
+func (m *License) ToRawInfo() interface{} {
+ info := yaml.MapSlice{}
+ if m.Name != "" {
+ info = append(info, yaml.MapItem{"name", m.Name})
+ }
+ if m.Url != "" {
+ info = append(info, yaml.MapItem{"url", m.Url})
+ }
+ if m.VendorExtension != nil {
+ for _, item := range m.VendorExtension {
+ info = append(info, yaml.MapItem{item.Name, item.Value.ToRawInfo()})
+ }
+ }
+ // &{Name:VendorExtension Type:NamedAny StringEnumValues:[] MapType:Any Repeated:true Pattern:^x- Implicit:true Description:}
+ return info
+}
+
+// ToRawInfo returns a description of NamedAny suitable for JSON or YAML export.
+func (m *NamedAny) ToRawInfo() interface{} {
+ info := yaml.MapSlice{}
+ if m.Name != "" {
+ info = append(info, yaml.MapItem{"name", m.Name})
+ }
+ // &{Name:value Type:Any StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:Mapped value}
+ return info
+}
+
+// ToRawInfo returns a description of NamedHeader suitable for JSON or YAML export.
+func (m *NamedHeader) ToRawInfo() interface{} {
+ info := yaml.MapSlice{}
+ if m.Name != "" {
+ info = append(info, yaml.MapItem{"name", m.Name})
+ }
+ // &{Name:value Type:Header StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:Mapped value}
+ return info
+}
+
+// ToRawInfo returns a description of NamedParameter suitable for JSON or YAML export.
+func (m *NamedParameter) ToRawInfo() interface{} {
+ info := yaml.MapSlice{}
+ if m.Name != "" {
+ info = append(info, yaml.MapItem{"name", m.Name})
+ }
+ // &{Name:value Type:Parameter StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:Mapped value}
+ return info
+}
+
+// ToRawInfo returns a description of NamedPathItem suitable for JSON or YAML export.
+func (m *NamedPathItem) ToRawInfo() interface{} {
+ info := yaml.MapSlice{}
+ if m.Name != "" {
+ info = append(info, yaml.MapItem{"name", m.Name})
+ }
+ // &{Name:value Type:PathItem StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:Mapped value}
+ return info
+}
+
+// ToRawInfo returns a description of NamedResponse suitable for JSON or YAML export.
+func (m *NamedResponse) ToRawInfo() interface{} {
+ info := yaml.MapSlice{}
+ if m.Name != "" {
+ info = append(info, yaml.MapItem{"name", m.Name})
+ }
+ // &{Name:value Type:Response StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:Mapped value}
+ return info
+}
+
+// ToRawInfo returns a description of NamedResponseValue suitable for JSON or YAML export.
+func (m *NamedResponseValue) ToRawInfo() interface{} {
+ info := yaml.MapSlice{}
+ if m.Name != "" {
+ info = append(info, yaml.MapItem{"name", m.Name})
+ }
+ // &{Name:value Type:ResponseValue StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:Mapped value}
+ return info
+}
+
+// ToRawInfo returns a description of NamedSchema suitable for JSON or YAML export.
+func (m *NamedSchema) ToRawInfo() interface{} {
+ info := yaml.MapSlice{}
+ if m.Name != "" {
+ info = append(info, yaml.MapItem{"name", m.Name})
+ }
+ // &{Name:value Type:Schema StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:Mapped value}
+ return info
+}
+
+// ToRawInfo returns a description of NamedSecurityDefinitionsItem suitable for JSON or YAML export.
+func (m *NamedSecurityDefinitionsItem) ToRawInfo() interface{} {
+ info := yaml.MapSlice{}
+ if m.Name != "" {
+ info = append(info, yaml.MapItem{"name", m.Name})
+ }
+ // &{Name:value Type:SecurityDefinitionsItem StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:Mapped value}
+ return info
+}
+
+// ToRawInfo returns a description of NamedString suitable for JSON or YAML export.
+func (m *NamedString) ToRawInfo() interface{} {
+ info := yaml.MapSlice{}
+ if m.Name != "" {
+ info = append(info, yaml.MapItem{"name", m.Name})
+ }
+ if m.Value != "" {
+ info = append(info, yaml.MapItem{"value", m.Value})
+ }
+ return info
+}
+
+// ToRawInfo returns a description of NamedStringArray suitable for JSON or YAML export.
+func (m *NamedStringArray) ToRawInfo() interface{} {
+ info := yaml.MapSlice{}
+ if m.Name != "" {
+ info = append(info, yaml.MapItem{"name", m.Name})
+ }
+ // &{Name:value Type:StringArray StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:Mapped value}
+ return info
+}
+
+// ToRawInfo returns a description of NonBodyParameter suitable for JSON or YAML export.
+func (m *NonBodyParameter) ToRawInfo() interface{} {
+ // ONE OF WRAPPER
+ // NonBodyParameter
+ // {Name:headerParameterSubSchema Type:HeaderParameterSubSchema StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ v0 := m.GetHeaderParameterSubSchema()
+ if v0 != nil {
+ return v0.ToRawInfo()
+ }
+ // {Name:formDataParameterSubSchema Type:FormDataParameterSubSchema StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ v1 := m.GetFormDataParameterSubSchema()
+ if v1 != nil {
+ return v1.ToRawInfo()
+ }
+ // {Name:queryParameterSubSchema Type:QueryParameterSubSchema StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ v2 := m.GetQueryParameterSubSchema()
+ if v2 != nil {
+ return v2.ToRawInfo()
+ }
+ // {Name:pathParameterSubSchema Type:PathParameterSubSchema StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ v3 := m.GetPathParameterSubSchema()
+ if v3 != nil {
+ return v3.ToRawInfo()
+ }
+ return nil
+}
+
+// ToRawInfo returns a description of Oauth2AccessCodeSecurity suitable for JSON or YAML export.
+func (m *Oauth2AccessCodeSecurity) ToRawInfo() interface{} {
+ info := yaml.MapSlice{}
+ if m.Type != "" {
+ info = append(info, yaml.MapItem{"type", m.Type})
+ }
+ if m.Flow != "" {
+ info = append(info, yaml.MapItem{"flow", m.Flow})
+ }
+ if m.Scopes != nil {
+ info = append(info, yaml.MapItem{"scopes", m.Scopes.ToRawInfo()})
+ }
+ // &{Name:scopes Type:Oauth2Scopes StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ if m.AuthorizationUrl != "" {
+ info = append(info, yaml.MapItem{"authorizationUrl", m.AuthorizationUrl})
+ }
+ if m.TokenUrl != "" {
+ info = append(info, yaml.MapItem{"tokenUrl", m.TokenUrl})
+ }
+ if m.Description != "" {
+ info = append(info, yaml.MapItem{"description", m.Description})
+ }
+ if m.VendorExtension != nil {
+ for _, item := range m.VendorExtension {
+ info = append(info, yaml.MapItem{item.Name, item.Value.ToRawInfo()})
+ }
+ }
+ // &{Name:VendorExtension Type:NamedAny StringEnumValues:[] MapType:Any Repeated:true Pattern:^x- Implicit:true Description:}
+ return info
+}
+
+// ToRawInfo returns a description of Oauth2ApplicationSecurity suitable for JSON or YAML export.
+func (m *Oauth2ApplicationSecurity) ToRawInfo() interface{} {
+ info := yaml.MapSlice{}
+ if m.Type != "" {
+ info = append(info, yaml.MapItem{"type", m.Type})
+ }
+ if m.Flow != "" {
+ info = append(info, yaml.MapItem{"flow", m.Flow})
+ }
+ if m.Scopes != nil {
+ info = append(info, yaml.MapItem{"scopes", m.Scopes.ToRawInfo()})
+ }
+ // &{Name:scopes Type:Oauth2Scopes StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ if m.TokenUrl != "" {
+ info = append(info, yaml.MapItem{"tokenUrl", m.TokenUrl})
+ }
+ if m.Description != "" {
+ info = append(info, yaml.MapItem{"description", m.Description})
+ }
+ if m.VendorExtension != nil {
+ for _, item := range m.VendorExtension {
+ info = append(info, yaml.MapItem{item.Name, item.Value.ToRawInfo()})
+ }
+ }
+ // &{Name:VendorExtension Type:NamedAny StringEnumValues:[] MapType:Any Repeated:true Pattern:^x- Implicit:true Description:}
+ return info
+}
+
+// ToRawInfo returns a description of Oauth2ImplicitSecurity suitable for JSON or YAML export.
+func (m *Oauth2ImplicitSecurity) ToRawInfo() interface{} {
+ info := yaml.MapSlice{}
+ if m.Type != "" {
+ info = append(info, yaml.MapItem{"type", m.Type})
+ }
+ if m.Flow != "" {
+ info = append(info, yaml.MapItem{"flow", m.Flow})
+ }
+ if m.Scopes != nil {
+ info = append(info, yaml.MapItem{"scopes", m.Scopes.ToRawInfo()})
+ }
+ // &{Name:scopes Type:Oauth2Scopes StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ if m.AuthorizationUrl != "" {
+ info = append(info, yaml.MapItem{"authorizationUrl", m.AuthorizationUrl})
+ }
+ if m.Description != "" {
+ info = append(info, yaml.MapItem{"description", m.Description})
+ }
+ if m.VendorExtension != nil {
+ for _, item := range m.VendorExtension {
+ info = append(info, yaml.MapItem{item.Name, item.Value.ToRawInfo()})
+ }
+ }
+ // &{Name:VendorExtension Type:NamedAny StringEnumValues:[] MapType:Any Repeated:true Pattern:^x- Implicit:true Description:}
+ return info
+}
+
+// ToRawInfo returns a description of Oauth2PasswordSecurity suitable for JSON or YAML export.
+func (m *Oauth2PasswordSecurity) ToRawInfo() interface{} {
+ info := yaml.MapSlice{}
+ if m.Type != "" {
+ info = append(info, yaml.MapItem{"type", m.Type})
+ }
+ if m.Flow != "" {
+ info = append(info, yaml.MapItem{"flow", m.Flow})
+ }
+ if m.Scopes != nil {
+ info = append(info, yaml.MapItem{"scopes", m.Scopes.ToRawInfo()})
+ }
+ // &{Name:scopes Type:Oauth2Scopes StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ if m.TokenUrl != "" {
+ info = append(info, yaml.MapItem{"tokenUrl", m.TokenUrl})
+ }
+ if m.Description != "" {
+ info = append(info, yaml.MapItem{"description", m.Description})
+ }
+ if m.VendorExtension != nil {
+ for _, item := range m.VendorExtension {
+ info = append(info, yaml.MapItem{item.Name, item.Value.ToRawInfo()})
+ }
+ }
+ // &{Name:VendorExtension Type:NamedAny StringEnumValues:[] MapType:Any Repeated:true Pattern:^x- Implicit:true Description:}
+ return info
+}
+
+// ToRawInfo returns a description of Oauth2Scopes suitable for JSON or YAML export.
+func (m *Oauth2Scopes) ToRawInfo() interface{} {
+ info := yaml.MapSlice{}
+ // &{Name:additionalProperties Type:NamedString StringEnumValues:[] MapType:string Repeated:true Pattern: Implicit:true Description:}
+ return info
+}
+
+// ToRawInfo returns a description of Operation suitable for JSON or YAML export.
+func (m *Operation) ToRawInfo() interface{} {
+ info := yaml.MapSlice{}
+ if len(m.Tags) != 0 {
+ info = append(info, yaml.MapItem{"tags", m.Tags})
+ }
+ if m.Summary != "" {
+ info = append(info, yaml.MapItem{"summary", m.Summary})
+ }
+ if m.Description != "" {
+ info = append(info, yaml.MapItem{"description", m.Description})
+ }
+ if m.ExternalDocs != nil {
+ info = append(info, yaml.MapItem{"externalDocs", m.ExternalDocs.ToRawInfo()})
+ }
+ // &{Name:externalDocs Type:ExternalDocs StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ if m.OperationId != "" {
+ info = append(info, yaml.MapItem{"operationId", m.OperationId})
+ }
+ if len(m.Produces) != 0 {
+ info = append(info, yaml.MapItem{"produces", m.Produces})
+ }
+ if len(m.Consumes) != 0 {
+ info = append(info, yaml.MapItem{"consumes", m.Consumes})
+ }
+ if len(m.Parameters) != 0 {
+ items := make([]interface{}, 0)
+ for _, item := range m.Parameters {
+ items = append(items, item.ToRawInfo())
+ }
+ info = append(info, yaml.MapItem{"parameters", items})
+ }
+ // &{Name:parameters Type:ParametersItem StringEnumValues:[] MapType: Repeated:true Pattern: Implicit:false Description:The parameters needed to send a valid API call.}
+ if m.Responses != nil {
+ info = append(info, yaml.MapItem{"responses", m.Responses.ToRawInfo()})
+ }
+ // &{Name:responses Type:Responses StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ if len(m.Schemes) != 0 {
+ info = append(info, yaml.MapItem{"schemes", m.Schemes})
+ }
+ if m.Deprecated != false {
+ info = append(info, yaml.MapItem{"deprecated", m.Deprecated})
+ }
+ if len(m.Security) != 0 {
+ items := make([]interface{}, 0)
+ for _, item := range m.Security {
+ items = append(items, item.ToRawInfo())
+ }
+ info = append(info, yaml.MapItem{"security", items})
+ }
+ // &{Name:security Type:SecurityRequirement StringEnumValues:[] MapType: Repeated:true Pattern: Implicit:false Description:}
+ if m.VendorExtension != nil {
+ for _, item := range m.VendorExtension {
+ info = append(info, yaml.MapItem{item.Name, item.Value.ToRawInfo()})
+ }
+ }
+ // &{Name:VendorExtension Type:NamedAny StringEnumValues:[] MapType:Any Repeated:true Pattern:^x- Implicit:true Description:}
+ return info
+}
+
+// ToRawInfo returns a description of Parameter suitable for JSON or YAML export.
+func (m *Parameter) ToRawInfo() interface{} {
+ // ONE OF WRAPPER
+ // Parameter
+ // {Name:bodyParameter Type:BodyParameter StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ v0 := m.GetBodyParameter()
+ if v0 != nil {
+ return v0.ToRawInfo()
+ }
+ // {Name:nonBodyParameter Type:NonBodyParameter StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ v1 := m.GetNonBodyParameter()
+ if v1 != nil {
+ return v1.ToRawInfo()
+ }
+ return nil
+}
+
+// ToRawInfo returns a description of ParameterDefinitions suitable for JSON or YAML export.
+func (m *ParameterDefinitions) ToRawInfo() interface{} {
+ info := yaml.MapSlice{}
+ if m.AdditionalProperties != nil {
+ for _, item := range m.AdditionalProperties {
+ info = append(info, yaml.MapItem{item.Name, item.Value.ToRawInfo()})
+ }
+ }
+ // &{Name:additionalProperties Type:NamedParameter StringEnumValues:[] MapType:Parameter Repeated:true Pattern: Implicit:true Description:}
+ return info
+}
+
+// ToRawInfo returns a description of ParametersItem suitable for JSON or YAML export.
+func (m *ParametersItem) ToRawInfo() interface{} {
+ // ONE OF WRAPPER
+ // ParametersItem
+ // {Name:parameter Type:Parameter StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ v0 := m.GetParameter()
+ if v0 != nil {
+ return v0.ToRawInfo()
+ }
+ // {Name:jsonReference Type:JsonReference StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ v1 := m.GetJsonReference()
+ if v1 != nil {
+ return v1.ToRawInfo()
+ }
+ return nil
+}
+
+// ToRawInfo returns a description of PathItem suitable for JSON or YAML export.
+func (m *PathItem) ToRawInfo() interface{} {
+ info := yaml.MapSlice{}
+ if m.XRef != "" {
+ info = append(info, yaml.MapItem{"$ref", m.XRef})
+ }
+ if m.Get != nil {
+ info = append(info, yaml.MapItem{"get", m.Get.ToRawInfo()})
+ }
+ // &{Name:get Type:Operation StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ if m.Put != nil {
+ info = append(info, yaml.MapItem{"put", m.Put.ToRawInfo()})
+ }
+ // &{Name:put Type:Operation StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ if m.Post != nil {
+ info = append(info, yaml.MapItem{"post", m.Post.ToRawInfo()})
+ }
+ // &{Name:post Type:Operation StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ if m.Delete != nil {
+ info = append(info, yaml.MapItem{"delete", m.Delete.ToRawInfo()})
+ }
+ // &{Name:delete Type:Operation StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ if m.Options != nil {
+ info = append(info, yaml.MapItem{"options", m.Options.ToRawInfo()})
+ }
+ // &{Name:options Type:Operation StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ if m.Head != nil {
+ info = append(info, yaml.MapItem{"head", m.Head.ToRawInfo()})
+ }
+ // &{Name:head Type:Operation StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ if m.Patch != nil {
+ info = append(info, yaml.MapItem{"patch", m.Patch.ToRawInfo()})
+ }
+ // &{Name:patch Type:Operation StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ if len(m.Parameters) != 0 {
+ items := make([]interface{}, 0)
+ for _, item := range m.Parameters {
+ items = append(items, item.ToRawInfo())
+ }
+ info = append(info, yaml.MapItem{"parameters", items})
+ }
+ // &{Name:parameters Type:ParametersItem StringEnumValues:[] MapType: Repeated:true Pattern: Implicit:false Description:The parameters needed to send a valid API call.}
+ if m.VendorExtension != nil {
+ for _, item := range m.VendorExtension {
+ info = append(info, yaml.MapItem{item.Name, item.Value.ToRawInfo()})
+ }
+ }
+ // &{Name:VendorExtension Type:NamedAny StringEnumValues:[] MapType:Any Repeated:true Pattern:^x- Implicit:true Description:}
+ return info
+}
+
+// ToRawInfo returns a description of PathParameterSubSchema suitable for JSON or YAML export.
+func (m *PathParameterSubSchema) ToRawInfo() interface{} {
+ info := yaml.MapSlice{}
+ if m.Required != false {
+ info = append(info, yaml.MapItem{"required", m.Required})
+ }
+ if m.In != "" {
+ info = append(info, yaml.MapItem{"in", m.In})
+ }
+ if m.Description != "" {
+ info = append(info, yaml.MapItem{"description", m.Description})
+ }
+ if m.Name != "" {
+ info = append(info, yaml.MapItem{"name", m.Name})
+ }
+ if m.Type != "" {
+ info = append(info, yaml.MapItem{"type", m.Type})
+ }
+ if m.Format != "" {
+ info = append(info, yaml.MapItem{"format", m.Format})
+ }
+ if m.Items != nil {
+ info = append(info, yaml.MapItem{"items", m.Items.ToRawInfo()})
+ }
+ // &{Name:items Type:PrimitivesItems StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ if m.CollectionFormat != "" {
+ info = append(info, yaml.MapItem{"collectionFormat", m.CollectionFormat})
+ }
+ if m.Default != nil {
+ info = append(info, yaml.MapItem{"default", m.Default.ToRawInfo()})
+ }
+ // &{Name:default Type:Any StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ if m.Maximum != 0.0 {
+ info = append(info, yaml.MapItem{"maximum", m.Maximum})
+ }
+ if m.ExclusiveMaximum != false {
+ info = append(info, yaml.MapItem{"exclusiveMaximum", m.ExclusiveMaximum})
+ }
+ if m.Minimum != 0.0 {
+ info = append(info, yaml.MapItem{"minimum", m.Minimum})
+ }
+ if m.ExclusiveMinimum != false {
+ info = append(info, yaml.MapItem{"exclusiveMinimum", m.ExclusiveMinimum})
+ }
+ if m.MaxLength != 0 {
+ info = append(info, yaml.MapItem{"maxLength", m.MaxLength})
+ }
+ if m.MinLength != 0 {
+ info = append(info, yaml.MapItem{"minLength", m.MinLength})
+ }
+ if m.Pattern != "" {
+ info = append(info, yaml.MapItem{"pattern", m.Pattern})
+ }
+ if m.MaxItems != 0 {
+ info = append(info, yaml.MapItem{"maxItems", m.MaxItems})
+ }
+ if m.MinItems != 0 {
+ info = append(info, yaml.MapItem{"minItems", m.MinItems})
+ }
+ if m.UniqueItems != false {
+ info = append(info, yaml.MapItem{"uniqueItems", m.UniqueItems})
+ }
+ if len(m.Enum) != 0 {
+ items := make([]interface{}, 0)
+ for _, item := range m.Enum {
+ items = append(items, item.ToRawInfo())
+ }
+ info = append(info, yaml.MapItem{"enum", items})
+ }
+ // &{Name:enum Type:Any StringEnumValues:[] MapType: Repeated:true Pattern: Implicit:false Description:}
+ if m.MultipleOf != 0.0 {
+ info = append(info, yaml.MapItem{"multipleOf", m.MultipleOf})
+ }
+ if m.VendorExtension != nil {
+ for _, item := range m.VendorExtension {
+ info = append(info, yaml.MapItem{item.Name, item.Value.ToRawInfo()})
+ }
+ }
+ // &{Name:VendorExtension Type:NamedAny StringEnumValues:[] MapType:Any Repeated:true Pattern:^x- Implicit:true Description:}
+ return info
+}
+
+// ToRawInfo returns a description of Paths suitable for JSON or YAML export.
+func (m *Paths) ToRawInfo() interface{} {
+ info := yaml.MapSlice{}
+ if m.VendorExtension != nil {
+ for _, item := range m.VendorExtension {
+ info = append(info, yaml.MapItem{item.Name, item.Value.ToRawInfo()})
+ }
+ }
+ // &{Name:VendorExtension Type:NamedAny StringEnumValues:[] MapType:Any Repeated:true Pattern:^x- Implicit:true Description:}
+ if m.Path != nil {
+ for _, item := range m.Path {
+ info = append(info, yaml.MapItem{item.Name, item.Value.ToRawInfo()})
+ }
+ }
+ // &{Name:Path Type:NamedPathItem StringEnumValues:[] MapType:PathItem Repeated:true Pattern:^/ Implicit:true Description:}
+ return info
+}
+
+// ToRawInfo returns a description of PrimitivesItems suitable for JSON or YAML export.
+func (m *PrimitivesItems) ToRawInfo() interface{} {
+ info := yaml.MapSlice{}
+ if m.Type != "" {
+ info = append(info, yaml.MapItem{"type", m.Type})
+ }
+ if m.Format != "" {
+ info = append(info, yaml.MapItem{"format", m.Format})
+ }
+ if m.Items != nil {
+ info = append(info, yaml.MapItem{"items", m.Items.ToRawInfo()})
+ }
+ // &{Name:items Type:PrimitivesItems StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ if m.CollectionFormat != "" {
+ info = append(info, yaml.MapItem{"collectionFormat", m.CollectionFormat})
+ }
+ if m.Default != nil {
+ info = append(info, yaml.MapItem{"default", m.Default.ToRawInfo()})
+ }
+ // &{Name:default Type:Any StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ if m.Maximum != 0.0 {
+ info = append(info, yaml.MapItem{"maximum", m.Maximum})
+ }
+ if m.ExclusiveMaximum != false {
+ info = append(info, yaml.MapItem{"exclusiveMaximum", m.ExclusiveMaximum})
+ }
+ if m.Minimum != 0.0 {
+ info = append(info, yaml.MapItem{"minimum", m.Minimum})
+ }
+ if m.ExclusiveMinimum != false {
+ info = append(info, yaml.MapItem{"exclusiveMinimum", m.ExclusiveMinimum})
+ }
+ if m.MaxLength != 0 {
+ info = append(info, yaml.MapItem{"maxLength", m.MaxLength})
+ }
+ if m.MinLength != 0 {
+ info = append(info, yaml.MapItem{"minLength", m.MinLength})
+ }
+ if m.Pattern != "" {
+ info = append(info, yaml.MapItem{"pattern", m.Pattern})
+ }
+ if m.MaxItems != 0 {
+ info = append(info, yaml.MapItem{"maxItems", m.MaxItems})
+ }
+ if m.MinItems != 0 {
+ info = append(info, yaml.MapItem{"minItems", m.MinItems})
+ }
+ if m.UniqueItems != false {
+ info = append(info, yaml.MapItem{"uniqueItems", m.UniqueItems})
+ }
+ if len(m.Enum) != 0 {
+ items := make([]interface{}, 0)
+ for _, item := range m.Enum {
+ items = append(items, item.ToRawInfo())
+ }
+ info = append(info, yaml.MapItem{"enum", items})
+ }
+ // &{Name:enum Type:Any StringEnumValues:[] MapType: Repeated:true Pattern: Implicit:false Description:}
+ if m.MultipleOf != 0.0 {
+ info = append(info, yaml.MapItem{"multipleOf", m.MultipleOf})
+ }
+ if m.VendorExtension != nil {
+ for _, item := range m.VendorExtension {
+ info = append(info, yaml.MapItem{item.Name, item.Value.ToRawInfo()})
+ }
+ }
+ // &{Name:VendorExtension Type:NamedAny StringEnumValues:[] MapType:Any Repeated:true Pattern:^x- Implicit:true Description:}
+ return info
+}
+
+// ToRawInfo returns a description of Properties suitable for JSON or YAML export.
+func (m *Properties) ToRawInfo() interface{} {
+ info := yaml.MapSlice{}
+ if m.AdditionalProperties != nil {
+ for _, item := range m.AdditionalProperties {
+ info = append(info, yaml.MapItem{item.Name, item.Value.ToRawInfo()})
+ }
+ }
+ // &{Name:additionalProperties Type:NamedSchema StringEnumValues:[] MapType:Schema Repeated:true Pattern: Implicit:true Description:}
+ return info
+}
+
+// ToRawInfo returns a description of QueryParameterSubSchema suitable for JSON or YAML export.
+func (m *QueryParameterSubSchema) ToRawInfo() interface{} {
+ info := yaml.MapSlice{}
+ if m.Required != false {
+ info = append(info, yaml.MapItem{"required", m.Required})
+ }
+ if m.In != "" {
+ info = append(info, yaml.MapItem{"in", m.In})
+ }
+ if m.Description != "" {
+ info = append(info, yaml.MapItem{"description", m.Description})
+ }
+ if m.Name != "" {
+ info = append(info, yaml.MapItem{"name", m.Name})
+ }
+ if m.AllowEmptyValue != false {
+ info = append(info, yaml.MapItem{"allowEmptyValue", m.AllowEmptyValue})
+ }
+ if m.Type != "" {
+ info = append(info, yaml.MapItem{"type", m.Type})
+ }
+ if m.Format != "" {
+ info = append(info, yaml.MapItem{"format", m.Format})
+ }
+ if m.Items != nil {
+ info = append(info, yaml.MapItem{"items", m.Items.ToRawInfo()})
+ }
+ // &{Name:items Type:PrimitivesItems StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ if m.CollectionFormat != "" {
+ info = append(info, yaml.MapItem{"collectionFormat", m.CollectionFormat})
+ }
+ if m.Default != nil {
+ info = append(info, yaml.MapItem{"default", m.Default.ToRawInfo()})
+ }
+ // &{Name:default Type:Any StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ if m.Maximum != 0.0 {
+ info = append(info, yaml.MapItem{"maximum", m.Maximum})
+ }
+ if m.ExclusiveMaximum != false {
+ info = append(info, yaml.MapItem{"exclusiveMaximum", m.ExclusiveMaximum})
+ }
+ if m.Minimum != 0.0 {
+ info = append(info, yaml.MapItem{"minimum", m.Minimum})
+ }
+ if m.ExclusiveMinimum != false {
+ info = append(info, yaml.MapItem{"exclusiveMinimum", m.ExclusiveMinimum})
+ }
+ if m.MaxLength != 0 {
+ info = append(info, yaml.MapItem{"maxLength", m.MaxLength})
+ }
+ if m.MinLength != 0 {
+ info = append(info, yaml.MapItem{"minLength", m.MinLength})
+ }
+ if m.Pattern != "" {
+ info = append(info, yaml.MapItem{"pattern", m.Pattern})
+ }
+ if m.MaxItems != 0 {
+ info = append(info, yaml.MapItem{"maxItems", m.MaxItems})
+ }
+ if m.MinItems != 0 {
+ info = append(info, yaml.MapItem{"minItems", m.MinItems})
+ }
+ if m.UniqueItems != false {
+ info = append(info, yaml.MapItem{"uniqueItems", m.UniqueItems})
+ }
+ if len(m.Enum) != 0 {
+ items := make([]interface{}, 0)
+ for _, item := range m.Enum {
+ items = append(items, item.ToRawInfo())
+ }
+ info = append(info, yaml.MapItem{"enum", items})
+ }
+ // &{Name:enum Type:Any StringEnumValues:[] MapType: Repeated:true Pattern: Implicit:false Description:}
+ if m.MultipleOf != 0.0 {
+ info = append(info, yaml.MapItem{"multipleOf", m.MultipleOf})
+ }
+ if m.VendorExtension != nil {
+ for _, item := range m.VendorExtension {
+ info = append(info, yaml.MapItem{item.Name, item.Value.ToRawInfo()})
+ }
+ }
+ // &{Name:VendorExtension Type:NamedAny StringEnumValues:[] MapType:Any Repeated:true Pattern:^x- Implicit:true Description:}
+ return info
+}
+
+// ToRawInfo returns a description of Response suitable for JSON or YAML export.
+func (m *Response) ToRawInfo() interface{} {
+ info := yaml.MapSlice{}
+ if m.Description != "" {
+ info = append(info, yaml.MapItem{"description", m.Description})
+ }
+ if m.Schema != nil {
+ info = append(info, yaml.MapItem{"schema", m.Schema.ToRawInfo()})
+ }
+ // &{Name:schema Type:SchemaItem StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ if m.Headers != nil {
+ info = append(info, yaml.MapItem{"headers", m.Headers.ToRawInfo()})
+ }
+ // &{Name:headers Type:Headers StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ if m.Examples != nil {
+ info = append(info, yaml.MapItem{"examples", m.Examples.ToRawInfo()})
+ }
+ // &{Name:examples Type:Examples StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ if m.VendorExtension != nil {
+ for _, item := range m.VendorExtension {
+ info = append(info, yaml.MapItem{item.Name, item.Value.ToRawInfo()})
+ }
+ }
+ // &{Name:VendorExtension Type:NamedAny StringEnumValues:[] MapType:Any Repeated:true Pattern:^x- Implicit:true Description:}
+ return info
+}
+
+// ToRawInfo returns a description of ResponseDefinitions suitable for JSON or YAML export.
+func (m *ResponseDefinitions) ToRawInfo() interface{} {
+ info := yaml.MapSlice{}
+ if m.AdditionalProperties != nil {
+ for _, item := range m.AdditionalProperties {
+ info = append(info, yaml.MapItem{item.Name, item.Value.ToRawInfo()})
+ }
+ }
+ // &{Name:additionalProperties Type:NamedResponse StringEnumValues:[] MapType:Response Repeated:true Pattern: Implicit:true Description:}
+ return info
+}
+
+// ToRawInfo returns a description of ResponseValue suitable for JSON or YAML export.
+func (m *ResponseValue) ToRawInfo() interface{} {
+ // ONE OF WRAPPER
+ // ResponseValue
+ // {Name:response Type:Response StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ v0 := m.GetResponse()
+ if v0 != nil {
+ return v0.ToRawInfo()
+ }
+ // {Name:jsonReference Type:JsonReference StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ v1 := m.GetJsonReference()
+ if v1 != nil {
+ return v1.ToRawInfo()
+ }
+ return nil
+}
+
+// ToRawInfo returns a description of Responses suitable for JSON or YAML export.
+func (m *Responses) ToRawInfo() interface{} {
+ info := yaml.MapSlice{}
+ if m.ResponseCode != nil {
+ for _, item := range m.ResponseCode {
+ info = append(info, yaml.MapItem{item.Name, item.Value.ToRawInfo()})
+ }
+ }
+ // &{Name:ResponseCode Type:NamedResponseValue StringEnumValues:[] MapType:ResponseValue Repeated:true Pattern:^([0-9]{3})$|^(default)$ Implicit:true Description:}
+ if m.VendorExtension != nil {
+ for _, item := range m.VendorExtension {
+ info = append(info, yaml.MapItem{item.Name, item.Value.ToRawInfo()})
+ }
+ }
+ // &{Name:VendorExtension Type:NamedAny StringEnumValues:[] MapType:Any Repeated:true Pattern:^x- Implicit:true Description:}
+ return info
+}
+
+// ToRawInfo returns a description of Schema suitable for JSON or YAML export.
+func (m *Schema) ToRawInfo() interface{} {
+ info := yaml.MapSlice{}
+ if m.XRef != "" {
+ info = append(info, yaml.MapItem{"$ref", m.XRef})
+ }
+ if m.Format != "" {
+ info = append(info, yaml.MapItem{"format", m.Format})
+ }
+ if m.Title != "" {
+ info = append(info, yaml.MapItem{"title", m.Title})
+ }
+ if m.Description != "" {
+ info = append(info, yaml.MapItem{"description", m.Description})
+ }
+ if m.Default != nil {
+ info = append(info, yaml.MapItem{"default", m.Default.ToRawInfo()})
+ }
+ // &{Name:default Type:Any StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ if m.MultipleOf != 0.0 {
+ info = append(info, yaml.MapItem{"multipleOf", m.MultipleOf})
+ }
+ if m.Maximum != 0.0 {
+ info = append(info, yaml.MapItem{"maximum", m.Maximum})
+ }
+ if m.ExclusiveMaximum != false {
+ info = append(info, yaml.MapItem{"exclusiveMaximum", m.ExclusiveMaximum})
+ }
+ if m.Minimum != 0.0 {
+ info = append(info, yaml.MapItem{"minimum", m.Minimum})
+ }
+ if m.ExclusiveMinimum != false {
+ info = append(info, yaml.MapItem{"exclusiveMinimum", m.ExclusiveMinimum})
+ }
+ if m.MaxLength != 0 {
+ info = append(info, yaml.MapItem{"maxLength", m.MaxLength})
+ }
+ if m.MinLength != 0 {
+ info = append(info, yaml.MapItem{"minLength", m.MinLength})
+ }
+ if m.Pattern != "" {
+ info = append(info, yaml.MapItem{"pattern", m.Pattern})
+ }
+ if m.MaxItems != 0 {
+ info = append(info, yaml.MapItem{"maxItems", m.MaxItems})
+ }
+ if m.MinItems != 0 {
+ info = append(info, yaml.MapItem{"minItems", m.MinItems})
+ }
+ if m.UniqueItems != false {
+ info = append(info, yaml.MapItem{"uniqueItems", m.UniqueItems})
+ }
+ if m.MaxProperties != 0 {
+ info = append(info, yaml.MapItem{"maxProperties", m.MaxProperties})
+ }
+ if m.MinProperties != 0 {
+ info = append(info, yaml.MapItem{"minProperties", m.MinProperties})
+ }
+ if len(m.Required) != 0 {
+ info = append(info, yaml.MapItem{"required", m.Required})
+ }
+ if len(m.Enum) != 0 {
+ items := make([]interface{}, 0)
+ for _, item := range m.Enum {
+ items = append(items, item.ToRawInfo())
+ }
+ info = append(info, yaml.MapItem{"enum", items})
+ }
+ // &{Name:enum Type:Any StringEnumValues:[] MapType: Repeated:true Pattern: Implicit:false Description:}
+ if m.AdditionalProperties != nil {
+ info = append(info, yaml.MapItem{"additionalProperties", m.AdditionalProperties.ToRawInfo()})
+ }
+ // &{Name:additionalProperties Type:AdditionalPropertiesItem StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ if m.Type != nil {
+ if len(m.Type.Value) == 1 {
+ info = append(info, yaml.MapItem{"type", m.Type.Value[0]})
+ } else {
+ info = append(info, yaml.MapItem{"type", m.Type.Value})
+ }
+ }
+ // &{Name:type Type:TypeItem StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ if m.Items != nil {
+ items := make([]interface{}, 0)
+ for _, item := range m.Items.Schema {
+ items = append(items, item.ToRawInfo())
+ }
+ info = append(info, yaml.MapItem{"items", items[0]})
+ }
+ // &{Name:items Type:ItemsItem StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ if len(m.AllOf) != 0 {
+ items := make([]interface{}, 0)
+ for _, item := range m.AllOf {
+ items = append(items, item.ToRawInfo())
+ }
+ info = append(info, yaml.MapItem{"allOf", items})
+ }
+ // &{Name:allOf Type:Schema StringEnumValues:[] MapType: Repeated:true Pattern: Implicit:false Description:}
+ if m.Properties != nil {
+ info = append(info, yaml.MapItem{"properties", m.Properties.ToRawInfo()})
+ }
+ // &{Name:properties Type:Properties StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ if m.Discriminator != "" {
+ info = append(info, yaml.MapItem{"discriminator", m.Discriminator})
+ }
+ if m.ReadOnly != false {
+ info = append(info, yaml.MapItem{"readOnly", m.ReadOnly})
+ }
+ if m.Xml != nil {
+ info = append(info, yaml.MapItem{"xml", m.Xml.ToRawInfo()})
+ }
+ // &{Name:xml Type:Xml StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ if m.ExternalDocs != nil {
+ info = append(info, yaml.MapItem{"externalDocs", m.ExternalDocs.ToRawInfo()})
+ }
+ // &{Name:externalDocs Type:ExternalDocs StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ if m.Example != nil {
+ info = append(info, yaml.MapItem{"example", m.Example.ToRawInfo()})
+ }
+ // &{Name:example Type:Any StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ if m.VendorExtension != nil {
+ for _, item := range m.VendorExtension {
+ info = append(info, yaml.MapItem{item.Name, item.Value.ToRawInfo()})
+ }
+ }
+ // &{Name:VendorExtension Type:NamedAny StringEnumValues:[] MapType:Any Repeated:true Pattern:^x- Implicit:true Description:}
+ return info
+}
+
+// ToRawInfo returns a description of SchemaItem suitable for JSON or YAML export.
+func (m *SchemaItem) ToRawInfo() interface{} {
+ // ONE OF WRAPPER
+ // SchemaItem
+ // {Name:schema Type:Schema StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ v0 := m.GetSchema()
+ if v0 != nil {
+ return v0.ToRawInfo()
+ }
+ // {Name:fileSchema Type:FileSchema StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ v1 := m.GetFileSchema()
+ if v1 != nil {
+ return v1.ToRawInfo()
+ }
+ return nil
+}
+
+// ToRawInfo returns a description of SecurityDefinitions suitable for JSON or YAML export.
+func (m *SecurityDefinitions) ToRawInfo() interface{} {
+ info := yaml.MapSlice{}
+ if m.AdditionalProperties != nil {
+ for _, item := range m.AdditionalProperties {
+ info = append(info, yaml.MapItem{item.Name, item.Value.ToRawInfo()})
+ }
+ }
+ // &{Name:additionalProperties Type:NamedSecurityDefinitionsItem StringEnumValues:[] MapType:SecurityDefinitionsItem Repeated:true Pattern: Implicit:true Description:}
+ return info
+}
+
+// ToRawInfo returns a description of SecurityDefinitionsItem suitable for JSON or YAML export.
+func (m *SecurityDefinitionsItem) ToRawInfo() interface{} {
+ // ONE OF WRAPPER
+ // SecurityDefinitionsItem
+ // {Name:basicAuthenticationSecurity Type:BasicAuthenticationSecurity StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ v0 := m.GetBasicAuthenticationSecurity()
+ if v0 != nil {
+ return v0.ToRawInfo()
+ }
+ // {Name:apiKeySecurity Type:ApiKeySecurity StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ v1 := m.GetApiKeySecurity()
+ if v1 != nil {
+ return v1.ToRawInfo()
+ }
+ // {Name:oauth2ImplicitSecurity Type:Oauth2ImplicitSecurity StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ v2 := m.GetOauth2ImplicitSecurity()
+ if v2 != nil {
+ return v2.ToRawInfo()
+ }
+ // {Name:oauth2PasswordSecurity Type:Oauth2PasswordSecurity StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ v3 := m.GetOauth2PasswordSecurity()
+ if v3 != nil {
+ return v3.ToRawInfo()
+ }
+ // {Name:oauth2ApplicationSecurity Type:Oauth2ApplicationSecurity StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ v4 := m.GetOauth2ApplicationSecurity()
+ if v4 != nil {
+ return v4.ToRawInfo()
+ }
+ // {Name:oauth2AccessCodeSecurity Type:Oauth2AccessCodeSecurity StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ v5 := m.GetOauth2AccessCodeSecurity()
+ if v5 != nil {
+ return v5.ToRawInfo()
+ }
+ return nil
+}
+
+// ToRawInfo returns a description of SecurityRequirement suitable for JSON or YAML export.
+func (m *SecurityRequirement) ToRawInfo() interface{} {
+ info := yaml.MapSlice{}
+ if m.AdditionalProperties != nil {
+ for _, item := range m.AdditionalProperties {
+ info = append(info, yaml.MapItem{item.Name, item.Value.ToRawInfo()})
+ }
+ }
+ // &{Name:additionalProperties Type:NamedStringArray StringEnumValues:[] MapType:StringArray Repeated:true Pattern: Implicit:true Description:}
+ return info
+}
+
+// ToRawInfo returns a description of StringArray suitable for JSON or YAML export.
+func (m *StringArray) ToRawInfo() interface{} {
+ return m.Value
+}
+
+// ToRawInfo returns a description of Tag suitable for JSON or YAML export.
+func (m *Tag) ToRawInfo() interface{} {
+ info := yaml.MapSlice{}
+ if m.Name != "" {
+ info = append(info, yaml.MapItem{"name", m.Name})
+ }
+ if m.Description != "" {
+ info = append(info, yaml.MapItem{"description", m.Description})
+ }
+ if m.ExternalDocs != nil {
+ info = append(info, yaml.MapItem{"externalDocs", m.ExternalDocs.ToRawInfo()})
+ }
+ // &{Name:externalDocs Type:ExternalDocs StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
+ if m.VendorExtension != nil {
+ for _, item := range m.VendorExtension {
+ info = append(info, yaml.MapItem{item.Name, item.Value.ToRawInfo()})
+ }
+ }
+ // &{Name:VendorExtension Type:NamedAny StringEnumValues:[] MapType:Any Repeated:true Pattern:^x- Implicit:true Description:}
+ return info
+}
+
+// ToRawInfo returns a description of TypeItem suitable for JSON or YAML export.
+func (m *TypeItem) ToRawInfo() interface{} {
+ info := yaml.MapSlice{}
+ if len(m.Value) != 0 {
+ info = append(info, yaml.MapItem{"value", m.Value})
+ }
+ return info
+}
+
+// ToRawInfo returns a description of VendorExtension suitable for JSON or YAML export.
+func (m *VendorExtension) ToRawInfo() interface{} {
+ info := yaml.MapSlice{}
+ if m.AdditionalProperties != nil {
+ for _, item := range m.AdditionalProperties {
+ info = append(info, yaml.MapItem{item.Name, item.Value.ToRawInfo()})
+ }
+ }
+ // &{Name:additionalProperties Type:NamedAny StringEnumValues:[] MapType:Any Repeated:true Pattern: Implicit:true Description:}
+ return info
+}
+
+// ToRawInfo returns a description of Xml suitable for JSON or YAML export.
+func (m *Xml) ToRawInfo() interface{} {
+ info := yaml.MapSlice{}
+ if m.Name != "" {
+ info = append(info, yaml.MapItem{"name", m.Name})
+ }
+ if m.Namespace != "" {
+ info = append(info, yaml.MapItem{"namespace", m.Namespace})
+ }
+ if m.Prefix != "" {
+ info = append(info, yaml.MapItem{"prefix", m.Prefix})
+ }
+ if m.Attribute != false {
+ info = append(info, yaml.MapItem{"attribute", m.Attribute})
+ }
+ if m.Wrapped != false {
+ info = append(info, yaml.MapItem{"wrapped", m.Wrapped})
+ }
+ if m.VendorExtension != nil {
+ for _, item := range m.VendorExtension {
+ info = append(info, yaml.MapItem{item.Name, item.Value.ToRawInfo()})
+ }
+ }
+ // &{Name:VendorExtension Type:NamedAny StringEnumValues:[] MapType:Any Repeated:true Pattern:^x- Implicit:true Description:}
+ return info
+}
+
+var (
+ pattern0 = regexp.MustCompile("^x-")
+ pattern1 = regexp.MustCompile("^/")
+ pattern2 = regexp.MustCompile("^([0-9]{3})$|^(default)$")
+)
diff --git a/vendor/github.com/googleapis/gnostic/OpenAPIv2/OpenAPIv2.pb.go b/vendor/github.com/googleapis/gnostic/OpenAPIv2/OpenAPIv2.pb.go
index c815ae96..37da7df2 100644
--- a/vendor/github.com/googleapis/gnostic/OpenAPIv2/OpenAPIv2.pb.go
+++ b/vendor/github.com/googleapis/gnostic/OpenAPIv2/OpenAPIv2.pb.go
@@ -1376,7 +1376,7 @@ func (m *ItemsItem) GetSchema() []*Schema {
}
type JsonReference struct {
- XRef string `protobuf:"bytes,1,opt,name=_ref,json=ref" json:"_ref,omitempty"`
+ XRef string `protobuf:"bytes,1,opt,name=_ref,json=Ref" json:"_ref,omitempty"`
Description string `protobuf:"bytes,2,opt,name=description" json:"description,omitempty"`
}
@@ -2513,7 +2513,7 @@ func _ParametersItem_OneofSizer(msg proto.Message) (n int) {
}
type PathItem struct {
- XRef string `protobuf:"bytes,1,opt,name=_ref,json=ref" json:"_ref,omitempty"`
+ XRef string `protobuf:"bytes,1,opt,name=_ref,json=Ref" json:"_ref,omitempty"`
Get *Operation `protobuf:"bytes,2,opt,name=get" json:"get,omitempty"`
Put *Operation `protobuf:"bytes,3,opt,name=put" json:"put,omitempty"`
Post *Operation `protobuf:"bytes,4,opt,name=post" json:"post,omitempty"`
@@ -3392,7 +3392,7 @@ func (m *Responses) GetVendorExtension() []*NamedAny {
// A deterministic version of a JSON Schema object.
type Schema struct {
- XRef string `protobuf:"bytes,1,opt,name=_ref,json=ref" json:"_ref,omitempty"`
+ XRef string `protobuf:"bytes,1,opt,name=_ref,json=Ref" json:"_ref,omitempty"`
Format string `protobuf:"bytes,2,opt,name=format" json:"format,omitempty"`
Title string `protobuf:"bytes,3,opt,name=title" json:"title,omitempty"`
Description string `protobuf:"bytes,4,opt,name=description" json:"description,omitempty"`
@@ -4351,7 +4351,7 @@ var fileDescriptor0 = []byte{
0xfe, 0x90, 0x83, 0x0c, 0x89, 0xa3, 0x14, 0x7e, 0x7d, 0x1e, 0xe1, 0xbf, 0x05, 0x4d, 0xa6, 0x0c,
0xac, 0x56, 0x77, 0x23, 0x51, 0xab, 0x2b, 0x4f, 0x2e, 0xac, 0x6c, 0xdd, 0x85, 0xd6, 0x37, 0x02,
0xe2, 0x1a, 0x78, 0x80, 0x7d, 0xec, 0xf6, 0xb0, 0xb6, 0x0c, 0x15, 0xd3, 0xc7, 0x03, 0x21, 0xe3,
- 0xb2, 0x8f, 0x07, 0xd3, 0xeb, 0x4f, 0x5b, 0x1e, 0xd4, 0xc5, 0x33, 0xcd, 0x58, 0x5c, 0x39, 0xf3,
+ 0xb2, 0x81, 0x07, 0xd3, 0xeb, 0x4f, 0x5b, 0x1e, 0xd4, 0xc5, 0x33, 0xcd, 0x58, 0x5c, 0x39, 0xf3,
0x59, 0xe6, 0x1e, 0x34, 0x24, 0x50, 0xb9, 0xe5, 0x2b, 0xb2, 0xaa, 0x58, 0x52, 0x3b, 0x20, 0x0e,
0xdd, 0x7a, 0x17, 0x16, 0x12, 0x0a, 0xa8, 0xa4, 0x74, 0x2d, 0x4d, 0x29, 0x25, 0x4c, 0xa1, 0xb7,
0x82, 0xd8, 0xfb, 0xd0, 0x66, 0xc4, 0xe2, 0x22, 0x9a, 0x8a, 0xde, 0xeb, 0x69, 0x7a, 0x17, 0x94,
@@ -4452,5 +4452,5 @@ var fileDescriptor0 = []byte{
0xf3, 0x70, 0x5f, 0x1c, 0xc1, 0xe5, 0xf0, 0xcc, 0x7d, 0xcc, 0xdb, 0xaf, 0x42, 0x9b, 0xf8, 0x47,
0x12, 0xd7, 0x3c, 0xd9, 0xb9, 0xbd, 0x28, 0xbe, 0x5d, 0xdd, 0xf7, 0x49, 0x48, 0xf6, 0x8b, 0xbf,
0x28, 0x95, 0xf7, 0x76, 0x0f, 0x0e, 0x6b, 0xec, 0x63, 0xd0, 0x37, 0xff, 0x19, 0x00, 0x00, 0xff,
- 0xff, 0x3c, 0x01, 0x3f, 0x38, 0xe4, 0x3a, 0x00, 0x00,
+ 0xff, 0xd4, 0x0a, 0xef, 0xca, 0xe4, 0x3a, 0x00, 0x00,
}
diff --git a/vendor/github.com/googleapis/gnostic/compiler/context.go b/vendor/github.com/googleapis/gnostic/compiler/context.go
index 2e5242ee..a64c1b75 100644
--- a/vendor/github.com/googleapis/gnostic/compiler/context.go
+++ b/vendor/github.com/googleapis/gnostic/compiler/context.go
@@ -14,28 +14,30 @@
package compiler
+// Context contains state of the compiler as it traverses a document.
type Context struct {
Parent *Context
Name string
ExtensionHandlers *[]ExtensionHandler
}
+// NewContextWithExtensions returns a new object representing the compiler state
func NewContextWithExtensions(name string, parent *Context, extensionHandlers *[]ExtensionHandler) *Context {
return &Context{Name: name, Parent: parent, ExtensionHandlers: extensionHandlers}
}
+// NewContext returns a new object representing the compiler state
func NewContext(name string, parent *Context) *Context {
if parent != nil {
return &Context{Name: name, Parent: parent, ExtensionHandlers: parent.ExtensionHandlers}
- } else {
- return &Context{Name: name, Parent: parent, ExtensionHandlers: nil}
}
+ return &Context{Name: name, Parent: parent, ExtensionHandlers: nil}
}
+// Description returns a text description of the compiler state
func (context *Context) Description() string {
if context.Parent != nil {
return context.Parent.Description() + "." + context.Name
- } else {
- return context.Name
}
+ return context.Name
}
diff --git a/vendor/github.com/googleapis/gnostic/compiler/error.go b/vendor/github.com/googleapis/gnostic/compiler/error.go
index 942536a7..d8672c10 100644
--- a/vendor/github.com/googleapis/gnostic/compiler/error.go
+++ b/vendor/github.com/googleapis/gnostic/compiler/error.go
@@ -14,29 +14,31 @@
package compiler
-// basic error type
+// Error represents compiler errors and their location in the document.
type Error struct {
Context *Context
Message string
}
+// NewError creates an Error.
func NewError(context *Context, message string) *Error {
return &Error{Context: context, Message: message}
}
+// Error returns the string value of an Error.
func (err *Error) Error() string {
- if err.Context != nil {
- return "ERROR " + err.Context.Description() + " " + err.Message
- } else {
+ if err.Context == nil {
return "ERROR " + err.Message
}
+ return "ERROR " + err.Context.Description() + " " + err.Message
}
-// container for groups of errors
+// ErrorGroup is a container for groups of Error values.
type ErrorGroup struct {
Errors []error
}
+// NewErrorGroupOrNil returns a new ErrorGroup for a slice of errors or nil if the slice is empty.
func NewErrorGroupOrNil(errors []error) error {
if len(errors) == 0 {
return nil
diff --git a/vendor/github.com/googleapis/gnostic/compiler/extension-handler.go b/vendor/github.com/googleapis/gnostic/compiler/extension-handler.go
index 426663c2..1f85b650 100644
--- a/vendor/github.com/googleapis/gnostic/compiler/extension-handler.go
+++ b/vendor/github.com/googleapis/gnostic/compiler/extension-handler.go
@@ -29,16 +29,18 @@ import (
yaml "gopkg.in/yaml.v2"
)
+// ExtensionHandler describes a binary that is called by the compiler to handle specification extensions.
type ExtensionHandler struct {
Name string
}
+// HandleExtension calls a binary extension handler.
func HandleExtension(context *Context, in interface{}, extensionName string) (bool, *any.Any, error) {
handled := false
var errFromPlugin error
var outFromPlugin *any.Any
- if context.ExtensionHandlers != nil && len(*(context.ExtensionHandlers)) != 0 {
+ if context != nil && context.ExtensionHandlers != nil && len(*(context.ExtensionHandlers)) != 0 {
for _, customAnyProtoGenerator := range *(context.ExtensionHandlers) {
outFromPlugin, errFromPlugin = customAnyProtoGenerator.handle(in, extensionName)
if outFromPlugin == nil {
diff --git a/vendor/github.com/googleapis/gnostic/compiler/helpers.go b/vendor/github.com/googleapis/gnostic/compiler/helpers.go
index 56306c40..76df635f 100644
--- a/vendor/github.com/googleapis/gnostic/compiler/helpers.go
+++ b/vendor/github.com/googleapis/gnostic/compiler/helpers.go
@@ -19,27 +19,27 @@ import (
"gopkg.in/yaml.v2"
"regexp"
"sort"
- "strings"
+ "strconv"
)
// compiler helper functions, usually called from generated code
+// UnpackMap gets a yaml.MapSlice if possible.
func UnpackMap(in interface{}) (yaml.MapSlice, bool) {
m, ok := in.(yaml.MapSlice)
if ok {
- return m, ok
- } else {
- // do we have an empty array?
- a, ok := in.([]interface{})
- if ok && len(a) == 0 {
- // if so, return an empty map
- return yaml.MapSlice{}, ok
- } else {
- return nil, ok
- }
+ return m, true
}
+ // do we have an empty array?
+ a, ok := in.([]interface{})
+ if ok && len(a) == 0 {
+ // if so, return an empty map
+ return yaml.MapSlice{}, true
+ }
+ return nil, false
}
+// SortedKeysForMap returns the sorted keys of a yaml.MapSlice.
func SortedKeysForMap(m yaml.MapSlice) []string {
keys := make([]string, 0)
for _, item := range m {
@@ -49,6 +49,7 @@ func SortedKeysForMap(m yaml.MapSlice) []string {
return keys
}
+// MapHasKey returns true if a yaml.MapSlice contains a specified key.
func MapHasKey(m yaml.MapSlice, key string) bool {
for _, item := range m {
itemKey, ok := item.Key.(string)
@@ -59,6 +60,7 @@ func MapHasKey(m yaml.MapSlice, key string) bool {
return false
}
+// MapValueForKey gets the value of a map value for a specified key.
func MapValueForKey(m yaml.MapSlice, key string) interface{} {
for _, item := range m {
itemKey, ok := item.Key.(string)
@@ -69,6 +71,7 @@ func MapValueForKey(m yaml.MapSlice, key string) interface{} {
return nil
}
+// ConvertInterfaceArrayToStringArray converts an array of interfaces to an array of strings, if possible.
func ConvertInterfaceArrayToStringArray(interfaceArray []interface{}) []string {
stringArray := make([]string, 0)
for _, item := range interfaceArray {
@@ -80,22 +83,7 @@ func ConvertInterfaceArrayToStringArray(interfaceArray []interface{}) []string {
return stringArray
}
-func PatternMatches(pattern string, value string) bool {
- // if pattern contains a subpattern like "{path}", replace it with ".*"
- if pattern[0] != '^' {
- subpatternPattern := regexp.MustCompile("^.*(\\{.*\\}).*$")
- if matches := subpatternPattern.FindSubmatch([]byte(pattern)); matches != nil {
- match := string(matches[1])
- pattern = strings.Replace(pattern, match, ".*", -1)
- }
- }
- matched, err := regexp.Match(pattern, []byte(value))
- if err != nil {
- panic(err)
- }
- return matched
-}
-
+// MissingKeysInMap identifies which keys from a list of required keys are not in a map.
func MissingKeysInMap(m yaml.MapSlice, requiredKeys []string) []string {
missingKeys := make([]string, 0)
for _, k := range requiredKeys {
@@ -106,7 +94,8 @@ func MissingKeysInMap(m yaml.MapSlice, requiredKeys []string) []string {
return missingKeys
}
-func InvalidKeysInMap(m yaml.MapSlice, allowedKeys []string, allowedPatterns []string) []string {
+// InvalidKeysInMap returns keys in a map that don't match a list of allowed keys and patterns.
+func InvalidKeysInMap(m yaml.MapSlice, allowedKeys []string, allowedPatterns []*regexp.Regexp) []string {
invalidKeys := make([]string, 0)
for _, item := range m {
itemKey, ok := item.Key.(string)
@@ -123,7 +112,7 @@ func InvalidKeysInMap(m yaml.MapSlice, allowedKeys []string, allowedPatterns []s
if !found {
// does the key match an allowed pattern?
for _, allowedPattern := range allowedPatterns {
- if PatternMatches(allowedPattern, key) {
+ if allowedPattern.MatchString(key) {
found = true
break
}
@@ -137,13 +126,13 @@ func InvalidKeysInMap(m yaml.MapSlice, allowedKeys []string, allowedPatterns []s
return invalidKeys
}
-// describe a map (for debugging purposes)
+// DescribeMap describes a map (for debugging purposes).
func DescribeMap(in interface{}, indent string) string {
description := ""
m, ok := in.(map[string]interface{})
if ok {
keys := make([]string, 0)
- for k, _ := range m {
+ for k := range m {
keys = append(keys, k)
}
sort.Strings(keys)
@@ -166,14 +155,15 @@ func DescribeMap(in interface{}, indent string) string {
return description
}
+// PluralProperties returns the string "properties" pluralized.
func PluralProperties(count int) string {
if count == 1 {
return "property"
- } else {
- return "properties"
}
+ return "properties"
}
+// StringArrayContainsValue returns true if a string array contains a specified value.
func StringArrayContainsValue(array []string, value string) bool {
for _, item := range array {
if item == value {
@@ -183,6 +173,7 @@ func StringArrayContainsValue(array []string, value string) bool {
return false
}
+// StringArrayContainsValues returns true if a string array contains all of a list of specified values.
func StringArrayContainsValues(array []string, values []string) bool {
for _, value := range values {
if !StringArrayContainsValue(array, value) {
@@ -191,3 +182,16 @@ func StringArrayContainsValues(array []string, values []string) bool {
}
return true
}
+
+// StringValue returns the string value of an item.
+func StringValue(item interface{}) (value string, ok bool) {
+ value, ok = item.(string)
+ if ok {
+ return value, ok
+ }
+ intValue, ok := item.(int)
+ if ok {
+ return strconv.Itoa(intValue), true
+ }
+ return "", false
+}
diff --git a/vendor/github.com/googleapis/gnostic/compiler/reader.go b/vendor/github.com/googleapis/gnostic/compiler/reader.go
index 1878e060..604a46a6 100644
--- a/vendor/github.com/googleapis/gnostic/compiler/reader.go
+++ b/vendor/github.com/googleapis/gnostic/compiler/reader.go
@@ -25,29 +25,30 @@ import (
"strings"
)
-var file_cache map[string][]byte
-var info_cache map[string]interface{}
+var fileCache map[string][]byte
+var infoCache map[string]interface{}
var count int64
-var VERBOSE_READER = false
+var verboseReader = false
func initializeFileCache() {
- if file_cache == nil {
- file_cache = make(map[string][]byte, 0)
+ if fileCache == nil {
+ fileCache = make(map[string][]byte, 0)
}
}
func initializeInfoCache() {
- if info_cache == nil {
- info_cache = make(map[string]interface{}, 0)
+ if infoCache == nil {
+ infoCache = make(map[string]interface{}, 0)
}
}
+// FetchFile gets a specified file from the local filesystem or a remote location.
func FetchFile(fileurl string) ([]byte, error) {
initializeFileCache()
- bytes, ok := file_cache[fileurl]
+ bytes, ok := fileCache[fileurl]
if ok {
- if VERBOSE_READER {
+ if verboseReader {
log.Printf("Cache hit %s", fileurl)
}
return bytes, nil
@@ -56,30 +57,17 @@ func FetchFile(fileurl string) ([]byte, error) {
response, err := http.Get(fileurl)
if err != nil {
return nil, err
- } else {
- defer response.Body.Close()
- bytes, err := ioutil.ReadAll(response.Body)
- if err == nil {
- file_cache[fileurl] = bytes
- }
- return bytes, err
}
+ defer response.Body.Close()
+ bytes, err = ioutil.ReadAll(response.Body)
+ if err == nil {
+ fileCache[fileurl] = bytes
+ }
+ return bytes, err
}
-// read a file and unmarshal it as a yaml.MapSlice
-func ReadInfoForFile(filename string) (interface{}, error) {
- initializeInfoCache()
- info, ok := info_cache[filename]
- if ok {
- if VERBOSE_READER {
- log.Printf("Cache hit info for file %s", filename)
- }
- return info, nil
- }
- if VERBOSE_READER {
- log.Printf("Reading info for file %s", filename)
- }
-
+// ReadBytesForFile reads the bytes of a file.
+func ReadBytesForFile(filename string) ([]byte, error) {
// is the filename a url?
fileurl, _ := url.Parse(filename)
if fileurl.Scheme != "" {
@@ -88,43 +76,51 @@ func ReadInfoForFile(filename string) (interface{}, error) {
if err != nil {
return nil, err
}
- var info yaml.MapSlice
- err = yaml.Unmarshal(bytes, &info)
- if err != nil {
- return nil, err
- }
- info_cache[filename] = info
- return info, nil
- } else {
- // no, it's a local filename
- bytes, err := ioutil.ReadFile(filename)
- if err != nil {
- log.Printf("File error: %v\n", err)
- return nil, err
- }
- var info yaml.MapSlice
- err = yaml.Unmarshal(bytes, &info)
- if err != nil {
- return nil, err
- }
- info_cache[filename] = info
- return info, nil
+ return bytes, nil
}
+ // no, it's a local filename
+ bytes, err := ioutil.ReadFile(filename)
+ if err != nil {
+ return nil, err
+ }
+ return bytes, nil
}
-// read a file and return the fragment needed to resolve a $ref
+// ReadInfoFromBytes unmarshals a file as a yaml.MapSlice.
+func ReadInfoFromBytes(filename string, bytes []byte) (interface{}, error) {
+ initializeInfoCache()
+ cachedInfo, ok := infoCache[filename]
+ if ok {
+ if verboseReader {
+ log.Printf("Cache hit info for file %s", filename)
+ }
+ return cachedInfo, nil
+ }
+ if verboseReader {
+ log.Printf("Reading info for file %s", filename)
+ }
+ var info yaml.MapSlice
+ err := yaml.Unmarshal(bytes, &info)
+ if err != nil {
+ return nil, err
+ }
+ infoCache[filename] = info
+ return info, nil
+}
+
+// ReadInfoForRef reads a file and return the fragment needed to resolve a $ref.
func ReadInfoForRef(basefile string, ref string) (interface{}, error) {
initializeInfoCache()
{
- info, ok := info_cache[ref]
+ info, ok := infoCache[ref]
if ok {
- if VERBOSE_READER {
+ if verboseReader {
log.Printf("Cache hit for ref %s#%s", basefile, ref)
}
return info, nil
}
}
- if VERBOSE_READER {
+ if verboseReader {
log.Printf("Reading info for ref %s#%s", basefile, ref)
}
count = count + 1
@@ -136,7 +132,11 @@ func ReadInfoForRef(basefile string, ref string) (interface{}, error) {
} else {
filename = basefile
}
- info, err := ReadInfoForFile(filename)
+ bytes, err := ReadBytesForFile(filename)
+ if err != nil {
+ return nil, err
+ }
+ info, err := ReadInfoFromBytes(filename, bytes)
if err != nil {
log.Printf("File error: %v\n", err)
} else {
@@ -154,7 +154,7 @@ func ReadInfoForRef(basefile string, ref string) (interface{}, error) {
}
}
if !found {
- info_cache[ref] = nil
+ infoCache[ref] = nil
return nil, NewError(nil, fmt.Sprintf("could not resolve %s", ref))
}
}
@@ -162,6 +162,6 @@ func ReadInfoForRef(basefile string, ref string) (interface{}, error) {
}
}
}
- info_cache[ref] = info
+ infoCache[ref] = info
return info, nil
}
diff --git a/vendor/github.com/googleapis/gnostic/extensions/COMPILE-EXTENSION.sh b/vendor/github.com/googleapis/gnostic/extensions/COMPILE-EXTENSION.sh
index 64badc40..68d02a02 100755
--- a/vendor/github.com/googleapis/gnostic/extensions/COMPILE-EXTENSION.sh
+++ b/vendor/github.com/googleapis/gnostic/extensions/COMPILE-EXTENSION.sh
@@ -3,5 +3,3 @@ go get github.com/golang/protobuf/protoc-gen-go
protoc \
--go_out=Mgoogle/protobuf/any.proto=github.com/golang/protobuf/ptypes/any:. *.proto
-go build
-go install
diff --git a/vendor/github.com/googleapis/gnostic/extensions/extensions.go b/vendor/github.com/googleapis/gnostic/extensions/extensions.go
index 12800ac5..94a8e62a 100644
--- a/vendor/github.com/googleapis/gnostic/extensions/extensions.go
+++ b/vendor/github.com/googleapis/gnostic/extensions/extensions.go
@@ -21,40 +21,39 @@ import (
"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/ptypes"
- "gopkg.in/yaml.v2"
)
type documentHandler func(version string, extensionName string, document string)
-type extensionHandler func(name string, info yaml.MapSlice) (bool, proto.Message, error)
+type extensionHandler func(name string, yamlInput string) (bool, proto.Message, error)
func forInputYamlFromOpenapic(handler documentHandler) {
data, err := ioutil.ReadAll(os.Stdin)
-
if err != nil {
fmt.Println("File error:", err.Error())
os.Exit(1)
}
+ if len(data) == 0 {
+ fmt.Println("No input data.")
+ os.Exit(1)
+ }
request := &ExtensionHandlerRequest{}
err = proto.Unmarshal(data, request)
+ if err != nil {
+ fmt.Println("Input error:", err.Error())
+ os.Exit(1)
+ }
handler(request.Wrapper.Version, request.Wrapper.ExtensionName, request.Wrapper.Yaml)
}
+// ProcessExtension calles the handler for a specified extension.
func ProcessExtension(handleExtension extensionHandler) {
response := &ExtensionHandlerResponse{}
forInputYamlFromOpenapic(
func(version string, extensionName string, yamlInput string) {
- var info yaml.MapSlice
var newObject proto.Message
var err error
- err = yaml.Unmarshal([]byte(yamlInput), &info)
- if err != nil {
- response.Error = append(response.Error, err.Error())
- responseBytes, _ := proto.Marshal(response)
- os.Stdout.Write(responseBytes)
- os.Exit(0)
- }
- handled, newObject, err := handleExtension(extensionName, info)
+ handled, newObject, err := handleExtension(extensionName, yamlInput)
if !handled {
responseBytes, _ := proto.Marshal(response)
os.Stdout.Write(responseBytes)
diff --git a/vendor/github.com/gregjones/httpcache/.travis.yml b/vendor/github.com/gregjones/httpcache/.travis.yml
new file mode 100644
index 00000000..2bca4c59
--- /dev/null
+++ b/vendor/github.com/gregjones/httpcache/.travis.yml
@@ -0,0 +1,18 @@
+sudo: false
+language: go
+go:
+ - 1.6.x
+ - 1.7.x
+ - 1.8.x
+ - master
+matrix:
+ allow_failures:
+ - go: master
+ fast_finish: true
+install:
+ - # Do nothing. This is needed to prevent default install action "go get -t -v ./..." from happening here (we want it to happen inside script step).
+script:
+ - go get -t -v ./...
+ - diff -u <(echo -n) <(gofmt -d .)
+ - go tool vet .
+ - go test -v -race ./...
diff --git a/vendor/github.com/gregjones/httpcache/LICENSE.txt b/vendor/github.com/gregjones/httpcache/LICENSE.txt
new file mode 100644
index 00000000..81316beb
--- /dev/null
+++ b/vendor/github.com/gregjones/httpcache/LICENSE.txt
@@ -0,0 +1,7 @@
+Copyright © 2012 Greg Jones (greg.jones@gmail.com)
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file
diff --git a/vendor/github.com/gregjones/httpcache/README.md b/vendor/github.com/gregjones/httpcache/README.md
new file mode 100644
index 00000000..61bd830e
--- /dev/null
+++ b/vendor/github.com/gregjones/httpcache/README.md
@@ -0,0 +1,24 @@
+httpcache
+=========
+
+[](https://travis-ci.org/gregjones/httpcache) [](https://godoc.org/github.com/gregjones/httpcache)
+
+Package httpcache provides a http.RoundTripper implementation that works as a mostly RFC-compliant cache for http responses.
+
+It is only suitable for use as a 'private' cache (i.e. for a web-browser or an API-client and not for a shared proxy).
+
+Cache Backends
+--------------
+
+- The built-in 'memory' cache stores responses in an in-memory map.
+- [`github.com/gregjones/httpcache/diskcache`](https://github.com/gregjones/httpcache/tree/master/diskcache) provides a filesystem-backed cache using the [diskv](https://github.com/peterbourgon/diskv) library.
+- [`github.com/gregjones/httpcache/memcache`](https://github.com/gregjones/httpcache/tree/master/memcache) provides memcache implementations, for both App Engine and 'normal' memcache servers.
+- [`sourcegraph.com/sourcegraph/s3cache`](https://sourcegraph.com/github.com/sourcegraph/s3cache) uses Amazon S3 for storage.
+- [`github.com/gregjones/httpcache/leveldbcache`](https://github.com/gregjones/httpcache/tree/master/leveldbcache) provides a filesystem-backed cache using [leveldb](https://github.com/syndtr/goleveldb/leveldb).
+- [`github.com/die-net/lrucache`](https://github.com/die-net/lrucache) provides an in-memory cache that will evict least-recently used entries.
+- [`github.com/die-net/lrucache/twotier`](https://github.com/die-net/lrucache/tree/master/twotier) allows caches to be combined, for example to use lrucache above with a persistent disk-cache.
+
+License
+-------
+
+- [MIT License](LICENSE.txt)
diff --git a/vendor/github.com/gregjones/httpcache/diskcache/diskcache.go b/vendor/github.com/gregjones/httpcache/diskcache/diskcache.go
new file mode 100644
index 00000000..42e3129d
--- /dev/null
+++ b/vendor/github.com/gregjones/httpcache/diskcache/diskcache.go
@@ -0,0 +1,61 @@
+// Package diskcache provides an implementation of httpcache.Cache that uses the diskv package
+// to supplement an in-memory map with persistent storage
+//
+package diskcache
+
+import (
+ "bytes"
+ "crypto/md5"
+ "encoding/hex"
+ "github.com/peterbourgon/diskv"
+ "io"
+)
+
+// Cache is an implementation of httpcache.Cache that supplements the in-memory map with persistent storage
+type Cache struct {
+ d *diskv.Diskv
+}
+
+// Get returns the response corresponding to key if present
+func (c *Cache) Get(key string) (resp []byte, ok bool) {
+ key = keyToFilename(key)
+ resp, err := c.d.Read(key)
+ if err != nil {
+ return []byte{}, false
+ }
+ return resp, true
+}
+
+// Set saves a response to the cache as key
+func (c *Cache) Set(key string, resp []byte) {
+ key = keyToFilename(key)
+ c.d.WriteStream(key, bytes.NewReader(resp), true)
+}
+
+// Delete removes the response with key from the cache
+func (c *Cache) Delete(key string) {
+ key = keyToFilename(key)
+ c.d.Erase(key)
+}
+
+func keyToFilename(key string) string {
+ h := md5.New()
+ io.WriteString(h, key)
+ return hex.EncodeToString(h.Sum(nil))
+}
+
+// New returns a new Cache that will store files in basePath
+func New(basePath string) *Cache {
+ return &Cache{
+ d: diskv.New(diskv.Options{
+ BasePath: basePath,
+ CacheSizeMax: 100 * 1024 * 1024, // 100MB
+ }),
+ }
+}
+
+// NewWithDiskv returns a new Cache using the provided Diskv as underlying
+// storage.
+func NewWithDiskv(d *diskv.Diskv) *Cache {
+ return &Cache{d}
+}
diff --git a/vendor/github.com/gregjones/httpcache/httpcache.go b/vendor/github.com/gregjones/httpcache/httpcache.go
new file mode 100644
index 00000000..8239edc2
--- /dev/null
+++ b/vendor/github.com/gregjones/httpcache/httpcache.go
@@ -0,0 +1,553 @@
+// Package httpcache provides a http.RoundTripper implementation that works as a
+// mostly RFC-compliant cache for http responses.
+//
+// It is only suitable for use as a 'private' cache (i.e. for a web-browser or an API-client
+// and not for a shared proxy).
+//
+package httpcache
+
+import (
+ "bufio"
+ "bytes"
+ "errors"
+ "fmt"
+ "io"
+ "io/ioutil"
+ "net/http"
+ "net/http/httputil"
+ "strings"
+ "sync"
+ "time"
+)
+
+const (
+ stale = iota
+ fresh
+ transparent
+ // XFromCache is the header added to responses that are returned from the cache
+ XFromCache = "X-From-Cache"
+)
+
+// A Cache interface is used by the Transport to store and retrieve responses.
+type Cache interface {
+ // Get returns the []byte representation of a cached response and a bool
+ // set to true if the value isn't empty
+ Get(key string) (responseBytes []byte, ok bool)
+ // Set stores the []byte representation of a response against a key
+ Set(key string, responseBytes []byte)
+ // Delete removes the value associated with the key
+ Delete(key string)
+}
+
+// cacheKey returns the cache key for req.
+func cacheKey(req *http.Request) string {
+ return req.URL.String()
+}
+
+// CachedResponse returns the cached http.Response for req if present, and nil
+// otherwise.
+func CachedResponse(c Cache, req *http.Request) (resp *http.Response, err error) {
+ cachedVal, ok := c.Get(cacheKey(req))
+ if !ok {
+ return
+ }
+
+ b := bytes.NewBuffer(cachedVal)
+ return http.ReadResponse(bufio.NewReader(b), req)
+}
+
+// MemoryCache is an implemtation of Cache that stores responses in an in-memory map.
+type MemoryCache struct {
+ mu sync.RWMutex
+ items map[string][]byte
+}
+
+// Get returns the []byte representation of the response and true if present, false if not
+func (c *MemoryCache) Get(key string) (resp []byte, ok bool) {
+ c.mu.RLock()
+ resp, ok = c.items[key]
+ c.mu.RUnlock()
+ return resp, ok
+}
+
+// Set saves response resp to the cache with key
+func (c *MemoryCache) Set(key string, resp []byte) {
+ c.mu.Lock()
+ c.items[key] = resp
+ c.mu.Unlock()
+}
+
+// Delete removes key from the cache
+func (c *MemoryCache) Delete(key string) {
+ c.mu.Lock()
+ delete(c.items, key)
+ c.mu.Unlock()
+}
+
+// NewMemoryCache returns a new Cache that will store items in an in-memory map
+func NewMemoryCache() *MemoryCache {
+ c := &MemoryCache{items: map[string][]byte{}}
+ return c
+}
+
+// Transport is an implementation of http.RoundTripper that will return values from a cache
+// where possible (avoiding a network request) and will additionally add validators (etag/if-modified-since)
+// to repeated requests allowing servers to return 304 / Not Modified
+type Transport struct {
+ // The RoundTripper interface actually used to make requests
+ // If nil, http.DefaultTransport is used
+ Transport http.RoundTripper
+ Cache Cache
+ // If true, responses returned from the cache will be given an extra header, X-From-Cache
+ MarkCachedResponses bool
+}
+
+// NewTransport returns a new Transport with the
+// provided Cache implementation and MarkCachedResponses set to true
+func NewTransport(c Cache) *Transport {
+ return &Transport{Cache: c, MarkCachedResponses: true}
+}
+
+// Client returns an *http.Client that caches responses.
+func (t *Transport) Client() *http.Client {
+ return &http.Client{Transport: t}
+}
+
+// varyMatches will return false unless all of the cached values for the headers listed in Vary
+// match the new request
+func varyMatches(cachedResp *http.Response, req *http.Request) bool {
+ for _, header := range headerAllCommaSepValues(cachedResp.Header, "vary") {
+ header = http.CanonicalHeaderKey(header)
+ if header != "" && req.Header.Get(header) != cachedResp.Header.Get("X-Varied-"+header) {
+ return false
+ }
+ }
+ return true
+}
+
+// RoundTrip takes a Request and returns a Response
+//
+// If there is a fresh Response already in cache, then it will be returned without connecting to
+// the server.
+//
+// If there is a stale Response, then any validators it contains will be set on the new request
+// to give the server a chance to respond with NotModified. If this happens, then the cached Response
+// will be returned.
+func (t *Transport) RoundTrip(req *http.Request) (resp *http.Response, err error) {
+ cacheKey := cacheKey(req)
+ cacheable := (req.Method == "GET" || req.Method == "HEAD") && req.Header.Get("range") == ""
+ var cachedResp *http.Response
+ if cacheable {
+ cachedResp, err = CachedResponse(t.Cache, req)
+ } else {
+ // Need to invalidate an existing value
+ t.Cache.Delete(cacheKey)
+ }
+
+ transport := t.Transport
+ if transport == nil {
+ transport = http.DefaultTransport
+ }
+
+ if cacheable && cachedResp != nil && err == nil {
+ if t.MarkCachedResponses {
+ cachedResp.Header.Set(XFromCache, "1")
+ }
+
+ if varyMatches(cachedResp, req) {
+ // Can only use cached value if the new request doesn't Vary significantly
+ freshness := getFreshness(cachedResp.Header, req.Header)
+ if freshness == fresh {
+ return cachedResp, nil
+ }
+
+ if freshness == stale {
+ var req2 *http.Request
+ // Add validators if caller hasn't already done so
+ etag := cachedResp.Header.Get("etag")
+ if etag != "" && req.Header.Get("etag") == "" {
+ req2 = cloneRequest(req)
+ req2.Header.Set("if-none-match", etag)
+ }
+ lastModified := cachedResp.Header.Get("last-modified")
+ if lastModified != "" && req.Header.Get("last-modified") == "" {
+ if req2 == nil {
+ req2 = cloneRequest(req)
+ }
+ req2.Header.Set("if-modified-since", lastModified)
+ }
+ if req2 != nil {
+ req = req2
+ }
+ }
+ }
+
+ resp, err = transport.RoundTrip(req)
+ if err == nil && req.Method == "GET" && resp.StatusCode == http.StatusNotModified {
+ // Replace the 304 response with the one from cache, but update with some new headers
+ endToEndHeaders := getEndToEndHeaders(resp.Header)
+ for _, header := range endToEndHeaders {
+ cachedResp.Header[header] = resp.Header[header]
+ }
+ cachedResp.Status = fmt.Sprintf("%d %s", http.StatusOK, http.StatusText(http.StatusOK))
+ cachedResp.StatusCode = http.StatusOK
+
+ resp = cachedResp
+ } else if (err != nil || (cachedResp != nil && resp.StatusCode >= 500)) &&
+ req.Method == "GET" && canStaleOnError(cachedResp.Header, req.Header) {
+ // In case of transport failure and stale-if-error activated, returns cached content
+ // when available
+ cachedResp.Status = fmt.Sprintf("%d %s", http.StatusOK, http.StatusText(http.StatusOK))
+ cachedResp.StatusCode = http.StatusOK
+ return cachedResp, nil
+ } else {
+ if err != nil || resp.StatusCode != http.StatusOK {
+ t.Cache.Delete(cacheKey)
+ }
+ if err != nil {
+ return nil, err
+ }
+ }
+ } else {
+ reqCacheControl := parseCacheControl(req.Header)
+ if _, ok := reqCacheControl["only-if-cached"]; ok {
+ resp = newGatewayTimeoutResponse(req)
+ } else {
+ resp, err = transport.RoundTrip(req)
+ if err != nil {
+ return nil, err
+ }
+ }
+ }
+
+ if cacheable && canStore(parseCacheControl(req.Header), parseCacheControl(resp.Header)) {
+ for _, varyKey := range headerAllCommaSepValues(resp.Header, "vary") {
+ varyKey = http.CanonicalHeaderKey(varyKey)
+ fakeHeader := "X-Varied-" + varyKey
+ reqValue := req.Header.Get(varyKey)
+ if reqValue != "" {
+ resp.Header.Set(fakeHeader, reqValue)
+ }
+ }
+ switch req.Method {
+ case "GET":
+ // Delay caching until EOF is reached.
+ resp.Body = &cachingReadCloser{
+ R: resp.Body,
+ OnEOF: func(r io.Reader) {
+ resp := *resp
+ resp.Body = ioutil.NopCloser(r)
+ respBytes, err := httputil.DumpResponse(&resp, true)
+ if err == nil {
+ t.Cache.Set(cacheKey, respBytes)
+ }
+ },
+ }
+ default:
+ respBytes, err := httputil.DumpResponse(resp, true)
+ if err == nil {
+ t.Cache.Set(cacheKey, respBytes)
+ }
+ }
+ } else {
+ t.Cache.Delete(cacheKey)
+ }
+ return resp, nil
+}
+
+// ErrNoDateHeader indicates that the HTTP headers contained no Date header.
+var ErrNoDateHeader = errors.New("no Date header")
+
+// Date parses and returns the value of the Date header.
+func Date(respHeaders http.Header) (date time.Time, err error) {
+ dateHeader := respHeaders.Get("date")
+ if dateHeader == "" {
+ err = ErrNoDateHeader
+ return
+ }
+
+ return time.Parse(time.RFC1123, dateHeader)
+}
+
+type realClock struct{}
+
+func (c *realClock) since(d time.Time) time.Duration {
+ return time.Since(d)
+}
+
+type timer interface {
+ since(d time.Time) time.Duration
+}
+
+var clock timer = &realClock{}
+
+// getFreshness will return one of fresh/stale/transparent based on the cache-control
+// values of the request and the response
+//
+// fresh indicates the response can be returned
+// stale indicates that the response needs validating before it is returned
+// transparent indicates the response should not be used to fulfil the request
+//
+// Because this is only a private cache, 'public' and 'private' in cache-control aren't
+// signficant. Similarly, smax-age isn't used.
+func getFreshness(respHeaders, reqHeaders http.Header) (freshness int) {
+ respCacheControl := parseCacheControl(respHeaders)
+ reqCacheControl := parseCacheControl(reqHeaders)
+ if _, ok := reqCacheControl["no-cache"]; ok {
+ return transparent
+ }
+ if _, ok := respCacheControl["no-cache"]; ok {
+ return stale
+ }
+ if _, ok := reqCacheControl["only-if-cached"]; ok {
+ return fresh
+ }
+
+ date, err := Date(respHeaders)
+ if err != nil {
+ return stale
+ }
+ currentAge := clock.since(date)
+
+ var lifetime time.Duration
+ var zeroDuration time.Duration
+
+ // If a response includes both an Expires header and a max-age directive,
+ // the max-age directive overrides the Expires header, even if the Expires header is more restrictive.
+ if maxAge, ok := respCacheControl["max-age"]; ok {
+ lifetime, err = time.ParseDuration(maxAge + "s")
+ if err != nil {
+ lifetime = zeroDuration
+ }
+ } else {
+ expiresHeader := respHeaders.Get("Expires")
+ if expiresHeader != "" {
+ expires, err := time.Parse(time.RFC1123, expiresHeader)
+ if err != nil {
+ lifetime = zeroDuration
+ } else {
+ lifetime = expires.Sub(date)
+ }
+ }
+ }
+
+ if maxAge, ok := reqCacheControl["max-age"]; ok {
+ // the client is willing to accept a response whose age is no greater than the specified time in seconds
+ lifetime, err = time.ParseDuration(maxAge + "s")
+ if err != nil {
+ lifetime = zeroDuration
+ }
+ }
+ if minfresh, ok := reqCacheControl["min-fresh"]; ok {
+ // the client wants a response that will still be fresh for at least the specified number of seconds.
+ minfreshDuration, err := time.ParseDuration(minfresh + "s")
+ if err == nil {
+ currentAge = time.Duration(currentAge + minfreshDuration)
+ }
+ }
+
+ if maxstale, ok := reqCacheControl["max-stale"]; ok {
+ // Indicates that the client is willing to accept a response that has exceeded its expiration time.
+ // If max-stale is assigned a value, then the client is willing to accept a response that has exceeded
+ // its expiration time by no more than the specified number of seconds.
+ // If no value is assigned to max-stale, then the client is willing to accept a stale response of any age.
+ //
+ // Responses served only because of a max-stale value are supposed to have a Warning header added to them,
+ // but that seems like a hassle, and is it actually useful? If so, then there needs to be a different
+ // return-value available here.
+ if maxstale == "" {
+ return fresh
+ }
+ maxstaleDuration, err := time.ParseDuration(maxstale + "s")
+ if err == nil {
+ currentAge = time.Duration(currentAge - maxstaleDuration)
+ }
+ }
+
+ if lifetime > currentAge {
+ return fresh
+ }
+
+ return stale
+}
+
+// Returns true if either the request or the response includes the stale-if-error
+// cache control extension: https://tools.ietf.org/html/rfc5861
+func canStaleOnError(respHeaders, reqHeaders http.Header) bool {
+ respCacheControl := parseCacheControl(respHeaders)
+ reqCacheControl := parseCacheControl(reqHeaders)
+
+ var err error
+ lifetime := time.Duration(-1)
+
+ if staleMaxAge, ok := respCacheControl["stale-if-error"]; ok {
+ if staleMaxAge != "" {
+ lifetime, err = time.ParseDuration(staleMaxAge + "s")
+ if err != nil {
+ return false
+ }
+ } else {
+ return true
+ }
+ }
+ if staleMaxAge, ok := reqCacheControl["stale-if-error"]; ok {
+ if staleMaxAge != "" {
+ lifetime, err = time.ParseDuration(staleMaxAge + "s")
+ if err != nil {
+ return false
+ }
+ } else {
+ return true
+ }
+ }
+
+ if lifetime >= 0 {
+ date, err := Date(respHeaders)
+ if err != nil {
+ return false
+ }
+ currentAge := clock.since(date)
+ if lifetime > currentAge {
+ return true
+ }
+ }
+
+ return false
+}
+
+func getEndToEndHeaders(respHeaders http.Header) []string {
+ // These headers are always hop-by-hop
+ hopByHopHeaders := map[string]struct{}{
+ "Connection": struct{}{},
+ "Keep-Alive": struct{}{},
+ "Proxy-Authenticate": struct{}{},
+ "Proxy-Authorization": struct{}{},
+ "Te": struct{}{},
+ "Trailers": struct{}{},
+ "Transfer-Encoding": struct{}{},
+ "Upgrade": struct{}{},
+ }
+
+ for _, extra := range strings.Split(respHeaders.Get("connection"), ",") {
+ // any header listed in connection, if present, is also considered hop-by-hop
+ if strings.Trim(extra, " ") != "" {
+ hopByHopHeaders[http.CanonicalHeaderKey(extra)] = struct{}{}
+ }
+ }
+ endToEndHeaders := []string{}
+ for respHeader, _ := range respHeaders {
+ if _, ok := hopByHopHeaders[respHeader]; !ok {
+ endToEndHeaders = append(endToEndHeaders, respHeader)
+ }
+ }
+ return endToEndHeaders
+}
+
+func canStore(reqCacheControl, respCacheControl cacheControl) (canStore bool) {
+ if _, ok := respCacheControl["no-store"]; ok {
+ return false
+ }
+ if _, ok := reqCacheControl["no-store"]; ok {
+ return false
+ }
+ return true
+}
+
+func newGatewayTimeoutResponse(req *http.Request) *http.Response {
+ var braw bytes.Buffer
+ braw.WriteString("HTTP/1.1 504 Gateway Timeout\r\n\r\n")
+ resp, err := http.ReadResponse(bufio.NewReader(&braw), req)
+ if err != nil {
+ panic(err)
+ }
+ return resp
+}
+
+// cloneRequest returns a clone of the provided *http.Request.
+// The clone is a shallow copy of the struct and its Header map.
+// (This function copyright goauth2 authors: https://code.google.com/p/goauth2)
+func cloneRequest(r *http.Request) *http.Request {
+ // shallow copy of the struct
+ r2 := new(http.Request)
+ *r2 = *r
+ // deep copy of the Header
+ r2.Header = make(http.Header)
+ for k, s := range r.Header {
+ r2.Header[k] = s
+ }
+ return r2
+}
+
+type cacheControl map[string]string
+
+func parseCacheControl(headers http.Header) cacheControl {
+ cc := cacheControl{}
+ ccHeader := headers.Get("Cache-Control")
+ for _, part := range strings.Split(ccHeader, ",") {
+ part = strings.Trim(part, " ")
+ if part == "" {
+ continue
+ }
+ if strings.ContainsRune(part, '=') {
+ keyval := strings.Split(part, "=")
+ cc[strings.Trim(keyval[0], " ")] = strings.Trim(keyval[1], ",")
+ } else {
+ cc[part] = ""
+ }
+ }
+ return cc
+}
+
+// headerAllCommaSepValues returns all comma-separated values (each
+// with whitespace trimmed) for header name in headers. According to
+// Section 4.2 of the HTTP/1.1 spec
+// (http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2),
+// values from multiple occurrences of a header should be concatenated, if
+// the header's value is a comma-separated list.
+func headerAllCommaSepValues(headers http.Header, name string) []string {
+ var vals []string
+ for _, val := range headers[http.CanonicalHeaderKey(name)] {
+ fields := strings.Split(val, ",")
+ for i, f := range fields {
+ fields[i] = strings.TrimSpace(f)
+ }
+ vals = append(vals, fields...)
+ }
+ return vals
+}
+
+// cachingReadCloser is a wrapper around ReadCloser R that calls OnEOF
+// handler with a full copy of the content read from R when EOF is
+// reached.
+type cachingReadCloser struct {
+ // Underlying ReadCloser.
+ R io.ReadCloser
+ // OnEOF is called with a copy of the content of R when EOF is reached.
+ OnEOF func(io.Reader)
+
+ buf bytes.Buffer // buf stores a copy of the content of R.
+}
+
+// Read reads the next len(p) bytes from R or until R is drained. The
+// return value n is the number of bytes read. If R has no data to
+// return, err is io.EOF and OnEOF is called with a full copy of what
+// has been read so far.
+func (r *cachingReadCloser) Read(p []byte) (n int, err error) {
+ n, err = r.R.Read(p)
+ r.buf.Write(p[:n])
+ if err == io.EOF {
+ r.OnEOF(bytes.NewReader(r.buf.Bytes()))
+ }
+ return n, err
+}
+
+func (r *cachingReadCloser) Close() error {
+ return r.R.Close()
+}
+
+// NewMemoryCacheTransport returns a new Transport using the in-memory cache implementation
+func NewMemoryCacheTransport() *Transport {
+ c := NewMemoryCache()
+ t := NewTransport(c)
+ return t
+}
diff --git a/vendor/github.com/peterbourgon/diskv/LICENSE b/vendor/github.com/peterbourgon/diskv/LICENSE
new file mode 100644
index 00000000..41ce7f16
--- /dev/null
+++ b/vendor/github.com/peterbourgon/diskv/LICENSE
@@ -0,0 +1,19 @@
+Copyright (c) 2011-2012 Peter Bourgon
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/vendor/github.com/peterbourgon/diskv/README.md b/vendor/github.com/peterbourgon/diskv/README.md
new file mode 100644
index 00000000..3474739e
--- /dev/null
+++ b/vendor/github.com/peterbourgon/diskv/README.md
@@ -0,0 +1,141 @@
+# What is diskv?
+
+Diskv (disk-vee) is a simple, persistent key-value store written in the Go
+language. It starts with an incredibly simple API for storing arbitrary data on
+a filesystem by key, and builds several layers of performance-enhancing
+abstraction on top. The end result is a conceptually simple, but highly
+performant, disk-backed storage system.
+
+[![Build Status][1]][2]
+
+[1]: https://drone.io/github.com/peterbourgon/diskv/status.png
+[2]: https://drone.io/github.com/peterbourgon/diskv/latest
+
+
+# Installing
+
+Install [Go 1][3], either [from source][4] or [with a prepackaged binary][5].
+Then,
+
+```bash
+$ go get github.com/peterbourgon/diskv
+```
+
+[3]: http://golang.org
+[4]: http://golang.org/doc/install/source
+[5]: http://golang.org/doc/install
+
+
+# Usage
+
+```go
+package main
+
+import (
+ "fmt"
+ "github.com/peterbourgon/diskv"
+)
+
+func main() {
+ // Simplest transform function: put all the data files into the base dir.
+ flatTransform := func(s string) []string { return []string{} }
+
+ // Initialize a new diskv store, rooted at "my-data-dir", with a 1MB cache.
+ d := diskv.New(diskv.Options{
+ BasePath: "my-data-dir",
+ Transform: flatTransform,
+ CacheSizeMax: 1024 * 1024,
+ })
+
+ // Write three bytes to the key "alpha".
+ key := "alpha"
+ d.Write(key, []byte{'1', '2', '3'})
+
+ // Read the value back out of the store.
+ value, _ := d.Read(key)
+ fmt.Printf("%v\n", value)
+
+ // Erase the key+value from the store (and the disk).
+ d.Erase(key)
+}
+```
+
+More complex examples can be found in the "examples" subdirectory.
+
+
+# Theory
+
+## Basic idea
+
+At its core, diskv is a map of a key (`string`) to arbitrary data (`[]byte`).
+The data is written to a single file on disk, with the same name as the key.
+The key determines where that file will be stored, via a user-provided
+`TransformFunc`, which takes a key and returns a slice (`[]string`)
+corresponding to a path list where the key file will be stored. The simplest
+TransformFunc,
+
+```go
+func SimpleTransform (key string) []string {
+ return []string{}
+}
+```
+
+will place all keys in the same, base directory. The design is inspired by
+[Redis diskstore][6]; a TransformFunc which emulates the default diskstore
+behavior is available in the content-addressable-storage example.
+
+[6]: http://groups.google.com/group/redis-db/browse_thread/thread/d444bc786689bde9?pli=1
+
+**Note** that your TransformFunc should ensure that one valid key doesn't
+transform to a subset of another valid key. That is, it shouldn't be possible
+to construct valid keys that resolve to directory names. As a concrete example,
+if your TransformFunc splits on every 3 characters, then
+
+```go
+d.Write("abcabc", val) // OK: written to /abc/abc/abcabc
+d.Write("abc", val) // Error: attempted write to /abc/abc, but it's a directory
+```
+
+This will be addressed in an upcoming version of diskv.
+
+Probably the most important design principle behind diskv is that your data is
+always flatly available on the disk. diskv will never do anything that would
+prevent you from accessing, copying, backing up, or otherwise interacting with
+your data via common UNIX commandline tools.
+
+## Adding a cache
+
+An in-memory caching layer is provided by combining the BasicStore
+functionality with a simple map structure, and keeping it up-to-date as
+appropriate. Since the map structure in Go is not threadsafe, it's combined
+with a RWMutex to provide safe concurrent access.
+
+## Adding order
+
+diskv is a key-value store and therefore inherently unordered. An ordering
+system can be injected into the store by passing something which satisfies the
+diskv.Index interface. (A default implementation, using Google's
+[btree][7] package, is provided.) Basically, diskv keeps an ordered (by a
+user-provided Less function) index of the keys, which can be queried.
+
+[7]: https://github.com/google/btree
+
+## Adding compression
+
+Something which implements the diskv.Compression interface may be passed
+during store creation, so that all Writes and Reads are filtered through
+a compression/decompression pipeline. Several default implementations,
+using stdlib compression algorithms, are provided. Note that data is cached
+compressed; the cost of decompression is borne with each Read.
+
+## Streaming
+
+diskv also now provides ReadStream and WriteStream methods, to allow very large
+data to be handled efficiently.
+
+
+# Future plans
+
+ * Needs plenty of robust testing: huge datasets, etc...
+ * More thorough benchmarking
+ * Your suggestions for use-cases I haven't thought of
diff --git a/vendor/github.com/peterbourgon/diskv/compression.go b/vendor/github.com/peterbourgon/diskv/compression.go
new file mode 100644
index 00000000..5192b027
--- /dev/null
+++ b/vendor/github.com/peterbourgon/diskv/compression.go
@@ -0,0 +1,64 @@
+package diskv
+
+import (
+ "compress/flate"
+ "compress/gzip"
+ "compress/zlib"
+ "io"
+)
+
+// Compression is an interface that Diskv uses to implement compression of
+// data. Writer takes a destination io.Writer and returns a WriteCloser that
+// compresses all data written through it. Reader takes a source io.Reader and
+// returns a ReadCloser that decompresses all data read through it. You may
+// define these methods on your own type, or use one of the NewCompression
+// helpers.
+type Compression interface {
+ Writer(dst io.Writer) (io.WriteCloser, error)
+ Reader(src io.Reader) (io.ReadCloser, error)
+}
+
+// NewGzipCompression returns a Gzip-based Compression.
+func NewGzipCompression() Compression {
+ return NewGzipCompressionLevel(flate.DefaultCompression)
+}
+
+// NewGzipCompressionLevel returns a Gzip-based Compression with the given level.
+func NewGzipCompressionLevel(level int) Compression {
+ return &genericCompression{
+ wf: func(w io.Writer) (io.WriteCloser, error) { return gzip.NewWriterLevel(w, level) },
+ rf: func(r io.Reader) (io.ReadCloser, error) { return gzip.NewReader(r) },
+ }
+}
+
+// NewZlibCompression returns a Zlib-based Compression.
+func NewZlibCompression() Compression {
+ return NewZlibCompressionLevel(flate.DefaultCompression)
+}
+
+// NewZlibCompressionLevel returns a Zlib-based Compression with the given level.
+func NewZlibCompressionLevel(level int) Compression {
+ return NewZlibCompressionLevelDict(level, nil)
+}
+
+// NewZlibCompressionLevelDict returns a Zlib-based Compression with the given
+// level, based on the given dictionary.
+func NewZlibCompressionLevelDict(level int, dict []byte) Compression {
+ return &genericCompression{
+ func(w io.Writer) (io.WriteCloser, error) { return zlib.NewWriterLevelDict(w, level, dict) },
+ func(r io.Reader) (io.ReadCloser, error) { return zlib.NewReaderDict(r, dict) },
+ }
+}
+
+type genericCompression struct {
+ wf func(w io.Writer) (io.WriteCloser, error)
+ rf func(r io.Reader) (io.ReadCloser, error)
+}
+
+func (g *genericCompression) Writer(dst io.Writer) (io.WriteCloser, error) {
+ return g.wf(dst)
+}
+
+func (g *genericCompression) Reader(src io.Reader) (io.ReadCloser, error) {
+ return g.rf(src)
+}
diff --git a/vendor/github.com/peterbourgon/diskv/diskv.go b/vendor/github.com/peterbourgon/diskv/diskv.go
new file mode 100644
index 00000000..ea05842c
--- /dev/null
+++ b/vendor/github.com/peterbourgon/diskv/diskv.go
@@ -0,0 +1,578 @@
+// Diskv (disk-vee) is a simple, persistent, key-value store.
+// It stores all data flatly on the filesystem.
+
+package diskv
+
+import (
+ "bytes"
+ "errors"
+ "fmt"
+ "io"
+ "io/ioutil"
+ "os"
+ "path/filepath"
+ "strings"
+ "sync"
+ "syscall"
+)
+
+const (
+ defaultBasePath = "diskv"
+ defaultFilePerm os.FileMode = 0666
+ defaultPathPerm os.FileMode = 0777
+)
+
+var (
+ defaultTransform = func(s string) []string { return []string{} }
+ errCanceled = errors.New("canceled")
+ errEmptyKey = errors.New("empty key")
+ errBadKey = errors.New("bad key")
+ errImportDirectory = errors.New("can't import a directory")
+)
+
+// TransformFunction transforms a key into a slice of strings, with each
+// element in the slice representing a directory in the file path where the
+// key's entry will eventually be stored.
+//
+// For example, if TransformFunc transforms "abcdef" to ["ab", "cde", "f"],
+// the final location of the data file will be /ab/cde/f/abcdef
+type TransformFunction func(s string) []string
+
+// Options define a set of properties that dictate Diskv behavior.
+// All values are optional.
+type Options struct {
+ BasePath string
+ Transform TransformFunction
+ CacheSizeMax uint64 // bytes
+ PathPerm os.FileMode
+ FilePerm os.FileMode
+
+ Index Index
+ IndexLess LessFunction
+
+ Compression Compression
+}
+
+// Diskv implements the Diskv interface. You shouldn't construct Diskv
+// structures directly; instead, use the New constructor.
+type Diskv struct {
+ Options
+ mu sync.RWMutex
+ cache map[string][]byte
+ cacheSize uint64
+}
+
+// New returns an initialized Diskv structure, ready to use.
+// If the path identified by baseDir already contains data,
+// it will be accessible, but not yet cached.
+func New(o Options) *Diskv {
+ if o.BasePath == "" {
+ o.BasePath = defaultBasePath
+ }
+ if o.Transform == nil {
+ o.Transform = defaultTransform
+ }
+ if o.PathPerm == 0 {
+ o.PathPerm = defaultPathPerm
+ }
+ if o.FilePerm == 0 {
+ o.FilePerm = defaultFilePerm
+ }
+
+ d := &Diskv{
+ Options: o,
+ cache: map[string][]byte{},
+ cacheSize: 0,
+ }
+
+ if d.Index != nil && d.IndexLess != nil {
+ d.Index.Initialize(d.IndexLess, d.Keys(nil))
+ }
+
+ return d
+}
+
+// Write synchronously writes the key-value pair to disk, making it immediately
+// available for reads. Write relies on the filesystem to perform an eventual
+// sync to physical media. If you need stronger guarantees, see WriteStream.
+func (d *Diskv) Write(key string, val []byte) error {
+ return d.WriteStream(key, bytes.NewBuffer(val), false)
+}
+
+// WriteStream writes the data represented by the io.Reader to the disk, under
+// the provided key. If sync is true, WriteStream performs an explicit sync on
+// the file as soon as it's written.
+//
+// bytes.Buffer provides io.Reader semantics for basic data types.
+func (d *Diskv) WriteStream(key string, r io.Reader, sync bool) error {
+ if len(key) <= 0 {
+ return errEmptyKey
+ }
+
+ d.mu.Lock()
+ defer d.mu.Unlock()
+
+ return d.writeStreamWithLock(key, r, sync)
+}
+
+// writeStream does no input validation checking.
+// TODO: use atomic FS ops.
+func (d *Diskv) writeStreamWithLock(key string, r io.Reader, sync bool) error {
+ if err := d.ensurePathWithLock(key); err != nil {
+ return fmt.Errorf("ensure path: %s", err)
+ }
+
+ mode := os.O_WRONLY | os.O_CREATE | os.O_TRUNC // overwrite if exists
+ f, err := os.OpenFile(d.completeFilename(key), mode, d.FilePerm)
+ if err != nil {
+ return fmt.Errorf("open file: %s", err)
+ }
+
+ wc := io.WriteCloser(&nopWriteCloser{f})
+ if d.Compression != nil {
+ wc, err = d.Compression.Writer(f)
+ if err != nil {
+ f.Close() // error deliberately ignored
+ return fmt.Errorf("compression writer: %s", err)
+ }
+ }
+
+ if _, err := io.Copy(wc, r); err != nil {
+ f.Close() // error deliberately ignored
+ return fmt.Errorf("i/o copy: %s", err)
+ }
+
+ if err := wc.Close(); err != nil {
+ f.Close() // error deliberately ignored
+ return fmt.Errorf("compression close: %s", err)
+ }
+
+ if sync {
+ if err := f.Sync(); err != nil {
+ f.Close() // error deliberately ignored
+ return fmt.Errorf("file sync: %s", err)
+ }
+ }
+
+ if err := f.Close(); err != nil {
+ return fmt.Errorf("file close: %s", err)
+ }
+
+ if d.Index != nil {
+ d.Index.Insert(key)
+ }
+
+ d.bustCacheWithLock(key) // cache only on read
+
+ return nil
+}
+
+// Import imports the source file into diskv under the destination key. If the
+// destination key already exists, it's overwritten. If move is true, the
+// source file is removed after a successful import.
+func (d *Diskv) Import(srcFilename, dstKey string, move bool) (err error) {
+ if dstKey == "" {
+ return errEmptyKey
+ }
+
+ if fi, err := os.Stat(srcFilename); err != nil {
+ return err
+ } else if fi.IsDir() {
+ return errImportDirectory
+ }
+
+ d.mu.Lock()
+ defer d.mu.Unlock()
+
+ if err := d.ensurePathWithLock(dstKey); err != nil {
+ return fmt.Errorf("ensure path: %s", err)
+ }
+
+ if move {
+ if err := syscall.Rename(srcFilename, d.completeFilename(dstKey)); err == nil {
+ d.bustCacheWithLock(dstKey)
+ return nil
+ } else if err != syscall.EXDEV {
+ // If it failed due to being on a different device, fall back to copying
+ return err
+ }
+ }
+
+ f, err := os.Open(srcFilename)
+ if err != nil {
+ return err
+ }
+ defer f.Close()
+ err = d.writeStreamWithLock(dstKey, f, false)
+ if err == nil && move {
+ err = os.Remove(srcFilename)
+ }
+ return err
+}
+
+// Read reads the key and returns the value.
+// If the key is available in the cache, Read won't touch the disk.
+// If the key is not in the cache, Read will have the side-effect of
+// lazily caching the value.
+func (d *Diskv) Read(key string) ([]byte, error) {
+ rc, err := d.ReadStream(key, false)
+ if err != nil {
+ return []byte{}, err
+ }
+ defer rc.Close()
+ return ioutil.ReadAll(rc)
+}
+
+// ReadStream reads the key and returns the value (data) as an io.ReadCloser.
+// If the value is cached from a previous read, and direct is false,
+// ReadStream will use the cached value. Otherwise, it will return a handle to
+// the file on disk, and cache the data on read.
+//
+// If direct is true, ReadStream will lazily delete any cached value for the
+// key, and return a direct handle to the file on disk.
+//
+// If compression is enabled, ReadStream taps into the io.Reader stream prior
+// to decompression, and caches the compressed data.
+func (d *Diskv) ReadStream(key string, direct bool) (io.ReadCloser, error) {
+ d.mu.RLock()
+ defer d.mu.RUnlock()
+
+ if val, ok := d.cache[key]; ok {
+ if !direct {
+ buf := bytes.NewBuffer(val)
+ if d.Compression != nil {
+ return d.Compression.Reader(buf)
+ }
+ return ioutil.NopCloser(buf), nil
+ }
+
+ go func() {
+ d.mu.Lock()
+ defer d.mu.Unlock()
+ d.uncacheWithLock(key, uint64(len(val)))
+ }()
+ }
+
+ return d.readWithRLock(key)
+}
+
+// read ignores the cache, and returns an io.ReadCloser representing the
+// decompressed data for the given key, streamed from the disk. Clients should
+// acquire a read lock on the Diskv and check the cache themselves before
+// calling read.
+func (d *Diskv) readWithRLock(key string) (io.ReadCloser, error) {
+ filename := d.completeFilename(key)
+
+ fi, err := os.Stat(filename)
+ if err != nil {
+ return nil, err
+ }
+ if fi.IsDir() {
+ return nil, os.ErrNotExist
+ }
+
+ f, err := os.Open(filename)
+ if err != nil {
+ return nil, err
+ }
+
+ var r io.Reader
+ if d.CacheSizeMax > 0 {
+ r = newSiphon(f, d, key)
+ } else {
+ r = &closingReader{f}
+ }
+
+ var rc = io.ReadCloser(ioutil.NopCloser(r))
+ if d.Compression != nil {
+ rc, err = d.Compression.Reader(r)
+ if err != nil {
+ return nil, err
+ }
+ }
+
+ return rc, nil
+}
+
+// closingReader provides a Reader that automatically closes the
+// embedded ReadCloser when it reaches EOF
+type closingReader struct {
+ rc io.ReadCloser
+}
+
+func (cr closingReader) Read(p []byte) (int, error) {
+ n, err := cr.rc.Read(p)
+ if err == io.EOF {
+ if closeErr := cr.rc.Close(); closeErr != nil {
+ return n, closeErr // close must succeed for Read to succeed
+ }
+ }
+ return n, err
+}
+
+// siphon is like a TeeReader: it copies all data read through it to an
+// internal buffer, and moves that buffer to the cache at EOF.
+type siphon struct {
+ f *os.File
+ d *Diskv
+ key string
+ buf *bytes.Buffer
+}
+
+// newSiphon constructs a siphoning reader that represents the passed file.
+// When a successful series of reads ends in an EOF, the siphon will write
+// the buffered data to Diskv's cache under the given key.
+func newSiphon(f *os.File, d *Diskv, key string) io.Reader {
+ return &siphon{
+ f: f,
+ d: d,
+ key: key,
+ buf: &bytes.Buffer{},
+ }
+}
+
+// Read implements the io.Reader interface for siphon.
+func (s *siphon) Read(p []byte) (int, error) {
+ n, err := s.f.Read(p)
+
+ if err == nil {
+ return s.buf.Write(p[0:n]) // Write must succeed for Read to succeed
+ }
+
+ if err == io.EOF {
+ s.d.cacheWithoutLock(s.key, s.buf.Bytes()) // cache may fail
+ if closeErr := s.f.Close(); closeErr != nil {
+ return n, closeErr // close must succeed for Read to succeed
+ }
+ return n, err
+ }
+
+ return n, err
+}
+
+// Erase synchronously erases the given key from the disk and the cache.
+func (d *Diskv) Erase(key string) error {
+ d.mu.Lock()
+ defer d.mu.Unlock()
+
+ d.bustCacheWithLock(key)
+
+ // erase from index
+ if d.Index != nil {
+ d.Index.Delete(key)
+ }
+
+ // erase from disk
+ filename := d.completeFilename(key)
+ if s, err := os.Stat(filename); err == nil {
+ if s.IsDir() {
+ return errBadKey
+ }
+ if err = os.Remove(filename); err != nil {
+ return err
+ }
+ } else {
+ // Return err as-is so caller can do os.IsNotExist(err).
+ return err
+ }
+
+ // clean up and return
+ d.pruneDirsWithLock(key)
+ return nil
+}
+
+// EraseAll will delete all of the data from the store, both in the cache and on
+// the disk. Note that EraseAll doesn't distinguish diskv-related data from non-
+// diskv-related data. Care should be taken to always specify a diskv base
+// directory that is exclusively for diskv data.
+func (d *Diskv) EraseAll() error {
+ d.mu.Lock()
+ defer d.mu.Unlock()
+ d.cache = make(map[string][]byte)
+ d.cacheSize = 0
+ return os.RemoveAll(d.BasePath)
+}
+
+// Has returns true if the given key exists.
+func (d *Diskv) Has(key string) bool {
+ d.mu.Lock()
+ defer d.mu.Unlock()
+
+ if _, ok := d.cache[key]; ok {
+ return true
+ }
+
+ filename := d.completeFilename(key)
+ s, err := os.Stat(filename)
+ if err != nil {
+ return false
+ }
+ if s.IsDir() {
+ return false
+ }
+
+ return true
+}
+
+// Keys returns a channel that will yield every key accessible by the store,
+// in undefined order. If a cancel channel is provided, closing it will
+// terminate and close the keys channel.
+func (d *Diskv) Keys(cancel <-chan struct{}) <-chan string {
+ return d.KeysPrefix("", cancel)
+}
+
+// KeysPrefix returns a channel that will yield every key accessible by the
+// store with the given prefix, in undefined order. If a cancel channel is
+// provided, closing it will terminate and close the keys channel. If the
+// provided prefix is the empty string, all keys will be yielded.
+func (d *Diskv) KeysPrefix(prefix string, cancel <-chan struct{}) <-chan string {
+ var prepath string
+ if prefix == "" {
+ prepath = d.BasePath
+ } else {
+ prepath = d.pathFor(prefix)
+ }
+ c := make(chan string)
+ go func() {
+ filepath.Walk(prepath, walker(c, prefix, cancel))
+ close(c)
+ }()
+ return c
+}
+
+// walker returns a function which satisfies the filepath.WalkFunc interface.
+// It sends every non-directory file entry down the channel c.
+func walker(c chan<- string, prefix string, cancel <-chan struct{}) filepath.WalkFunc {
+ return func(path string, info os.FileInfo, err error) error {
+ if err != nil {
+ return err
+ }
+
+ if info.IsDir() || !strings.HasPrefix(info.Name(), prefix) {
+ return nil // "pass"
+ }
+
+ select {
+ case c <- info.Name():
+ case <-cancel:
+ return errCanceled
+ }
+
+ return nil
+ }
+}
+
+// pathFor returns the absolute path for location on the filesystem where the
+// data for the given key will be stored.
+func (d *Diskv) pathFor(key string) string {
+ return filepath.Join(d.BasePath, filepath.Join(d.Transform(key)...))
+}
+
+// ensurePathWithLock is a helper function that generates all necessary
+// directories on the filesystem for the given key.
+func (d *Diskv) ensurePathWithLock(key string) error {
+ return os.MkdirAll(d.pathFor(key), d.PathPerm)
+}
+
+// completeFilename returns the absolute path to the file for the given key.
+func (d *Diskv) completeFilename(key string) string {
+ return filepath.Join(d.pathFor(key), key)
+}
+
+// cacheWithLock attempts to cache the given key-value pair in the store's
+// cache. It can fail if the value is larger than the cache's maximum size.
+func (d *Diskv) cacheWithLock(key string, val []byte) error {
+ valueSize := uint64(len(val))
+ if err := d.ensureCacheSpaceWithLock(valueSize); err != nil {
+ return fmt.Errorf("%s; not caching", err)
+ }
+
+ // be very strict about memory guarantees
+ if (d.cacheSize + valueSize) > d.CacheSizeMax {
+ panic(fmt.Sprintf("failed to make room for value (%d/%d)", valueSize, d.CacheSizeMax))
+ }
+
+ d.cache[key] = val
+ d.cacheSize += valueSize
+ return nil
+}
+
+// cacheWithoutLock acquires the store's (write) mutex and calls cacheWithLock.
+func (d *Diskv) cacheWithoutLock(key string, val []byte) error {
+ d.mu.Lock()
+ defer d.mu.Unlock()
+ return d.cacheWithLock(key, val)
+}
+
+func (d *Diskv) bustCacheWithLock(key string) {
+ if val, ok := d.cache[key]; ok {
+ d.uncacheWithLock(key, uint64(len(val)))
+ }
+}
+
+func (d *Diskv) uncacheWithLock(key string, sz uint64) {
+ d.cacheSize -= sz
+ delete(d.cache, key)
+}
+
+// pruneDirsWithLock deletes empty directories in the path walk leading to the
+// key k. Typically this function is called after an Erase is made.
+func (d *Diskv) pruneDirsWithLock(key string) error {
+ pathlist := d.Transform(key)
+ for i := range pathlist {
+ dir := filepath.Join(d.BasePath, filepath.Join(pathlist[:len(pathlist)-i]...))
+
+ // thanks to Steven Blenkinsop for this snippet
+ switch fi, err := os.Stat(dir); true {
+ case err != nil:
+ return err
+ case !fi.IsDir():
+ panic(fmt.Sprintf("corrupt dirstate at %s", dir))
+ }
+
+ nlinks, err := filepath.Glob(filepath.Join(dir, "*"))
+ if err != nil {
+ return err
+ } else if len(nlinks) > 0 {
+ return nil // has subdirs -- do not prune
+ }
+ if err = os.Remove(dir); err != nil {
+ return err
+ }
+ }
+
+ return nil
+}
+
+// ensureCacheSpaceWithLock deletes entries from the cache in arbitrary order
+// until the cache has at least valueSize bytes available.
+func (d *Diskv) ensureCacheSpaceWithLock(valueSize uint64) error {
+ if valueSize > d.CacheSizeMax {
+ return fmt.Errorf("value size (%d bytes) too large for cache (%d bytes)", valueSize, d.CacheSizeMax)
+ }
+
+ safe := func() bool { return (d.cacheSize + valueSize) <= d.CacheSizeMax }
+
+ for key, val := range d.cache {
+ if safe() {
+ break
+ }
+
+ d.uncacheWithLock(key, uint64(len(val)))
+ }
+
+ if !safe() {
+ panic(fmt.Sprintf("%d bytes still won't fit in the cache! (max %d bytes)", valueSize, d.CacheSizeMax))
+ }
+
+ return nil
+}
+
+// nopWriteCloser wraps an io.Writer and provides a no-op Close method to
+// satisfy the io.WriteCloser interface.
+type nopWriteCloser struct {
+ io.Writer
+}
+
+func (wc *nopWriteCloser) Write(p []byte) (int, error) { return wc.Writer.Write(p) }
+func (wc *nopWriteCloser) Close() error { return nil }
diff --git a/vendor/github.com/peterbourgon/diskv/index.go b/vendor/github.com/peterbourgon/diskv/index.go
new file mode 100644
index 00000000..96fee515
--- /dev/null
+++ b/vendor/github.com/peterbourgon/diskv/index.go
@@ -0,0 +1,115 @@
+package diskv
+
+import (
+ "sync"
+
+ "github.com/google/btree"
+)
+
+// Index is a generic interface for things that can
+// provide an ordered list of keys.
+type Index interface {
+ Initialize(less LessFunction, keys <-chan string)
+ Insert(key string)
+ Delete(key string)
+ Keys(from string, n int) []string
+}
+
+// LessFunction is used to initialize an Index of keys in a specific order.
+type LessFunction func(string, string) bool
+
+// btreeString is a custom data type that satisfies the BTree Less interface,
+// making the strings it wraps sortable by the BTree package.
+type btreeString struct {
+ s string
+ l LessFunction
+}
+
+// Less satisfies the BTree.Less interface using the btreeString's LessFunction.
+func (s btreeString) Less(i btree.Item) bool {
+ return s.l(s.s, i.(btreeString).s)
+}
+
+// BTreeIndex is an implementation of the Index interface using google/btree.
+type BTreeIndex struct {
+ sync.RWMutex
+ LessFunction
+ *btree.BTree
+}
+
+// Initialize populates the BTree tree with data from the keys channel,
+// according to the passed less function. It's destructive to the BTreeIndex.
+func (i *BTreeIndex) Initialize(less LessFunction, keys <-chan string) {
+ i.Lock()
+ defer i.Unlock()
+ i.LessFunction = less
+ i.BTree = rebuild(less, keys)
+}
+
+// Insert inserts the given key (only) into the BTree tree.
+func (i *BTreeIndex) Insert(key string) {
+ i.Lock()
+ defer i.Unlock()
+ if i.BTree == nil || i.LessFunction == nil {
+ panic("uninitialized index")
+ }
+ i.BTree.ReplaceOrInsert(btreeString{s: key, l: i.LessFunction})
+}
+
+// Delete removes the given key (only) from the BTree tree.
+func (i *BTreeIndex) Delete(key string) {
+ i.Lock()
+ defer i.Unlock()
+ if i.BTree == nil || i.LessFunction == nil {
+ panic("uninitialized index")
+ }
+ i.BTree.Delete(btreeString{s: key, l: i.LessFunction})
+}
+
+// Keys yields a maximum of n keys in order. If the passed 'from' key is empty,
+// Keys will return the first n keys. If the passed 'from' key is non-empty, the
+// first key in the returned slice will be the key that immediately follows the
+// passed key, in key order.
+func (i *BTreeIndex) Keys(from string, n int) []string {
+ i.RLock()
+ defer i.RUnlock()
+
+ if i.BTree == nil || i.LessFunction == nil {
+ panic("uninitialized index")
+ }
+
+ if i.BTree.Len() <= 0 {
+ return []string{}
+ }
+
+ btreeFrom := btreeString{s: from, l: i.LessFunction}
+ skipFirst := true
+ if len(from) <= 0 || !i.BTree.Has(btreeFrom) {
+ // no such key, so fabricate an always-smallest item
+ btreeFrom = btreeString{s: "", l: func(string, string) bool { return true }}
+ skipFirst = false
+ }
+
+ keys := []string{}
+ iterator := func(i btree.Item) bool {
+ keys = append(keys, i.(btreeString).s)
+ return len(keys) < n
+ }
+ i.BTree.AscendGreaterOrEqual(btreeFrom, iterator)
+
+ if skipFirst && len(keys) > 0 {
+ keys = keys[1:]
+ }
+
+ return keys
+}
+
+// rebuildIndex does the work of regenerating the index
+// with the given keys.
+func rebuild(less LessFunction, keys <-chan string) *btree.BTree {
+ tree := btree.New(2)
+ for key := range keys {
+ tree.ReplaceOrInsert(btreeString{s: key, l: less})
+ }
+ return tree
+}