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>
This commit is contained in:
Yong Tang 2017-11-03 00:20:15 -07:00 committed by Miek Gieben
parent af6086d653
commit 1fc0c16968
370 changed files with 15091 additions and 5902 deletions

View file

@ -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),

View file

@ -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"
}
}
}
}
}
}
}
`

View file

@ -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) {

View file

@ -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

82
vendor/github.com/go-openapi/spec/refmodifier.go generated vendored Normal file
View file

@ -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
}
}

335
vendor/github.com/go-openapi/spec/refmodifier_test.go generated vendored Normal file
View file

@ -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))
}

View file

@ -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