1// Copyright 2015 go-swagger maintainers 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15package spec 16 17import ( 18 "encoding/json" 19 "testing" 20 21 "github.com/stretchr/testify/assert" 22) 23 24func float64Ptr(f float64) *float64 { 25 return &f 26} 27func int64Ptr(f int64) *int64 { 28 return &f 29} 30 31var header = Header{ 32 VendorExtensible: VendorExtensible{Extensions: map[string]interface{}{ 33 "x-framework": "swagger-go", 34 }}, 35 HeaderProps: HeaderProps{Description: "the description of this header"}, 36 SimpleSchema: SimpleSchema{ 37 Items: &Items{ 38 Refable: Refable{Ref: MustCreateRef("Cat")}, 39 }, 40 Type: "string", 41 Format: "date", 42 Default: "8", 43 }, 44 CommonValidations: CommonValidations{ 45 Maximum: float64Ptr(100), 46 ExclusiveMaximum: true, 47 ExclusiveMinimum: true, 48 Minimum: float64Ptr(5), 49 MaxLength: int64Ptr(100), 50 MinLength: int64Ptr(5), 51 Pattern: "\\w{1,5}\\w+", 52 MaxItems: int64Ptr(100), 53 MinItems: int64Ptr(5), 54 UniqueItems: true, 55 MultipleOf: float64Ptr(5), 56 Enum: []interface{}{"hello", "world"}, 57 }, 58} 59 60const headerJSON = `{ 61 "items": { 62 "$ref": "Cat" 63 }, 64 "x-framework": "swagger-go", 65 "description": "the description of this header", 66 "maximum": 100, 67 "minimum": 5, 68 "exclusiveMaximum": true, 69 "exclusiveMinimum": true, 70 "maxLength": 100, 71 "minLength": 5, 72 "pattern": "\\w{1,5}\\w+", 73 "maxItems": 100, 74 "minItems": 5, 75 "uniqueItems": true, 76 "multipleOf": 5, 77 "enum": ["hello", "world"], 78 "type": "string", 79 "format": "date", 80 "default": "8" 81}` 82 83func TestIntegrationHeader(t *testing.T) { 84 var actual Header 85 if assert.NoError(t, json.Unmarshal([]byte(headerJSON), &actual)) { 86 assert.EqualValues(t, actual, header) 87 } 88 89 assertParsesJSON(t, headerJSON, header) 90} 91