aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/go-openapi
diff options
context:
space:
mode:
authorGravatar Yong Tang <yong.tang.github@outlook.com> 2017-11-03 00:20:15 -0700
committerGravatar Miek Gieben <miek@miek.nl> 2017-11-03 07:20:15 +0000
commit1fc0c16968304b169fb7eb52f162ffa4c7cdc55c (patch)
treee242db88ffc7aa291a6344d1ab1d6cd07293cba7 /vendor/github.com/go-openapi
parentaf6086d6535e3309e3bd1e521cb4d51ef113f850 (diff)
downloadcoredns-1fc0c16968304b169fb7eb52f162ffa4c7cdc55c.tar.gz
coredns-1fc0c16968304b169fb7eb52f162ffa4c7cdc55c.tar.zst
coredns-1fc0c16968304b169fb7eb52f162ffa4c7cdc55c.zip
Update vendor libraries except client-go, apimachinery and ugorji/go (#1197)
This fix updates vendor libraries except client-go, apimachinery and ugorji/go, as github.com/ugorji/go/codec is causing compatibilities issues. Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
Diffstat (limited to 'vendor/github.com/go-openapi')
-rw-r--r--vendor/github.com/go-openapi/loads/spec.go2
-rw-r--r--vendor/github.com/go-openapi/loads/spec_test.go142
-rw-r--r--vendor/github.com/go-openapi/spec/expander.go24
-rw-r--r--vendor/github.com/go-openapi/spec/items.go11
-rw-r--r--vendor/github.com/go-openapi/spec/refmodifier.go82
-rw-r--r--vendor/github.com/go-openapi/spec/refmodifier_test.go335
-rw-r--r--vendor/github.com/go-openapi/spec/swagger.go2
7 files changed, 587 insertions, 11 deletions
diff --git a/vendor/github.com/go-openapi/loads/spec.go b/vendor/github.com/go-openapi/loads/spec.go
index 6d967389b..2db5cb558 100644
--- a/vendor/github.com/go-openapi/loads/spec.go
+++ b/vendor/github.com/go-openapi/loads/spec.go
@@ -186,7 +186,7 @@ func (d *Document) Expanded(options ...*spec.ExpandOptions) (*Document, error) {
var expandOptions *spec.ExpandOptions
if len(options) > 0 {
- expandOptions = options[1]
+ expandOptions = options[0]
} else {
expandOptions = &spec.ExpandOptions{
RelativeBase: filepath.Dir(d.specFilePath),
diff --git a/vendor/github.com/go-openapi/loads/spec_test.go b/vendor/github.com/go-openapi/loads/spec_test.go
index 5c5e7ca4e..a3b241d95 100644
--- a/vendor/github.com/go-openapi/loads/spec_test.go
+++ b/vendor/github.com/go-openapi/loads/spec_test.go
@@ -32,6 +32,19 @@ func TestLoadsYAMLContent(t *testing.T) {
}
}
+// for issue 11
+func TestRegressionExpand(t *testing.T) {
+ swaggerFile := "fixtures/yaml/swagger/1/2/3/4/swagger.yaml"
+ document, err := Spec(swaggerFile)
+ assert.NoError(t, err)
+ assert.NotNil(t, document)
+ d, err := document.Expanded()
+ assert.NoError(t, err)
+ assert.NotNil(t, d)
+ b, _ := d.Spec().MarshalJSON()
+ assert.JSONEq(t, expectedExpanded, string(b))
+}
+
func TestFailsInvalidJSON(t *testing.T) {
_, err := Analyzed(json.RawMessage([]byte("{]")), "")
@@ -499,3 +512,132 @@ const PetStore20 = `{
}
}
`
+
+const expectedExpanded = `
+{
+ "produces":[
+ "application/json",
+ "plain/text"
+ ],
+ "schemes":[
+ "https",
+ "http"
+ ],
+ "swagger":"2.0",
+ "info":{
+ "description":"Something",
+ "title":"Something",
+ "contact":{
+ "name":"Somebody",
+ "url":"https://url.com",
+ "email":"email@url.com"
+ },
+ "version":"v1"
+ },
+ "host":"security.sonusnet.com",
+ "basePath":"/api",
+ "paths":{
+ "/whatnot":{
+ "get":{
+ "description":"Get something",
+ "responses":{
+ "200":{
+ "description":"The something",
+ "schema":{
+ "description":"A collection of service events",
+ "type":"object",
+ "properties":{
+ "page":{
+ "description":"A description of a paged result",
+ "type":"object",
+ "properties":{
+ "page":{
+ "description":"the page that was requested",
+ "type":"integer"
+ },
+ "page_items":{
+ "description":"the number of items per page requested",
+ "type":"integer"
+ },
+ "pages":{
+ "description":"the total number of pages available",
+ "type":"integer"
+ },
+ "total_items":{
+ "description":"the total number of items available",
+ "type":"integer",
+ "format":"int64"
+ }
+ }
+ },
+ "something":{
+ "description":"Something",
+ "type":"object",
+ "properties":{
+ "p1":{
+ "description":"A string",
+ "type":"string"
+ },
+ "p2":{
+ "description":"An integer",
+ "type":"integer"
+ }
+ }
+ }
+ }
+ }
+ },
+ "500":{
+ "description":"Oops"
+ }
+ }
+ }
+ }
+ },
+ "definitions":{
+ "Something":{
+ "description":"A collection of service events",
+ "type":"object",
+ "properties":{
+ "page":{
+ "description":"A description of a paged result",
+ "type":"object",
+ "properties":{
+ "page":{
+ "description":"the page that was requested",
+ "type":"integer"
+ },
+ "page_items":{
+ "description":"the number of items per page requested",
+ "type":"integer"
+ },
+ "pages":{
+ "description":"the total number of pages available",
+ "type":"integer"
+ },
+ "total_items":{
+ "description":"the total number of items available",
+ "type":"integer",
+ "format":"int64"
+ }
+ }
+ },
+ "something":{
+ "description":"Something",
+ "type":"object",
+ "properties":{
+ "p1":{
+ "description":"A string",
+ "type":"string"
+ },
+ "p2":{
+ "description":"An integer",
+ "type":"integer"
+ }
+ }
+ }
+ }
+ }
+ }
+}
+`
diff --git a/vendor/github.com/go-openapi/spec/expander.go b/vendor/github.com/go-openapi/spec/expander.go
index b4429a21c..7af80691f 100644
--- a/vendor/github.com/go-openapi/spec/expander.go
+++ b/vendor/github.com/go-openapi/spec/expander.go
@@ -352,14 +352,12 @@ func normalizeFileRef(ref *Ref, relativeBase string) *Ref {
}
func (r *schemaLoader) resolveRef(currentRef, ref *Ref, node, target interface{}) error {
-
tgt := reflect.ValueOf(target)
if tgt.Kind() != reflect.Ptr {
return fmt.Errorf("resolve ref: target needs to be a pointer")
}
oldRef := currentRef
-
if currentRef != nil {
debugLog("resolve ref current %s new %s", currentRef.String(), ref.String())
nextRef := nextRef(node, ref, currentRef.GetPointer())
@@ -467,8 +465,6 @@ func (r *schemaLoader) resolveRef(currentRef, ref *Ref, node, target interface{}
return err
}
- r.currentRef = currentRef
-
return nil
}
@@ -645,14 +641,18 @@ func expandSchema(target Schema, parentRefs []string, resolver *schemaLoader) (*
return resolver.root.(*Schema), nil
}
- // t is the new expanded schema
var t *Schema
-
+ var basePath string
+ b, _ := json.Marshal(target)
+ debugLog("Target is: %s", string(b))
for target.Ref.String() != "" {
if swag.ContainsStringsCI(parentRefs, target.Ref.String()) {
return &target, nil
}
-
+ basePath = target.Ref.RemoteURI()
+ debugLog("\n\n\n\n\nbasePath: %s", basePath)
+ b, _ := json.Marshal(target)
+ debugLog("calling Resolve with target: %s", string(b))
if err := resolver.Resolve(&target.Ref, &t); shouldStopOnError(err, resolver.options) {
return &target, err
}
@@ -666,7 +666,13 @@ func expandSchema(target Schema, parentRefs []string, resolver *schemaLoader) (*
target = *t
}
}
-
+ if target.Ref.String() == "" {
+ b, _ := json.Marshal(target)
+ debugLog("before: %s", string(b))
+ modifyRefs(&target, basePath)
+ b, _ = json.Marshal(target)
+ debugLog("after: %s", string(b))
+ }
t, err := expandItems(target, parentRefs, resolver)
if shouldStopOnError(err, resolver.options) {
return &target, err
@@ -675,6 +681,8 @@ func expandSchema(target Schema, parentRefs []string, resolver *schemaLoader) (*
target = *t
}
+ resolver.reset()
+
for i := range target.AllOf {
t, err := expandSchema(target.AllOf[i], parentRefs, resolver)
if shouldStopOnError(err, resolver.options) {
diff --git a/vendor/github.com/go-openapi/spec/items.go b/vendor/github.com/go-openapi/spec/items.go
index 46944fb69..07ac88e66 100644
--- a/vendor/github.com/go-openapi/spec/items.go
+++ b/vendor/github.com/go-openapi/spec/items.go
@@ -178,9 +178,14 @@ func (i *Items) UnmarshalJSON(data []byte) error {
if err := json.Unmarshal(data, &simpleSchema); err != nil {
return err
}
+ var vendorExtensible VendorExtensible
+ if err := json.Unmarshal(data, &vendorExtensible); err != nil {
+ return err
+ }
i.Refable = ref
i.CommonValidations = validations
i.SimpleSchema = simpleSchema
+ i.VendorExtensible = vendorExtensible
return nil
}
@@ -198,7 +203,11 @@ func (i Items) MarshalJSON() ([]byte, error) {
if err != nil {
return nil, err
}
- return swag.ConcatJSON(b3, b1, b2), nil
+ b4, err := json.Marshal(i.VendorExtensible)
+ if err != nil {
+ return nil, err
+ }
+ return swag.ConcatJSON(b4, b3, b1, b2), nil
}
// JSONLookup look up a value by the json property name
diff --git a/vendor/github.com/go-openapi/spec/refmodifier.go b/vendor/github.com/go-openapi/spec/refmodifier.go
new file mode 100644
index 000000000..8482608ea
--- /dev/null
+++ b/vendor/github.com/go-openapi/spec/refmodifier.go
@@ -0,0 +1,82 @@
+// Copyright 2017 go-swagger maintainers
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package spec
+
+import (
+ "fmt"
+)
+
+func modifyItemsRefs(target *Schema, basePath string) {
+ if target.Items != nil {
+ if target.Items.Schema != nil {
+ modifyRefs(target.Items.Schema, basePath)
+ }
+ for i := range target.Items.Schemas {
+ s := target.Items.Schemas[i]
+ modifyRefs(&s, basePath)
+ target.Items.Schemas[i] = s
+ }
+ }
+}
+
+func modifyRefs(target *Schema, basePath string) {
+ if target.Ref.String() != "" {
+ if target.Ref.RemoteURI() == basePath {
+ return
+ }
+ newURL := fmt.Sprintf("%s%s", basePath, target.Ref.String())
+ target.Ref, _ = NewRef(newURL)
+ }
+
+ modifyItemsRefs(target, basePath)
+ for i := range target.AllOf {
+ modifyRefs(&target.AllOf[i], basePath)
+ }
+ for i := range target.AnyOf {
+ modifyRefs(&target.AnyOf[i], basePath)
+ }
+ for i := range target.OneOf {
+ modifyRefs(&target.OneOf[i], basePath)
+ }
+ if target.Not != nil {
+ modifyRefs(target.Not, basePath)
+ }
+ for k := range target.Properties {
+ s := target.Properties[k]
+ modifyRefs(&s, basePath)
+ target.Properties[k] = s
+ }
+ if target.AdditionalProperties != nil && target.AdditionalProperties.Schema != nil {
+ modifyRefs(target.AdditionalProperties.Schema, basePath)
+ }
+ for k := range target.PatternProperties {
+ s := target.PatternProperties[k]
+ modifyRefs(&s, basePath)
+ target.PatternProperties[k] = s
+ }
+ for k := range target.Dependencies {
+ if target.Dependencies[k].Schema != nil {
+ modifyRefs(target.Dependencies[k].Schema, basePath)
+ }
+ }
+ if target.AdditionalItems != nil && target.AdditionalItems.Schema != nil {
+ modifyRefs(target.AdditionalItems.Schema, basePath)
+ }
+ for k := range target.Definitions {
+ s := target.Definitions[k]
+ modifyRefs(&s, basePath)
+ target.Definitions[k] = s
+ }
+}
diff --git a/vendor/github.com/go-openapi/spec/refmodifier_test.go b/vendor/github.com/go-openapi/spec/refmodifier_test.go
new file mode 100644
index 000000000..c456cb43f
--- /dev/null
+++ b/vendor/github.com/go-openapi/spec/refmodifier_test.go
@@ -0,0 +1,335 @@
+// Copyright 2017 go-swagger maintainers
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package spec
+
+import (
+ "encoding/json"
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+)
+
+var testJsonSchema = `{
+ "id": "http://json-schema.org/draft-04/schema#",
+ "$schema": "http://json-schema.org/draft-04/schema#",
+ "description": "Core schema meta-schema",
+ "definitions": {
+ "schemaArray": {
+ "type": "array",
+ "minItems": 1,
+ "items": { "$ref": "#" }
+ },
+ "positiveInteger": {
+ "type": "integer",
+ "minimum": 0
+ },
+ "positiveIntegerDefault0": {
+ "allOf": [ { "$ref": "#/definitions/positiveInteger" }, { "default": 0 } ]
+ },
+ "simpleTypes": {
+ "enum": [ "array", "boolean", "integer", "null", "number", "object", "string" ]
+ },
+ "stringArray": {
+ "type": "array",
+ "items": { "type": "string" },
+ "minItems": 1,
+ "uniqueItems": true
+ }
+ },
+ "type": "object",
+ "properties": {
+ "id": {
+ "type": "string",
+ "format": "uri"
+ },
+ "$schema": {
+ "type": "string",
+ "format": "uri"
+ },
+ "title": {
+ "type": "string"
+ },
+ "description": {
+ "type": "string"
+ },
+ "default": {},
+ "multipleOf": {
+ "type": "number",
+ "minimum": 0,
+ "exclusiveMinimum": true
+ },
+ "maximum": {
+ "type": "number"
+ },
+ "exclusiveMaximum": {
+ "type": "boolean",
+ "default": false
+ },
+ "minimum": {
+ "type": "number"
+ },
+ "exclusiveMinimum": {
+ "type": "boolean",
+ "default": false
+ },
+ "maxLength": { "$ref": "#/definitions/positiveInteger" },
+ "minLength": { "$ref": "#/definitions/positiveIntegerDefault0" },
+ "pattern": {
+ "type": "string",
+ "format": "regex"
+ },
+ "additionalItems": {
+ "anyOf": [
+ { "type": "boolean" },
+ { "$ref": "#" }
+ ],
+ "default": {}
+ },
+ "items": {
+ "anyOf": [
+ { "$ref": "#" },
+ { "$ref": "#/definitions/schemaArray" }
+ ],
+ "default": {}
+ },
+ "maxItems": { "$ref": "#/definitions/positiveInteger" },
+ "minItems": { "$ref": "#/definitions/positiveIntegerDefault0" },
+ "uniqueItems": {
+ "type": "boolean",
+ "default": false
+ },
+ "maxProperties": { "$ref": "#/definitions/positiveInteger" },
+ "minProperties": { "$ref": "#/definitions/positiveIntegerDefault0" },
+ "required": { "$ref": "#/definitions/stringArray" },
+ "additionalProperties": {
+ "anyOf": [
+ { "type": "boolean" },
+ { "$ref": "#" }
+ ],
+ "default": {}
+ },
+ "definitions": {
+ "type": "object",
+ "additionalProperties": { "$ref": "#" },
+ "default": {}
+ },
+ "properties": {
+ "type": "object",
+ "additionalProperties": { "$ref": "#" },
+ "default": {}
+ },
+ "patternProperties": {
+ "type": "object",
+ "additionalProperties": { "$ref": "#" },
+ "default": {}
+ },
+ "dependencies": {
+ "type": "object",
+ "additionalProperties": {
+ "anyOf": [
+ { "$ref": "#" },
+ { "$ref": "#/definitions/stringArray" }
+ ]
+ }
+ },
+ "enum": {
+ "type": "array",
+ "minItems": 1,
+ "uniqueItems": true
+ },
+ "type": {
+ "anyOf": [
+ { "$ref": "#/definitions/simpleTypes" },
+ {
+ "type": "array",
+ "items": { "$ref": "#/definitions/simpleTypes" },
+ "minItems": 1,
+ "uniqueItems": true
+ }
+ ]
+ },
+ "allOf": { "$ref": "#/definitions/schemaArray" },
+ "anyOf": { "$ref": "#/definitions/schemaArray" },
+ "oneOf": { "$ref": "#/definitions/schemaArray" },
+ "not": { "$ref": "#" }
+ },
+ "dependencies": {
+ "exclusiveMaximum": [ "maximum" ],
+ "exclusiveMinimum": [ "minimum" ]
+ },
+ "default": {}
+}
+`
+
+var modifiedTestJsonSchema = `{
+ "id": "http://json-schema.org/draft-04/schema#",
+ "$schema": "http://json-schema.org/draft-04/schema",
+ "description": "Core schema meta-schema",
+ "definitions": {
+ "schemaArray": {
+ "type": "array",
+ "minItems": 1,
+ "items": { "$ref": "" }
+ },
+ "positiveInteger": {
+ "type": "integer",
+ "minimum": 0
+ },
+ "positiveIntegerDefault0": {
+ "allOf": [ { "$ref": "http://json-schema.org/draft-04/schema#/definitions/positiveInteger" }, { "default": 0 } ]
+ },
+ "simpleTypes": {
+ "enum": [ "array", "boolean", "integer", "null", "number", "object", "string" ]
+ },
+ "stringArray": {
+ "type": "array",
+ "items": { "type": "string" },
+ "minItems": 1,
+ "uniqueItems": true
+ }
+ },
+ "type": "object",
+ "properties": {
+ "id": {
+ "type": "string",
+ "format": "uri"
+ },
+ "$schema": {
+ "type": "string",
+ "format": "uri"
+ },
+ "title": {
+ "type": "string"
+ },
+ "description": {
+ "type": "string"
+ },
+ "default": {},
+ "multipleOf": {
+ "type": "number",
+ "minimum": 0,
+ "exclusiveMinimum": true
+ },
+ "maximum": {
+ "type": "number"
+ },
+ "exclusiveMaximum": {
+ "type": "boolean",
+ "default": false
+ },
+ "minimum": {
+ "type": "number"
+ },
+ "exclusiveMinimum": {
+ "type": "boolean",
+ "default": false
+ },
+ "maxLength": { "$ref": "http://json-schema.org/draft-04/schema#/definitions/positiveInteger" },
+ "minLength": { "$ref": "http://json-schema.org/draft-04/schema#/definitions/positiveIntegerDefault0" },
+ "pattern": {
+ "type": "string",
+ "format": "regex"
+ },
+ "additionalItems": {
+ "anyOf": [
+ { "type": "boolean" },
+ { "$ref": "" }
+ ],
+ "default": {}
+ },
+ "items": {
+ "anyOf": [
+ { "$ref": "" },
+ { "$ref": "http://json-schema.org/draft-04/schema#/definitions/schemaArray" }
+ ],
+ "default": {}
+ },
+ "maxItems": { "$ref": "http://json-schema.org/draft-04/schema#/definitions/positiveInteger" },
+ "minItems": { "$ref": "http://json-schema.org/draft-04/schema#/definitions/positiveIntegerDefault0" },
+ "uniqueItems": {
+ "type": "boolean",
+ "default": false
+ },
+ "maxProperties": { "$ref": "http://json-schema.org/draft-04/schema#/definitions/positiveInteger" },
+ "minProperties": { "$ref": "http://json-schema.org/draft-04/schema#/definitions/positiveIntegerDefault0" },
+ "required": { "$ref": "http://json-schema.org/draft-04/schema#/definitions/stringArray" },
+ "additionalProperties": {
+ "anyOf": [
+ { "type": "boolean" },
+ { "$ref": "" }
+ ],
+ "default": {}
+ },
+ "definitions": {
+ "type": "object",
+ "additionalProperties": { "$ref": "" },
+ "default": {}
+ },
+ "properties": {
+ "type": "object",
+ "additionalProperties": { "$ref": "" },
+ "default": {}
+ },
+ "patternProperties": {
+ "type": "object",
+ "additionalProperties": { "$ref": "" },
+ "default": {}
+ },
+ "dependencies": {
+ "type": "object",
+ "additionalProperties": {
+ "anyOf": [
+ { "$ref": "" },
+ { "$ref": "http://json-schema.org/draft-04/schema#/definitions/stringArray" }
+ ]
+ }
+ },
+ "enum": {
+ "type": "array",
+ "minItems": 1,
+ "uniqueItems": true
+ },
+ "type": {
+ "anyOf": [
+ { "$ref": "http://json-schema.org/draft-04/schema#/definitions/simpleTypes" },
+ {
+ "type": "array",
+ "items": { "$ref": "http://json-schema.org/draft-04/schema#/definitions/simpleTypes" },
+ "minItems": 1,
+ "uniqueItems": true
+ }
+ ]
+ },
+ "allOf": { "$ref": "http://json-schema.org/draft-04/schema#/definitions/schemaArray" },
+ "anyOf": { "$ref": "http://json-schema.org/draft-04/schema#/definitions/schemaArray" },
+ "oneOf": { "$ref": "http://json-schema.org/draft-04/schema#/definitions/schemaArray" },
+ "not": { "$ref": "" }
+ },
+ "dependencies": {
+ "exclusiveMaximum": [ "maximum" ],
+ "exclusiveMinimum": [ "minimum" ]
+ },
+ "default": {}
+}
+`
+
+func TestRefModifier(t *testing.T) {
+ sch := Schema{}
+ assert.NoError(t, json.Unmarshal([]byte(testJsonSchema), &sch))
+ modifyRefs(&sch, "http://json-schema.org/draft-04/schema")
+ b, err := sch.MarshalJSON()
+ assert.NoError(t, err)
+ assert.JSONEq(t, modifiedTestJsonSchema, string(b))
+}
diff --git a/vendor/github.com/go-openapi/spec/swagger.go b/vendor/github.com/go-openapi/spec/swagger.go
index 393a31677..23780c78a 100644
--- a/vendor/github.com/go-openapi/spec/swagger.go
+++ b/vendor/github.com/go-openapi/spec/swagger.go
@@ -156,7 +156,7 @@ func (s SchemaOrStringArray) MarshalJSON() ([]byte, error) {
if s.Schema != nil {
return json.Marshal(s.Schema)
}
- return nil, nil
+ return []byte("null"), nil
}
// UnmarshalJSON converts this schema object or array from a JSON structure