github.com/emreu/go-swagger@v0.22.1/generator/parameter_test.go (about) 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 15 package generator 16 17 import ( 18 "bytes" 19 "fmt" 20 "io/ioutil" 21 "log" 22 "os" 23 "path" 24 "path/filepath" 25 "strings" 26 "testing" 27 28 "github.com/go-openapi/spec" 29 "github.com/go-openapi/swag" 30 "github.com/stretchr/testify/assert" 31 ) 32 33 func TestBodyParams(t *testing.T) { 34 b, err := opBuilder("updateTask", "../fixtures/codegen/todolist.bodyparams.yml") 35 36 if !assert.NoError(t, err) { 37 t.FailNow() 38 } 39 40 _, _, op, ok := b.Analyzed.OperationForName("updateTask") 41 if assert.True(t, ok) && assert.NotNil(t, op) { 42 resolver := &typeResolver{ModelsPackage: b.ModelsPackage, Doc: b.Doc} 43 resolver.KnownDefs = make(map[string]struct{}) 44 for k := range b.Doc.Spec().Definitions { 45 resolver.KnownDefs[k] = struct{}{} 46 } 47 for _, param := range op.Parameters { 48 if param.Name == "body" { 49 gp, perr := b.MakeParameter("a", resolver, param, nil) 50 if assert.NoError(t, perr) { 51 assert.True(t, gp.IsBodyParam()) 52 if assert.NotNil(t, gp.Schema) { 53 assert.True(t, gp.Schema.IsComplexObject) 54 assert.False(t, gp.Schema.IsAnonymous) 55 assert.Equal(t, "models.Task", gp.Schema.GoType) 56 } 57 } 58 } 59 } 60 } 61 62 b, err = opBuilder("createTask", "../fixtures/codegen/todolist.bodyparams.yml") 63 64 if !assert.NoError(t, err) { 65 t.FailNow() 66 } 67 68 _, _, op, ok = b.Analyzed.OperationForName("createTask") 69 if assert.True(t, ok) && assert.NotNil(t, op) { 70 resolver := &typeResolver{ModelsPackage: b.ModelsPackage, Doc: b.Doc} 71 resolver.KnownDefs = make(map[string]struct{}) 72 for k := range b.Doc.Spec().Definitions { 73 resolver.KnownDefs[k] = struct{}{} 74 } 75 for _, param := range op.Parameters { 76 if param.Name == "body" { 77 gp, err := b.MakeParameter("a", resolver, param, nil) 78 if assert.NoError(t, err) { 79 assert.True(t, gp.IsBodyParam()) 80 if assert.NotNil(t, gp.Schema) { 81 assert.True(t, gp.Schema.IsComplexObject) 82 assert.False(t, gp.Schema.IsAnonymous) 83 assert.Equal(t, "CreateTaskBody", gp.Schema.GoType) 84 85 gpe, ok := b.ExtraSchemas["CreateTaskBody"] 86 assert.True(t, ok) 87 assert.True(t, gpe.IsComplexObject) 88 assert.False(t, gpe.IsAnonymous) 89 assert.Equal(t, "CreateTaskBody", gpe.GoType) 90 } 91 } 92 } 93 } 94 } 95 } 96 97 var arrayFormParams = []paramTestContext{ 98 {"siBool", "arrayFormParams", "", "", codeGenOpBuilder{}, ¶mItemsTestContext{"swag.FormatBool", "swag.ConvertBool", nil}}, 99 {"siString", "arrayFormParams", "", "", codeGenOpBuilder{}, ¶mItemsTestContext{"", "", nil}}, 100 {"siNested", "arrayFormParams", "", "", codeGenOpBuilder{}, ¶mItemsTestContext{"", "", ¶mItemsTestContext{"", "", ¶mItemsTestContext{"", "", nil}}}}, 101 {"siInt", "arrayFormParams", "", "", codeGenOpBuilder{}, ¶mItemsTestContext{"swag.FormatInt64", "swag.ConvertInt64", nil}}, 102 {"siInt32", "arrayFormParams", "", "", codeGenOpBuilder{}, ¶mItemsTestContext{"swag.FormatInt32", "swag.ConvertInt32", nil}}, 103 {"siInt64", "arrayFormParams", "", "", codeGenOpBuilder{}, ¶mItemsTestContext{"swag.FormatInt64", "swag.ConvertInt64", nil}}, 104 {"siFloat", "arrayFormParams", "", "", codeGenOpBuilder{}, ¶mItemsTestContext{"swag.FormatFloat64", "swag.ConvertFloat64", nil}}, 105 {"siFloat32", "arrayFormParams", "", "", codeGenOpBuilder{}, ¶mItemsTestContext{"swag.FormatFloat32", "swag.ConvertFloat32", nil}}, 106 {"siFloat64", "arrayFormParams", "", "", codeGenOpBuilder{}, ¶mItemsTestContext{"swag.FormatFloat64", "swag.ConvertFloat64", nil}}, 107 } 108 109 func TestFormArrayParams(t *testing.T) { 110 b, err := opBuilder("arrayFormParams", "../fixtures/codegen/todolist.arrayform.yml") 111 112 if !assert.NoError(t, err) { 113 t.FailNow() 114 } 115 116 for _, v := range arrayFormParams { 117 v.B = b 118 if !v.assertParameter(t) { 119 t.FailNow() 120 } 121 } 122 } 123 124 var arrayQueryParams = []paramTestContext{ 125 {"siBool", "arrayQueryParams", "", "", codeGenOpBuilder{}, ¶mItemsTestContext{"swag.FormatBool", "swag.ConvertBool", nil}}, 126 {"siString", "arrayQueryParams", "", "", codeGenOpBuilder{}, ¶mItemsTestContext{"", "", nil}}, 127 {"siNested", "arrayQueryParams", "", "", codeGenOpBuilder{}, ¶mItemsTestContext{"", "", ¶mItemsTestContext{"", "", ¶mItemsTestContext{"", "", nil}}}}, 128 {"siInt", "arrayQueryParams", "", "", codeGenOpBuilder{}, ¶mItemsTestContext{"swag.FormatInt64", "swag.ConvertInt64", nil}}, 129 {"siInt32", "arrayQueryParams", "", "", codeGenOpBuilder{}, ¶mItemsTestContext{"swag.FormatInt32", "swag.ConvertInt32", nil}}, 130 {"siInt64", "arrayQueryParams", "", "", codeGenOpBuilder{}, ¶mItemsTestContext{"swag.FormatInt64", "swag.ConvertInt64", nil}}, 131 {"siFloat", "arrayQueryParams", "", "", codeGenOpBuilder{}, ¶mItemsTestContext{"swag.FormatFloat64", "swag.ConvertFloat64", nil}}, 132 {"siFloat32", "arrayQueryParams", "", "", codeGenOpBuilder{}, ¶mItemsTestContext{"swag.FormatFloat32", "swag.ConvertFloat32", nil}}, 133 {"siFloat64", "arrayQueryParams", "", "", codeGenOpBuilder{}, ¶mItemsTestContext{"swag.FormatFloat64", "swag.ConvertFloat64", nil}}, 134 } 135 136 func TestQueryArrayParams(t *testing.T) { 137 b, err := opBuilder("arrayQueryParams", "../fixtures/codegen/todolist.arrayquery.yml") 138 139 if !assert.NoError(t, err) { 140 t.FailNow() 141 } 142 143 for _, v := range arrayQueryParams { 144 v.B = b 145 if !v.assertParameter(t) { 146 t.FailNow() 147 } 148 } 149 } 150 151 var simplePathParams = []paramTestContext{ 152 {"siBool", "simplePathParams", "swag.FormatBool", "swag.ConvertBool", codeGenOpBuilder{}, nil}, 153 {"siString", "simplePathParams", "", "", codeGenOpBuilder{}, nil}, 154 {"siInt", "simplePathParams", "swag.FormatInt64", "swag.ConvertInt64", codeGenOpBuilder{}, nil}, 155 {"siInt32", "simplePathParams", "swag.FormatInt32", "swag.ConvertInt32", codeGenOpBuilder{}, nil}, 156 {"siInt64", "simplePathParams", "swag.FormatInt64", "swag.ConvertInt64", codeGenOpBuilder{}, nil}, 157 {"siFloat", "simplePathParams", "swag.FormatFloat64", "swag.ConvertFloat64", codeGenOpBuilder{}, nil}, 158 {"siFloat32", "simplePathParams", "swag.FormatFloat32", "swag.ConvertFloat32", codeGenOpBuilder{}, nil}, 159 {"siFloat64", "simplePathParams", "swag.FormatFloat64", "swag.ConvertFloat64", codeGenOpBuilder{}, nil}, 160 } 161 162 func TestSimplePathParams(t *testing.T) { 163 b, err := opBuilder("simplePathParams", "../fixtures/codegen/todolist.simplepath.yml") 164 165 if !assert.NoError(t, err) { 166 t.FailNow() 167 } 168 for _, v := range simplePathParams { 169 v.B = b 170 if !v.assertParameter(t) { 171 t.FailNow() 172 } 173 } 174 } 175 176 var simpleHeaderParams = []paramTestContext{ 177 {"id", "simpleHeaderParams", "swag.FormatInt32", "swag.ConvertInt32", codeGenOpBuilder{}, nil}, 178 {"siBool", "simpleHeaderParams", "swag.FormatBool", "swag.ConvertBool", codeGenOpBuilder{}, nil}, 179 {"siString", "simpleHeaderParams", "", "", codeGenOpBuilder{}, nil}, 180 {"siInt", "simpleHeaderParams", "swag.FormatInt64", "swag.ConvertInt64", codeGenOpBuilder{}, nil}, 181 {"siInt32", "simpleHeaderParams", "swag.FormatInt32", "swag.ConvertInt32", codeGenOpBuilder{}, nil}, 182 {"siInt64", "simpleHeaderParams", "swag.FormatInt64", "swag.ConvertInt64", codeGenOpBuilder{}, nil}, 183 {"siFloat", "simpleHeaderParams", "swag.FormatFloat64", "swag.ConvertFloat64", codeGenOpBuilder{}, nil}, 184 {"siFloat32", "simpleHeaderParams", "swag.FormatFloat32", "swag.ConvertFloat32", codeGenOpBuilder{}, nil}, 185 {"siFloat64", "simpleHeaderParams", "swag.FormatFloat64", "swag.ConvertFloat64", codeGenOpBuilder{}, nil}, 186 } 187 188 func TestSimpleHeaderParams(t *testing.T) { 189 b, err := opBuilder("simpleHeaderParams", "../fixtures/codegen/todolist.simpleheader.yml") 190 191 if !assert.NoError(t, err) { 192 t.FailNow() 193 } 194 for _, v := range simpleHeaderParams { 195 v.B = b 196 if !v.assertParameter(t) { 197 t.FailNow() 198 } 199 } 200 } 201 202 var simpleFormParams = []paramTestContext{ 203 {"id", "simpleFormParams", "swag.FormatInt32", "swag.ConvertInt32", codeGenOpBuilder{}, nil}, 204 {"siBool", "simpleFormParams", "swag.FormatBool", "swag.ConvertBool", codeGenOpBuilder{}, nil}, 205 {"siString", "simpleFormParams", "", "", codeGenOpBuilder{}, nil}, 206 {"siInt", "simpleFormParams", "swag.FormatInt64", "swag.ConvertInt64", codeGenOpBuilder{}, nil}, 207 {"siInt32", "simpleFormParams", "swag.FormatInt32", "swag.ConvertInt32", codeGenOpBuilder{}, nil}, 208 {"siInt64", "simpleFormParams", "swag.FormatInt64", "swag.ConvertInt64", codeGenOpBuilder{}, nil}, 209 {"siFloat", "simpleFormParams", "swag.FormatFloat64", "swag.ConvertFloat64", codeGenOpBuilder{}, nil}, 210 {"siFloat32", "simpleFormParams", "swag.FormatFloat32", "swag.ConvertFloat32", codeGenOpBuilder{}, nil}, 211 {"siFloat64", "simpleFormParams", "swag.FormatFloat64", "swag.ConvertFloat64", codeGenOpBuilder{}, nil}, 212 } 213 214 func TestSimpleFormParams(t *testing.T) { 215 b, err := opBuilder("simpleFormParams", "../fixtures/codegen/todolist.simpleform.yml") 216 217 if !assert.NoError(t, err) { 218 t.FailNow() 219 } 220 for _, v := range simpleFormParams { 221 v.B = b 222 if !v.assertParameter(t) { 223 t.FailNow() 224 } 225 } 226 } 227 228 var simpleQueryParams = []paramTestContext{ 229 {"id", "simpleQueryParams", "swag.FormatInt32", "swag.ConvertInt32", codeGenOpBuilder{}, nil}, 230 {"siBool", "simpleQueryParams", "swag.FormatBool", "swag.ConvertBool", codeGenOpBuilder{}, nil}, 231 {"siString", "simpleQueryParams", "", "", codeGenOpBuilder{}, nil}, 232 {"siInt", "simpleQueryParams", "swag.FormatInt64", "swag.ConvertInt64", codeGenOpBuilder{}, nil}, 233 {"siInt32", "simpleQueryParams", "swag.FormatInt32", "swag.ConvertInt32", codeGenOpBuilder{}, nil}, 234 {"siInt64", "simpleQueryParams", "swag.FormatInt64", "swag.ConvertInt64", codeGenOpBuilder{}, nil}, 235 {"siFloat", "simpleQueryParams", "swag.FormatFloat64", "swag.ConvertFloat64", codeGenOpBuilder{}, nil}, 236 {"siFloat32", "simpleQueryParams", "swag.FormatFloat32", "swag.ConvertFloat32", codeGenOpBuilder{}, nil}, 237 {"siFloat64", "simpleQueryParams", "swag.FormatFloat64", "swag.ConvertFloat64", codeGenOpBuilder{}, nil}, 238 } 239 240 func TestSimpleQueryParamsAST(t *testing.T) { 241 b, err := opBuilder("simpleQueryParams", "../fixtures/codegen/todolist.simplequery.yml") 242 243 if !assert.NoError(t, err) { 244 t.FailNow() 245 } 246 for _, v := range simpleQueryParams { 247 v.B = b 248 if !v.assertParameter(t) { 249 t.FailNow() 250 } 251 } 252 } 253 254 type paramItemsTestContext struct { 255 Formatter string 256 Converter string 257 Items *paramItemsTestContext 258 } 259 260 type paramTestContext struct { 261 Name string 262 OpID string 263 Formatter string 264 Converter string 265 B codeGenOpBuilder 266 Items *paramItemsTestContext 267 } 268 269 func (ctx *paramTestContext) assertParameter(t testing.TB) bool { 270 _, _, op, err := ctx.B.Analyzed.OperationForName(ctx.OpID) 271 if assert.True(t, err) && assert.NotNil(t, op) { 272 resolver := &typeResolver{ModelsPackage: ctx.B.ModelsPackage, Doc: ctx.B.Doc} 273 resolver.KnownDefs = make(map[string]struct{}) 274 for k := range ctx.B.Doc.Spec().Definitions { 275 resolver.KnownDefs[k] = struct{}{} 276 } 277 for _, param := range op.Parameters { 278 if param.Name == ctx.Name { 279 gp, err := ctx.B.MakeParameter("a", resolver, param, nil) 280 if assert.NoError(t, err) { 281 return assert.True(t, ctx.assertGenParam(t, param, gp)) 282 } 283 } 284 } 285 return false 286 } 287 return false 288 } 289 290 func (ctx *paramTestContext) assertGenParam(t testing.TB, param spec.Parameter, gp GenParameter) bool { 291 // went with the verbose option here, easier to debug 292 if !assert.Equal(t, param.In, gp.Location) { 293 return false 294 } 295 if !assert.Equal(t, param.Name, gp.Name) { 296 return false 297 } 298 if !assert.Equal(t, fmt.Sprintf("%q", param.Name), gp.Path) { 299 return false 300 } 301 if !assert.Equal(t, "i", gp.IndexVar) { 302 return false 303 } 304 if !assert.Equal(t, "a", gp.ReceiverName) { 305 return false 306 } 307 if !assert.Equal(t, "a."+swag.ToGoName(param.Name), gp.ValueExpression) { 308 return false 309 } 310 if !assert.Equal(t, ctx.Formatter, gp.Formatter) { 311 return false 312 } 313 if !assert.Equal(t, ctx.Converter, gp.Converter) { 314 return false 315 } 316 if !assert.Equal(t, param.Description, gp.Description) { 317 return false 318 } 319 if !assert.Equal(t, param.CollectionFormat, gp.CollectionFormat) { 320 return false 321 } 322 if !assert.Equal(t, param.Required, gp.Required) { 323 return false 324 } 325 if !assert.Equal(t, param.Minimum, gp.Minimum) || !assert.Equal(t, param.ExclusiveMinimum, gp.ExclusiveMinimum) { 326 return false 327 } 328 if !assert.Equal(t, param.Maximum, gp.Maximum) || !assert.Equal(t, param.ExclusiveMaximum, gp.ExclusiveMaximum) { 329 return false 330 } 331 if !assert.Equal(t, param.MinLength, gp.MinLength) { 332 return false 333 } 334 if !assert.Equal(t, param.MaxLength, gp.MaxLength) { 335 return false 336 } 337 if !assert.Equal(t, param.Pattern, gp.Pattern) { 338 return false 339 } 340 if !assert.Equal(t, param.MaxItems, gp.MaxItems) { 341 return false 342 } 343 if !assert.Equal(t, param.MinItems, gp.MinItems) { 344 return false 345 } 346 if !assert.Equal(t, param.UniqueItems, gp.UniqueItems) { 347 return false 348 } 349 if !assert.Equal(t, param.MultipleOf, gp.MultipleOf) { 350 return false 351 } 352 if !assert.EqualValues(t, param.Enum, gp.Enum) { 353 return false 354 } 355 if !assert.Equal(t, param.Type, gp.SwaggerType) { 356 return false 357 } 358 if !assert.Equal(t, param.Format, gp.SwaggerFormat) { 359 return false 360 } 361 if _, ok := primitives[gp.GoType]; ok { 362 if !assert.True(t, gp.IsPrimitive) { 363 return false 364 } 365 } else { 366 if !assert.False(t, gp.IsPrimitive) { 367 return false 368 } 369 } 370 // verify rendered template 371 if param.In == "body" { 372 return assertBodyParam(t, param, gp) 373 } 374 375 if ctx.Items != nil { 376 return ctx.Items.Assert(t, param.Items, gp.Child) 377 } 378 379 return true 380 } 381 382 func assertBodyParam(t testing.TB, param spec.Parameter, gp GenParameter) bool { 383 if !assert.Equal(t, "body", param.In) || !assert.Equal(t, "body", gp.Location) { 384 return false 385 } 386 if !assert.NotNil(t, gp.Schema) { 387 return false 388 } 389 return true 390 } 391 392 func (ctx *paramItemsTestContext) Assert(t testing.TB, pItems *spec.Items, gpItems *GenItems) bool { 393 if !assert.NotNil(t, pItems) || !assert.NotNil(t, gpItems) { 394 return false 395 } 396 // went with the verbose option here, easier to debug 397 if !assert.Equal(t, ctx.Formatter, gpItems.Formatter) { 398 return false 399 } 400 if !assert.Equal(t, ctx.Converter, gpItems.Converter) { 401 return false 402 } 403 if !assert.Equal(t, pItems.CollectionFormat, gpItems.CollectionFormat) { 404 return false 405 } 406 if !assert.Equal(t, pItems.Minimum, gpItems.Minimum) || !assert.Equal(t, pItems.ExclusiveMinimum, gpItems.ExclusiveMinimum) { 407 return false 408 } 409 if !assert.Equal(t, pItems.Maximum, gpItems.Maximum) || !assert.Equal(t, pItems.ExclusiveMaximum, gpItems.ExclusiveMaximum) { 410 return false 411 } 412 if !assert.Equal(t, pItems.MinLength, gpItems.MinLength) { 413 return false 414 } 415 if !assert.Equal(t, pItems.MaxLength, gpItems.MaxLength) { 416 return false 417 } 418 if !assert.Equal(t, pItems.Pattern, gpItems.Pattern) { 419 return false 420 } 421 if !assert.Equal(t, pItems.MaxItems, gpItems.MaxItems) { 422 return false 423 } 424 if !assert.Equal(t, pItems.MinItems, gpItems.MinItems) { 425 return false 426 } 427 if !assert.Equal(t, pItems.UniqueItems, gpItems.UniqueItems) { 428 return false 429 } 430 if !assert.Equal(t, pItems.MultipleOf, gpItems.MultipleOf) { 431 return false 432 } 433 if !assert.EqualValues(t, pItems.Enum, gpItems.Enum) { 434 return false 435 } 436 if !assert.Equal(t, pItems.Type, gpItems.SwaggerType) { 437 return false 438 } 439 if !assert.Equal(t, pItems.Format, gpItems.SwaggerFormat) { 440 return false 441 } 442 if ctx.Items != nil { 443 return ctx.Items.Assert(t, pItems.Items, gpItems.Child) 444 } 445 return true 446 447 } 448 449 var bug163Properties = []paramTestContext{ 450 {"stringTypeInQuery", "getSearch", "", "", codeGenOpBuilder{}, nil}, 451 {"numberTypeInQuery", "getSearch", "swag.FormatFloat64", "swag.ConvertFloat64", codeGenOpBuilder{}, nil}, 452 {"integerTypeInQuery", "getSearch", "swag.FormatInt64", "swag.ConvertInt64", codeGenOpBuilder{}, nil}, 453 {"booleanTypeInQuery", "getSearch", "swag.FormatBool", "swag.ConvertBool", codeGenOpBuilder{}, nil}, 454 } 455 456 func TestGenParameters_Simple(t *testing.T) { 457 log.SetOutput(ioutil.Discard) 458 defer func() { 459 log.SetOutput(os.Stdout) 460 }() 461 462 b, err := opBuilder("getSearch", "../fixtures/bugs/163/swagger.yml") 463 if !assert.NoError(t, err) { 464 t.FailNow() 465 } 466 for _, v := range bug163Properties { 467 v.B = b 468 if !v.assertParameter(t) { 469 t.FailNow() 470 } 471 } 472 } 473 474 func TestGenParameter_Issue163(t *testing.T) { 475 log.SetOutput(ioutil.Discard) 476 defer func() { 477 log.SetOutput(os.Stdout) 478 }() 479 480 b, err := opBuilder("getSearch", "../fixtures/bugs/163/swagger.yml") 481 if assert.NoError(t, err) { 482 op, err := b.MakeOperation() 483 if assert.NoError(t, err) { 484 buf := bytes.NewBuffer(nil) 485 opts := opts() 486 err := templates.MustGet("serverParameter").Execute(buf, op) 487 if assert.NoError(t, err) { 488 ff, err := opts.LanguageOpts.FormatContent("get_search_parameters.go", buf.Bytes()) 489 if assert.NoError(t, err) { 490 res := string(ff) 491 // NOTE(fredbi): removed default values resolution from private details (defaults are resolved in NewXXXParams()) 492 assertInCode(t, "stringTypeInQueryDefault = string(\"qsValue\")", res) 493 assertInCode(t, "StringTypeInQuery: &stringTypeInQueryDefault", res) 494 } else { 495 fmt.Println(buf.String()) 496 } 497 } 498 } 499 } 500 } 501 502 func TestGenParameter_Issue195(t *testing.T) { 503 log.SetOutput(ioutil.Discard) 504 defer func() { 505 log.SetOutput(os.Stdout) 506 }() 507 508 b, err := opBuilder("getTesting", "../fixtures/bugs/195/swagger.json") 509 if assert.NoError(t, err) { 510 op, err := b.MakeOperation() 511 if assert.NoError(t, err) { 512 buf := bytes.NewBuffer(nil) 513 opts := opts() 514 err := templates.MustGet("clientParameter").Execute(buf, op) 515 if assert.NoError(t, err) { 516 ff, err := opts.LanguageOpts.FormatContent("get_testing.go", buf.Bytes()) 517 if assert.NoError(t, err) { 518 res := string(ff) 519 assertInCode(t, "TestingThis *int64", res) 520 } else { 521 fmt.Println(buf.String()) 522 } 523 } 524 } 525 } 526 } 527 528 func TestGenParameter_Issue196(t *testing.T) { 529 log.SetOutput(ioutil.Discard) 530 defer func() { 531 log.SetOutput(os.Stdout) 532 }() 533 534 b, err := opBuilder("postEvents", "../fixtures/bugs/196/swagger.yml") 535 if assert.NoError(t, err) { 536 op, err := b.MakeOperation() 537 if assert.NoError(t, err) { 538 buf := bytes.NewBuffer(nil) 539 opts := opts() 540 err := templates.MustGet("serverParameter").Execute(buf, op) 541 if assert.NoError(t, err) { 542 ff, err := opts.LanguageOpts.FormatContent("post_events.go", buf.Bytes()) 543 if assert.NoError(t, err) { 544 res := string(ff) 545 assertInCode(t, "body.Validate", res) 546 } else { 547 fmt.Println(buf.String()) 548 } 549 } 550 } 551 } 552 } 553 554 func TestGenParameter_Issue217(t *testing.T) { 555 // Check for string 556 557 assertNoValidator(t, "postEcho", "../fixtures/bugs/217/string.yml") 558 assertNoValidator(t, "postEcho", "../fixtures/bugs/217/interface.yml") 559 assertNoValidator(t, "postEcho", "../fixtures/bugs/217/map.yml") 560 assertNoValidator(t, "postEcho", "../fixtures/bugs/217/array.yml") 561 } 562 563 func assertNoValidator(t testing.TB, opName, path string) { 564 b, err := opBuilder(opName, path) 565 if assert.NoError(t, err) { 566 op, err := b.MakeOperation() 567 if assert.NoError(t, err) { 568 var buf bytes.Buffer 569 opts := opts() 570 err := templates.MustGet("serverParameter").Execute(&buf, op) 571 if assert.NoError(t, err) { 572 ff, err := opts.LanguageOpts.FormatContent("post_echo.go", buf.Bytes()) 573 if assert.NoError(t, err) { 574 res := string(ff) 575 assertNotInCode(t, "body.Validate", res) 576 } else { 577 fmt.Println(buf.String()) 578 } 579 } 580 } 581 } 582 } 583 584 func TestGenParameter_Issue249(t *testing.T) { 585 b, err := opBuilder("putTesting", "../fixtures/bugs/249/swagger.json") 586 if assert.NoError(t, err) { 587 op, err := b.MakeOperation() 588 if assert.NoError(t, err) { 589 buf := bytes.NewBuffer(nil) 590 opts := opts() 591 err := templates.MustGet("clientParameter").Execute(buf, op) 592 if assert.NoError(t, err) { 593 ff, err := opts.LanguageOpts.FormatContent("put_testing.go", buf.Bytes()) 594 if assert.NoError(t, err) { 595 res := string(ff) 596 assertNotInCode(t, "valuesTestingThis := o.TestingThis", res) 597 } else { 598 fmt.Println(buf.String()) 599 } 600 } 601 } 602 } 603 } 604 605 func TestGenParameter_Issue248(t *testing.T) { 606 b, err := opBuilder("CreateThing", "../fixtures/bugs/248/swagger.json") 607 if assert.NoError(t, err) { 608 op, err := b.MakeOperation() 609 if assert.NoError(t, err) { 610 buf := bytes.NewBuffer(nil) 611 opts := opts() 612 err := templates.MustGet("serverParameter").Execute(buf, op) 613 if assert.NoError(t, err) { 614 ff, err := opts.LanguageOpts.FormatContent("create_thing.go", buf.Bytes()) 615 if assert.NoError(t, err) { 616 res := string(ff) 617 assertInCode(t, ", *o.OptionalQueryEnum", res) 618 } else { 619 fmt.Println(buf.String()) 620 } 621 } 622 } 623 } 624 } 625 626 func TestGenParameter_Issue350(t *testing.T) { 627 b, err := opBuilder("withBoolDefault", "../fixtures/codegen/todolist.allparams.yml") 628 if assert.NoError(t, err) { 629 op, err := b.MakeOperation() 630 if assert.NoError(t, err) { 631 buf := bytes.NewBuffer(nil) 632 opts := opts() 633 err := templates.MustGet("serverParameter").Execute(buf, op) 634 if assert.NoError(t, err) { 635 ff, err := opts.LanguageOpts.FormatContent("with_bool_default.go", buf.Bytes()) 636 if assert.NoError(t, err) { 637 res := string(ff) 638 assertInCode(t, "Verbose: &verboseDefault", res) 639 } else { 640 fmt.Println(buf.String()) 641 } 642 } 643 } 644 } 645 } 646 647 func TestGenParameter_Issue351(t *testing.T) { 648 b, err := opBuilder("withArray", "../fixtures/codegen/todolist.allparams.yml") 649 if assert.NoError(t, err) { 650 op, err := b.MakeOperation() 651 if assert.NoError(t, err) { 652 buf := bytes.NewBuffer(nil) 653 opts := opts() 654 err := templates.MustGet("serverParameter").Execute(buf, op) 655 if assert.NoError(t, err) { 656 ff, err := opts.LanguageOpts.FormatContent("with_array.go", buf.Bytes()) 657 if assert.NoError(t, err) { 658 res := string(ff) 659 assertInCode(t, "validate.MinLength(fmt.Sprintf(\"%s.%v\", \"sha256\", i), \"query\", sha256I, 64)", res) 660 } else { 661 fmt.Println(buf.String()) 662 } 663 } 664 } 665 } 666 } 667 668 func TestGenParameter_Issue511(t *testing.T) { 669 assert := assert.New(t) 670 671 gen, err := opBuilder("postModels", "../fixtures/bugs/511/swagger.yml") 672 if assert.NoError(err) { 673 op, err := gen.MakeOperation() 674 if assert.NoError(err) { 675 buf := bytes.NewBuffer(nil) 676 opts := opts() 677 err := templates.MustGet("serverParameter").Execute(buf, op) 678 if assert.NoError(err) { 679 ff, err := opts.LanguageOpts.FormatContent("post_models.go", buf.Bytes()) 680 if assert.NoError(err) { 681 res := string(ff) 682 assertNotInCode(t, "fds := runtime.Values(r.Form)", res) 683 } else { 684 fmt.Println(buf.String()) 685 } 686 } 687 } 688 } 689 } 690 691 func TestGenParameter_Issue628_Collection(t *testing.T) { 692 assert := assert.New(t) 693 694 gen, err := opBuilder("collection", "../fixtures/bugs/628/swagger.yml") 695 if assert.NoError(err) { 696 op, err := gen.MakeOperation() 697 if assert.NoError(err) { 698 buf := bytes.NewBuffer(nil) 699 opts := opts() 700 err := templates.MustGet("serverParameter").Execute(buf, op) 701 if assert.NoError(err) { 702 ff, err := opts.LanguageOpts.FormatContent("post_models.go", buf.Bytes()) 703 if assert.NoError(err) { 704 res := string(ff) 705 assertInCode(t, `value, err := formats.Parse("uuid", workspaceIDIV)`, res) // NOTE(fredbi): added type assertion 706 assertInCode(t, `workspaceIDI := *(value.(*strfmt.UUID))`, res) 707 assertInCode(t, `workspaceIDIR = append(workspaceIDIR, workspaceIDI)`, res) 708 } else { 709 fmt.Println(buf.String()) 710 } 711 } 712 } 713 } 714 } 715 716 func TestGenParameter_Issue628_Single(t *testing.T) { 717 assert := assert.New(t) 718 719 gen, err := opBuilder("single", "../fixtures/bugs/628/swagger.yml") 720 if assert.NoError(err) { 721 op, err := gen.MakeOperation() 722 if assert.NoError(err) { 723 buf := bytes.NewBuffer(nil) 724 opts := opts() 725 err := templates.MustGet("serverParameter").Execute(buf, op) 726 if assert.NoError(err) { 727 ff, err := opts.LanguageOpts.FormatContent("post_models.go", buf.Bytes()) 728 if assert.NoError(err) { 729 res := string(ff) 730 assertInCode(t, `value, err := formats.Parse("uuid", raw)`, res) 731 assertInCode(t, `o.WorkspaceID = *(value.(*strfmt.UUID))`, res) 732 } else { 733 fmt.Println(buf.String()) 734 } 735 } 736 } 737 } 738 } 739 740 func TestGenParameter_Issue628_Details(t *testing.T) { 741 assert := assert.New(t) 742 743 gen, err := opBuilder("details", "../fixtures/bugs/628/swagger.yml") 744 if assert.NoError(err) { 745 op, err := gen.MakeOperation() 746 if assert.NoError(err) { 747 buf := bytes.NewBuffer(nil) 748 opts := opts() 749 err := templates.MustGet("serverParameter").Execute(buf, op) 750 if assert.NoError(err) { 751 ff, err := opts.LanguageOpts.FormatContent("post_models.go", buf.Bytes()) 752 if assert.NoError(err) { 753 res := string(ff) 754 assertInCode(t, `value, err := formats.Parse("uuid", raw)`, res) 755 assertInCode(t, `o.ID = *(value.(*strfmt.UUID))`, res) 756 } else { 757 fmt.Println(buf.String()) 758 } 759 } 760 } 761 } 762 } 763 764 func TestGenParameter_Issue731_Collection(t *testing.T) { 765 assert := assert.New(t) 766 767 gen, err := opBuilder("collection", "../fixtures/bugs/628/swagger.yml") 768 if assert.NoError(err) { 769 op, err := gen.MakeOperation() 770 if assert.NoError(err) { 771 buf := bytes.NewBuffer(nil) 772 opts := opts() 773 err := templates.MustGet("clientParameter").Execute(buf, op) 774 if assert.NoError(err) { 775 ff, err := opts.LanguageOpts.FormatContent("post_models.go", buf.Bytes()) 776 if assert.NoError(err) { 777 res := string(ff) 778 assertInCode(t, `for _, v := range o.WorkspaceID`, res) 779 assertInCode(t, `valuesWorkspaceID = append(valuesWorkspaceID, v.String())`, res) 780 assertInCode(t, `joinedWorkspaceID := swag.JoinByFormat(valuesWorkspaceID, "")`, res) 781 } else { 782 fmt.Println(buf.String()) 783 } 784 } 785 } 786 } 787 } 788 789 func TestGenParameter_Issue731_Single(t *testing.T) { 790 assert := assert.New(t) 791 792 gen, err := opBuilder("single", "../fixtures/bugs/628/swagger.yml") 793 if assert.NoError(err) { 794 op, err := gen.MakeOperation() 795 if assert.NoError(err) { 796 buf := bytes.NewBuffer(nil) 797 opts := opts() 798 err := templates.MustGet("clientParameter").Execute(buf, op) 799 if assert.NoError(err) { 800 ff, err := opts.LanguageOpts.FormatContent("post_models.go", buf.Bytes()) 801 if assert.NoError(err) { 802 res := string(ff) 803 assertInCode(t, `qWorkspaceID := qrWorkspaceID.String()`, res) 804 assertInCode(t, `r.SetQueryParam("workspace_id", qWorkspaceID)`, res) 805 } else { 806 fmt.Println(buf.String()) 807 } 808 } 809 } 810 } 811 } 812 813 func TestGenParameter_Issue731_Details(t *testing.T) { 814 assert := assert.New(t) 815 816 gen, err := opBuilder("details", "../fixtures/bugs/628/swagger.yml") 817 if assert.NoError(err) { 818 op, err := gen.MakeOperation() 819 if assert.NoError(err) { 820 buf := bytes.NewBuffer(nil) 821 opts := opts() 822 err := templates.MustGet("clientParameter").Execute(buf, op) 823 if assert.NoError(err) { 824 ff, err := opts.LanguageOpts.FormatContent("post_models.go", buf.Bytes()) 825 if assert.NoError(err) { 826 res := string(ff) 827 assertInCode(t, `r.SetPathParam("id", o.ID.String())`, res) 828 } else { 829 fmt.Println(buf.String()) 830 } 831 } 832 } 833 } 834 } 835 836 func TestGenParameter_Issue809_Client(t *testing.T) { 837 assert := assert.New(t) 838 839 gen, err := methodPathOpBuilder("get", "/foo", "../fixtures/bugs/809/swagger.yml") 840 if assert.NoError(err) { 841 op, err := gen.MakeOperation() 842 if assert.NoError(err) { 843 buf := bytes.NewBuffer(nil) 844 opts := opts() 845 err := templates.MustGet("clientParameter").Execute(buf, op) 846 if assert.NoError(err) { 847 ff, err := opts.LanguageOpts.FormatContent("post_models.go", buf.Bytes()) 848 if assert.NoError(err) { 849 res := string(ff) 850 assertInCode(t, "valuesGroups", res) 851 } else { 852 fmt.Println(buf.String()) 853 } 854 } 855 } 856 } 857 } 858 859 func TestGenParameter_Issue809_Server(t *testing.T) { 860 assert := assert.New(t) 861 862 gen, err := methodPathOpBuilder("get", "/foo", "../fixtures/bugs/809/swagger.yml") 863 if assert.NoError(err) { 864 op, err := gen.MakeOperation() 865 if assert.NoError(err) { 866 buf := bytes.NewBuffer(nil) 867 opts := opts() 868 err := templates.MustGet("serverParameter").Execute(buf, op) 869 if assert.NoError(err) { 870 ff, err := opts.LanguageOpts.FormatContent("post_models.go", buf.Bytes()) 871 if assert.NoError(err) { 872 res := string(ff) 873 assertInCode(t, "groupsIC := rawData", res) 874 } else { 875 fmt.Println(buf.String()) 876 } 877 } 878 } 879 } 880 } 881 882 func TestGenParameter_Issue1010_Server(t *testing.T) { 883 assert := assert.New(t) 884 885 gen, err := methodPathOpBuilder("get", "/widgets/", "../fixtures/bugs/1010/swagger.yml") 886 if assert.NoError(err) { 887 op, err := gen.MakeOperation() 888 if assert.NoError(err) { 889 buf := bytes.NewBuffer(nil) 890 opts := opts() 891 err := templates.MustGet("serverParameter").Execute(buf, op) 892 if assert.NoError(err) { 893 ff, err := opts.LanguageOpts.FormatContent("get_widgets.go", buf.Bytes()) 894 if assert.NoError(err) { 895 res := string(ff) 896 assertInCode(t, "validate.Pattern(fmt.Sprintf(\"%s.%v\", \"category_id\", i), \"query\", categoryIDI, `^[0-9abcdefghjkmnpqrtuvwxyz]{29}$`)", res) 897 } else { 898 fmt.Println(buf.String()) 899 } 900 } 901 } 902 } 903 } 904 905 func TestGenParameter_Issue710(t *testing.T) { 906 log.SetOutput(ioutil.Discard) 907 defer func() { 908 log.SetOutput(os.Stdout) 909 }() 910 911 assert := assert.New(t) 912 913 gen, err := opBuilder("createTask", "../fixtures/codegen/todolist.allparams.yml") 914 if assert.NoError(err) { 915 op, err := gen.MakeOperation() 916 if assert.NoError(err) { 917 buf := bytes.NewBuffer(nil) 918 opts := opts() 919 err := templates.MustGet("clientParameter").Execute(buf, op) 920 if assert.NoError(err) { 921 ff, err := opts.LanguageOpts.FormatContent("create_task_parameter.go", buf.Bytes()) 922 if assert.NoError(err) { 923 res := string(ff) 924 assertInCode(t, "(typeVar", res) 925 } else { 926 fmt.Println(buf.String()) 927 } 928 } 929 } 930 } 931 } 932 933 func TestGenParameter_Issue776_LocalFileRef(t *testing.T) { 934 //spec.Debug = true 935 log.SetOutput(ioutil.Discard) 936 defer func() { 937 //spec.Debug = false 938 log.SetOutput(os.Stdout) 939 }() 940 b, err := opBuilderWithFlatten("GetItem", "../fixtures/bugs/776/param.yaml") 941 if assert.NoError(t, err) { 942 op, err := b.MakeOperation() 943 if assert.NoError(t, err) { 944 var buf bytes.Buffer 945 opts := opts() 946 if assert.NoError(t, templates.MustGet("serverParameter").Execute(&buf, op)) { 947 ff, err := opts.LanguageOpts.FormatContent("do_empty_responses.go", buf.Bytes()) 948 if assert.NoError(t, err) { 949 assertInCode(t, "Body *models.Item", string(ff)) 950 assertNotInCode(t, "type GetItemParamsBody struct", string(ff)) 951 } else { 952 fmt.Println(buf.String()) 953 } 954 } 955 } 956 } 957 958 } 959 960 func TestGenParameter_Issue1111(t *testing.T) { 961 assert := assert.New(t) 962 963 gen, err := opBuilder("start-es-cluster-instances", "../fixtures/bugs/1111/arrayParam.json") 964 if assert.NoError(err) { 965 op, err := gen.MakeOperation() 966 if assert.NoError(err) { 967 buf := bytes.NewBuffer(nil) 968 opts := opts() 969 err := templates.MustGet("clientParameter").Execute(buf, op) 970 if assert.NoError(err) { 971 ff, err := opts.LanguageOpts.FormatContent("post_clusters_elasticsearch_cluster_id_instances_instance_ids_start_parameters.go", buf.Bytes()) 972 if assert.NoError(err) { 973 res := string(ff) 974 assertInCode(t, `r.SetPathParam("instance_ids", joinedInstanceIds[0])`, res) 975 } else { 976 fmt.Println(buf.String()) 977 } 978 } 979 } 980 } 981 } 982 983 func TestGenParameter_Issue1462(t *testing.T) { 984 assert := assert.New(t) 985 986 gen, err := opBuilder("start-es-cluster-instances", "../fixtures/bugs/1462/arrayParam.json") 987 if assert.NoError(err) { 988 op, err := gen.MakeOperation() 989 if assert.NoError(err) { 990 buf := bytes.NewBuffer(nil) 991 opts := opts() 992 err := templates.MustGet("clientParameter").Execute(buf, op) 993 if assert.NoError(err) { 994 ff, err := opts.LanguageOpts.FormatContent("post_clusters_elasticsearch_cluster_id_instances_instance_ids_start_parameters.go", buf.Bytes()) 995 if assert.NoError(err) { 996 res := string(ff) 997 assertInCode(t, `if len(joinedInstanceIds) > 0 {`, res) 998 } else { 999 fmt.Println(buf.String()) 1000 } 1001 } 1002 } 1003 } 1004 } 1005 1006 func TestGenParameter_Issue1199(t *testing.T) { 1007 assert := assert.New(t) 1008 var assertion = `if o.Body != nil { 1009 if err := r.SetBodyParam(o.Body); err != nil { 1010 return err 1011 } 1012 }` 1013 gen, err := opBuilder("move-clusters", "../fixtures/bugs/1199/nonEmptyBody.json") 1014 if assert.NoError(err) { 1015 op, err := gen.MakeOperation() 1016 if assert.NoError(err) { 1017 buf := bytes.NewBuffer(nil) 1018 opts := opts() 1019 err := templates.MustGet("clientParameter").Execute(buf, op) 1020 if assert.NoError(err) { 1021 ff, err := opts.LanguageOpts.FormatContent("move_clusters_parameters.go", buf.Bytes()) 1022 if assert.NoError(err) { 1023 res := string(ff) 1024 assertInCode(t, assertion, res) 1025 } else { 1026 fmt.Println(buf.String()) 1027 } 1028 } 1029 } 1030 } 1031 } 1032 1033 func TestGenParameter_Issue1325(t *testing.T) { 1034 log.SetOutput(ioutil.Discard) 1035 defer func() { 1036 log.SetOutput(os.Stdout) 1037 }() 1038 1039 assert := assert.New(t) 1040 1041 gen, err := opBuilder("uploadFile", "../fixtures/bugs/1325/swagger.yaml") 1042 if assert.NoError(err) { 1043 op, err := gen.MakeOperation() 1044 if assert.NoError(err) { 1045 buf := bytes.NewBuffer(nil) 1046 opts := opts() 1047 err := templates.MustGet("clientParameter").Execute(buf, op) 1048 if assert.NoError(err) { 1049 ff, err := opts.LanguageOpts.FormatContent("create_task_parameter.go", buf.Bytes()) 1050 if assert.NoError(err) { 1051 res := string(ff) 1052 assertInCode(t, "runtime.NamedReadCloser", res) 1053 } else { 1054 fmt.Println(buf.String()) 1055 } 1056 } 1057 } 1058 } 1059 } 1060 1061 func TestGenParameter_ArrayQueryParameters(t *testing.T) { 1062 assert := assert.New(t) 1063 1064 gen, err := opBuilder("arrayQueryParams", "../fixtures/codegen/todolist.arrayquery.yml") 1065 if assert.NoError(err) { 1066 op, err := gen.MakeOperation() 1067 if assert.NoError(err) { 1068 buf := bytes.NewBuffer(nil) 1069 opts := opts() 1070 err := templates.MustGet("serverParameter").Execute(buf, op) 1071 if assert.NoError(err) { 1072 ff, err := opts.LanguageOpts.FormatContent("array_query_params.go", buf.Bytes()) 1073 if assert.NoError(err) { 1074 res := string(ff) 1075 assertInCode(t, `siBoolIC := swag.SplitByFormat(qvSiBool, "ssv")`, res) 1076 assertInCode(t, `var siBoolIR []bool`, res) 1077 assertInCode(t, `for i, siBoolIV := range siBoolIC`, res) 1078 assertInCode(t, `siBoolI, err := swag.ConvertBool(siBoolIV)`, res) 1079 assertInCode(t, `siBoolIR = append(siBoolIR, siBoolI)`, res) 1080 assertInCode(t, `o.SiBool = siBoolIR`, res) 1081 assertInCode(t, `siBoolSize := int64(len(o.SiBool))`, res) 1082 assertInCode(t, `err := validate.MinItems("siBool", "query", siBoolSize, 5)`, res) 1083 assertInCode(t, `err := validate.MaxItems("siBool", "query", siBoolSize, 50)`, res) 1084 1085 assertInCode(t, `siFloatIC := rawData`, res) 1086 assertInCode(t, `var siFloatIR []float64`, res) 1087 assertInCode(t, `for i, siFloatIV := range siFloatIC`, res) 1088 assertInCode(t, `siFloatI, err := swag.ConvertFloat64(siFloatIV)`, res) 1089 assertInCode(t, `return errors.InvalidType(fmt.Sprintf("%s.%v", "siFloat", i), "query", "float64", siFloatI)`, res) 1090 assertInCode(t, `err := validate.Minimum(fmt.Sprintf("%s.%v", "siFloat", i), "query", float64(siFloatI), 3, true)`, res) 1091 assertInCode(t, `err := validate.Maximum(fmt.Sprintf("%s.%v", "siFloat", i), "query", float64(siFloatI), 100, true); err != nil`, res) 1092 assertInCode(t, `err := validate.MultipleOf(fmt.Sprintf("%s.%v", "siFloat", i), "query", float64(siFloatI), 1.5)`, res) 1093 assertInCode(t, `siFloatIR = append(siFloatIR, siFloatI)`, res) 1094 assertInCode(t, `o.SiFloat = siFloatIR`, res) 1095 assertInCode(t, `siFloatSize := int64(len(o.SiFloat))`, res) 1096 assertInCode(t, `err := validate.MinItems("siFloat", "query", siFloatSize, 5)`, res) 1097 assertInCode(t, `err := validate.MaxItems("siFloat", "query", siFloatSize, 50)`, res) 1098 1099 assertInCode(t, `siFloat32IC := swag.SplitByFormat(qvSiFloat32, "")`, res) 1100 assertInCode(t, `var siFloat32IR []float32`, res) 1101 assertInCode(t, `for i, siFloat32IV := range siFloat32IC`, res) 1102 assertInCode(t, `siFloat32I, err := swag.ConvertFloat32(siFloat32IV)`, res) 1103 assertInCode(t, `err := validate.Minimum(fmt.Sprintf("%s.%v", "siFloat32", i), "query", float64(siFloat32I), 3, true)`, res) 1104 assertInCode(t, `err := validate.Maximum(fmt.Sprintf("%s.%v", "siFloat32", i), "query", float64(siFloat32I), 100, true)`, res) 1105 assertInCode(t, `err := validate.MultipleOf(fmt.Sprintf("%s.%v", "siFloat32", i), "query", float64(siFloat32I), 1.5)`, res) 1106 assertInCode(t, `siFloat32IR = append(siFloat32IR, siFloat32I)`, res) 1107 assertInCode(t, `o.SiFloat32 = siFloat32IR`, res) 1108 1109 assertInCode(t, `siFloat64IC := swag.SplitByFormat(qvSiFloat64, "pipes")`, res) 1110 assertInCode(t, `var siFloat64IR []float64`, res) 1111 assertInCode(t, `for i, siFloat64IV := range siFloat64IC`, res) 1112 assertInCode(t, `siFloat64I, err := swag.ConvertFloat64(siFloat64IV)`, res) 1113 assertInCode(t, `err := validate.Minimum(fmt.Sprintf("%s.%v", "siFloat64", i), "query", float64(siFloat64I), 3, true)`, res) 1114 assertInCode(t, `err := validate.Maximum(fmt.Sprintf("%s.%v", "siFloat64", i), "query", float64(siFloat64I), 100, true)`, res) 1115 assertInCode(t, `err := validate.MultipleOf(fmt.Sprintf("%s.%v", "siFloat64", i), "query", float64(siFloat64I), 1.5)`, res) 1116 assertInCode(t, `siFloat64IR = append(siFloat64IR, siFloat64I)`, res) 1117 assertInCode(t, `o.SiFloat64 = siFloat64IR`, res) 1118 assertInCode(t, `siFloat64Size := int64(len(o.SiFloat64))`, res) 1119 assertInCode(t, `err := validate.MinItems("siFloat64", "query", siFloat64Size, 5)`, res) 1120 assertInCode(t, `err := validate.MaxItems("siFloat64", "query", siFloat64Size, 50)`, res) 1121 1122 assertInCode(t, `siIntIC := swag.SplitByFormat(qvSiInt, "pipes")`, res) 1123 assertInCode(t, `var siIntIR []int64`, res) 1124 assertInCode(t, `for i, siIntIV := range siIntIC`, res) 1125 assertInCode(t, `siIntI, err := swag.ConvertInt64(siIntIV)`, res) 1126 assertInCode(t, `err := validate.MinimumInt(fmt.Sprintf("%s.%v", "siInt", i), "query", int64(siIntI), 8, true)`, res) 1127 assertInCode(t, `err := validate.MaximumInt(fmt.Sprintf("%s.%v", "siInt", i), "query", int64(siIntI), 100, true)`, res) 1128 assertInCode(t, `err := validate.MultipleOf(fmt.Sprintf("%s.%v", "siInt", i), "query", float64(siIntI), 2)`, res) 1129 assertInCode(t, `siIntIR = append(siIntIR, siIntI)`, res) 1130 assertInCode(t, `o.SiInt = siIntIR`, res) 1131 assertInCode(t, `siIntSize := int64(len(o.SiInt))`, res) 1132 assertInCode(t, `err := validate.MinItems("siInt", "query", siIntSize, 5)`, res) 1133 assertInCode(t, `err := validate.MaxItems("siInt", "query", siIntSize, 50)`, res) 1134 1135 assertInCode(t, `siInt32IC := swag.SplitByFormat(qvSiInt32, "tsv")`, res) 1136 assertInCode(t, `var siInt32IR []int32`, res) 1137 assertInCode(t, `for i, siInt32IV := range siInt32IC`, res) 1138 assertInCode(t, `siInt32I, err := swag.ConvertInt32(siInt32IV)`, res) 1139 assertInCode(t, `err := validate.MinimumInt(fmt.Sprintf("%s.%v", "siInt32", i), "query", int64(siInt32I), 8, true)`, res) 1140 assertInCode(t, `err := validate.MaximumInt(fmt.Sprintf("%s.%v", "siInt32", i), "query", int64(siInt32I), 100, true)`, res) 1141 assertInCode(t, `err := validate.MultipleOf(fmt.Sprintf("%s.%v", "siInt32", i), "query", float64(siInt32I), 2)`, res) 1142 assertInCode(t, `siInt32IR = append(siInt32IR, siInt32I)`, res) 1143 assertInCode(t, `o.SiInt32 = siInt32IR`, res) 1144 assertInCode(t, `siFloat32Size := int64(len(o.SiFloat32))`, res) 1145 assertInCode(t, `err := validate.MinItems("siFloat32", "query", siFloat32Size, 5)`, res) 1146 assertInCode(t, `err := validate.MaxItems("siFloat32", "query", siFloat32Size, 50)`, res) 1147 assertInCode(t, `siInt32Size := int64(len(o.SiInt32))`, res) 1148 assertInCode(t, `err := validate.MinItems("siInt32", "query", siInt32Size, 5)`, res) 1149 assertInCode(t, `err := validate.MaxItems("siInt32", "query", siInt32Size, 50)`, res) 1150 1151 assertInCode(t, `siInt64IC := swag.SplitByFormat(qvSiInt64, "ssv")`, res) 1152 assertInCode(t, `var siInt64IR []int64`, res) 1153 assertInCode(t, `for i, siInt64IV := range siInt64IC`, res) 1154 assertInCode(t, `siInt64I, err := swag.ConvertInt64(siInt64IV)`, res) 1155 assertInCode(t, `err := validate.MinimumInt(fmt.Sprintf("%s.%v", "siInt64", i), "query", int64(siInt64I), 8, true)`, res) 1156 assertInCode(t, `err := validate.MaximumInt(fmt.Sprintf("%s.%v", "siInt64", i), "query", int64(siInt64I), 100, true)`, res) 1157 assertInCode(t, `err := validate.MultipleOf(fmt.Sprintf("%s.%v", "siInt64", i), "query", float64(siInt64I), 2)`, res) 1158 assertInCode(t, `siInt64IR = append(siInt64IR, siInt64I)`, res) 1159 assertInCode(t, `o.SiInt64 = siInt64IR`, res) 1160 assertInCode(t, `siInt64Size := int64(len(o.SiInt64))`, res) 1161 assertInCode(t, `err := validate.MinItems("siInt64", "query", siInt64Size, 5)`, res) 1162 assertInCode(t, `err := validate.MaxItems("siInt64", "query", siInt64Size, 50)`, res) 1163 1164 assertInCode(t, `siStringIC := swag.SplitByFormat(qvSiString, "csv")`, res) 1165 assertInCode(t, `var siStringIR []string`, res) 1166 assertInCode(t, `for i, siStringIV := range siStringIC`, res) 1167 assertInCode(t, `siStringI := siStringIV`, res) 1168 assertInCode(t, `err := validate.MinLength(fmt.Sprintf("%s.%v", "siString", i), "query", siStringI, 5)`, res) 1169 assertInCode(t, `err := validate.MaxLength(fmt.Sprintf("%s.%v", "siString", i), "query", siStringI, 50)`, res) 1170 assertInCode(t, `err := validate.Pattern(fmt.Sprintf("%s.%v", "siString", i), "query", siStringI, `+"`"+`[A-Z][\w-]+`+"`"+`)`, res) 1171 assertInCode(t, `siStringIR = append(siStringIR, siStringI)`, res) 1172 assertInCode(t, `o.SiString = siStringIR`, res) 1173 assertInCode(t, `siStringSize := int64(len(o.SiString))`, res) 1174 assertInCode(t, `err := validate.MinItems("siString", "query", siStringSize, 5)`, res) 1175 assertInCode(t, `err := validate.MaxItems("siString", "query", siStringSize, 50)`, res) 1176 1177 assertInCode(t, `siNestedIC := rawData`, res) 1178 assertInCode(t, `var siNestedIR [][][]string`, res) 1179 assertInCode(t, `for i, siNestedIV := range siNestedIC`, res) 1180 assertInCode(t, `siNestedIIC := swag.SplitByFormat(siNestedIV, "pipes")`, res) 1181 assertInCode(t, `var siNestedIIR [][]string`, res) 1182 assertInCode(t, `for ii, siNestedIIV := range siNestedIIC {`, res) 1183 assertInCode(t, `siNestedIIIC := swag.SplitByFormat(siNestedIIV, "csv")`, res) 1184 assertInCode(t, `var siNestedIIIR []string`, res) 1185 assertInCode(t, `for iii, siNestedIIIV := range siNestedIIIC`, res) 1186 assertInCode(t, `siNestedIII := siNestedIIIV`, res) 1187 assertInCode(t, `err := validate.MinLength(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "siNested", i), ii), iii), "query", siNestedIII, 5)`, res) 1188 assertInCode(t, `err := validate.MaxLength(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "siNested", i), ii), iii), "query", siNestedIII, 50)`, res) 1189 assertInCode(t, `err := validate.Pattern(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "siNested", i), ii), iii), "query", siNestedIII, `+"`"+`[A-Z][\w-]+`+"`"+`)`, res) 1190 assertInCode(t, `siNestedIIIR = append(siNestedIIIR, siNestedIII)`, res) 1191 assertInCode(t, `siNestedIIiSize := int64(len(siNestedIIIC))`, res) // NOTE(fredbi): fixed variable (nested arrays) 1192 assertInCode(t, `err := validate.MinItems(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "siNested", i), ii), "query", siNestedIIiSize, 3)`, res) 1193 assertInCode(t, `err := validate.MaxItems(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "siNested", i), ii), "query", siNestedIIiSize, 30)`, res) 1194 assertInCode(t, `siNestedIIR = append(siNestedIIR, siNestedIIIR)`, res) // NOTE(fredbi): fixed variable (nested arrays) 1195 assertInCode(t, `siNestedISize := int64(len(siNestedIIC))`, res) //NOTE(fredbi): fixed variable (nested arrays) 1196 assertInCode(t, `err := validate.MinItems(fmt.Sprintf("%s.%v", "siNested", i), "query", siNestedISize, 2)`, res) 1197 assertInCode(t, `err := validate.MaxItems(fmt.Sprintf("%s.%v", "siNested", i), "query", siNestedISize, 20)`, res) 1198 assertInCode(t, `siNestedIR = append(siNestedIR, siNestedIIR)`, res) // NOTE(fredbi): fixed variable (nested arrays) 1199 assertInCode(t, `o.SiNested = siNestedIR`, res) 1200 } else { 1201 fmt.Println(buf.String()) 1202 } 1203 } 1204 } 1205 } 1206 } 1207 1208 func assertParams(t *testing.T, fixtureConfig map[string]map[string][]string, fixture string, minimalFlatten bool, withExpand bool) { 1209 fixtureSpec := path.Base(fixture) 1210 tassert := assert.New(t) 1211 for fixtureIndex, fixtureContents := range fixtureConfig { 1212 var gen codeGenOpBuilder 1213 var err error 1214 switch { 1215 case minimalFlatten && !withExpand: 1216 // proceed with minimal spec flattening 1217 gen, err = opBuilder(fixtureIndex, fixture) 1218 case !minimalFlatten: 1219 // proceed with full flattening 1220 gen, err = opBuilderWithFlatten(fixtureIndex, fixture) 1221 default: 1222 // proceed with spec expansion 1223 gen, err = opBuilderWithExpand(fixtureIndex, fixture) 1224 } 1225 if tassert.NoError(err) { 1226 op, err := gen.MakeOperation() 1227 if tassert.NoError(err) { 1228 opts := opts() 1229 for fixtureTemplate, expectedCode := range fixtureContents { 1230 buf := bytes.NewBuffer(nil) 1231 err := templates.MustGet(fixtureTemplate).Execute(buf, op) 1232 if tassert.NoError(err, "Expected generation to go well on %s with template %s", fixtureSpec, fixtureTemplate) { 1233 ff, err := opts.LanguageOpts.FormatContent("foo.go", buf.Bytes()) 1234 if tassert.NoError(err, "Expected formatting to go well on %s with template %s", fixtureSpec, fixtureTemplate) { 1235 res := string(ff) 1236 for line, codeLine := range expectedCode { 1237 if !assertInCode(t, strings.TrimSpace(codeLine), res) { 1238 t.Logf("Code expected did not match for fixture %s at line %d", fixtureSpec, line) 1239 } 1240 } 1241 } else { 1242 fmt.Println(buf.String()) 1243 } 1244 } 1245 } 1246 } 1247 } 1248 } 1249 } 1250 1251 func TestGenParameter_Issue909(t *testing.T) { 1252 log.SetOutput(ioutil.Discard) 1253 defer func() { 1254 log.SetOutput(os.Stdout) 1255 }() 1256 1257 assert := assert.New(t) 1258 fixtureConfig := map[string]map[string][]string{ 1259 "1": { // fixture index 1260 "serverParameter": { // executed template 1261 // expected code lines 1262 `strfmt "github.com/go-openapi/strfmt"`, 1263 `NotAnOption1 *strfmt.DateTime`, 1264 `NotAnOption2 *strfmt.UUID`, 1265 `NotAnOption3 *models.ContainerConfig`, 1266 `value, err := formats.Parse("date-time", raw)`, 1267 `o.NotAnOption1 = (value.(*strfmt.DateTime))`, 1268 `if err := o.validateNotAnOption1(formats); err != nil {`, 1269 `if err := validate.FormatOf("notAnOption1", "query", "date-time", o.NotAnOption1.String(), formats); err != nil {`, 1270 `value, err := formats.Parse("uuid", raw)`, 1271 `o.NotAnOption2 = (value.(*strfmt.UUID))`, 1272 `if err := o.validateNotAnOption2(formats); err != nil {`, 1273 `if err := validate.FormatOf("notAnOption2", "query", "uuid", o.NotAnOption2.String(), formats); err != nil {`, 1274 }, 1275 }, 1276 "2": { 1277 "serverParameter": { 1278 // expected code lines 1279 `"github.com/go-openapi/validate"`, 1280 `IsAnOption2 []strfmt.UUID`, 1281 `NotAnOption1 []strfmt.DateTime`, 1282 `NotAnOption3 *models.ContainerConfig`, 1283 `isAnOption2IC := swag.SplitByFormat(qvIsAnOption2, "csv")`, 1284 `var isAnOption2IR []strfmt.UUID`, 1285 `for i, isAnOption2IV := range isAnOption2IC {`, 1286 `value, err := formats.Parse("uuid", isAnOption2IV)`, 1287 `isAnOption2I := *(value.(*strfmt.UUID))`, 1288 `if err := validate.FormatOf(fmt.Sprintf("%s.%v", "isAnOption2", i), "query", "uuid", isAnOption2I.String(), formats); err != nil {`, 1289 `isAnOption2IR = append(isAnOption2IR, isAnOption2I)`, 1290 `o.IsAnOption2 = isAnOption2IR`, 1291 `return errors.Required("notAnOption1", "query")`, 1292 `notAnOption1IC := swag.SplitByFormat(qvNotAnOption1, "csv")`, 1293 `var notAnOption1IR []strfmt.DateTime`, 1294 `for i, notAnOption1IV := range notAnOption1IC {`, 1295 `value, err := formats.Parse("date-time", notAnOption1IV)`, 1296 `return errors.InvalidType(fmt.Sprintf("%s.%v", "notAnOption1", i), "query", "strfmt.DateTime", value)`, 1297 `notAnOption1I := *(value.(*strfmt.DateTime))`, 1298 `if err := validate.FormatOf(fmt.Sprintf("%s.%v", "notAnOption1", i), "query", "date-time", notAnOption1I.String(), formats); err != nil {`, 1299 `notAnOption1IR = append(notAnOption1IR, notAnOption1I)`, 1300 `o.NotAnOption1 = notAnOption1IR`, 1301 }, 1302 }, 1303 "3": { 1304 "serverParameter": { 1305 // expected code lines 1306 `"github.com/go-openapi/validate"`, 1307 `strfmt "github.com/go-openapi/strfmt"`, 1308 `IsAnOption2 [][]strfmt.UUID`, 1309 `IsAnOption4 [][][]strfmt.UUID`, 1310 `IsAnOptionalHeader [][]strfmt.UUID`, 1311 `NotAnOption1 [][]strfmt.DateTime`, 1312 `NotAnOption3 *models.ContainerConfig`, 1313 `isAnOption2IC := swag.SplitByFormat(qvIsAnOption2, "pipes")`, 1314 `var isAnOption2IR [][]strfmt.UUID`, 1315 `for i, isAnOption2IV := range isAnOption2IC {`, 1316 `isAnOption2IIC := swag.SplitByFormat(isAnOption2IV, "")`, 1317 `if len(isAnOption2IIC) > 0 {`, 1318 `var isAnOption2IIR []strfmt.UUID`, 1319 `for ii, isAnOption2IIV := range isAnOption2IIC {`, 1320 `value, err := formats.Parse("uuid", isAnOption2IIV)`, 1321 `isAnOption2II := *(value.(*strfmt.UUID))`, 1322 `if err := validate.FormatOf(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "isAnOption2", i), ii), "query", "uuid", isAnOption2II.String(), formats); err != nil {`, 1323 `isAnOption2IIR = append(isAnOption2IIR, isAnOption2II)`, 1324 `isAnOption2IR = append(isAnOption2IR, isAnOption2IIR)`, 1325 `o.IsAnOption2 = isAnOption2IR`, 1326 `isAnOption4IC := swag.SplitByFormat(qvIsAnOption4, "csv")`, 1327 `var isAnOption4IR [][][]strfmt.UUID`, 1328 `for i, isAnOption4IV := range isAnOption4IC {`, 1329 `isAnOption4IIC := swag.SplitByFormat(isAnOption4IV, "")`, 1330 `if len(isAnOption4IIC) > 0 {`, 1331 `var isAnOption4IIR [][]strfmt.UUID`, 1332 `for ii, isAnOption4IIV := range isAnOption4IIC {`, 1333 `isAnOption4IIIC := swag.SplitByFormat(isAnOption4IIV, "pipes")`, 1334 `if len(isAnOption4IIIC) > 0 {`, 1335 `var isAnOption4IIIR []strfmt.UUID`, 1336 `for iii, isAnOption4IIIV := range isAnOption4IIIC {`, 1337 `value, err := formats.Parse("uuid", isAnOption4IIIV)`, 1338 `isAnOption4III := *(value.(*strfmt.UUID))`, 1339 `if err := validate.Enum(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "isAnOption4", i), ii), iii), "query", isAnOption4III.String(), []interface{}{"a", "b", "c"}); err != nil {`, 1340 `if err := validate.FormatOf(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "isAnOption4", i), ii), iii), "query", "uuid", isAnOption4III.String(), formats); err != nil {`, 1341 `isAnOption4IIIR = append(isAnOption4IIIR, isAnOption4III)`, 1342 `isAnOption4IIR = append(isAnOption4IIR, isAnOption4IIIR)`, 1343 `isAnOption4IIiSize := int64(len(isAnOption4IIIC))`, 1344 `if err := validate.MinItems(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "isAnOption4", i), ii), "query", isAnOption4IIiSize, 3); err != nil {`, 1345 `if err := validate.UniqueItems(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "isAnOption4", i), ii), "query", isAnOption4IIIC); err != nil {`, 1346 `isAnOption4IR = append(isAnOption4IR, isAnOption4IIR)`, 1347 `if err := validate.UniqueItems(fmt.Sprintf("%s.%v", "isAnOption4", i), "query", isAnOption4IIC); err != nil {`, 1348 `o.IsAnOption4 = isAnOption4IR`, 1349 `if err := o.validateIsAnOption4(formats); err != nil {`, 1350 `if err := validate.MaxItems("isAnOption4", "query", isAnOption4Size, 4); err != nil {`, 1351 `isAnOptionalHeaderIC := swag.SplitByFormat(qvIsAnOptionalHeader, "pipes")`, 1352 `var isAnOptionalHeaderIR [][]strfmt.UUID`, 1353 `for i, isAnOptionalHeaderIV := range isAnOptionalHeaderIC {`, 1354 `isAnOptionalHeaderIIC := swag.SplitByFormat(isAnOptionalHeaderIV, "")`, 1355 `if len(isAnOptionalHeaderIIC) > 0 {`, 1356 `var isAnOptionalHeaderIIR []strfmt.UUID`, 1357 `for ii, isAnOptionalHeaderIIV := range isAnOptionalHeaderIIC {`, 1358 `value, err := formats.Parse("uuid", isAnOptionalHeaderIIV)`, 1359 `isAnOptionalHeaderII := *(value.(*strfmt.UUID))`, 1360 `if err := validate.FormatOf(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "isAnOptionalHeader", i), ii), "header", "uuid", isAnOptionalHeaderII.String(), formats); err != nil {`, 1361 `isAnOptionalHeaderIIR = append(isAnOptionalHeaderIIR, isAnOptionalHeaderII)`, 1362 `isAnOptionalHeaderIR = append(isAnOptionalHeaderIR, isAnOptionalHeaderIIR)`, 1363 `o.IsAnOptionalHeader = isAnOptionalHeaderIR`, 1364 `if err := o.validateIsAnOptionalHeader(formats); err != nil {`, 1365 `if err := validate.UniqueItems("isAnOptionalHeader", "header", o.IsAnOptionalHeader); err != nil {`, 1366 `notAnOption1IC := swag.SplitByFormat(qvNotAnOption1, "csv")`, 1367 `var notAnOption1IR [][]strfmt.DateTime`, 1368 `for i, notAnOption1IV := range notAnOption1IC {`, 1369 `notAnOption1IIC := swag.SplitByFormat(notAnOption1IV, "pipes")`, 1370 `if len(notAnOption1IIC) > 0 {`, 1371 `var notAnOption1IIR []strfmt.DateTime`, 1372 `for ii, notAnOption1IIV := range notAnOption1IIC {`, 1373 `value, err := formats.Parse("date-time", notAnOption1IIV)`, 1374 `notAnOption1II := *(value.(*strfmt.DateTime))`, 1375 `if err := validate.FormatOf(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "notAnOption1", i), ii), "query", "date-time", notAnOption1II.String(), formats); err != nil {`, 1376 `notAnOption1IIR = append(notAnOption1IIR, notAnOption1II)`, 1377 `notAnOption1IR = append(notAnOption1IR, notAnOption1IIR)`, 1378 `o.NotAnOption1 = notAnOption1IR`, 1379 }, 1380 }, 1381 "4": { 1382 "serverParameter": { 1383 // expected code lines 1384 `"github.com/go-openapi/validate"`, 1385 `strfmt "github.com/go-openapi/strfmt"`, 1386 `IsAnOption2 [][]strfmt.UUID`, 1387 `IsAnOption4 [][][]strfmt.UUID`, 1388 `NotAnOption1 [][]strfmt.DateTime`, 1389 `NotAnOption3 *models.ContainerConfig`, 1390 `isAnOption2IC := swag.SplitByFormat(qvIsAnOption2, "")`, 1391 `var isAnOption2IR [][]strfmt.UUID`, 1392 `for i, isAnOption2IV := range isAnOption2IC {`, 1393 `isAnOption2IIC := swag.SplitByFormat(isAnOption2IV, "pipes")`, 1394 `if len(isAnOption2IIC) > 0 {`, 1395 `var isAnOption2IIR []strfmt.UUID`, 1396 `for ii, isAnOption2IIV := range isAnOption2IIC {`, 1397 `value, err := formats.Parse("uuid", isAnOption2IIV)`, 1398 `isAnOption2II := *(value.(*strfmt.UUID))`, 1399 `if err := validate.FormatOf(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "isAnOption2", i), ii), "query", "uuid", isAnOption2II.String(), formats); err != nil {`, 1400 `isAnOption2IIR = append(isAnOption2IIR, isAnOption2II)`, 1401 `isAnOption2IR = append(isAnOption2IR, isAnOption2IIR)`, 1402 `o.IsAnOption2 = isAnOption2IR`, 1403 `isAnOption4IC := swag.SplitByFormat(qvIsAnOption4, "")`, 1404 `var isAnOption4IR [][][]strfmt.UUID`, 1405 `for i, isAnOption4IV := range isAnOption4IC {`, 1406 `isAnOption4IIC := swag.SplitByFormat(isAnOption4IV, "pipes")`, 1407 `if len(isAnOption4IIC) > 0 {`, 1408 `var isAnOption4IIR [][]strfmt.UUID`, 1409 `for ii, isAnOption4IIV := range isAnOption4IIC {`, 1410 `isAnOption4IIIC := swag.SplitByFormat(isAnOption4IIV, "tsv")`, 1411 `if len(isAnOption4IIIC) > 0 {`, 1412 `var isAnOption4IIIR []strfmt.UUID`, 1413 `for iii, isAnOption4IIIV := range isAnOption4IIIC {`, 1414 `value, err := formats.Parse("uuid", isAnOption4IIIV)`, 1415 `isAnOption4III := *(value.(*strfmt.UUID))`, 1416 `if err := validate.Enum(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "isAnOption4", i), ii), iii), "query", isAnOption4III.String(), []interface{}{"a", "b", "c"}); err != nil {`, 1417 `if err := validate.FormatOf(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "isAnOption4", i), ii), iii), "query", "uuid", isAnOption4III.String(), formats); err != nil {`, 1418 `isAnOption4IIIR = append(isAnOption4IIIR, isAnOption4III)`, 1419 `isAnOption4IIR = append(isAnOption4IIR, isAnOption4IIIR)`, 1420 `isAnOption4IIiSize := int64(len(isAnOption4IIIC))`, 1421 `if err := validate.MinItems(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "isAnOption4", i), ii), "query", isAnOption4IIiSize, 3); err != nil {`, 1422 `if err := validate.UniqueItems(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "isAnOption4", i), ii), "query", isAnOption4IIIC); err != nil {`, 1423 `isAnOption4IR = append(isAnOption4IR, isAnOption4IIR)`, 1424 `if err := validate.UniqueItems(fmt.Sprintf("%s.%v", "isAnOption4", i), "query", isAnOption4IIC); err != nil {`, 1425 `o.IsAnOption4 = isAnOption4IR`, 1426 `if err := o.validateIsAnOption4(formats); err != nil {`, 1427 `isAnOption4Size := int64(len(o.IsAnOption4))`, 1428 `if err := validate.MaxItems("isAnOption4", "query", isAnOption4Size, 4); err != nil {`, 1429 `return errors.Required("notAnOption1", "query")`, 1430 `notAnOption1IC := swag.SplitByFormat(qvNotAnOption1, "")`, 1431 `var notAnOption1IR [][]strfmt.DateTime`, 1432 `for i, notAnOption1IV := range notAnOption1IC {`, 1433 `notAnOption1IIC := swag.SplitByFormat(notAnOption1IV, "")`, 1434 `if len(notAnOption1IIC) > 0 {`, 1435 `var notAnOption1IIR []strfmt.DateTime`, 1436 `for ii, notAnOption1IIV := range notAnOption1IIC {`, 1437 `value, err := formats.Parse("date-time", notAnOption1IIV)`, 1438 `notAnOption1II := *(value.(*strfmt.DateTime))`, 1439 `if err := validate.FormatOf(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "notAnOption1", i), ii), "query", "date-time", notAnOption1II.String(), formats); err != nil {`, 1440 `notAnOption1IIR = append(notAnOption1IIR, notAnOption1II)`, 1441 `notAnOption1IR = append(notAnOption1IR, notAnOption1IIR)`, 1442 `o.NotAnOption1 = notAnOption1IR`, 1443 }, 1444 }, 1445 "5": { 1446 "serverResponses": { 1447 // expected code lines 1448 `"github.com/go-openapi/strfmt"`, 1449 "XIsAnOptionalHeader0 strfmt.DateTime `json:\"x-isAnOptionalHeader0\"`", 1450 "XIsAnOptionalHeader1 []strfmt.DateTime `json:\"x-isAnOptionalHeader1\"`", 1451 "XIsAnOptionalHeader2 [][]int32 `json:\"x-isAnOptionalHeader2\"`", 1452 "XIsAnOptionalHeader3 [][][]strfmt.UUID `json:\"x-isAnOptionalHeader3\"`", 1453 `xIsAnOptionalHeader0 := o.XIsAnOptionalHeader0.String()`, 1454 `rw.Header().Set("x-isAnOptionalHeader0", xIsAnOptionalHeader0)`, 1455 `var xIsAnOptionalHeader1IR []string`, 1456 `for _, xIsAnOptionalHeader1I := range o.XIsAnOptionalHeader1 {`, 1457 `xIsAnOptionalHeader1IS := xIsAnOptionalHeader1I.String()`, 1458 `if xIsAnOptionalHeader1IS != "" {`, 1459 `xIsAnOptionalHeader1IR = append(xIsAnOptionalHeader1IR, xIsAnOptionalHeader1IS)`, 1460 `xIsAnOptionalHeader1 := swag.JoinByFormat(xIsAnOptionalHeader1IR, "tsv")`, 1461 `hv := xIsAnOptionalHeader1[0]`, 1462 `rw.Header().Set("x-isAnOptionalHeader1", hv)`, 1463 `var xIsAnOptionalHeader2IR []string`, 1464 `for _, xIsAnOptionalHeader2I := range o.XIsAnOptionalHeader2 {`, 1465 `var xIsAnOptionalHeader2IIR []string`, 1466 `for _, xIsAnOptionalHeader2II := range xIsAnOptionalHeader2I {`, 1467 `xIsAnOptionalHeader2IIS := swag.FormatInt32(xIsAnOptionalHeader2II)`, 1468 `if xIsAnOptionalHeader2IIS != "" {`, 1469 `xIsAnOptionalHeader2IIR = append(xIsAnOptionalHeader2IIR, xIsAnOptionalHeader2IIS)`, 1470 `xIsAnOptionalHeader2IS := swag.JoinByFormat(xIsAnOptionalHeader2IIR, "pipes")`, 1471 `xIsAnOptionalHeader2ISs := xIsAnOptionalHeader2IS[0]`, 1472 `if xIsAnOptionalHeader2ISs != "" {`, 1473 `xIsAnOptionalHeader2IR = append(xIsAnOptionalHeader2IR, xIsAnOptionalHeader2ISs)`, 1474 `xIsAnOptionalHeader2 := swag.JoinByFormat(xIsAnOptionalHeader2IR, "")`, 1475 `hv := xIsAnOptionalHeader2[0]`, 1476 `rw.Header().Set("x-isAnOptionalHeader2", hv)`, 1477 `var xIsAnOptionalHeader3IR []string`, 1478 `for _, xIsAnOptionalHeader3I := range o.XIsAnOptionalHeader3 {`, 1479 `var xIsAnOptionalHeader3IIR []string`, 1480 `for _, xIsAnOptionalHeader3II := range xIsAnOptionalHeader3I {`, 1481 `var xIsAnOptionalHeader3IIIR []string`, 1482 `for _, xIsAnOptionalHeader3III := range xIsAnOptionalHeader3II {`, 1483 `xIsAnOptionalHeader3IIIS := xIsAnOptionalHeader3III.String()`, 1484 `if xIsAnOptionalHeader3IIIS != "" {`, 1485 `xIsAnOptionalHeader3IIIR = append(xIsAnOptionalHeader3IIIR, xIsAnOptionalHeader3IIIS)`, 1486 `xIsAnOptionalHeader3IIS := swag.JoinByFormat(xIsAnOptionalHeader3IIIR, "")`, 1487 `xIsAnOptionalHeader3IISs := xIsAnOptionalHeader3IIS[0]`, 1488 `if xIsAnOptionalHeader3IISs != "" {`, 1489 `xIsAnOptionalHeader3IIR = append(xIsAnOptionalHeader3IIR, xIsAnOptionalHeader3IISs)`, 1490 `xIsAnOptionalHeader3IS := swag.JoinByFormat(xIsAnOptionalHeader3IIR, "pipes")`, 1491 `xIsAnOptionalHeader3ISs := xIsAnOptionalHeader3IS[0]`, 1492 `if xIsAnOptionalHeader3ISs != "" {`, 1493 `xIsAnOptionalHeader3IR = append(xIsAnOptionalHeader3IR, xIsAnOptionalHeader3ISs)`, 1494 `xIsAnOptionalHeader3 := swag.JoinByFormat(xIsAnOptionalHeader3IR, "")`, 1495 `hv := xIsAnOptionalHeader3[0]`, 1496 `rw.Header().Set("x-isAnOptionalHeader3", hv)`, 1497 }, 1498 }, 1499 } 1500 1501 for fixtureIndex, fixtureContents := range fixtureConfig { 1502 fixtureSpec := strings.Join([]string{"fixture-909-", fixtureIndex, ".yaml"}, "") 1503 gen, err := opBuilder("getOptional", filepath.Join("..", "fixtures", "bugs", "909", fixtureSpec)) 1504 if assert.NoError(err) { 1505 op, err := gen.MakeOperation() 1506 if assert.NoError(err) { 1507 opts := opts() 1508 for fixtureTemplate, expectedCode := range fixtureContents { 1509 buf := bytes.NewBuffer(nil) 1510 err := templates.MustGet(fixtureTemplate).Execute(buf, op) 1511 if assert.NoError(err, "Expected generation to go well on %s with template %s", fixtureSpec, fixtureTemplate) { 1512 ff, err := opts.LanguageOpts.FormatContent("foo.go", buf.Bytes()) 1513 if assert.NoError(err, "Expected formatting to go well on %s with template %s", fixtureSpec, fixtureTemplate) { 1514 res := string(ff) 1515 for line, codeLine := range expectedCode { 1516 if !assertInCode(t, strings.TrimSpace(codeLine), res) { 1517 t.Logf("Code expected did not match for fixture %s at line %d", fixtureSpec, line) 1518 } 1519 } 1520 } else { 1521 fmt.Println(buf.String()) 1522 } 1523 } 1524 } 1525 } 1526 } 1527 } 1528 } 1529 1530 // verifies that validation method is called on body param with $ref 1531 func TestGenParameter_Issue1237(t *testing.T) { 1532 log.SetOutput(ioutil.Discard) 1533 defer func() { 1534 log.SetOutput(os.Stdout) 1535 }() 1536 1537 assert := assert.New(t) 1538 fixtureConfig := map[string]map[string][]string{ 1539 "1": { // fixture index 1540 "serverParameter": { // executed template 1541 // expected code lines 1542 `var body models.Sg`, 1543 `if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 1544 `if err == io.EOF {`, 1545 `res = append(res, errors.Required("body", "body"))`, 1546 `} else {`, 1547 `res = append(res, errors.NewParseError("body", "body", "", err))`, 1548 `if err := body.Validate(route.Formats); err != nil {`, 1549 }, 1550 }, 1551 } 1552 for _, fixtureContents := range fixtureConfig { 1553 fixtureSpec := strings.Join([]string{"fixture-1237", ".json"}, "") 1554 gen, err := opBuilder("add sg", filepath.Join("..", "fixtures", "bugs", "1237", fixtureSpec)) 1555 if assert.NoError(err) { 1556 op, err := gen.MakeOperation() 1557 if assert.NoError(err) { 1558 opts := opts() 1559 for fixtureTemplate, expectedCode := range fixtureContents { 1560 buf := bytes.NewBuffer(nil) 1561 err := templates.MustGet(fixtureTemplate).Execute(buf, op) 1562 if assert.NoError(err, "Expected generation to go well on %s with template %s", fixtureSpec, fixtureTemplate) { 1563 ff, err := opts.LanguageOpts.FormatContent("foo.go", buf.Bytes()) 1564 if assert.NoError(err, "Expected formatting to go well on %s with template %s", fixtureSpec, fixtureTemplate) { 1565 res := string(ff) 1566 for line, codeLine := range expectedCode { 1567 if !assertInCode(t, strings.TrimSpace(codeLine), res) { 1568 t.Logf("Code expected did not match for fixture %s at line %d", fixtureSpec, line) 1569 } 1570 } 1571 } else { 1572 fmt.Println(buf.String()) 1573 } 1574 } 1575 } 1576 } 1577 } 1578 } 1579 } 1580 1581 func TestGenParameter_Issue1392(t *testing.T) { 1582 log.SetOutput(ioutil.Discard) 1583 defer func() { 1584 log.SetOutput(os.Stdout) 1585 }() 1586 1587 assert := assert.New(t) 1588 fixtureConfig := map[string]map[string][]string{ 1589 "1": { // fixture index 1590 "serverParameter": { // executed template 1591 `func (o *PatchSomeResourceParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 1592 ` var res []error`, 1593 ` o.HTTPRequest = r`, 1594 ` if runtime.HasBody(r) {`, 1595 ` defer r.Body.Close()`, 1596 ` var body models.BulkUpdateState`, 1597 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 1598 ` res = append(res, errors.NewParseError("massUpdate", "body", "", err))`, 1599 ` } else {`, 1600 ` if err := body.Validate(route.Formats); err != nil {`, 1601 ` res = append(res, err)`, 1602 ` if len(res) == 0 {`, 1603 ` o.MassUpdate = body`, 1604 ` if len(res) > 0 {`, 1605 ` return errors.CompositeValidationError(res...)`, 1606 }, 1607 }, 1608 "2": { // fixture index 1609 "serverParameter": { // executed template 1610 // expected code lines 1611 `func (o *PostBodybuilder20Params) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 1612 ` var res []error`, 1613 ` o.HTTPRequest = r`, 1614 ` if runtime.HasBody(r) {`, 1615 ` defer r.Body.Close()`, 1616 ` var body []strfmt.URI`, 1617 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 1618 ` res = append(res, errors.NewParseError("myObject", "body", "", err))`, 1619 ` } else {`, 1620 ` // validate inline body array`, 1621 ` o.MyObject = body`, 1622 ` if err := o.validateMyObjectBody(route.Formats); err != nil {`, 1623 ` res = append(res, err)`, 1624 ` if len(res) > 0 {`, 1625 ` return errors.CompositeValidationError(res...)`, 1626 `func (o *PostBodybuilder20Params) validateMyObjectBody(formats strfmt.Registry) error {`, 1627 ` // uniqueItems: true`, 1628 ` if err := validate.UniqueItems("myObject", "body", o.MyObject); err != nil {`, 1629 ` myObjectIC := o.MyObject`, 1630 ` var myObjectIR []strfmt.URI`, 1631 ` for i, myObjectIV := range myObjectIC {`, 1632 ` myObjectI := myObjectIV`, 1633 ` if err := validate.FormatOf(fmt.Sprintf("%s.%v", "myObject", i), "body", "uri", myObjectI.String(), formats); err != nil {`, 1634 ` myObjectIR = append(myObjectIR, myObjectI)`, 1635 ` o.MyObject = myObjectIR`, 1636 }, 1637 }, 1638 "3": { // fixture index 1639 "serverParameter": { // executed template 1640 // expected code lines 1641 `func (o *PostBodybuilder26Params) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 1642 ` var res []error`, 1643 ` o.HTTPRequest = r`, 1644 ` qs := runtime.Values(r.URL.Query())`, 1645 ` if runtime.HasBody(r) {`, 1646 ` defer r.Body.Close()`, 1647 ` var body strfmt.Date`, 1648 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 1649 ` res = append(res, errors.NewParseError("myObject", "body", "", err))`, 1650 ` } else {`, 1651 ` // validate inline body`, 1652 ` o.MyObject = body`, 1653 ` if err := o.validateMyObjectBody(route.Formats); err != nil {`, 1654 ` res = append(res, err)`, 1655 ` qMyquery, qhkMyquery, _ := qs.GetOK("myquery")`, 1656 ` if err := o.bindMyquery(qMyquery, qhkMyquery, route.Formats); err != nil {`, 1657 ` res = append(res, err)`, 1658 ` if len(res) > 0 {`, 1659 ` return errors.CompositeValidationError(res...)`, 1660 ` return nil`, 1661 `func (o *PostBodybuilder26Params) validateMyObjectBody(formats strfmt.Registry) error {`, 1662 ` if err := validate.Enum("myObject", "body", o.MyObject.String(), []interface{}{"1992-01-01", "2012-01-01"}); err != nil {`, 1663 ` if err := validate.FormatOf("myObject", "body", "date", o.MyObject.String(), formats); err != nil {`, 1664 }, 1665 }, 1666 "4": { // fixture index 1667 "serverParameter": { // executed template 1668 // expected code lines 1669 `func (o *PostBodybuilder27Params) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 1670 ` var res []error`, 1671 ` o.HTTPRequest = r`, 1672 ` if runtime.HasBody(r) {`, 1673 ` defer r.Body.Close()`, 1674 ` var body [][]strfmt.Date`, 1675 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 1676 ` res = append(res, errors.NewParseError("myObject", "body", "", err))`, 1677 ` } else {`, 1678 ` o.MyObject = body`, 1679 ` if err := o.validateMyObjectBody(route.Formats); err != nil {`, 1680 ` res = append(res, err)`, 1681 ` if len(res) > 0 {`, 1682 ` return errors.CompositeValidationError(res...)`, 1683 `func (o *PostBodybuilder27Params) validateMyObjectBody(formats strfmt.Registry) error {`, 1684 ` if err := validate.Enum("myObject", "body", o.MyObject, []interface{}{[]interface{}{[]interface{}{"1992-01-01", "2012-01-01"}}}); err != nil {`, 1685 ` return err`, 1686 ` myObjectIC := o.MyObject`, 1687 ` var myObjectIR [][]strfmt.Date`, 1688 ` for i, myObjectIV := range myObjectIC {`, 1689 ` myObjectIIC := myObjectIV`, 1690 ` if len(myObjectIIC) > 0 {`, 1691 ` var myObjectIIR []strfmt.Date`, 1692 ` for ii, myObjectIIV := range myObjectIIC {`, 1693 ` myObjectII := myObjectIIV`, 1694 ` if err := validate.Enum(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "myObject", i), ii), "", myObjectII.String(), []interface{}{"1992-01-01", "2012-01-01"}); err != nil {`, 1695 ` return err`, 1696 ` if err := validate.FormatOf(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "myObject", i), ii), "", "date", myObjectII.String(), formats); err != nil {`, 1697 ` return err`, 1698 ` myObjectIIR = append(myObjectIIR, myObjectII)`, 1699 ` myObjectIR = append(myObjectIR, myObjectIIR)`, 1700 // fixed missing enum validation 1701 ` if err := validate.Enum(fmt.Sprintf("%s.%v", "myObject", i), "body", myObjectIIC, []interface{}{[]interface{}{"1992-01-01", "2012-01-01"}}); err != nil {`, 1702 ` o.MyObject = myObjectIR`, 1703 }, 1704 }, 1705 "5": { // fixture index 1706 "serverParameter": { // executed template 1707 `func (o *Bodybuilder23Params) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 1708 ` var res []error`, 1709 ` o.HTTPRequest = r`, 1710 ` if runtime.HasBody(r) {`, 1711 ` defer r.Body.Close()`, 1712 ` var body []models.ASimpleArray`, 1713 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 1714 ` res = append(res, errors.NewParseError("myObject", "body", "", err))`, 1715 ` } else {`, 1716 ` o.MyObject = body`, 1717 ` myObjectSize := int64(len(o.MyObject))`, 1718 ` if err := validate.MinItems("myObject", "body", myObjectSize, 15); err != nil {`, 1719 ` return err`, 1720 // changed index 1721 ` for i := range body {`, 1722 ` if err := body[i].Validate(route.Formats); err != nil {`, 1723 ` res = append(res, err)`, 1724 ` break`, 1725 // removed redundant assignment 1726 //` if len(res) == 0 {`, 1727 //` o.MyObject = body`, 1728 ` if len(res) > 0 {`, 1729 ` return errors.CompositeValidationError(res...)`, 1730 }, 1731 }, 1732 } 1733 1734 for fixtureIndex, fixtureContents := range fixtureConfig { 1735 fixtureSpec := strings.Join([]string{"fixture-1392-", fixtureIndex, ".yaml"}, "") 1736 // pick selected operation id in fixture 1737 operationToTest := "" 1738 switch fixtureIndex { 1739 case "1": 1740 operationToTest = "PatchSomeResource" 1741 case "2": 1742 operationToTest = "PostBodybuilder20" 1743 case "3": 1744 operationToTest = "PostBodybuilder26" 1745 case "4": 1746 operationToTest = "PostBodybuilder27" 1747 case "5": 1748 operationToTest = "Bodybuilder23" 1749 } 1750 gen, err := opBuilder(operationToTest, filepath.Join("..", "fixtures", "bugs", "1392", fixtureSpec)) 1751 if assert.NoError(err) { 1752 op, err := gen.MakeOperation() 1753 if assert.NoError(err) { 1754 opts := opts() 1755 for fixtureTemplate, expectedCode := range fixtureContents { 1756 buf := bytes.NewBuffer(nil) 1757 err := templates.MustGet(fixtureTemplate).Execute(buf, op) 1758 if assert.NoError(err, "Expected generation to go well on %s with template %s", fixtureSpec, fixtureTemplate) { 1759 ff, err := opts.LanguageOpts.FormatContent("foo.go", buf.Bytes()) 1760 if assert.NoError(err, "Expected formatting to go well on %s with template %s", fixtureSpec, fixtureTemplate) { 1761 res := string(ff) 1762 for line, codeLine := range expectedCode { 1763 if !assertInCode(t, strings.TrimSpace(codeLine), res) { 1764 t.Logf("Code expected did not match for fixture %s at line %d", fixtureSpec, line) 1765 } 1766 } 1767 } else { 1768 fmt.Println(buf.String()) 1769 } 1770 } 1771 } 1772 } 1773 } 1774 } 1775 } 1776 1777 func TestGenParameter_Issue1513(t *testing.T) { 1778 log.SetOutput(ioutil.Discard) 1779 defer log.SetOutput(os.Stdout) 1780 1781 assert := assert.New(t) 1782 var assertion = `r.SetBodyParam(o.Something)` 1783 gen, err := opBuilderWithFlatten("put-enum", "../fixtures/bugs/1513/enums.yaml") 1784 if assert.NoError(err) { 1785 op, err := gen.MakeOperation() 1786 if assert.NoError(err) { 1787 buf := bytes.NewBuffer(nil) 1788 opts := opts() 1789 err := templates.MustGet("clientParameter").Execute(buf, op) 1790 if assert.NoError(err) { 1791 ff, err := opts.LanguageOpts.FormatContent("move_clusters_parameters.go", buf.Bytes()) 1792 if assert.NoError(err) { 1793 res := string(ff) 1794 assertInCode(t, assertion, res) 1795 } else { 1796 fmt.Println(buf.String()) 1797 } 1798 } 1799 } 1800 } 1801 } 1802 1803 // Body param validation on empty objects 1804 func TestGenParameter_Issue1536(t *testing.T) { 1805 log.SetOutput(ioutil.Discard) 1806 defer func() { 1807 log.SetOutput(os.Stdout) 1808 }() 1809 1810 // testing fixture-1536.yaml with flatten 1811 // param body with array of empty objects 1812 1813 fixtureConfig := map[string]map[string][]string{ 1814 1815 // load expectations for parameters in operation get_interface_parameters.go 1816 "getInterface": { // fixture index 1817 "serverParameter": { // executed template 1818 // expected code lines 1819 `func NewGetInterfaceParams() GetInterfaceParams {`, 1820 ` return GetInterfaceParams{`, 1821 `type GetInterfaceParams struct {`, 1822 " HTTPRequest *http.Request `json:\"-\"`", 1823 ` Generic interface{`, 1824 `func (o *GetInterfaceParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 1825 ` o.HTTPRequest = r`, 1826 ` if runtime.HasBody(r) {`, 1827 ` defer r.Body.Close(`, 1828 ` var body interface{`, 1829 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 1830 ` res = append(res, errors.NewParseError("generic", "body", "", err)`, 1831 ` } else {`, 1832 ` o.Generic = body`, 1833 ` return errors.CompositeValidationError(res...`, 1834 }, 1835 }, 1836 1837 // load expectations for parameters in operation get_map_slice_parameters.go 1838 "getMapSlice": { // fixture index 1839 "serverParameter": { // executed template 1840 // expected code lines 1841 `func NewGetMapSliceParams() GetMapSliceParams {`, 1842 ` return GetMapSliceParams{`, 1843 `type GetMapSliceParams struct {`, 1844 " HTTPRequest *http.Request `json:\"-\"`", 1845 ` GenericMapSlice []map[string]models.ModelInterface`, 1846 `func (o *GetMapSliceParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 1847 ` o.HTTPRequest = r`, 1848 ` if runtime.HasBody(r) {`, 1849 ` defer r.Body.Close(`, 1850 ` var body []map[string]models.ModelInterface`, 1851 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 1852 ` res = append(res, errors.NewParseError("genericMapSlice", "body", "", err)`, 1853 ` } else {`, 1854 ` o.GenericMapSlice = body`, 1855 ` return errors.CompositeValidationError(res...`, 1856 }, 1857 }, 1858 1859 // load expectations for parameters in operation get_nested_with_validations_parameters.go 1860 "getNestedWithValidations": { // fixture index 1861 "serverParameter": { // executed template 1862 // expected code lines 1863 `func NewGetNestedWithValidationsParams() GetNestedWithValidationsParams {`, 1864 ` return GetNestedWithValidationsParams{`, 1865 `type GetNestedWithValidationsParams struct {`, 1866 " HTTPRequest *http.Request `json:\"-\"`", 1867 ` GenericNestedWithValidations [][][][]interface{`, 1868 `func (o *GetNestedWithValidationsParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 1869 ` o.HTTPRequest = r`, 1870 ` if runtime.HasBody(r) {`, 1871 ` defer r.Body.Close(`, 1872 ` var body [][][][]interface{`, 1873 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 1874 ` res = append(res, errors.NewParseError("genericNestedWithValidations", "body", "", err)`, 1875 ` } else {`, 1876 ` o.GenericNestedWithValidations = body`, 1877 ` if err := o.validateGenericNestedWithValidationsBody(route.Formats); err != nil {`, 1878 ` return errors.CompositeValidationError(res...`, 1879 `func (o *GetNestedWithValidationsParams) validateGenericNestedWithValidationsBody(formats strfmt.Registry) error {`, 1880 ` genericNestedWithValidationsIC := o.GenericNestedWithValidations`, 1881 ` var genericNestedWithValidationsIR [][][][]interface{`, 1882 ` for i, genericNestedWithValidationsIV := range genericNestedWithValidationsIC {`, 1883 ` genericNestedWithValidationsIIC := genericNestedWithValidationsIV`, 1884 ` if len(genericNestedWithValidationsIIC) > 0 {`, 1885 ` var genericNestedWithValidationsIIR [][][]interface{`, 1886 ` for ii, genericNestedWithValidationsIIV := range genericNestedWithValidationsIIC {`, 1887 ` genericNestedWithValidationsIIIC := genericNestedWithValidationsIIV`, 1888 ` if len(genericNestedWithValidationsIIIC) > 0 {`, 1889 ` var genericNestedWithValidationsIIIR [][]interface{`, 1890 ` for iii, genericNestedWithValidationsIIIV := range genericNestedWithValidationsIIIC {`, 1891 ` genericNestedWithValidationsIIIIC := genericNestedWithValidationsIIIV`, 1892 ` if len(genericNestedWithValidationsIIIIC) > 0 {`, 1893 ` var genericNestedWithValidationsIIIIR []interface{`, 1894 ` for _, genericNestedWithValidationsIIIIV := range genericNestedWithValidationsIIIIC {`, 1895 ` genericNestedWithValidationsIIII := genericNestedWithValidationsIIIIV`, 1896 ` genericNestedWithValidationsIIIIR = append(genericNestedWithValidationsIIIIR, genericNestedWithValidationsIIII`, 1897 ` genericNestedWithValidationsIIIR = append(genericNestedWithValidationsIIIR, genericNestedWithValidationsIIIIR`, 1898 ` genericNestedWithValidationsIiiiiiSize := int64(len(genericNestedWithValidationsIIIIC)`, 1899 ` if err := validate.MaxItems(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "genericNestedWithValidations", i), ii), iii), "", genericNestedWithValidationsIiiiiiSize, 10); err != nil {`, 1900 ` genericNestedWithValidationsIIR = append(genericNestedWithValidationsIIR, genericNestedWithValidationsIIIR`, 1901 ` genericNestedWithValidationsIR = append(genericNestedWithValidationsIR, genericNestedWithValidationsIIR`, 1902 ` o.GenericNestedWithValidations = genericNestedWithValidationsIR`, 1903 }, 1904 }, 1905 1906 // load expectations for parameters in operation get_another_interface_parameters.go 1907 "getAnotherInterface": { // fixture index 1908 "serverParameter": { // executed template 1909 // expected code lines 1910 `func NewGetAnotherInterfaceParams() GetAnotherInterfaceParams {`, 1911 ` return GetAnotherInterfaceParams{`, 1912 `type GetAnotherInterfaceParams struct {`, 1913 " HTTPRequest *http.Request `json:\"-\"`", 1914 ` AnotherGeneric interface{`, 1915 `func (o *GetAnotherInterfaceParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 1916 ` o.HTTPRequest = r`, 1917 ` if runtime.HasBody(r) {`, 1918 ` defer r.Body.Close(`, 1919 ` var body interface{`, 1920 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 1921 ` res = append(res, errors.NewParseError("anotherGeneric", "body", "", err)`, 1922 ` } else {`, 1923 ` o.AnotherGeneric = body`, 1924 ` return errors.CompositeValidationError(res...`, 1925 }, 1926 }, 1927 1928 // load expectations for parameters in operation get_nested_required_parameters.go 1929 "getNestedRequired": { // fixture index 1930 "serverParameter": { // executed template 1931 // expected code lines 1932 `func NewGetNestedRequiredParams() GetNestedRequiredParams {`, 1933 ` return GetNestedRequiredParams{`, 1934 `type GetNestedRequiredParams struct {`, 1935 " HTTPRequest *http.Request `json:\"-\"`", 1936 ` ObjectNestedRequired [][][][]*models.GetNestedRequiredParamsBodyItemsItemsItemsItems`, 1937 `func (o *GetNestedRequiredParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 1938 ` o.HTTPRequest = r`, 1939 ` if runtime.HasBody(r) {`, 1940 ` defer r.Body.Close(`, 1941 ` var body [][][][]*models.GetNestedRequiredParamsBodyItemsItemsItemsItems`, 1942 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 1943 ` res = append(res, errors.NewParseError("objectNestedRequired", "body", "", err)`, 1944 ` } else {`, 1945 ` o.ObjectNestedRequired = body`, 1946 ` if err := o.validateObjectNestedRequiredBody(route.Formats); err != nil {`, 1947 ` return errors.CompositeValidationError(res...`, 1948 `func (o *GetNestedRequiredParams) validateObjectNestedRequiredBody(formats strfmt.Registry) error {`, 1949 ` objectNestedRequiredIC := o.ObjectNestedRequired`, 1950 ` var objectNestedRequiredIR [][][][]*models.GetNestedRequiredParamsBodyItemsItemsItemsItems`, 1951 ` for i, objectNestedRequiredIV := range objectNestedRequiredIC {`, 1952 ` objectNestedRequiredIIC := objectNestedRequiredIV`, 1953 ` if len(objectNestedRequiredIIC) > 0 {`, 1954 ` var objectNestedRequiredIIR [][][]*models.GetNestedRequiredParamsBodyItemsItemsItemsItems`, 1955 ` for ii, objectNestedRequiredIIV := range objectNestedRequiredIIC {`, 1956 ` objectNestedRequiredIIIC := objectNestedRequiredIIV`, 1957 ` if len(objectNestedRequiredIIIC) > 0 {`, 1958 ` var objectNestedRequiredIIIR [][]*models.GetNestedRequiredParamsBodyItemsItemsItemsItems`, 1959 ` for iii, objectNestedRequiredIIIV := range objectNestedRequiredIIIC {`, 1960 ` objectNestedRequiredIIIIC := objectNestedRequiredIIIV`, 1961 ` if len(objectNestedRequiredIIIIC) > 0 {`, 1962 ` var objectNestedRequiredIIIIR []*models.GetNestedRequiredParamsBodyItemsItemsItemsItems`, 1963 ` for iiii, objectNestedRequiredIIIIV := range objectNestedRequiredIIIIC {`, 1964 ` objectNestedRequiredIIII := objectNestedRequiredIIIIV`, 1965 ` if err := objectNestedRequiredIIII.Validate(formats); err != nil {`, 1966 ` if ve, ok := err.(*errors.Validation); ok {`, 1967 ` return ve.ValidateName(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "objectNestedRequired", i), ii), iii), iiii)`, 1968 ` objectNestedRequiredIIIIR = append(objectNestedRequiredIIIIR, objectNestedRequiredIIII`, 1969 ` objectNestedRequiredIIIR = append(objectNestedRequiredIIIR, objectNestedRequiredIIIIR`, 1970 ` objectNestedRequiredIIR = append(objectNestedRequiredIIR, objectNestedRequiredIIIR`, 1971 ` objectNestedRequiredIR = append(objectNestedRequiredIR, objectNestedRequiredIIR`, 1972 ` o.ObjectNestedRequired = objectNestedRequiredIR`, 1973 }, 1974 }, 1975 1976 // load expectations for parameters in operation get_records_max_parameters.go 1977 "getRecordsMax": { // fixture index 1978 "serverParameter": { // executed template 1979 // expected code lines 1980 `func NewGetRecordsMaxParams() GetRecordsMaxParams {`, 1981 ` return GetRecordsMaxParams{`, 1982 `type GetRecordsMaxParams struct {`, 1983 " HTTPRequest *http.Request `json:\"-\"`", 1984 ` MaxRecords []interface{`, 1985 `func (o *GetRecordsMaxParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 1986 ` o.HTTPRequest = r`, 1987 ` if runtime.HasBody(r) {`, 1988 ` defer r.Body.Close(`, 1989 ` var body []interface{`, 1990 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 1991 ` if err == io.EOF {`, 1992 ` res = append(res, errors.Required("maxRecords", "body")`, 1993 ` } else {`, 1994 ` res = append(res, errors.NewParseError("maxRecords", "body", "", err)`, 1995 ` } else {`, 1996 ` o.MaxRecords = body`, 1997 ` if err := o.validateMaxRecordsBody(route.Formats); err != nil {`, 1998 ` } else {`, 1999 ` res = append(res, errors.Required("maxRecords", "body")`, 2000 ` return errors.CompositeValidationError(res...`, 2001 `func (o *GetRecordsMaxParams) validateMaxRecordsBody(formats strfmt.Registry) error {`, 2002 ` maxRecordsSize := int64(len(o.MaxRecords)`, 2003 ` if err := validate.MaxItems("maxRecords", "body", maxRecordsSize, 10); err != nil {`, 2004 }, 2005 }, 2006 2007 // load expectations for parameters in operation get_records_parameters.go 2008 "getRecords": { // fixture index 2009 "serverParameter": { // executed template 2010 // expected code lines 2011 `func NewGetRecordsParams() GetRecordsParams {`, 2012 ` return GetRecordsParams{`, 2013 `type GetRecordsParams struct {`, 2014 " HTTPRequest *http.Request `json:\"-\"`", 2015 ` Records []interface{`, 2016 `func (o *GetRecordsParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 2017 ` o.HTTPRequest = r`, 2018 ` if runtime.HasBody(r) {`, 2019 ` defer r.Body.Close(`, 2020 ` var body []interface{`, 2021 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 2022 ` if err == io.EOF {`, 2023 ` res = append(res, errors.Required("records", "body")`, 2024 ` } else {`, 2025 ` res = append(res, errors.NewParseError("records", "body", "", err)`, 2026 ` } else {`, 2027 ` o.Records = body`, 2028 // fixed: no validation has to be carried on 2029 ` } else {`, 2030 ` res = append(res, errors.Required("records", "body")`, 2031 ` return errors.CompositeValidationError(res...`, 2032 }, 2033 }, 2034 // load expectations for parameters in operation get_records_non_required_parameters.go 2035 "getRecordsNonRequired": { // fixture index 2036 "serverParameter": { // executed template 2037 // expected code lines 2038 `func NewGetRecordsNonRequiredParams() GetRecordsNonRequiredParams {`, 2039 ` return GetRecordsNonRequiredParams{`, 2040 `type GetRecordsNonRequiredParams struct {`, 2041 " HTTPRequest *http.Request `json:\"-\"`", 2042 ` RecordsNonRequired []interface{`, 2043 `func (o *GetRecordsNonRequiredParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 2044 ` o.HTTPRequest = r`, 2045 ` if runtime.HasBody(r) {`, 2046 ` defer r.Body.Close(`, 2047 ` var body []interface{`, 2048 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 2049 ` res = append(res, errors.NewParseError("recordsNonRequired", "body", "", err)`, 2050 ` } else {`, 2051 ` o.RecordsNonRequired = body`, 2052 ` return errors.CompositeValidationError(res...`, 2053 }, 2054 }, 2055 // load expectations for parameters in operation get_map_parameters.go 2056 "getMap": { // fixture index 2057 "serverParameter": { // executed template 2058 // expected code lines 2059 `func NewGetMapParams() GetMapParams {`, 2060 ` return GetMapParams{`, 2061 `type GetMapParams struct {`, 2062 " HTTPRequest *http.Request `json:\"-\"`", 2063 ` GenericMap map[string]models.ModelInterface`, 2064 `func (o *GetMapParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 2065 ` o.HTTPRequest = r`, 2066 ` if runtime.HasBody(r) {`, 2067 ` defer r.Body.Close(`, 2068 ` var body map[string]models.ModelInterface`, 2069 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 2070 ` res = append(res, errors.NewParseError("genericMap", "body", "", err)`, 2071 ` } else {`, 2072 ` o.GenericMap = body`, 2073 ` return errors.CompositeValidationError(res...`, 2074 }, 2075 }, 2076 2077 // load expectations for parameters in operation get_slice_map_parameters.go 2078 "getSliceMap": { // fixture index 2079 "serverParameter": { // executed template 2080 // expected code lines 2081 `func NewGetSliceMapParams() GetSliceMapParams {`, 2082 ` return GetSliceMapParams{`, 2083 `type GetSliceMapParams struct {`, 2084 " HTTPRequest *http.Request `json:\"-\"`", 2085 ` GenericSliceMap map[string][]models.ModelInterface`, 2086 `func (o *GetSliceMapParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 2087 ` o.HTTPRequest = r`, 2088 ` if runtime.HasBody(r) {`, 2089 ` defer r.Body.Close(`, 2090 ` var body map[string][]models.ModelInterface`, 2091 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 2092 ` res = append(res, errors.NewParseError("genericSliceMap", "body", "", err)`, 2093 ` } else {`, 2094 ` o.GenericSliceMap = body`, 2095 ` return errors.CompositeValidationError(res...`, 2096 }, 2097 }, 2098 2099 // load expectations for parameters in operation get_nested_parameters.go 2100 "getNested": { // fixture index 2101 "serverParameter": { // executed template 2102 // expected code lines 2103 `func NewGetNestedParams() GetNestedParams {`, 2104 ` return GetNestedParams{`, 2105 `type GetNestedParams struct {`, 2106 " HTTPRequest *http.Request `json:\"-\"`", 2107 ` GenericNested [][][][]interface{`, 2108 `func (o *GetNestedParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 2109 ` o.HTTPRequest = r`, 2110 ` if runtime.HasBody(r) {`, 2111 ` defer r.Body.Close(`, 2112 ` var body [][][][]interface{`, 2113 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 2114 ` res = append(res, errors.NewParseError("genericNested", "body", "", err)`, 2115 ` } else {`, 2116 ` o.GenericNested = body`, 2117 ` return errors.CompositeValidationError(res...`, 2118 }, 2119 }, 2120 } 2121 2122 assertParams(t, fixtureConfig, filepath.Join("..", "fixtures", "bugs", "1536", "fixture-1536.yaml"), false, false) 2123 } 2124 2125 func TestGenParameter_Issue15362(t *testing.T) { 2126 log.SetOutput(ioutil.Discard) 2127 defer func() { 2128 log.SetOutput(os.Stdout) 2129 }() 2130 2131 fixtureConfig := map[string]map[string][]string{ 2132 // load expectations for parameters in operation get_nested_with_validations_parameters.go 2133 "getNestedWithValidations": { // fixture index 2134 "serverParameter": { // executed template 2135 // expected code lines 2136 `func NewGetNestedWithValidationsParams() GetNestedWithValidationsParams {`, 2137 ` return GetNestedWithValidationsParams{`, 2138 `type GetNestedWithValidationsParams struct {`, 2139 " HTTPRequest *http.Request `json:\"-\"`", 2140 ` GenericNestedWithValidations [][][][]interface{`, 2141 `func (o *GetNestedWithValidationsParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 2142 ` o.HTTPRequest = r`, 2143 ` if runtime.HasBody(r) {`, 2144 ` defer r.Body.Close(`, 2145 ` var body [][][][]interface{`, 2146 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 2147 ` res = append(res, errors.NewParseError("genericNestedWithValidations", "body", "", err)`, 2148 ` } else {`, 2149 ` o.GenericNestedWithValidations = body`, 2150 ` if err := o.validateGenericNestedWithValidationsBody(route.Formats); err != nil {`, 2151 ` return errors.CompositeValidationError(res...`, 2152 `func (o *GetNestedWithValidationsParams) validateGenericNestedWithValidationsBody(formats strfmt.Registry) error {`, 2153 ` genericNestedWithValidationsIC := o.GenericNestedWithValidations`, 2154 ` var genericNestedWithValidationsIR [][][][]interface{`, 2155 ` for i, genericNestedWithValidationsIV := range genericNestedWithValidationsIC {`, 2156 ` genericNestedWithValidationsIIC := genericNestedWithValidationsIV`, 2157 ` if len(genericNestedWithValidationsIIC) > 0 {`, 2158 ` var genericNestedWithValidationsIIR [][][]interface{`, 2159 ` for ii, genericNestedWithValidationsIIV := range genericNestedWithValidationsIIC {`, 2160 ` genericNestedWithValidationsIIIC := genericNestedWithValidationsIIV`, 2161 ` if len(genericNestedWithValidationsIIIC) > 0 {`, 2162 ` var genericNestedWithValidationsIIIR [][]interface{`, 2163 ` for iii, genericNestedWithValidationsIIIV := range genericNestedWithValidationsIIIC {`, 2164 ` genericNestedWithValidationsIIIIC := genericNestedWithValidationsIIIV`, 2165 ` if len(genericNestedWithValidationsIIIIC) > 0 {`, 2166 ` var genericNestedWithValidationsIIIIR []interface{`, 2167 ` for _, genericNestedWithValidationsIIIIV := range genericNestedWithValidationsIIIIC {`, 2168 ` genericNestedWithValidationsIIII := genericNestedWithValidationsIIIIV`, 2169 ` genericNestedWithValidationsIIIIR = append(genericNestedWithValidationsIIIIR, genericNestedWithValidationsIIII`, 2170 ` genericNestedWithValidationsIIIR = append(genericNestedWithValidationsIIIR, genericNestedWithValidationsIIIIR`, 2171 ` genericNestedWithValidationsIiiiiiSize := int64(len(genericNestedWithValidationsIIIIC)`, 2172 ` if err := validate.MaxItems(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "genericNestedWithValidations", i), ii), iii), "", genericNestedWithValidationsIiiiiiSize, 10); err != nil {`, 2173 ` genericNestedWithValidationsIIR = append(genericNestedWithValidationsIIR, genericNestedWithValidationsIIIR`, 2174 ` genericNestedWithValidationsIR = append(genericNestedWithValidationsIR, genericNestedWithValidationsIIR`, 2175 ` o.GenericNestedWithValidations = genericNestedWithValidationsIR`, 2176 }, 2177 }, 2178 2179 // load expectations for parameters in operation get_nested_required_parameters.go 2180 "getNestedRequired": { // fixture index 2181 "serverParameter": { // executed template 2182 // expected code lines 2183 `func NewGetNestedRequiredParams() GetNestedRequiredParams {`, 2184 ` return GetNestedRequiredParams{`, 2185 `type GetNestedRequiredParams struct {`, 2186 " HTTPRequest *http.Request `json:\"-\"`", 2187 ` ObjectNestedRequired [][][][]*models.GetNestedRequiredParamsBodyItemsItemsItemsItems`, 2188 `func (o *GetNestedRequiredParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 2189 ` o.HTTPRequest = r`, 2190 ` if runtime.HasBody(r) {`, 2191 ` defer r.Body.Close(`, 2192 ` var body [][][][]*models.GetNestedRequiredParamsBodyItemsItemsItemsItems`, 2193 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 2194 ` res = append(res, errors.NewParseError("objectNestedRequired", "body", "", err)`, 2195 ` } else {`, 2196 ` o.ObjectNestedRequired = body`, 2197 ` if err := o.validateObjectNestedRequiredBody(route.Formats); err != nil {`, 2198 ` return errors.CompositeValidationError(res...`, 2199 `func (o *GetNestedRequiredParams) validateObjectNestedRequiredBody(formats strfmt.Registry) error {`, 2200 ` objectNestedRequiredIC := o.ObjectNestedRequired`, 2201 ` var objectNestedRequiredIR [][][][]*models.GetNestedRequiredParamsBodyItemsItemsItemsItems`, 2202 ` for i, objectNestedRequiredIV := range objectNestedRequiredIC {`, 2203 ` objectNestedRequiredIIC := objectNestedRequiredIV`, 2204 ` if len(objectNestedRequiredIIC) > 0 {`, 2205 ` var objectNestedRequiredIIR [][][]*models.GetNestedRequiredParamsBodyItemsItemsItemsItems`, 2206 ` for ii, objectNestedRequiredIIV := range objectNestedRequiredIIC {`, 2207 ` objectNestedRequiredIIIC := objectNestedRequiredIIV`, 2208 ` if len(objectNestedRequiredIIIC) > 0 {`, 2209 ` var objectNestedRequiredIIIR [][]*models.GetNestedRequiredParamsBodyItemsItemsItemsItems`, 2210 ` for iii, objectNestedRequiredIIIV := range objectNestedRequiredIIIC {`, 2211 ` objectNestedRequiredIIIIC := objectNestedRequiredIIIV`, 2212 ` if len(objectNestedRequiredIIIIC) > 0 {`, 2213 ` var objectNestedRequiredIIIIR []*models.GetNestedRequiredParamsBodyItemsItemsItemsItems`, 2214 ` for iiii, objectNestedRequiredIIIIV := range objectNestedRequiredIIIIC {`, 2215 ` if objectNestedRequiredIIIIV == nil {`, 2216 // continue 2217 ` objectNestedRequiredIIII := objectNestedRequiredIIIIV`, 2218 ` if err := objectNestedRequiredIIII.Validate(formats); err != nil {`, 2219 ` if ve, ok := err.(*errors.Validation); ok {`, 2220 ` return ve.ValidateName(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "objectNestedRequired", i), ii), iii), iiii)`, 2221 ` objectNestedRequiredIIIIR = append(objectNestedRequiredIIIIR, objectNestedRequiredIIII`, 2222 ` objectNestedRequiredIIIR = append(objectNestedRequiredIIIR, objectNestedRequiredIIIIR`, 2223 ` objectNestedRequiredIIR = append(objectNestedRequiredIIR, objectNestedRequiredIIIR`, 2224 ` objectNestedRequiredIR = append(objectNestedRequiredIR, objectNestedRequiredIIR`, 2225 ` o.ObjectNestedRequired = objectNestedRequiredIR`, 2226 }, 2227 }, 2228 2229 // load expectations for parameters in operation get_simple_array_with_slice_validation_parameters.go 2230 "getSimpleArrayWithSliceValidation": { // fixture index 2231 "serverParameter": { // executed template 2232 // expected code lines 2233 `func NewGetSimpleArrayWithSliceValidationParams() GetSimpleArrayWithSliceValidationParams {`, 2234 ` return GetSimpleArrayWithSliceValidationParams{`, 2235 `type GetSimpleArrayWithSliceValidationParams struct {`, 2236 " HTTPRequest *http.Request `json:\"-\"`", 2237 ` SimpleArrayWithSliceValidation []int64`, 2238 `func (o *GetSimpleArrayWithSliceValidationParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 2239 ` o.HTTPRequest = r`, 2240 ` if runtime.HasBody(r) {`, 2241 ` defer r.Body.Close(`, 2242 ` var body []int64`, 2243 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 2244 ` res = append(res, errors.NewParseError("simpleArrayWithSliceValidation", "body", "", err)`, 2245 ` } else {`, 2246 ` o.SimpleArrayWithSliceValidation = body`, 2247 ` if err := o.validateSimpleArrayWithSliceValidationBody(route.Formats); err != nil {`, 2248 ` return errors.CompositeValidationError(res...`, 2249 `func (o *GetSimpleArrayWithSliceValidationParams) validateSimpleArrayWithSliceValidationBody(formats strfmt.Registry) error {`, 2250 ` if err := validate.Enum("simpleArrayWithSliceValidation", "body", o.SimpleArrayWithSliceValidation, []interface{}{[]interface{}{1, 2, 3}, []interface{}{4, 5, 6}}); err != nil {`, 2251 }, 2252 }, 2253 2254 // load expectations for parameters in operation get_simple_parameters.go 2255 "getSimple": { // fixture index 2256 "serverParameter": { // executed template 2257 // expected code lines 2258 `func NewGetSimpleParams() GetSimpleParams {`, 2259 ` return GetSimpleParams{`, 2260 `type GetSimpleParams struct {`, 2261 " HTTPRequest *http.Request `json:\"-\"`", 2262 ` SimpleBody *models.GetSimpleParamsBody`, 2263 `func (o *GetSimpleParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 2264 ` o.HTTPRequest = r`, 2265 ` if runtime.HasBody(r) {`, 2266 ` defer r.Body.Close(`, 2267 ` var body models.GetSimpleParamsBody`, 2268 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 2269 ` res = append(res, errors.NewParseError("simpleBody", "body", "", err)`, 2270 ` } else {`, 2271 ` if err := body.Validate(route.Formats); err != nil {`, 2272 ` if len(res) == 0 {`, 2273 ` o.SimpleBody = &body`, 2274 ` return errors.CompositeValidationError(res...`, 2275 }, 2276 }, 2277 2278 // load expectations for parameters in operation get_simple_array_with_validation_parameters.go 2279 "getSimpleArrayWithValidation": { // fixture index 2280 "serverParameter": { // executed template 2281 // expected code lines 2282 `func NewGetSimpleArrayWithValidationParams() GetSimpleArrayWithValidationParams {`, 2283 ` return GetSimpleArrayWithValidationParams{`, 2284 `type GetSimpleArrayWithValidationParams struct {`, 2285 " HTTPRequest *http.Request `json:\"-\"`", 2286 ` SimpleArrayWithValidation []int64`, 2287 `func (o *GetSimpleArrayWithValidationParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 2288 ` o.HTTPRequest = r`, 2289 ` if runtime.HasBody(r) {`, 2290 ` defer r.Body.Close(`, 2291 ` var body []int64`, 2292 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 2293 ` res = append(res, errors.NewParseError("simpleArrayWithValidation", "body", "", err)`, 2294 ` } else {`, 2295 ` o.SimpleArrayWithValidation = body`, 2296 ` if err := o.validateSimpleArrayWithValidationBody(route.Formats); err != nil {`, 2297 ` return errors.CompositeValidationError(res...`, 2298 `func (o *GetSimpleArrayWithValidationParams) validateSimpleArrayWithValidationBody(formats strfmt.Registry) error {`, 2299 ` simpleArrayWithValidationIC := o.SimpleArrayWithValidation`, 2300 ` var simpleArrayWithValidationIR []int64`, 2301 ` for i, simpleArrayWithValidationIV := range simpleArrayWithValidationIC {`, 2302 ` simpleArrayWithValidationI := simpleArrayWithValidationIV`, 2303 ` if err := validate.MaximumInt(fmt.Sprintf("%s.%v", "simpleArrayWithValidation", i), "body", int64(simpleArrayWithValidationI), 12, false); err != nil {`, 2304 ` simpleArrayWithValidationIR = append(simpleArrayWithValidationIR, simpleArrayWithValidationI`, 2305 ` o.SimpleArrayWithValidation = simpleArrayWithValidationIR`, 2306 }, 2307 }, 2308 2309 // load expectations for parameters in operation get_nested_parameters.go 2310 "getNested": { // fixture index 2311 "serverParameter": { // executed template 2312 // expected code lines 2313 `func NewGetNestedParams() GetNestedParams {`, 2314 ` return GetNestedParams{`, 2315 `type GetNestedParams struct {`, 2316 " HTTPRequest *http.Request `json:\"-\"`", 2317 ` GenericNested [][][][]interface{`, 2318 `func (o *GetNestedParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 2319 ` o.HTTPRequest = r`, 2320 ` if runtime.HasBody(r) {`, 2321 ` defer r.Body.Close(`, 2322 ` var body [][][][]interface{`, 2323 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 2324 ` res = append(res, errors.NewParseError("genericNested", "body", "", err)`, 2325 ` } else {`, 2326 ` o.GenericNested = body`, 2327 ` return errors.CompositeValidationError(res...`, 2328 }, 2329 }, 2330 2331 // load expectations for parameters in operation get_simple_array_parameters.go 2332 "getSimpleArray": { // fixture index 2333 "serverParameter": { // executed template 2334 // expected code lines 2335 `func NewGetSimpleArrayParams() GetSimpleArrayParams {`, 2336 ` return GetSimpleArrayParams{`, 2337 `type GetSimpleArrayParams struct {`, 2338 " HTTPRequest *http.Request `json:\"-\"`", 2339 ` SimpleArray []int64`, 2340 `func (o *GetSimpleArrayParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 2341 ` o.HTTPRequest = r`, 2342 ` if runtime.HasBody(r) {`, 2343 ` defer r.Body.Close(`, 2344 ` var body []int64`, 2345 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 2346 ` res = append(res, errors.NewParseError("simpleArray", "body", "", err)`, 2347 ` } else {`, 2348 ` o.SimpleArray = body`, 2349 ` return errors.CompositeValidationError(res...`, 2350 }, 2351 }, 2352 } 2353 assertParams(t, fixtureConfig, filepath.Join("..", "fixtures", "bugs", "1536", "fixture-1536-2.yaml"), false, false) 2354 } 2355 2356 func TestGenParameter_Issue1536_Maps(t *testing.T) { 2357 log.SetOutput(ioutil.Discard) 2358 defer func() { 2359 log.SetOutput(os.Stdout) 2360 }() 2361 2362 fixtureConfig := map[string]map[string][]string{ 2363 2364 // load expectations for parameters in operation get_map_interface_parameters.go 2365 "getMapInterface": { // fixture index 2366 "serverParameter": { // executed template 2367 // expected code lines 2368 `func NewGetMapInterfaceParams() GetMapInterfaceParams {`, 2369 ` return GetMapInterfaceParams{`, 2370 `type GetMapInterfaceParams struct {`, 2371 " HTTPRequest *http.Request `json:\"-\"`", 2372 ` MapOfInterface map[string]models.ModelInterface`, 2373 `func (o *GetMapInterfaceParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 2374 ` o.HTTPRequest = r`, 2375 ` if runtime.HasBody(r) {`, 2376 ` defer r.Body.Close(`, 2377 ` var body map[string]models.ModelInterface`, 2378 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 2379 ` if err == io.EOF {`, 2380 ` res = append(res, errors.Required("mapOfInterface", "body")`, 2381 ` } else {`, 2382 ` res = append(res, errors.NewParseError("mapOfInterface", "body", "", err)`, 2383 ` } else {`, 2384 ` o.MapOfInterface = body`, 2385 ` } else {`, 2386 ` res = append(res, errors.Required("mapOfInterface", "body")`, 2387 ` return errors.CompositeValidationError(res...`, 2388 }, 2389 }, 2390 2391 // load expectations for parameters in operation get_array_of_interface_parameters.go 2392 "getArrayOfInterface": { // fixture index 2393 "serverParameter": { // executed template 2394 // expected code lines 2395 `func NewGetArrayOfInterfaceParams() GetArrayOfInterfaceParams {`, 2396 ` return GetArrayOfInterfaceParams{`, 2397 `type GetArrayOfInterfaceParams struct {`, 2398 " HTTPRequest *http.Request `json:\"-\"`", 2399 ` ArrayOfInterface []interface{`, 2400 `func (o *GetArrayOfInterfaceParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 2401 ` o.HTTPRequest = r`, 2402 ` if runtime.HasBody(r) {`, 2403 ` defer r.Body.Close(`, 2404 ` var body []interface{`, 2405 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 2406 ` if err == io.EOF {`, 2407 ` res = append(res, errors.Required("arrayOfInterface", "body")`, 2408 ` } else {`, 2409 ` res = append(res, errors.NewParseError("arrayOfInterface", "body", "", err)`, 2410 ` } else {`, 2411 ` o.ArrayOfInterface = body`, 2412 ` } else {`, 2413 ` res = append(res, errors.Required("arrayOfInterface", "body")`, 2414 ` return errors.CompositeValidationError(res...`, 2415 }, 2416 }, 2417 2418 // load expectations for parameters in operation get_map_array_with_max_parameters.go 2419 "getMapArrayWithMax": { // fixture index 2420 "serverParameter": { // executed template 2421 // expected code lines 2422 `func NewGetMapArrayWithMaxParams() GetMapArrayWithMaxParams {`, 2423 ` return GetMapArrayWithMaxParams{`, 2424 `type GetMapArrayWithMaxParams struct {`, 2425 " HTTPRequest *http.Request `json:\"-\"`", 2426 ` MapOfArrayWithMax map[string]models.ModelArrayWithMax`, 2427 `func (o *GetMapArrayWithMaxParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 2428 ` o.HTTPRequest = r`, 2429 ` if runtime.HasBody(r) {`, 2430 ` defer r.Body.Close(`, 2431 ` var body map[string]models.ModelArrayWithMax`, 2432 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 2433 ` if err == io.EOF {`, 2434 ` res = append(res, errors.Required("mapOfArrayWithMax", "body")`, 2435 ` } else {`, 2436 ` res = append(res, errors.NewParseError("mapOfArrayWithMax", "body", "", err)`, 2437 ` } else {`, 2438 ` for k := range body {`, 2439 ` if val, ok := body[k]; ok {`, 2440 ` if err := val.Validate(route.Formats); err != nil {`, 2441 ` break`, 2442 ` if len(res) == 0 {`, 2443 ` o.MapOfArrayWithMax = body`, 2444 ` } else {`, 2445 ` res = append(res, errors.Required("mapOfArrayWithMax", "body")`, 2446 ` return errors.CompositeValidationError(res...`, 2447 }, 2448 }, 2449 2450 // load expectations for parameters in operation get_array_nested_simple_parameters.go 2451 "getArrayNestedSimple": { // fixture index 2452 "serverParameter": { // executed template 2453 // expected code lines 2454 `func NewGetArrayNestedSimpleParams() GetArrayNestedSimpleParams {`, 2455 ` return GetArrayNestedSimpleParams{`, 2456 `type GetArrayNestedSimpleParams struct {`, 2457 " HTTPRequest *http.Request `json:\"-\"`", 2458 ` ArrayOfarraySimple [][]string`, 2459 `func (o *GetArrayNestedSimpleParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 2460 ` o.HTTPRequest = r`, 2461 ` if runtime.HasBody(r) {`, 2462 ` defer r.Body.Close(`, 2463 ` var body [][]string`, 2464 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 2465 ` if err == io.EOF {`, 2466 ` res = append(res, errors.Required("arrayOfarraySimple", "body")`, 2467 ` } else {`, 2468 ` res = append(res, errors.NewParseError("arrayOfarraySimple", "body", "", err)`, 2469 ` } else {`, 2470 ` o.ArrayOfarraySimple = body`, 2471 ` if err := o.validateArrayOfarraySimpleBody(route.Formats); err != nil {`, 2472 ` } else {`, 2473 ` res = append(res, errors.Required("arrayOfarraySimple", "body")`, 2474 ` return errors.CompositeValidationError(res...`, 2475 `func (o *GetArrayNestedSimpleParams) validateArrayOfarraySimpleBody(formats strfmt.Registry) error {`, 2476 ` arrayOfarraySimpleIC := o.ArrayOfarraySimple`, 2477 ` var arrayOfarraySimpleIR [][]string`, 2478 ` for i, arrayOfarraySimpleIV := range arrayOfarraySimpleIC {`, 2479 ` arrayOfarraySimpleIIC := arrayOfarraySimpleIV`, 2480 ` if len(arrayOfarraySimpleIIC) > 0 {`, 2481 ` var arrayOfarraySimpleIIR []string`, 2482 ` for ii, arrayOfarraySimpleIIV := range arrayOfarraySimpleIIC {`, 2483 ` arrayOfarraySimpleII := arrayOfarraySimpleIIV`, 2484 ` if err := validate.MaxLength(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "arrayOfarraySimple", i), ii), "", arrayOfarraySimpleII, 100); err != nil {`, 2485 ` arrayOfarraySimpleIIR = append(arrayOfarraySimpleIIR, arrayOfarraySimpleII`, 2486 ` arrayOfarraySimpleIR = append(arrayOfarraySimpleIR, arrayOfarraySimpleIIR`, 2487 ` o.ArrayOfarraySimple = arrayOfarraySimpleIR`, 2488 }, 2489 }, 2490 2491 // load expectations for parameters in operation get_map_of_format_parameters.go 2492 "getMapOfFormat": { // fixture index 2493 "serverParameter": { // executed template 2494 // expected code lines 2495 `func NewGetMapOfFormatParams() GetMapOfFormatParams {`, 2496 ` return GetMapOfFormatParams{`, 2497 `type GetMapOfFormatParams struct {`, 2498 " HTTPRequest *http.Request `json:\"-\"`", 2499 ` MapOfFormat map[string]strfmt.UUID`, 2500 `func (o *GetMapOfFormatParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 2501 ` o.HTTPRequest = r`, 2502 ` if runtime.HasBody(r) {`, 2503 ` defer r.Body.Close(`, 2504 ` var body map[string]strfmt.UUID`, 2505 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 2506 ` if err == io.EOF {`, 2507 ` res = append(res, errors.Required("mapOfFormat", "body")`, 2508 ` } else {`, 2509 ` res = append(res, errors.NewParseError("mapOfFormat", "body", "", err)`, 2510 ` } else {`, 2511 ` o.MapOfFormat = body`, 2512 ` if err := o.validateMapOfFormatBody(route.Formats); err != nil {`, 2513 ` } else {`, 2514 ` res = append(res, errors.Required("mapOfFormat", "body")`, 2515 ` return errors.CompositeValidationError(res...`, 2516 `func (o *GetMapOfFormatParams) validateMapOfFormatBody(formats strfmt.Registry) error {`, 2517 ` mapOfFormatIC := o.MapOfFormat`, 2518 ` mapOfFormatIR := make(map[string]strfmt.UUID, len(mapOfFormatIC)`, 2519 ` for k, mapOfFormatIV := range mapOfFormatIC {`, 2520 ` mapOfFormatI := mapOfFormatIV`, 2521 ` if err := validate.FormatOf(fmt.Sprintf("%s.%v", "mapOfFormat", k), "body", "uuid", mapOfFormatI.String(), formats); err != nil {`, 2522 ` mapOfFormatIR[k] = mapOfFormatI`, 2523 ` o.MapOfFormat = mapOfFormatIR`, 2524 }, 2525 }, 2526 2527 // load expectations for parameters in operation get_array_of_map_parameters.go 2528 "getArrayOfMap": { // fixture index 2529 "serverParameter": { // executed template 2530 // expected code lines 2531 `func NewGetArrayOfMapParams() GetArrayOfMapParams {`, 2532 ` return GetArrayOfMapParams{`, 2533 `type GetArrayOfMapParams struct {`, 2534 " HTTPRequest *http.Request `json:\"-\"`", 2535 ` ArrayOfMap []map[string][]int32`, 2536 `func (o *GetArrayOfMapParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 2537 ` o.HTTPRequest = r`, 2538 ` if runtime.HasBody(r) {`, 2539 ` defer r.Body.Close(`, 2540 ` var body []map[string][]int32`, 2541 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 2542 ` if err == io.EOF {`, 2543 ` res = append(res, errors.Required("arrayOfMap", "body")`, 2544 ` } else {`, 2545 ` res = append(res, errors.NewParseError("arrayOfMap", "body", "", err)`, 2546 ` } else {`, 2547 ` o.ArrayOfMap = body`, 2548 ` if err := o.validateArrayOfMapBody(route.Formats); err != nil {`, 2549 ` } else {`, 2550 ` res = append(res, errors.Required("arrayOfMap", "body")`, 2551 ` return errors.CompositeValidationError(res...`, 2552 `func (o *GetArrayOfMapParams) validateArrayOfMapBody(formats strfmt.Registry) error {`, 2553 ` arrayOfMapSize := int64(len(o.ArrayOfMap)`, 2554 ` if err := validate.MaxItems("arrayOfMap", "body", arrayOfMapSize, 50); err != nil {`, 2555 ` arrayOfMapIC := o.ArrayOfMap`, 2556 ` var arrayOfMapIR []map[string][]int32`, 2557 ` for i, arrayOfMapIV := range arrayOfMapIC {`, 2558 ` arrayOfMapIIC := arrayOfMapIV`, 2559 ` arrayOfMapIIR := make(map[string][]int32, len(arrayOfMapIIC)`, 2560 ` for kk, arrayOfMapIIV := range arrayOfMapIIC {`, 2561 ` arrayOfMapIIIC := arrayOfMapIIV`, 2562 ` var arrayOfMapIIIR []int32`, 2563 ` for iii, arrayOfMapIIIV := range arrayOfMapIIIC {`, 2564 ` arrayOfMapIII := arrayOfMapIIIV`, 2565 ` if err := validate.MaximumInt(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "arrayOfMap", i), kk), iii), "", int64(arrayOfMapIII), 100, false); err != nil {`, 2566 ` arrayOfMapIIIR = append(arrayOfMapIIIR, arrayOfMapIII`, 2567 ` arrayOfMapIIR[kk] = arrayOfMapIIIR`, 2568 ` arrayOfMapIR = append(arrayOfMapIR, arrayOfMapIIR`, 2569 ` o.ArrayOfMap = arrayOfMapIR`, 2570 }, 2571 }, 2572 2573 // load expectations for parameters in operation get_map_anon_array_with_x_nullable_parameters.go 2574 "getMapAnonArrayWithXNullable": { // fixture index 2575 "serverParameter": { // executed template 2576 // expected code lines 2577 `func NewGetMapAnonArrayWithXNullableParams() GetMapAnonArrayWithXNullableParams {`, 2578 ` return GetMapAnonArrayWithXNullableParams{`, 2579 `type GetMapAnonArrayWithXNullableParams struct {`, 2580 " HTTPRequest *http.Request `json:\"-\"`", 2581 ` MapOfAnonArrayWithXNullable map[string][]*int64`, 2582 `func (o *GetMapAnonArrayWithXNullableParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 2583 ` o.HTTPRequest = r`, 2584 ` if runtime.HasBody(r) {`, 2585 ` defer r.Body.Close(`, 2586 ` var body map[string][]*int64`, 2587 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 2588 ` if err == io.EOF {`, 2589 ` res = append(res, errors.Required("mapOfAnonArrayWithXNullable", "body")`, 2590 ` } else {`, 2591 ` res = append(res, errors.NewParseError("mapOfAnonArrayWithXNullable", "body", "", err)`, 2592 ` } else {`, 2593 ` o.MapOfAnonArrayWithXNullable = body`, 2594 ` } else {`, 2595 ` res = append(res, errors.Required("mapOfAnonArrayWithXNullable", "body")`, 2596 ` return errors.CompositeValidationError(res...`, 2597 }, 2598 }, 2599 2600 // load expectations for parameters in operation get_array_nested_parameters.go 2601 "getArrayNested": { // fixture index 2602 "serverParameter": { // executed template 2603 // expected code lines 2604 `func NewGetArrayNestedParams() GetArrayNestedParams {`, 2605 ` return GetArrayNestedParams{`, 2606 `type GetArrayNestedParams struct {`, 2607 " HTTPRequest *http.Request `json:\"-\"`", 2608 ` ArrayOfarray [][]*models.ModelObject`, 2609 `func (o *GetArrayNestedParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 2610 ` o.HTTPRequest = r`, 2611 ` if runtime.HasBody(r) {`, 2612 ` defer r.Body.Close(`, 2613 ` var body [][]*models.ModelObject`, 2614 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 2615 ` if err == io.EOF {`, 2616 ` res = append(res, errors.Required("arrayOfarray", "body")`, 2617 ` } else {`, 2618 ` res = append(res, errors.NewParseError("arrayOfarray", "body", "", err)`, 2619 ` } else {`, 2620 ` o.ArrayOfarray = body`, 2621 ` if err := o.validateArrayOfarrayBody(route.Formats); err != nil {`, 2622 ` } else {`, 2623 ` res = append(res, errors.Required("arrayOfarray", "body")`, 2624 ` return errors.CompositeValidationError(res...`, 2625 `func (o *GetArrayNestedParams) validateArrayOfarrayBody(formats strfmt.Registry) error {`, 2626 ` arrayOfarrayIC := o.ArrayOfarray`, 2627 ` var arrayOfarrayIR [][]*models.ModelObject`, 2628 ` for i, arrayOfarrayIV := range arrayOfarrayIC {`, 2629 ` arrayOfarrayIIC := arrayOfarrayIV`, 2630 ` if len(arrayOfarrayIIC) > 0 {`, 2631 ` var arrayOfarrayIIR []*models.ModelObject`, 2632 ` for ii, arrayOfarrayIIV := range arrayOfarrayIIC {`, 2633 ` if arrayOfarrayIIV == nil {`, 2634 ` if err := arrayOfarrayII.Validate(formats); err != nil {`, 2635 ` if ve, ok := err.(*errors.Validation); ok {`, 2636 ` return ve.ValidateName(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "arrayOfarray", i), ii)`, 2637 ` arrayOfarrayIIR = append(arrayOfarrayIIR, arrayOfarrayII`, 2638 ` arrayOfarrayIR = append(arrayOfarrayIR, arrayOfarrayIIR`, 2639 ` o.ArrayOfarray = arrayOfarrayIR`, 2640 }, 2641 }, 2642 2643 // load expectations for parameters in operation get_map_array_parameters.go 2644 "getMapArray": { // fixture index 2645 "serverParameter": { // executed template 2646 // expected code lines 2647 `func NewGetMapArrayParams() GetMapArrayParams {`, 2648 ` return GetMapArrayParams{`, 2649 `type GetMapArrayParams struct {`, 2650 " HTTPRequest *http.Request `json:\"-\"`", 2651 // maps are now simple types 2652 //` MapOfArray models.GetMapArrayParamsBody`, 2653 ` MapOfArray map[string]models.ModelArray`, 2654 `func (o *GetMapArrayParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 2655 ` o.HTTPRequest = r`, 2656 ` if runtime.HasBody(r) {`, 2657 ` defer r.Body.Close(`, 2658 //` var body models.GetMapArrayParamsBody`, 2659 ` var body map[string]models.ModelArray`, 2660 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 2661 ` if err == io.EOF {`, 2662 ` res = append(res, errors.Required("mapOfArray", "body")`, 2663 ` } else {`, 2664 ` res = append(res, errors.NewParseError("mapOfArray", "body", "", err)`, 2665 ` } else {`, 2666 //` if err := body.Validate(route.Formats); err != nil {`, 2667 ` for k := range body {`, 2668 ` if err := validate.Required(fmt.Sprintf("%s.%v", "mapOfArray", k), "body", body[k]); err != nil {`, 2669 ` if val, ok := body[k]; ok {`, 2670 ` if err := val.Validate(route.Formats); err != nil {`, 2671 ` if len(res) == 0 {`, 2672 ` o.MapOfArray = body`, 2673 ` } else {`, 2674 ` res = append(res, errors.Required("mapOfArray", "body")`, 2675 ` return errors.CompositeValidationError(res...`, 2676 }, 2677 }, 2678 2679 // load expectations for parameters in operation get_map_anon_array_with_nullable_parameters.go 2680 "getMapAnonArrayWithNullable": { // fixture index 2681 "serverParameter": { // executed template 2682 // expected code lines 2683 `func NewGetMapAnonArrayWithNullableParams() GetMapAnonArrayWithNullableParams {`, 2684 ` return GetMapAnonArrayWithNullableParams{`, 2685 `type GetMapAnonArrayWithNullableParams struct {`, 2686 " HTTPRequest *http.Request `json:\"-\"`", 2687 ` MapOfAnonArrayWithNullable map[string][]*int64`, 2688 `func (o *GetMapAnonArrayWithNullableParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 2689 ` o.HTTPRequest = r`, 2690 ` if runtime.HasBody(r) {`, 2691 ` defer r.Body.Close(`, 2692 ` var body map[string][]*int64`, 2693 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 2694 ` if err == io.EOF {`, 2695 ` res = append(res, errors.Required("mapOfAnonArrayWithNullable", "body")`, 2696 ` } else {`, 2697 ` res = append(res, errors.NewParseError("mapOfAnonArrayWithNullable", "body", "", err)`, 2698 ` } else {`, 2699 ` o.MapOfAnonArrayWithNullable = body`, 2700 ` if err := o.validateMapOfAnonArrayWithNullableBody(route.Formats); err != nil {`, 2701 ` } else {`, 2702 ` res = append(res, errors.Required("mapOfAnonArrayWithNullable", "body")`, 2703 ` return errors.CompositeValidationError(res...`, 2704 `func (o *GetMapAnonArrayWithNullableParams) validateMapOfAnonArrayWithNullableBody(formats strfmt.Registry) error {`, 2705 ` mapOfAnonArrayWithNullableIC := o.MapOfAnonArrayWithNullable`, 2706 ` mapOfAnonArrayWithNullableIR := make(map[string][]*int64, len(mapOfAnonArrayWithNullableIC)`, 2707 ` for k, mapOfAnonArrayWithNullableIV := range mapOfAnonArrayWithNullableIC {`, 2708 ` mapOfAnonArrayWithNullableIIC := mapOfAnonArrayWithNullableIV`, 2709 ` var mapOfAnonArrayWithNullableIIR []*int64`, 2710 ` for ii, mapOfAnonArrayWithNullableIIV := range mapOfAnonArrayWithNullableIIC {`, 2711 ` mapOfAnonArrayWithNullableII := mapOfAnonArrayWithNullableIIV`, 2712 ` if err := validate.MinimumInt(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "mapOfAnonArrayWithNullable", k), ii), "", int64(*mapOfAnonArrayWithNullableII), 0, false); err != nil {`, 2713 ` mapOfAnonArrayWithNullableIIR = append(mapOfAnonArrayWithNullableIIR, mapOfAnonArrayWithNullableII`, 2714 ` mapOfAnonArrayWithNullableIR[k] = mapOfAnonArrayWithNullableIIR`, 2715 ` o.MapOfAnonArrayWithNullable = mapOfAnonArrayWithNullableIR`, 2716 }, 2717 }, 2718 2719 // load expectations for parameters in operation get_map_of_anon_array_parameters.go 2720 "getMapOfAnonArray": { // fixture index 2721 "serverParameter": { // executed template 2722 // expected code lines 2723 `func NewGetMapOfAnonArrayParams() GetMapOfAnonArrayParams {`, 2724 ` return GetMapOfAnonArrayParams{`, 2725 `type GetMapOfAnonArrayParams struct {`, 2726 " HTTPRequest *http.Request `json:\"-\"`", 2727 ` MapOfAnonArray map[string][]int64`, 2728 `func (o *GetMapOfAnonArrayParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 2729 ` o.HTTPRequest = r`, 2730 ` if runtime.HasBody(r) {`, 2731 ` defer r.Body.Close(`, 2732 ` var body map[string][]int64`, 2733 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 2734 ` if err == io.EOF {`, 2735 ` res = append(res, errors.Required("mapOfAnonArray", "body")`, 2736 ` } else {`, 2737 ` res = append(res, errors.NewParseError("mapOfAnonArray", "body", "", err)`, 2738 ` } else {`, 2739 ` o.MapOfAnonArray = body`, 2740 ` if err := o.validateMapOfAnonArrayBody(route.Formats); err != nil {`, 2741 ` } else {`, 2742 ` res = append(res, errors.Required("mapOfAnonArray", "body")`, 2743 ` return errors.CompositeValidationError(res...`, 2744 `func (o *GetMapOfAnonArrayParams) validateMapOfAnonArrayBody(formats strfmt.Registry) error {`, 2745 ` mapOfAnonArrayIC := o.MapOfAnonArray`, 2746 ` mapOfAnonArrayIR := make(map[string][]int64, len(mapOfAnonArrayIC)`, 2747 ` for k, mapOfAnonArrayIV := range mapOfAnonArrayIC {`, 2748 ` mapOfAnonArrayIIC := mapOfAnonArrayIV`, 2749 ` var mapOfAnonArrayIIR []int64`, 2750 ` for ii, mapOfAnonArrayIIV := range mapOfAnonArrayIIC {`, 2751 ` mapOfAnonArrayII := mapOfAnonArrayIIV`, 2752 ` if err := validate.MaximumInt(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "mapOfAnonArray", k), ii), "", int64(mapOfAnonArrayII), 100, false); err != nil {`, 2753 ` mapOfAnonArrayIIR = append(mapOfAnonArrayIIR, mapOfAnonArrayII`, 2754 ` mapOfAnonArrayIR[k] = mapOfAnonArrayIIR`, 2755 ` o.MapOfAnonArray = mapOfAnonArrayIR`, 2756 }, 2757 }, 2758 2759 // load expectations for parameters in operation get_map_of_anon_map_parameters.go 2760 "getMapOfAnonMap": { // fixture index 2761 "serverParameter": { // executed template 2762 // expected code lines 2763 `func NewGetMapOfAnonMapParams() GetMapOfAnonMapParams {`, 2764 ` return GetMapOfAnonMapParams{`, 2765 `type GetMapOfAnonMapParams struct {`, 2766 " HTTPRequest *http.Request `json:\"-\"`", 2767 ` MapOfAnonMap map[string]map[string][]int64`, 2768 `func (o *GetMapOfAnonMapParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 2769 ` o.HTTPRequest = r`, 2770 ` if runtime.HasBody(r) {`, 2771 ` defer r.Body.Close(`, 2772 ` var body map[string]map[string][]int64`, 2773 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 2774 ` if err == io.EOF {`, 2775 ` res = append(res, errors.Required("mapOfAnonMap", "body")`, 2776 ` } else {`, 2777 ` res = append(res, errors.NewParseError("mapOfAnonMap", "body", "", err)`, 2778 ` } else {`, 2779 ` o.MapOfAnonMap = body`, 2780 ` if err := o.validateMapOfAnonMapBody(route.Formats); err != nil {`, 2781 ` } else {`, 2782 ` res = append(res, errors.Required("mapOfAnonMap", "body")`, 2783 ` return errors.CompositeValidationError(res...`, 2784 `func (o *GetMapOfAnonMapParams) validateMapOfAnonMapBody(formats strfmt.Registry) error {`, 2785 ` mapOfAnonMapIC := o.MapOfAnonMap`, 2786 ` mapOfAnonMapIR := make(map[string]map[string][]int64, len(mapOfAnonMapIC)`, 2787 ` for k, mapOfAnonMapIV := range mapOfAnonMapIC {`, 2788 ` mapOfAnonMapIIC := mapOfAnonMapIV`, 2789 ` mapOfAnonMapIIR := make(map[string][]int64, len(mapOfAnonMapIIC)`, 2790 ` for kk, mapOfAnonMapIIV := range mapOfAnonMapIIC {`, 2791 ` mapOfAnonMapIIIC := mapOfAnonMapIIV`, 2792 ` var mapOfAnonMapIIIR []int64`, 2793 ` for iii, mapOfAnonMapIIIV := range mapOfAnonMapIIIC {`, 2794 ` mapOfAnonMapIII := mapOfAnonMapIIIV`, 2795 ` if err := validate.MaximumInt(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "mapOfAnonMap", k), kk), iii), "", int64(mapOfAnonMapIII), 100, false); err != nil {`, 2796 ` mapOfAnonMapIIIR = append(mapOfAnonMapIIIR, mapOfAnonMapIII`, 2797 ` mapOfAnonMapIIR[kk] = mapOfAnonMapIIIR`, 2798 ` mapOfAnonMapIR[k] = mapOfAnonMapIIR`, 2799 ` o.MapOfAnonMap = mapOfAnonMapIR`, 2800 }, 2801 }, 2802 2803 // load expectations for parameters in operation get_map_anon_array_parameters.go 2804 "getMapAnonArray": { // fixture index 2805 "serverParameter": { // executed template 2806 // expected code lines 2807 `func NewGetMapAnonArrayParams() GetMapAnonArrayParams {`, 2808 ` return GetMapAnonArrayParams{`, 2809 `type GetMapAnonArrayParams struct {`, 2810 " HTTPRequest *http.Request `json:\"-\"`", 2811 ` MapOfAnonArray map[string][]int64`, 2812 `func (o *GetMapAnonArrayParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 2813 ` o.HTTPRequest = r`, 2814 ` if runtime.HasBody(r) {`, 2815 ` defer r.Body.Close(`, 2816 ` var body map[string][]int64`, 2817 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 2818 ` if err == io.EOF {`, 2819 ` res = append(res, errors.Required("mapOfAnonArray", "body")`, 2820 ` } else {`, 2821 ` res = append(res, errors.NewParseError("mapOfAnonArray", "body", "", err)`, 2822 ` } else {`, 2823 ` o.MapOfAnonArray = body`, 2824 ` if err := o.validateMapOfAnonArrayBody(route.Formats); err != nil {`, 2825 ` } else {`, 2826 ` res = append(res, errors.Required("mapOfAnonArray", "body")`, 2827 ` return errors.CompositeValidationError(res...`, 2828 `func (o *GetMapAnonArrayParams) validateMapOfAnonArrayBody(formats strfmt.Registry) error {`, 2829 ` mapOfAnonArrayIC := o.MapOfAnonArray`, 2830 ` mapOfAnonArrayIR := make(map[string][]int64, len(mapOfAnonArrayIC)`, 2831 ` for k, mapOfAnonArrayIV := range mapOfAnonArrayIC {`, 2832 ` mapOfAnonArrayIIC := mapOfAnonArrayIV`, 2833 ` var mapOfAnonArrayIIR []int64`, 2834 ` for ii, mapOfAnonArrayIIV := range mapOfAnonArrayIIC {`, 2835 ` mapOfAnonArrayII := mapOfAnonArrayIIV`, 2836 ` if err := validate.MinimumInt(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "mapOfAnonArray", k), ii), "", int64(mapOfAnonArrayII), 10, false); err != nil {`, 2837 ` mapOfAnonArrayIIR = append(mapOfAnonArrayIIR, mapOfAnonArrayII`, 2838 ` mapOfAnonArrayIR[k] = mapOfAnonArrayIIR`, 2839 ` o.MapOfAnonArray = mapOfAnonArrayIR`, 2840 }, 2841 }, 2842 2843 // load expectations for parameters in operation get_map_of_primitive_parameters.go 2844 "getMapOfPrimitive": { // fixture index 2845 "serverParameter": { // executed template 2846 // expected code lines 2847 `func NewGetMapOfPrimitiveParams() GetMapOfPrimitiveParams {`, 2848 ` return GetMapOfPrimitiveParams{`, 2849 `type GetMapOfPrimitiveParams struct {`, 2850 " HTTPRequest *http.Request `json:\"-\"`", 2851 ` MapOfPrimitive map[string]int64`, 2852 `func (o *GetMapOfPrimitiveParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 2853 ` o.HTTPRequest = r`, 2854 ` if runtime.HasBody(r) {`, 2855 ` defer r.Body.Close(`, 2856 ` var body map[string]int64`, 2857 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 2858 ` if err == io.EOF {`, 2859 ` res = append(res, errors.Required("mapOfPrimitive", "body")`, 2860 ` } else {`, 2861 ` res = append(res, errors.NewParseError("mapOfPrimitive", "body", "", err)`, 2862 ` } else {`, 2863 ` o.MapOfPrimitive = body`, 2864 ` if err := o.validateMapOfPrimitiveBody(route.Formats); err != nil {`, 2865 ` } else {`, 2866 ` res = append(res, errors.Required("mapOfPrimitive", "body")`, 2867 ` return errors.CompositeValidationError(res...`, 2868 `func (o *GetMapOfPrimitiveParams) validateMapOfPrimitiveBody(formats strfmt.Registry) error {`, 2869 ` mapOfPrimitiveIC := o.MapOfPrimitive`, 2870 ` mapOfPrimitiveIR := make(map[string]int64, len(mapOfPrimitiveIC)`, 2871 ` for k, mapOfPrimitiveIV := range mapOfPrimitiveIC {`, 2872 ` mapOfPrimitiveI := mapOfPrimitiveIV`, 2873 ` if err := validate.MaximumInt(fmt.Sprintf("%s.%v", "mapOfPrimitive", k), "body", int64(mapOfPrimitiveI), 100, false); err != nil {`, 2874 ` mapOfPrimitiveIR[k] = mapOfPrimitiveI`, 2875 ` o.MapOfPrimitive = mapOfPrimitiveIR`, 2876 }, 2877 }, 2878 2879 // load expectations for parameters in operation get_array_parameters.go 2880 "getArray": { // fixture index 2881 "serverParameter": { // executed template 2882 // expected code lines 2883 `func NewGetArrayParams() GetArrayParams {`, 2884 ` return GetArrayParams{`, 2885 `type GetArrayParams struct {`, 2886 " HTTPRequest *http.Request `json:\"-\"`", 2887 ` ArrayOfObject []*models.ModelObject`, 2888 `func (o *GetArrayParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 2889 ` o.HTTPRequest = r`, 2890 ` if runtime.HasBody(r) {`, 2891 ` defer r.Body.Close(`, 2892 ` var body []*models.ModelObject`, 2893 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 2894 ` if err == io.EOF {`, 2895 ` res = append(res, errors.Required("arrayOfObject", "body")`, 2896 ` } else {`, 2897 ` res = append(res, errors.NewParseError("arrayOfObject", "body", "", err)`, 2898 ` } else {`, 2899 ` for i := range body {`, 2900 ` if body[i] == nil {`, 2901 ` if err := body[i].Validate(route.Formats); err != nil {`, 2902 ` break`, 2903 ` if len(res) == 0 {`, 2904 ` o.ArrayOfObject = body`, 2905 ` } else {`, 2906 ` res = append(res, errors.Required("arrayOfObject", "body")`, 2907 ` return errors.CompositeValidationError(res...`, 2908 }, 2909 }, 2910 2911 // load expectations for parameters in operation get_map_object_parameters.go 2912 "getMapObject": { // fixture index 2913 "serverParameter": { // executed template 2914 // expected code lines 2915 `func NewGetMapObjectParams() GetMapObjectParams {`, 2916 ` return GetMapObjectParams{`, 2917 `type GetMapObjectParams struct {`, 2918 " HTTPRequest *http.Request `json:\"-\"`", 2919 //` MapOfObject models.GetMapObjectParamsBody`, 2920 // maps are now simple types 2921 ` MapOfObject map[string]models.ModelObject`, 2922 `func (o *GetMapObjectParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 2923 ` o.HTTPRequest = r`, 2924 ` if runtime.HasBody(r) {`, 2925 ` defer r.Body.Close(`, 2926 //` var body models.GetMapObjectParamsBody`, 2927 ` var body map[string]models.ModelObject`, 2928 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 2929 ` if err == io.EOF {`, 2930 ` res = append(res, errors.Required("mapOfObject", "body")`, 2931 ` } else {`, 2932 ` res = append(res, errors.NewParseError("mapOfObject", "body", "", err)`, 2933 ` } else {`, 2934 //` if err := body.Validate(route.Formats); err != nil {`, 2935 ` for k := range body {`, 2936 ` if err := validate.Required(fmt.Sprintf("%s.%v", "mapOfObject", k), "body", body[k]); err != nil {`, 2937 ` if val, ok := body[k]; ok {`, 2938 ` if err := val.Validate(route.Formats); err != nil {`, 2939 ` if len(res) == 0 {`, 2940 ` o.MapOfObject = body`, 2941 ` } else {`, 2942 ` res = append(res, errors.Required("mapOfObject", "body")`, 2943 ` return errors.CompositeValidationError(res...`, 2944 }, 2945 }, 2946 2947 // load expectations for parameters in operation get_map_of_map_parameters.go 2948 "getMapOfMap": { // fixture index 2949 "serverParameter": { // executed template 2950 // expected code lines 2951 `func NewGetMapOfMapParams() GetMapOfMapParams {`, 2952 ` return GetMapOfMapParams{`, 2953 `type GetMapOfMapParams struct {`, 2954 " HTTPRequest *http.Request `json:\"-\"`", 2955 ` MapOfMap map[string]map[string]models.ModelArrayWithMax`, 2956 `func (o *GetMapOfMapParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 2957 ` o.HTTPRequest = r`, 2958 ` if runtime.HasBody(r) {`, 2959 ` defer r.Body.Close(`, 2960 ` var body map[string]map[string]models.ModelArrayWithMax`, 2961 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 2962 ` if err == io.EOF {`, 2963 ` res = append(res, errors.Required("mapOfMap", "body")`, 2964 ` } else {`, 2965 ` res = append(res, errors.NewParseError("mapOfMap", "body", "", err)`, 2966 ` } else {`, 2967 ` o.MapOfMap = body`, 2968 ` if err := o.validateMapOfMapBody(route.Formats); err != nil {`, 2969 ` } else {`, 2970 ` res = append(res, errors.Required("mapOfMap", "body")`, 2971 ` return errors.CompositeValidationError(res...`, 2972 `func (o *GetMapOfMapParams) validateMapOfMapBody(formats strfmt.Registry) error {`, 2973 ` mapOfMapIC := o.MapOfMap`, 2974 ` mapOfMapIR := make(map[string]map[string]models.ModelArrayWithMax, len(mapOfMapIC)`, 2975 ` for k, mapOfMapIV := range mapOfMapIC {`, 2976 ` mapOfMapIIC := mapOfMapIV`, 2977 ` mapOfMapIIR := make(map[string]models.ModelArrayWithMax, len(mapOfMapIIC)`, 2978 ` for kk, mapOfMapIIV := range mapOfMapIIC {`, 2979 ` mapOfMapII := mapOfMapIIV`, 2980 ` if err := mapOfMapII.Validate(formats); err != nil {`, 2981 ` if ve, ok := err.(*errors.Validation); ok {`, 2982 ` return ve.ValidateName(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "mapOfMap", k), kk)`, 2983 ` mapOfMapIIR[kk] = mapOfMapII`, 2984 ` mapOfMapIR[k] = mapOfMapIIR`, 2985 ` o.MapOfMap = mapOfMapIR`, 2986 }, 2987 }, 2988 } 2989 assertParams(t, fixtureConfig, filepath.Join("..", "fixtures", "bugs", "1536", "fixture-1536-3.yaml"), false, false) 2990 } 2991 2992 func TestGenParameter_Issue1536_MapsWithExpand(t *testing.T) { 2993 log.SetOutput(ioutil.Discard) 2994 defer func() { 2995 log.SetOutput(os.Stdout) 2996 }() 2997 2998 fixtureConfig := map[string]map[string][]string{ 2999 // load expectations for parameters in operation get_map_of_array_of_map_parameters.go 3000 "getMapOfArrayOfMap": { // fixture index 3001 "serverParameter": { // executed template 3002 // expected code lines 3003 `func NewGetMapOfArrayOfMapParams() GetMapOfArrayOfMapParams {`, 3004 ` return GetMapOfArrayOfMapParams{`, 3005 `type GetMapOfArrayOfMapParams struct {`, 3006 " HTTPRequest *http.Request `json:\"-\"`", 3007 ` MapOfArrayOfMap map[string][]map[string]int64`, 3008 `func (o *GetMapOfArrayOfMapParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 3009 ` o.HTTPRequest = r`, 3010 ` if runtime.HasBody(r) {`, 3011 ` defer r.Body.Close(`, 3012 ` var body map[string][]map[string]int64`, 3013 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 3014 ` if err == io.EOF {`, 3015 ` res = append(res, errors.Required("mapOfArrayOfMap", "body")`, 3016 ` } else {`, 3017 ` res = append(res, errors.NewParseError("mapOfArrayOfMap", "body", "", err)`, 3018 ` } else {`, 3019 ` o.MapOfArrayOfMap = body`, 3020 ` if err := o.validateMapOfArrayOfMapBody(route.Formats); err != nil {`, 3021 ` } else {`, 3022 ` res = append(res, errors.Required("mapOfArrayOfMap", "body")`, 3023 ` return errors.CompositeValidationError(res...`, 3024 `func (o *GetMapOfArrayOfMapParams) validateMapOfArrayOfMapBody(formats strfmt.Registry) error {`, 3025 ` mapOfArrayOfMapIC := o.MapOfArrayOfMap`, 3026 ` mapOfArrayOfMapIR := make(map[string][]map[string]int64, len(mapOfArrayOfMapIC)`, 3027 ` for k, mapOfArrayOfMapIV := range mapOfArrayOfMapIC {`, 3028 ` mapOfArrayOfMapIIC := mapOfArrayOfMapIV`, 3029 ` mapOfArrayOfMapISize := int64(len(mapOfArrayOfMapIIC)`, 3030 ` if err := validate.MaxItems(fmt.Sprintf("%s.%v", "mapOfArrayOfMap", k), "body", mapOfArrayOfMapISize, 10); err != nil {`, 3031 ` var mapOfArrayOfMapIIR []map[string]int64`, 3032 ` for _, mapOfArrayOfMapIIV := range mapOfArrayOfMapIIC {`, 3033 ` mapOfArrayOfMapIIIC := mapOfArrayOfMapIIV`, 3034 ` mapOfArrayOfMapIIIR := make(map[string]int64, len(mapOfArrayOfMapIIIC)`, 3035 ` for kkk, mapOfArrayOfMapIIIV := range mapOfArrayOfMapIIIC {`, 3036 ` mapOfArrayOfMapIII := mapOfArrayOfMapIIIV`, 3037 ` mapOfArrayOfMapIIIR[kkk] = mapOfArrayOfMapIII`, 3038 ` mapOfArrayOfMapIIR = append(mapOfArrayOfMapIIR, mapOfArrayOfMapIIIR`, 3039 ` mapOfArrayOfMapIR[k] = mapOfArrayOfMapIIR`, 3040 ` o.MapOfArrayOfMap = mapOfArrayOfMapIR`, 3041 }, 3042 }, 3043 3044 // load expectations for parameters in operation get_map_of_array_of_nullable_map_parameters.go 3045 "getMapOfArrayOfNullableMap": { // fixture index 3046 "serverParameter": { // executed template 3047 // expected code lines 3048 `func NewGetMapOfArrayOfNullableMapParams() GetMapOfArrayOfNullableMapParams {`, 3049 ` return GetMapOfArrayOfNullableMapParams{`, 3050 `type GetMapOfArrayOfNullableMapParams struct {`, 3051 " HTTPRequest *http.Request `json:\"-\"`", 3052 ` MapOfArrayOfNullableMap map[string][]GetMapOfArrayOfNullableMapParamsBodyItems0`, 3053 `func (o *GetMapOfArrayOfNullableMapParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 3054 ` o.HTTPRequest = r`, 3055 ` if runtime.HasBody(r) {`, 3056 ` defer r.Body.Close(`, 3057 ` var body map[string][]GetMapOfArrayOfNullableMapParamsBodyItems0`, 3058 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 3059 ` if err == io.EOF {`, 3060 ` res = append(res, errors.Required("mapOfArrayOfNullableMap", "body")`, 3061 ` } else {`, 3062 ` res = append(res, errors.NewParseError("mapOfArrayOfNullableMap", "body", "", err)`, 3063 ` } else {`, 3064 ` o.MapOfArrayOfNullableMap = body`, 3065 ` if err := o.validateMapOfArrayOfNullableMapBody(route.Formats); err != nil {`, 3066 ` } else {`, 3067 ` res = append(res, errors.Required("mapOfArrayOfNullableMap", "body")`, 3068 ` return errors.CompositeValidationError(res...`, 3069 `func (o *GetMapOfArrayOfNullableMapParams) validateMapOfArrayOfNullableMapBody(formats strfmt.Registry) error {`, 3070 ` mapOfArrayOfNullableMapIC := o.MapOfArrayOfNullableMap`, 3071 ` mapOfArrayOfNullableMapIR := make(map[string][]GetMapOfArrayOfNullableMapParamsBodyItems0, len(mapOfArrayOfNullableMapIC)`, 3072 ` for k, mapOfArrayOfNullableMapIV := range mapOfArrayOfNullableMapIC {`, 3073 ` mapOfArrayOfNullableMapIIC := mapOfArrayOfNullableMapIV`, 3074 ` mapOfArrayOfNullableMapISize := int64(len(mapOfArrayOfNullableMapIIC)`, 3075 ` if err := validate.MaxItems(fmt.Sprintf("%s.%v", "mapOfArrayOfNullableMap", k), "body", mapOfArrayOfNullableMapISize, 10); err != nil {`, 3076 ` var mapOfArrayOfNullableMapIIR []GetMapOfArrayOfNullableMapParamsBodyItems0`, 3077 ` for ii, mapOfArrayOfNullableMapIIV := range mapOfArrayOfNullableMapIIC {`, 3078 ` mapOfArrayOfNullableMapII := mapOfArrayOfNullableMapIIV`, 3079 ` if err := mapOfArrayOfNullableMapII.Validate(formats); err != nil {`, 3080 ` if ve, ok := err.(*errors.Validation); ok {`, 3081 ` return ve.ValidateName(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "mapOfArrayOfNullableMap", k), ii)`, 3082 ` mapOfArrayOfNullableMapIIR = append(mapOfArrayOfNullableMapIIR, mapOfArrayOfNullableMapII`, 3083 ` mapOfArrayOfNullableMapIR[k] = mapOfArrayOfNullableMapIIR`, 3084 ` o.MapOfArrayOfNullableMap = mapOfArrayOfNullableMapIR`, 3085 }, 3086 }, 3087 3088 // load expectations for parameters in operation get_map_array_of_array_parameters.go 3089 "getMapArrayOfArray": { // fixture index 3090 "serverParameter": { // executed template 3091 // expected code lines 3092 `func NewGetMapArrayOfArrayParams() GetMapArrayOfArrayParams {`, 3093 ` return GetMapArrayOfArrayParams{`, 3094 `type GetMapArrayOfArrayParams struct {`, 3095 " HTTPRequest *http.Request `json:\"-\"`", 3096 ` MapOfArrayOfArray map[string][][]GetMapArrayOfArrayParamsBodyItems0`, 3097 `func (o *GetMapArrayOfArrayParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 3098 ` o.HTTPRequest = r`, 3099 ` if runtime.HasBody(r) {`, 3100 ` defer r.Body.Close(`, 3101 ` var body map[string][][]GetMapArrayOfArrayParamsBodyItems0`, 3102 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 3103 ` if err == io.EOF {`, 3104 ` res = append(res, errors.Required("mapOfArrayOfArray", "body")`, 3105 ` } else {`, 3106 ` res = append(res, errors.NewParseError("mapOfArrayOfArray", "body", "", err)`, 3107 ` } else {`, 3108 ` o.MapOfArrayOfArray = body`, 3109 ` if err := o.validateMapOfArrayOfArrayBody(route.Formats); err != nil {`, 3110 ` } else {`, 3111 ` res = append(res, errors.Required("mapOfArrayOfArray", "body")`, 3112 ` return errors.CompositeValidationError(res...`, 3113 `func (o *GetMapArrayOfArrayParams) validateMapOfArrayOfArrayBody(formats strfmt.Registry) error {`, 3114 ` mapOfArrayOfArrayIC := o.MapOfArrayOfArray`, 3115 ` mapOfArrayOfArrayIR := make(map[string][][]GetMapArrayOfArrayParamsBodyItems0, len(mapOfArrayOfArrayIC)`, 3116 ` for k, mapOfArrayOfArrayIV := range mapOfArrayOfArrayIC {`, 3117 ` mapOfArrayOfArrayIIC := mapOfArrayOfArrayIV`, 3118 ` mapOfArrayOfArrayISize := int64(len(mapOfArrayOfArrayIIC)`, 3119 ` if err := validate.MaxItems(fmt.Sprintf("%s.%v", "mapOfArrayOfArray", k), "body", mapOfArrayOfArrayISize, 10); err != nil {`, 3120 ` var mapOfArrayOfArrayIIR [][]GetMapArrayOfArrayParamsBodyItems0`, 3121 ` for ii, mapOfArrayOfArrayIIV := range mapOfArrayOfArrayIIC {`, 3122 ` mapOfArrayOfArrayIIIC := mapOfArrayOfArrayIIV`, 3123 ` if len(mapOfArrayOfArrayIIIC) > 0 {`, 3124 ` var mapOfArrayOfArrayIIIR []GetMapArrayOfArrayParamsBodyItems0`, 3125 ` for iii, mapOfArrayOfArrayIIIV := range mapOfArrayOfArrayIIIC {`, 3126 ` mapOfArrayOfArrayIII := mapOfArrayOfArrayIIIV`, 3127 ` if err := mapOfArrayOfArrayIII.Validate(formats); err != nil {`, 3128 ` if ve, ok := err.(*errors.Validation); ok {`, 3129 ` return ve.ValidateName(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "mapOfArrayOfArray", k), ii), iii)`, 3130 ` mapOfArrayOfArrayIIIR = append(mapOfArrayOfArrayIIIR, mapOfArrayOfArrayIII`, 3131 ` mapOfArrayOfArrayIIR = append(mapOfArrayOfArrayIIR, mapOfArrayOfArrayIIIR`, 3132 ` mapOfArrayOfArrayIR[k] = mapOfArrayOfArrayIIR`, 3133 ` o.MapOfArrayOfArray = mapOfArrayOfArrayIR`, 3134 }, 3135 }, 3136 3137 // load expectations for parameters in operation get_map_anon_array_with_nested_nullable_parameters.go 3138 "getMapAnonArrayWithNestedNullable": { // fixture index 3139 "serverParameter": { // executed template 3140 // expected code lines 3141 `func NewGetMapAnonArrayWithNestedNullableParams() GetMapAnonArrayWithNestedNullableParams {`, 3142 ` return GetMapAnonArrayWithNestedNullableParams{`, 3143 `type GetMapAnonArrayWithNestedNullableParams struct {`, 3144 " HTTPRequest *http.Request `json:\"-\"`", 3145 ` MapOfAnonArrayWithNestedNullable map[string][][]*int64`, 3146 `func (o *GetMapAnonArrayWithNestedNullableParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 3147 ` o.HTTPRequest = r`, 3148 ` if runtime.HasBody(r) {`, 3149 ` defer r.Body.Close(`, 3150 ` var body map[string][][]*int64`, 3151 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 3152 ` if err == io.EOF {`, 3153 ` res = append(res, errors.Required("mapOfAnonArrayWithNestedNullable", "body")`, 3154 ` } else {`, 3155 ` res = append(res, errors.NewParseError("mapOfAnonArrayWithNestedNullable", "body", "", err)`, 3156 ` } else {`, 3157 ` o.MapOfAnonArrayWithNestedNullable = body`, 3158 ` if err := o.validateMapOfAnonArrayWithNestedNullableBody(route.Formats); err != nil {`, 3159 ` } else {`, 3160 ` res = append(res, errors.Required("mapOfAnonArrayWithNestedNullable", "body")`, 3161 ` return errors.CompositeValidationError(res...`, 3162 `func (o *GetMapAnonArrayWithNestedNullableParams) validateMapOfAnonArrayWithNestedNullableBody(formats strfmt.Registry) error {`, 3163 ` mapOfAnonArrayWithNestedNullableIC := o.MapOfAnonArrayWithNestedNullable`, 3164 ` mapOfAnonArrayWithNestedNullableIR := make(map[string][][]*int64, len(mapOfAnonArrayWithNestedNullableIC)`, 3165 ` for k, mapOfAnonArrayWithNestedNullableIV := range mapOfAnonArrayWithNestedNullableIC {`, 3166 ` mapOfAnonArrayWithNestedNullableIIC := mapOfAnonArrayWithNestedNullableIV`, 3167 ` var mapOfAnonArrayWithNestedNullableIIR [][]*int64`, 3168 ` for ii, mapOfAnonArrayWithNestedNullableIIV := range mapOfAnonArrayWithNestedNullableIIC {`, 3169 ` mapOfAnonArrayWithNestedNullableIIIC := mapOfAnonArrayWithNestedNullableIIV`, 3170 ` if len(mapOfAnonArrayWithNestedNullableIIIC) > 0 {`, 3171 ` var mapOfAnonArrayWithNestedNullableIIIR []*int64`, 3172 ` for iii, mapOfAnonArrayWithNestedNullableIIIV := range mapOfAnonArrayWithNestedNullableIIIC {`, 3173 ` mapOfAnonArrayWithNestedNullableIII := mapOfAnonArrayWithNestedNullableIIIV`, 3174 ` if err := validate.MinimumInt(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "mapOfAnonArrayWithNestedNullable", k), ii), iii), "", int64(*mapOfAnonArrayWithNestedNullableIII), 0, false); err != nil {`, 3175 ` mapOfAnonArrayWithNestedNullableIIIR = append(mapOfAnonArrayWithNestedNullableIIIR, mapOfAnonArrayWithNestedNullableIII`, 3176 ` mapOfAnonArrayWithNestedNullableIIR = append(mapOfAnonArrayWithNestedNullableIIR, mapOfAnonArrayWithNestedNullableIIIR`, 3177 ` mapOfAnonArrayWithNestedNullableIR[k] = mapOfAnonArrayWithNestedNullableIIR`, 3178 ` o.MapOfAnonArrayWithNestedNullable = mapOfAnonArrayWithNestedNullableIR`, 3179 }, 3180 }, 3181 3182 // load expectations for parameters in operation get_map_of_model_map_parameters.go 3183 "getMapOfModelMap": { // fixture index 3184 "serverParameter": { // executed template 3185 // expected code lines 3186 `func NewGetMapOfModelMapParams() GetMapOfModelMapParams {`, 3187 ` return GetMapOfModelMapParams{`, 3188 `type GetMapOfModelMapParams struct {`, 3189 " HTTPRequest *http.Request `json:\"-\"`", 3190 ` MapOfModelMap map[string]map[string]int64`, 3191 `func (o *GetMapOfModelMapParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 3192 ` o.HTTPRequest = r`, 3193 ` if runtime.HasBody(r) {`, 3194 ` defer r.Body.Close(`, 3195 ` var body map[string]map[string]int64`, 3196 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 3197 ` if err == io.EOF {`, 3198 ` res = append(res, errors.Required("mapOfModelMap", "body")`, 3199 ` } else {`, 3200 ` res = append(res, errors.NewParseError("mapOfModelMap", "body", "", err)`, 3201 ` } else {`, 3202 ` o.MapOfModelMap = body`, 3203 ` } else {`, 3204 ` res = append(res, errors.Required("mapOfModelMap", "body")`, 3205 ` return errors.CompositeValidationError(res...`, 3206 }, 3207 }, 3208 3209 // load expectations for parameters in operation get_map_of_model_map_nullable_parameters.go 3210 "getMapOfModelMapNullable": { // fixture index 3211 "serverParameter": { // executed template 3212 // expected code lines 3213 `func NewGetMapOfModelMapNullableParams() GetMapOfModelMapNullableParams {`, 3214 ` return GetMapOfModelMapNullableParams{`, 3215 `type GetMapOfModelMapNullableParams struct {`, 3216 " HTTPRequest *http.Request `json:\"-\"`", 3217 ` MapOfModelMapNullable map[string]map[string]*int64`, 3218 `func (o *GetMapOfModelMapNullableParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 3219 ` o.HTTPRequest = r`, 3220 ` if runtime.HasBody(r) {`, 3221 ` defer r.Body.Close(`, 3222 ` var body map[string]map[string]*int64`, 3223 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 3224 ` if err == io.EOF {`, 3225 ` res = append(res, errors.Required("mapOfModelMapNullable", "body")`, 3226 ` } else {`, 3227 ` res = append(res, errors.NewParseError("mapOfModelMapNullable", "body", "", err)`, 3228 ` } else {`, 3229 ` o.MapOfModelMapNullable = body`, 3230 ` } else {`, 3231 ` res = append(res, errors.Required("mapOfModelMapNullable", "body")`, 3232 ` return errors.CompositeValidationError(res...`, 3233 }, 3234 }, 3235 } 3236 assertParams(t, fixtureConfig, filepath.Join("..", "fixtures", "bugs", "1536", "fixture-1536-3.yaml"), true, true) 3237 } 3238 func TestGenParameter_Issue1536_MoreMaps(t *testing.T) { 3239 log.SetOutput(ioutil.Discard) 3240 defer func() { 3241 log.SetOutput(os.Stdout) 3242 }() 3243 3244 // testing fixture-1536-4.yaml with flatten 3245 // param body with maps 3246 3247 fixtureConfig := map[string]map[string][]string{ 3248 3249 // load expectations for parameters in operation get_nested_map04_parameters.go 3250 "getNestedMap04": { // fixture index 3251 "serverParameter": { // executed template 3252 // expected code lines 3253 `func NewGetNestedMap04Params() GetNestedMap04Params {`, 3254 ` return GetNestedMap04Params{`, 3255 `type GetNestedMap04Params struct {`, 3256 " HTTPRequest *http.Request `json:\"-\"`", 3257 ` NestedMap04 map[string]map[string]map[string]*bool`, 3258 `func (o *GetNestedMap04Params) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 3259 ` o.HTTPRequest = r`, 3260 ` if runtime.HasBody(r) {`, 3261 ` defer r.Body.Close(`, 3262 ` var body map[string]map[string]map[string]*bool`, 3263 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 3264 ` if err == io.EOF {`, 3265 ` res = append(res, errors.Required("nestedMap04", "body")`, 3266 ` } else {`, 3267 ` res = append(res, errors.NewParseError("nestedMap04", "body", "", err)`, 3268 ` } else {`, 3269 ` o.NestedMap04 = body`, 3270 ` } else {`, 3271 ` res = append(res, errors.Required("nestedMap04", "body")`, 3272 ` return errors.CompositeValidationError(res...`, 3273 }, 3274 }, 3275 3276 // load expectations for parameters in operation get_nested_slice_and_map01_parameters.go 3277 "getNestedSliceAndMap01": { // fixture index 3278 "serverParameter": { // executed template 3279 // expected code lines 3280 `func NewGetNestedSliceAndMap01Params() GetNestedSliceAndMap01Params {`, 3281 ` return GetNestedSliceAndMap01Params{`, 3282 `type GetNestedSliceAndMap01Params struct {`, 3283 " HTTPRequest *http.Request `json:\"-\"`", 3284 ` NestedSliceAndMap01 []map[string][]map[string]strfmt.Date`, 3285 `func (o *GetNestedSliceAndMap01Params) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 3286 ` o.HTTPRequest = r`, 3287 ` if runtime.HasBody(r) {`, 3288 ` defer r.Body.Close(`, 3289 ` var body []map[string][]map[string]strfmt.Date`, 3290 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 3291 ` if err == io.EOF {`, 3292 ` res = append(res, errors.Required("nestedSliceAndMap01", "body")`, 3293 ` } else {`, 3294 ` res = append(res, errors.NewParseError("nestedSliceAndMap01", "body", "", err)`, 3295 ` } else {`, 3296 ` o.NestedSliceAndMap01 = body`, 3297 ` if err := o.validateNestedSliceAndMap01Body(route.Formats); err != nil {`, 3298 ` } else {`, 3299 ` res = append(res, errors.Required("nestedSliceAndMap01", "body")`, 3300 ` return errors.CompositeValidationError(res...`, 3301 `func (o *GetNestedSliceAndMap01Params) validateNestedSliceAndMap01Body(formats strfmt.Registry) error {`, 3302 ` if err := validate.UniqueItems("nestedSliceAndMap01", "body", o.NestedSliceAndMap01); err != nil {`, 3303 ` nestedSliceAndMap01IC := o.NestedSliceAndMap01`, 3304 ` var nestedSliceAndMap01IR []map[string][]map[string]strfmt.Date`, 3305 ` for i, nestedSliceAndMap01IV := range nestedSliceAndMap01IC {`, 3306 ` nestedSliceAndMap01IIC := nestedSliceAndMap01IV`, 3307 ` nestedSliceAndMap01IIR := make(map[string][]map[string]strfmt.Date, len(nestedSliceAndMap01IIC)`, 3308 ` for kk, nestedSliceAndMap01IIV := range nestedSliceAndMap01IIC {`, 3309 ` nestedSliceAndMap01IIIC := nestedSliceAndMap01IIV`, 3310 ` if err := validate.UniqueItems(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "nestedSliceAndMap01", i), kk), "", nestedSliceAndMap01IIIC); err != nil {`, 3311 ` var nestedSliceAndMap01IIIR []map[string]strfmt.Date`, 3312 ` for iii, nestedSliceAndMap01IIIV := range nestedSliceAndMap01IIIC {`, 3313 ` nestedSliceAndMap01IIIIC := nestedSliceAndMap01IIIV`, 3314 ` nestedSliceAndMap01IIIIR := make(map[string]strfmt.Date, len(nestedSliceAndMap01IIIIC)`, 3315 ` for kkkk, nestedSliceAndMap01IIIIV := range nestedSliceAndMap01IIIIC {`, 3316 ` nestedSliceAndMap01IIII := nestedSliceAndMap01IIIIV`, 3317 ` if err := validate.FormatOf(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "nestedSliceAndMap01", i), kk), iii), kkkk), "", "date", nestedSliceAndMap01IIII.String(), formats); err != nil {`, 3318 ` nestedSliceAndMap01IIIIR[kkkk] = nestedSliceAndMap01IIII`, 3319 ` nestedSliceAndMap01IIIR = append(nestedSliceAndMap01IIIR, nestedSliceAndMap01IIIIR`, 3320 ` nestedSliceAndMap01IIR[kk] = nestedSliceAndMap01IIIR`, 3321 ` nestedSliceAndMap01IR = append(nestedSliceAndMap01IR, nestedSliceAndMap01IIR`, 3322 ` o.NestedSliceAndMap01 = nestedSliceAndMap01IR`, 3323 }, 3324 }, 3325 3326 // load expectations for parameters in operation get_nested_map_and_slice02_parameters.go 3327 "getNestedMapAndSlice02": { // fixture index 3328 "serverParameter": { // executed template 3329 // expected code lines 3330 `func NewGetNestedMapAndSlice02Params() GetNestedMapAndSlice02Params {`, 3331 ` return GetNestedMapAndSlice02Params{`, 3332 `type GetNestedMapAndSlice02Params struct {`, 3333 " HTTPRequest *http.Request `json:\"-\"`", 3334 ` NestedMapAndSlice02 map[string][]map[string][]map[string]*int64`, 3335 `func (o *GetNestedMapAndSlice02Params) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 3336 ` o.HTTPRequest = r`, 3337 ` if runtime.HasBody(r) {`, 3338 ` defer r.Body.Close(`, 3339 ` var body map[string][]map[string][]map[string]*int64`, 3340 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 3341 ` if err == io.EOF {`, 3342 ` res = append(res, errors.Required("nestedMapAndSlice02", "body")`, 3343 ` } else {`, 3344 ` res = append(res, errors.NewParseError("nestedMapAndSlice02", "body", "", err)`, 3345 ` } else {`, 3346 ` o.NestedMapAndSlice02 = body`, 3347 ` if err := o.validateNestedMapAndSlice02Body(route.Formats); err != nil {`, 3348 ` } else {`, 3349 ` res = append(res, errors.Required("nestedMapAndSlice02", "body")`, 3350 ` return errors.CompositeValidationError(res...`, 3351 `func (o *GetNestedMapAndSlice02Params) validateNestedMapAndSlice02Body(formats strfmt.Registry) error {`, 3352 ` nestedMapAndSlice02IC := o.NestedMapAndSlice02`, 3353 ` nestedMapAndSlice02IR := make(map[string][]map[string][]map[string]*int64, len(nestedMapAndSlice02IC)`, 3354 ` for k, nestedMapAndSlice02IV := range nestedMapAndSlice02IC {`, 3355 ` nestedMapAndSlice02IIC := nestedMapAndSlice02IV`, 3356 ` if err := validate.UniqueItems(fmt.Sprintf("%s.%v", "nestedMapAndSlice02", k), "body", nestedMapAndSlice02IIC); err != nil {`, 3357 ` var nestedMapAndSlice02IIR []map[string][]map[string]*int64`, 3358 ` for ii, nestedMapAndSlice02IIV := range nestedMapAndSlice02IIC {`, 3359 ` nestedMapAndSlice02IIIC := nestedMapAndSlice02IIV`, 3360 ` nestedMapAndSlice02IIIR := make(map[string][]map[string]*int64, len(nestedMapAndSlice02IIIC)`, 3361 ` for kkk, nestedMapAndSlice02IIIV := range nestedMapAndSlice02IIIC {`, 3362 ` nestedMapAndSlice02IIIIC := nestedMapAndSlice02IIIV`, 3363 ` if err := validate.UniqueItems(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "nestedMapAndSlice02", k), ii), kkk), "", nestedMapAndSlice02IIIIC); err != nil {`, 3364 ` var nestedMapAndSlice02IIIIR []map[string]*int64`, 3365 ` for iiii, nestedMapAndSlice02IIIIV := range nestedMapAndSlice02IIIIC {`, 3366 ` nestedMapAndSlice02IIIIIC := nestedMapAndSlice02IIIIV`, 3367 ` nestedMapAndSlice02IIIIIR := make(map[string]*int64, len(nestedMapAndSlice02IIIIIC)`, 3368 ` for kkkkk, nestedMapAndSlice02IIIIIV := range nestedMapAndSlice02IIIIIC {`, 3369 ` if nestedMapAndSlice02IIIIIV == nil {`, 3370 ` nestedMapAndSlice02IIIII := nestedMapAndSlice02IIIIIV`, 3371 ` if err := validate.MinimumInt(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "nestedMapAndSlice02", k), ii), kkk), iiii), kkkkk), "", int64(*nestedMapAndSlice02IIIII), 0, false); err != nil {`, 3372 ` nestedMapAndSlice02IIIIIR[kkkkk] = nestedMapAndSlice02IIIII`, 3373 ` nestedMapAndSlice02IIIIR = append(nestedMapAndSlice02IIIIR, nestedMapAndSlice02IIIIIR`, 3374 ` nestedMapAndSlice02IIIR[kkk] = nestedMapAndSlice02IIIIR`, 3375 ` nestedMapAndSlice02IIR = append(nestedMapAndSlice02IIR, nestedMapAndSlice02IIIR`, 3376 ` nestedMapAndSlice02IR[k] = nestedMapAndSlice02IIR`, 3377 ` o.NestedMapAndSlice02 = nestedMapAndSlice02IR`, 3378 }, 3379 }, 3380 3381 // load expectations for parameters in operation get_nested_slice_and_map03_parameters.go 3382 "getNestedSliceAndMap03": { // fixture index 3383 "serverParameter": { // executed template 3384 // expected code lines 3385 `func NewGetNestedSliceAndMap03Params() GetNestedSliceAndMap03Params {`, 3386 ` return GetNestedSliceAndMap03Params{`, 3387 `type GetNestedSliceAndMap03Params struct {`, 3388 " HTTPRequest *http.Request `json:\"-\"`", 3389 ` NestedSliceAndMap03 []map[string][]map[string]string`, 3390 `func (o *GetNestedSliceAndMap03Params) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 3391 ` o.HTTPRequest = r`, 3392 ` if runtime.HasBody(r) {`, 3393 ` defer r.Body.Close(`, 3394 ` var body []map[string][]map[string]string`, 3395 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 3396 ` if err == io.EOF {`, 3397 ` res = append(res, errors.Required("nestedSliceAndMap03", "body")`, 3398 ` } else {`, 3399 ` res = append(res, errors.NewParseError("nestedSliceAndMap03", "body", "", err)`, 3400 ` } else {`, 3401 ` o.NestedSliceAndMap03 = body`, 3402 ` if err := o.validateNestedSliceAndMap03Body(route.Formats); err != nil {`, 3403 ` } else {`, 3404 ` res = append(res, errors.Required("nestedSliceAndMap03", "body")`, 3405 ` return errors.CompositeValidationError(res...`, 3406 `func (o *GetNestedSliceAndMap03Params) validateNestedSliceAndMap03Body(formats strfmt.Registry) error {`, 3407 ` if err := validate.UniqueItems("nestedSliceAndMap03", "body", o.NestedSliceAndMap03); err != nil {`, 3408 ` nestedSliceAndMap03IC := o.NestedSliceAndMap03`, 3409 ` var nestedSliceAndMap03IR []map[string][]map[string]string`, 3410 ` for i, nestedSliceAndMap03IV := range nestedSliceAndMap03IC {`, 3411 ` nestedSliceAndMap03IIC := nestedSliceAndMap03IV`, 3412 ` nestedSliceAndMap03IIR := make(map[string][]map[string]string, len(nestedSliceAndMap03IIC)`, 3413 ` for kk, nestedSliceAndMap03IIV := range nestedSliceAndMap03IIC {`, 3414 ` nestedSliceAndMap03IIIC := nestedSliceAndMap03IIV`, 3415 ` if err := validate.UniqueItems(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "nestedSliceAndMap03", i), kk), "", nestedSliceAndMap03IIIC); err != nil {`, 3416 ` var nestedSliceAndMap03IIIR []map[string]string`, 3417 ` for _, nestedSliceAndMap03IIIV := range nestedSliceAndMap03IIIC {`, 3418 ` nestedSliceAndMap03IIIIC := nestedSliceAndMap03IIIV`, 3419 ` nestedSliceAndMap03IIIIR := make(map[string]string, len(nestedSliceAndMap03IIIIC)`, 3420 ` for kkkk, nestedSliceAndMap03IIIIV := range nestedSliceAndMap03IIIIC {`, 3421 ` nestedSliceAndMap03IIII := nestedSliceAndMap03IIIIV`, 3422 ` nestedSliceAndMap03IIIIR[kkkk] = nestedSliceAndMap03IIII`, 3423 ` nestedSliceAndMap03IIIR = append(nestedSliceAndMap03IIIR, nestedSliceAndMap03IIIIR`, 3424 ` nestedSliceAndMap03IIR[kk] = nestedSliceAndMap03IIIR`, 3425 ` nestedSliceAndMap03IR = append(nestedSliceAndMap03IR, nestedSliceAndMap03IIR`, 3426 ` o.NestedSliceAndMap03 = nestedSliceAndMap03IR`, 3427 }, 3428 }, 3429 3430 // load expectations for parameters in operation get_nested_array03_parameters.go 3431 "getNestedArray03": { // fixture index 3432 "serverParameter": { // executed template 3433 // expected code lines 3434 `func NewGetNestedArray03Params() GetNestedArray03Params {`, 3435 ` return GetNestedArray03Params{`, 3436 `type GetNestedArray03Params struct {`, 3437 " HTTPRequest *http.Request `json:\"-\"`", 3438 ` NestedArray03 [][][]string`, 3439 `func (o *GetNestedArray03Params) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 3440 ` o.HTTPRequest = r`, 3441 ` if runtime.HasBody(r) {`, 3442 ` defer r.Body.Close(`, 3443 ` var body [][][]string`, 3444 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 3445 ` if err == io.EOF {`, 3446 ` res = append(res, errors.Required("nestedArray03", "body")`, 3447 ` } else {`, 3448 ` res = append(res, errors.NewParseError("nestedArray03", "body", "", err)`, 3449 ` } else {`, 3450 ` o.NestedArray03 = body`, 3451 ` } else {`, 3452 ` res = append(res, errors.Required("nestedArray03", "body")`, 3453 ` return errors.CompositeValidationError(res...`, 3454 }, 3455 }, 3456 3457 // load expectations for parameters in operation get_nested_array04_parameters.go 3458 "getNestedArray04": { // fixture index 3459 "serverParameter": { // executed template 3460 // expected code lines 3461 `func NewGetNestedArray04Params() GetNestedArray04Params {`, 3462 ` return GetNestedArray04Params{`, 3463 `type GetNestedArray04Params struct {`, 3464 " HTTPRequest *http.Request `json:\"-\"`", 3465 ` NestedArray03 [][][]string`, 3466 `func (o *GetNestedArray04Params) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 3467 ` o.HTTPRequest = r`, 3468 ` if runtime.HasBody(r) {`, 3469 ` defer r.Body.Close(`, 3470 ` var body [][][]string`, 3471 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 3472 ` if err == io.EOF {`, 3473 ` res = append(res, errors.Required("nestedArray03", "body")`, 3474 ` } else {`, 3475 ` res = append(res, errors.NewParseError("nestedArray03", "body", "", err)`, 3476 ` } else {`, 3477 ` o.NestedArray03 = body`, 3478 ` if err := o.validateNestedArray03Body(route.Formats); err != nil {`, 3479 ` } else {`, 3480 ` res = append(res, errors.Required("nestedArray03", "body")`, 3481 ` return errors.CompositeValidationError(res...`, 3482 `func (o *GetNestedArray04Params) validateNestedArray03Body(formats strfmt.Registry) error {`, 3483 ` if err := validate.UniqueItems("nestedArray03", "body", o.NestedArray03); err != nil {`, 3484 ` nestedArray03IC := o.NestedArray03`, 3485 ` var nestedArray03IR [][][]string`, 3486 ` for i, nestedArray03IV := range nestedArray03IC {`, 3487 ` nestedArray03IIC := nestedArray03IV`, 3488 ` if err := validate.UniqueItems(fmt.Sprintf("%s.%v", "nestedArray03", i), "body", nestedArray03IIC); err != nil {`, 3489 ` if len(nestedArray03IIC) > 0 {`, 3490 ` var nestedArray03IIR [][]string`, 3491 ` for ii, nestedArray03IIV := range nestedArray03IIC {`, 3492 ` nestedArray03IIIC := nestedArray03IIV`, 3493 ` if err := validate.UniqueItems(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "nestedArray03", i), ii), "", nestedArray03IIIC); err != nil {`, 3494 ` if len(nestedArray03IIIC) > 0 {`, 3495 ` var nestedArray03IIIR []string`, 3496 ` for _, nestedArray03IIIV := range nestedArray03IIIC {`, 3497 ` nestedArray03III := nestedArray03IIIV`, 3498 ` nestedArray03IIIR = append(nestedArray03IIIR, nestedArray03III`, 3499 ` nestedArray03IIR = append(nestedArray03IIR, nestedArray03IIIR`, 3500 ` nestedArray03IR = append(nestedArray03IR, nestedArray03IIR`, 3501 ` o.NestedArray03 = nestedArray03IR`, 3502 }, 3503 }, 3504 3505 // load expectations for parameters in operation get_nested_map_and_slice01_parameters.go 3506 "getNestedMapAndSlice01": { // fixture index 3507 "serverParameter": { // executed template 3508 // expected code lines 3509 `func NewGetNestedMapAndSlice01Params() GetNestedMapAndSlice01Params {`, 3510 ` return GetNestedMapAndSlice01Params{`, 3511 `type GetNestedMapAndSlice01Params struct {`, 3512 " HTTPRequest *http.Request `json:\"-\"`", 3513 ` NestedMapAndSlice01 map[string][]map[string][]map[string]strfmt.Date`, 3514 `func (o *GetNestedMapAndSlice01Params) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 3515 ` o.HTTPRequest = r`, 3516 ` if runtime.HasBody(r) {`, 3517 ` defer r.Body.Close(`, 3518 ` var body map[string][]map[string][]map[string]strfmt.Date`, 3519 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 3520 ` if err == io.EOF {`, 3521 ` res = append(res, errors.Required("nestedMapAndSlice01", "body")`, 3522 ` } else {`, 3523 ` res = append(res, errors.NewParseError("nestedMapAndSlice01", "body", "", err)`, 3524 ` } else {`, 3525 ` o.NestedMapAndSlice01 = body`, 3526 ` if err := o.validateNestedMapAndSlice01Body(route.Formats); err != nil {`, 3527 ` } else {`, 3528 ` res = append(res, errors.Required("nestedMapAndSlice01", "body")`, 3529 ` return errors.CompositeValidationError(res...`, 3530 `func (o *GetNestedMapAndSlice01Params) validateNestedMapAndSlice01Body(formats strfmt.Registry) error {`, 3531 ` nestedMapAndSlice01IC := o.NestedMapAndSlice01`, 3532 ` nestedMapAndSlice01IR := make(map[string][]map[string][]map[string]strfmt.Date, len(nestedMapAndSlice01IC)`, 3533 ` for k, nestedMapAndSlice01IV := range nestedMapAndSlice01IC {`, 3534 ` nestedMapAndSlice01IIC := nestedMapAndSlice01IV`, 3535 ` if err := validate.UniqueItems(fmt.Sprintf("%s.%v", "nestedMapAndSlice01", k), "body", nestedMapAndSlice01IIC); err != nil {`, 3536 ` var nestedMapAndSlice01IIR []map[string][]map[string]strfmt.Date`, 3537 ` for ii, nestedMapAndSlice01IIV := range nestedMapAndSlice01IIC {`, 3538 ` nestedMapAndSlice01IIIC := nestedMapAndSlice01IIV`, 3539 ` nestedMapAndSlice01IIIR := make(map[string][]map[string]strfmt.Date, len(nestedMapAndSlice01IIIC)`, 3540 ` for kkk, nestedMapAndSlice01IIIV := range nestedMapAndSlice01IIIC {`, 3541 ` nestedMapAndSlice01IIIIC := nestedMapAndSlice01IIIV`, 3542 ` if err := validate.UniqueItems(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "nestedMapAndSlice01", k), ii), kkk), "", nestedMapAndSlice01IIIIC); err != nil {`, 3543 ` var nestedMapAndSlice01IIIIR []map[string]strfmt.Date`, 3544 ` for iiii, nestedMapAndSlice01IIIIV := range nestedMapAndSlice01IIIIC {`, 3545 ` nestedMapAndSlice01IIIIIC := nestedMapAndSlice01IIIIV`, 3546 ` nestedMapAndSlice01IIIIIR := make(map[string]strfmt.Date, len(nestedMapAndSlice01IIIIIC)`, 3547 ` for kkkkk, nestedMapAndSlice01IIIIIV := range nestedMapAndSlice01IIIIIC {`, 3548 ` nestedMapAndSlice01IIIII := nestedMapAndSlice01IIIIIV`, 3549 ` if err := validate.FormatOf(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "nestedMapAndSlice01", k), ii), kkk), iiii), kkkkk), "", "date", nestedMapAndSlice01IIIII.String(), formats); err != nil {`, 3550 ` nestedMapAndSlice01IIIIIR[kkkkk] = nestedMapAndSlice01IIIII`, 3551 ` nestedMapAndSlice01IIIIR = append(nestedMapAndSlice01IIIIR, nestedMapAndSlice01IIIIIR`, 3552 ` nestedMapAndSlice01IIIR[kkk] = nestedMapAndSlice01IIIIR`, 3553 ` nestedMapAndSlice01IIR = append(nestedMapAndSlice01IIR, nestedMapAndSlice01IIIR`, 3554 ` nestedMapAndSlice01IR[k] = nestedMapAndSlice01IIR`, 3555 ` o.NestedMapAndSlice01 = nestedMapAndSlice01IR`, 3556 }, 3557 }, 3558 3559 // load expectations for parameters in operation get_nested_slice_and_map03_ref_parameters.go 3560 "getNestedSliceAndMap03Ref": { // fixture index 3561 "serverParameter": { // executed template 3562 // expected code lines 3563 `func NewGetNestedSliceAndMap03RefParams() GetNestedSliceAndMap03RefParams {`, 3564 ` return GetNestedSliceAndMap03RefParams{`, 3565 `type GetNestedSliceAndMap03RefParams struct {`, 3566 " HTTPRequest *http.Request `json:\"-\"`", 3567 ` NestedSliceAndMap03Ref models.NestedSliceAndMap03Ref`, 3568 `func (o *GetNestedSliceAndMap03RefParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 3569 ` o.HTTPRequest = r`, 3570 ` if runtime.HasBody(r) {`, 3571 ` defer r.Body.Close(`, 3572 ` var body models.NestedSliceAndMap03Ref`, 3573 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 3574 ` res = append(res, errors.NewParseError("nestedSliceAndMap03Ref", "body", "", err)`, 3575 ` } else {`, 3576 ` if err := body.Validate(route.Formats); err != nil {`, 3577 ` if len(res) == 0 {`, 3578 ` o.NestedSliceAndMap03Ref = body`, 3579 ` return errors.CompositeValidationError(res...`, 3580 }, 3581 }, 3582 3583 // load expectations for parameters in operation get_nested_map02_parameters.go 3584 "getNestedMap02": { // fixture index 3585 "serverParameter": { // executed template 3586 // expected code lines 3587 `func NewGetNestedMap02Params() GetNestedMap02Params {`, 3588 ` return GetNestedMap02Params{`, 3589 `type GetNestedMap02Params struct {`, 3590 " HTTPRequest *http.Request `json:\"-\"`", 3591 ` NestedMap02 map[string]map[string]map[string]*string`, 3592 `func (o *GetNestedMap02Params) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 3593 ` o.HTTPRequest = r`, 3594 ` if runtime.HasBody(r) {`, 3595 ` defer r.Body.Close(`, 3596 ` var body map[string]map[string]map[string]*string`, 3597 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 3598 ` if err == io.EOF {`, 3599 ` res = append(res, errors.Required("nestedMap02", "body")`, 3600 ` } else {`, 3601 ` res = append(res, errors.NewParseError("nestedMap02", "body", "", err)`, 3602 ` } else {`, 3603 ` o.NestedMap02 = body`, 3604 ` if err := o.validateNestedMap02Body(route.Formats); err != nil {`, 3605 ` } else {`, 3606 ` res = append(res, errors.Required("nestedMap02", "body")`, 3607 ` return errors.CompositeValidationError(res...`, 3608 `func (o *GetNestedMap02Params) validateNestedMap02Body(formats strfmt.Registry) error {`, 3609 ` nestedMap02IC := o.NestedMap02`, 3610 ` nestedMap02IR := make(map[string]map[string]map[string]*string, len(nestedMap02IC)`, 3611 ` for k, nestedMap02IV := range nestedMap02IC {`, 3612 ` nestedMap02IIC := nestedMap02IV`, 3613 ` nestedMap02IIR := make(map[string]map[string]*string, len(nestedMap02IIC)`, 3614 ` for kk, nestedMap02IIV := range nestedMap02IIC {`, 3615 ` nestedMap02IIIC := nestedMap02IIV`, 3616 ` nestedMap02IIIR := make(map[string]*string, len(nestedMap02IIIC)`, 3617 ` for kkk, nestedMap02IIIV := range nestedMap02IIIC {`, 3618 ` if nestedMap02IIIV == nil {`, 3619 ` nestedMap02III := nestedMap02IIIV`, 3620 ` if err := validate.MinLength(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "nestedMap02", k), kk), kkk), "", (*nestedMap02III), 0); err != nil {`, 3621 ` nestedMap02IIIR[kkk] = nestedMap02III`, 3622 ` nestedMap02IIR[kk] = nestedMap02IIIR`, 3623 ` nestedMap02IR[k] = nestedMap02IIR`, 3624 ` o.NestedMap02 = nestedMap02IR`, 3625 }, 3626 }, 3627 3628 // load expectations for parameters in operation get_nested_map_and_slice03_parameters.go 3629 "getNestedMapAndSlice03": { // fixture index 3630 "serverParameter": { // executed template 3631 // expected code lines 3632 `func NewGetNestedMapAndSlice03Params() GetNestedMapAndSlice03Params {`, 3633 ` return GetNestedMapAndSlice03Params{`, 3634 `type GetNestedMapAndSlice03Params struct {`, 3635 " HTTPRequest *http.Request `json:\"-\"`", 3636 ` NestedMapAndSlice03 map[string][]map[string][]map[string]int64`, 3637 `func (o *GetNestedMapAndSlice03Params) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 3638 ` o.HTTPRequest = r`, 3639 ` if runtime.HasBody(r) {`, 3640 ` defer r.Body.Close(`, 3641 ` var body map[string][]map[string][]map[string]int64`, 3642 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 3643 ` if err == io.EOF {`, 3644 ` res = append(res, errors.Required("nestedMapAndSlice03", "body")`, 3645 ` } else {`, 3646 ` res = append(res, errors.NewParseError("nestedMapAndSlice03", "body", "", err)`, 3647 ` } else {`, 3648 ` o.NestedMapAndSlice03 = body`, 3649 ` if err := o.validateNestedMapAndSlice03Body(route.Formats); err != nil {`, 3650 ` } else {`, 3651 ` res = append(res, errors.Required("nestedMapAndSlice03", "body")`, 3652 ` return errors.CompositeValidationError(res...`, 3653 `func (o *GetNestedMapAndSlice03Params) validateNestedMapAndSlice03Body(formats strfmt.Registry) error {`, 3654 ` nestedMapAndSlice03IC := o.NestedMapAndSlice03`, 3655 ` nestedMapAndSlice03IR := make(map[string][]map[string][]map[string]int64, len(nestedMapAndSlice03IC)`, 3656 ` for k, nestedMapAndSlice03IV := range nestedMapAndSlice03IC {`, 3657 ` nestedMapAndSlice03IIC := nestedMapAndSlice03IV`, 3658 ` if err := validate.UniqueItems(fmt.Sprintf("%s.%v", "nestedMapAndSlice03", k), "body", nestedMapAndSlice03IIC); err != nil {`, 3659 ` var nestedMapAndSlice03IIR []map[string][]map[string]int64`, 3660 ` for ii, nestedMapAndSlice03IIV := range nestedMapAndSlice03IIC {`, 3661 ` nestedMapAndSlice03IIIC := nestedMapAndSlice03IIV`, 3662 ` nestedMapAndSlice03IIIR := make(map[string][]map[string]int64, len(nestedMapAndSlice03IIIC)`, 3663 ` for kkk, nestedMapAndSlice03IIIV := range nestedMapAndSlice03IIIC {`, 3664 ` nestedMapAndSlice03IIIIC := nestedMapAndSlice03IIIV`, 3665 ` if err := validate.UniqueItems(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "nestedMapAndSlice03", k), ii), kkk), "", nestedMapAndSlice03IIIIC); err != nil {`, 3666 ` var nestedMapAndSlice03IIIIR []map[string]int64`, 3667 ` for _, nestedMapAndSlice03IIIIV := range nestedMapAndSlice03IIIIC {`, 3668 ` nestedMapAndSlice03IIIIIC := nestedMapAndSlice03IIIIV`, 3669 ` nestedMapAndSlice03IIIIIR := make(map[string]int64, len(nestedMapAndSlice03IIIIIC)`, 3670 ` for kkkkk, nestedMapAndSlice03IIIIIV := range nestedMapAndSlice03IIIIIC {`, 3671 ` nestedMapAndSlice03IIIII := nestedMapAndSlice03IIIIIV`, 3672 ` nestedMapAndSlice03IIIIIR[kkkkk] = nestedMapAndSlice03IIIII`, 3673 ` nestedMapAndSlice03IIIIR = append(nestedMapAndSlice03IIIIR, nestedMapAndSlice03IIIIIR`, 3674 ` nestedMapAndSlice03IIIR[kkk] = nestedMapAndSlice03IIIIR`, 3675 ` nestedMapAndSlice03IIR = append(nestedMapAndSlice03IIR, nestedMapAndSlice03IIIR`, 3676 ` nestedMapAndSlice03IR[k] = nestedMapAndSlice03IIR`, 3677 ` o.NestedMapAndSlice03 = nestedMapAndSlice03IR`, 3678 }, 3679 }, 3680 3681 // load expectations for parameters in operation get_nested_slice_and_map02_parameters.go 3682 "getNestedSliceAndMap02": { // fixture index 3683 "serverParameter": { // executed template 3684 // expected code lines 3685 `func NewGetNestedSliceAndMap02Params() GetNestedSliceAndMap02Params {`, 3686 ` return GetNestedSliceAndMap02Params{`, 3687 `type GetNestedSliceAndMap02Params struct {`, 3688 " HTTPRequest *http.Request `json:\"-\"`", 3689 ` NestedSliceAndMap02 []map[string][]map[string]*string`, 3690 `func (o *GetNestedSliceAndMap02Params) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 3691 ` o.HTTPRequest = r`, 3692 ` if runtime.HasBody(r) {`, 3693 ` defer r.Body.Close(`, 3694 ` var body []map[string][]map[string]*string`, 3695 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 3696 ` if err == io.EOF {`, 3697 ` res = append(res, errors.Required("nestedSliceAndMap02", "body")`, 3698 ` } else {`, 3699 ` res = append(res, errors.NewParseError("nestedSliceAndMap02", "body", "", err)`, 3700 ` } else {`, 3701 ` o.NestedSliceAndMap02 = body`, 3702 ` if err := o.validateNestedSliceAndMap02Body(route.Formats); err != nil {`, 3703 ` } else {`, 3704 ` res = append(res, errors.Required("nestedSliceAndMap02", "body")`, 3705 ` return errors.CompositeValidationError(res...`, 3706 `func (o *GetNestedSliceAndMap02Params) validateNestedSliceAndMap02Body(formats strfmt.Registry) error {`, 3707 ` if err := validate.UniqueItems("nestedSliceAndMap02", "body", o.NestedSliceAndMap02); err != nil {`, 3708 ` nestedSliceAndMap02IC := o.NestedSliceAndMap02`, 3709 ` var nestedSliceAndMap02IR []map[string][]map[string]*string`, 3710 ` for i, nestedSliceAndMap02IV := range nestedSliceAndMap02IC {`, 3711 ` nestedSliceAndMap02IIC := nestedSliceAndMap02IV`, 3712 ` nestedSliceAndMap02IIR := make(map[string][]map[string]*string, len(nestedSliceAndMap02IIC)`, 3713 ` for kk, nestedSliceAndMap02IIV := range nestedSliceAndMap02IIC {`, 3714 ` nestedSliceAndMap02IIIC := nestedSliceAndMap02IIV`, 3715 ` if err := validate.UniqueItems(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "nestedSliceAndMap02", i), kk), "", nestedSliceAndMap02IIIC); err != nil {`, 3716 ` var nestedSliceAndMap02IIIR []map[string]*string`, 3717 ` for iii, nestedSliceAndMap02IIIV := range nestedSliceAndMap02IIIC {`, 3718 ` nestedSliceAndMap02IIIIC := nestedSliceAndMap02IIIV`, 3719 ` nestedSliceAndMap02IIIIR := make(map[string]*string, len(nestedSliceAndMap02IIIIC)`, 3720 ` for kkkk, nestedSliceAndMap02IIIIV := range nestedSliceAndMap02IIIIC {`, 3721 ` if nestedSliceAndMap02IIIIV == nil {`, 3722 ` nestedSliceAndMap02IIII := nestedSliceAndMap02IIIIV`, 3723 ` if err := validate.MinLength(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "nestedSliceAndMap02", i), kk), iii), kkkk), "", (*nestedSliceAndMap02IIII), 0); err != nil {`, 3724 ` nestedSliceAndMap02IIIIR[kkkk] = nestedSliceAndMap02IIII`, 3725 ` nestedSliceAndMap02IIIR = append(nestedSliceAndMap02IIIR, nestedSliceAndMap02IIIIR`, 3726 ` nestedSliceAndMap02IIR[kk] = nestedSliceAndMap02IIIR`, 3727 ` nestedSliceAndMap02IR = append(nestedSliceAndMap02IR, nestedSliceAndMap02IIR`, 3728 ` o.NestedSliceAndMap02 = nestedSliceAndMap02IR`, 3729 }, 3730 }, 3731 3732 // load expectations for parameters in operation get_nested_map01_parameters.go 3733 "getNestedMap01": { // fixture index 3734 "serverParameter": { // executed template 3735 // expected code lines 3736 `func NewGetNestedMap01Params() GetNestedMap01Params {`, 3737 ` return GetNestedMap01Params{`, 3738 `type GetNestedMap01Params struct {`, 3739 " HTTPRequest *http.Request `json:\"-\"`", 3740 ` NestedMap01 map[string]map[string]map[string]strfmt.Date`, 3741 `func (o *GetNestedMap01Params) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 3742 ` o.HTTPRequest = r`, 3743 ` if runtime.HasBody(r) {`, 3744 ` defer r.Body.Close(`, 3745 ` var body map[string]map[string]map[string]strfmt.Date`, 3746 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 3747 ` if err == io.EOF {`, 3748 ` res = append(res, errors.Required("nestedMap01", "body")`, 3749 ` } else {`, 3750 ` res = append(res, errors.NewParseError("nestedMap01", "body", "", err)`, 3751 ` } else {`, 3752 ` o.NestedMap01 = body`, 3753 ` if err := o.validateNestedMap01Body(route.Formats); err != nil {`, 3754 ` } else {`, 3755 ` res = append(res, errors.Required("nestedMap01", "body")`, 3756 ` return errors.CompositeValidationError(res...`, 3757 `func (o *GetNestedMap01Params) validateNestedMap01Body(formats strfmt.Registry) error {`, 3758 ` nestedMap01IC := o.NestedMap01`, 3759 ` nestedMap01IR := make(map[string]map[string]map[string]strfmt.Date, len(nestedMap01IC)`, 3760 ` for k, nestedMap01IV := range nestedMap01IC {`, 3761 ` nestedMap01IIC := nestedMap01IV`, 3762 ` nestedMap01IIR := make(map[string]map[string]strfmt.Date, len(nestedMap01IIC)`, 3763 ` for kk, nestedMap01IIV := range nestedMap01IIC {`, 3764 ` nestedMap01IIIC := nestedMap01IIV`, 3765 ` nestedMap01IIIR := make(map[string]strfmt.Date, len(nestedMap01IIIC)`, 3766 ` for kkk, nestedMap01IIIV := range nestedMap01IIIC {`, 3767 ` nestedMap01III := nestedMap01IIIV`, 3768 ` if err := validate.FormatOf(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "nestedMap01", k), kk), kkk), "", "date", nestedMap01III.String(), formats); err != nil {`, 3769 ` nestedMap01IIIR[kkk] = nestedMap01III`, 3770 ` nestedMap01IIR[kk] = nestedMap01IIIR`, 3771 ` nestedMap01IR[k] = nestedMap01IIR`, 3772 ` o.NestedMap01 = nestedMap01IR`, 3773 }, 3774 }, 3775 3776 // load expectations for parameters in operation get_nested_map03_parameters.go 3777 "getNestedMap03": { // fixture index 3778 "serverParameter": { // executed template 3779 // expected code lines 3780 `func NewGetNestedMap03Params() GetNestedMap03Params {`, 3781 ` return GetNestedMap03Params{`, 3782 `type GetNestedMap03Params struct {`, 3783 " HTTPRequest *http.Request `json:\"-\"`", 3784 ` NestedMap03 map[string]map[string]map[string]string`, 3785 `func (o *GetNestedMap03Params) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 3786 ` o.HTTPRequest = r`, 3787 ` if runtime.HasBody(r) {`, 3788 ` defer r.Body.Close(`, 3789 ` var body map[string]map[string]map[string]string`, 3790 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 3791 ` if err == io.EOF {`, 3792 ` res = append(res, errors.Required("nestedMap03", "body")`, 3793 ` } else {`, 3794 ` res = append(res, errors.NewParseError("nestedMap03", "body", "", err)`, 3795 ` } else {`, 3796 ` o.NestedMap03 = body`, 3797 ` } else {`, 3798 ` res = append(res, errors.Required("nestedMap03", "body")`, 3799 ` return errors.CompositeValidationError(res...`, 3800 }, 3801 }, 3802 3803 // load expectations for parameters in operation get_nested_array01_parameters.go 3804 "getNestedArray01": { // fixture index 3805 "serverParameter": { // executed template 3806 // expected code lines 3807 `func NewGetNestedArray01Params() GetNestedArray01Params {`, 3808 ` return GetNestedArray01Params{`, 3809 `type GetNestedArray01Params struct {`, 3810 " HTTPRequest *http.Request `json:\"-\"`", 3811 ` NestedArray01 [][][]strfmt.Date`, 3812 `func (o *GetNestedArray01Params) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 3813 ` o.HTTPRequest = r`, 3814 ` if runtime.HasBody(r) {`, 3815 ` defer r.Body.Close(`, 3816 ` var body [][][]strfmt.Date`, 3817 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 3818 ` if err == io.EOF {`, 3819 ` res = append(res, errors.Required("nestedArray01", "body")`, 3820 ` } else {`, 3821 ` res = append(res, errors.NewParseError("nestedArray01", "body", "", err)`, 3822 ` } else {`, 3823 ` o.NestedArray01 = body`, 3824 ` if err := o.validateNestedArray01Body(route.Formats); err != nil {`, 3825 ` } else {`, 3826 ` res = append(res, errors.Required("nestedArray01", "body")`, 3827 ` return errors.CompositeValidationError(res...`, 3828 `func (o *GetNestedArray01Params) validateNestedArray01Body(formats strfmt.Registry) error {`, 3829 ` nestedArray01Size := int64(len(o.NestedArray01)`, 3830 ` if err := validate.MaxItems("nestedArray01", "body", nestedArray01Size, 10); err != nil {`, 3831 ` nestedArray01IC := o.NestedArray01`, 3832 ` var nestedArray01IR [][][]strfmt.Date`, 3833 ` for i, nestedArray01IV := range nestedArray01IC {`, 3834 ` nestedArray01IIC := nestedArray01IV`, 3835 ` nestedArray01ISize := int64(len(nestedArray01IIC)`, 3836 ` if err := validate.MaxItems(fmt.Sprintf("%s.%v", "nestedArray01", i), "body", nestedArray01ISize, 10); err != nil {`, 3837 ` if len(nestedArray01IIC) > 0 {`, 3838 ` var nestedArray01IIR [][]strfmt.Date`, 3839 ` for ii, nestedArray01IIV := range nestedArray01IIC {`, 3840 ` nestedArray01IIIC := nestedArray01IIV`, 3841 ` nestedArray01IiiSize := int64(len(nestedArray01IIIC)`, 3842 ` if err := validate.MaxItems(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "nestedArray01", i), ii), "", nestedArray01IiiSize, 10); err != nil {`, 3843 ` if len(nestedArray01IIIC) > 0 {`, 3844 ` var nestedArray01IIIR []strfmt.Date`, 3845 ` for iii, nestedArray01IIIV := range nestedArray01IIIC {`, 3846 ` nestedArray01III := nestedArray01IIIV`, 3847 ` if err := validate.FormatOf(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "nestedArray01", i), ii), iii), "", "date", nestedArray01III.String(), formats); err != nil {`, 3848 ` nestedArray01IIIR = append(nestedArray01IIIR, nestedArray01III`, 3849 ` nestedArray01IIR = append(nestedArray01IIR, nestedArray01IIIR`, 3850 ` nestedArray01IR = append(nestedArray01IR, nestedArray01IIR`, 3851 ` o.NestedArray01 = nestedArray01IR`, 3852 }, 3853 }, 3854 3855 // load expectations for parameters in operation get_nested_array02_parameters.go 3856 "getNestedArray02": { // fixture index 3857 "serverParameter": { // executed template 3858 // expected code lines 3859 `func NewGetNestedArray02Params() GetNestedArray02Params {`, 3860 ` return GetNestedArray02Params{`, 3861 `type GetNestedArray02Params struct {`, 3862 " HTTPRequest *http.Request `json:\"-\"`", 3863 ` NestedArray01 [][][]*string`, 3864 `func (o *GetNestedArray02Params) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 3865 ` o.HTTPRequest = r`, 3866 ` if runtime.HasBody(r) {`, 3867 ` defer r.Body.Close(`, 3868 ` var body [][][]*string`, 3869 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 3870 ` if err == io.EOF {`, 3871 ` res = append(res, errors.Required("nestedArray01", "body")`, 3872 ` } else {`, 3873 ` res = append(res, errors.NewParseError("nestedArray01", "body", "", err)`, 3874 ` } else {`, 3875 ` o.NestedArray01 = body`, 3876 ` if err := o.validateNestedArray01Body(route.Formats); err != nil {`, 3877 ` } else {`, 3878 ` res = append(res, errors.Required("nestedArray01", "body")`, 3879 ` return errors.CompositeValidationError(res...`, 3880 `func (o *GetNestedArray02Params) validateNestedArray01Body(formats strfmt.Registry) error {`, 3881 ` nestedArray01Size := int64(len(o.NestedArray01)`, 3882 ` if err := validate.MaxItems("nestedArray01", "body", nestedArray01Size, 10); err != nil {`, 3883 ` nestedArray01IC := o.NestedArray01`, 3884 ` var nestedArray01IR [][][]*string`, 3885 ` for i, nestedArray01IV := range nestedArray01IC {`, 3886 ` nestedArray01IIC := nestedArray01IV`, 3887 ` nestedArray01ISize := int64(len(nestedArray01IIC)`, 3888 ` if err := validate.MaxItems(fmt.Sprintf("%s.%v", "nestedArray01", i), "body", nestedArray01ISize, 10); err != nil {`, 3889 ` if len(nestedArray01IIC) > 0 {`, 3890 ` var nestedArray01IIR [][]*string`, 3891 ` for ii, nestedArray01IIV := range nestedArray01IIC {`, 3892 ` nestedArray01IIIC := nestedArray01IIV`, 3893 ` nestedArray01IiiSize := int64(len(nestedArray01IIIC)`, 3894 ` if err := validate.MaxItems(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "nestedArray01", i), ii), "", nestedArray01IiiSize, 10); err != nil {`, 3895 ` if len(nestedArray01IIIC) > 0 {`, 3896 ` var nestedArray01IIIR []*string`, 3897 ` for iii, nestedArray01IIIV := range nestedArray01IIIC {`, 3898 ` if nestedArray01IIIV == nil {`, 3899 // do we need Required on nullable in items? 3900 // without Required 3901 ` continue`, 3902 // with Required 3903 //` return errors.Required(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "nestedArray01", i), ii), iii), ""`, 3904 ` nestedArray01III := nestedArray01IIIV`, 3905 ` if err := validate.MinLength(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "nestedArray01", i), ii), iii), "", (*nestedArray01III), 0); err != nil {`, 3906 ` nestedArray01IIIR = append(nestedArray01IIIR, nestedArray01III`, 3907 ` nestedArray01IIR = append(nestedArray01IIR, nestedArray01IIIR`, 3908 ` nestedArray01IR = append(nestedArray01IR, nestedArray01IIR`, 3909 ` o.NestedArray01 = nestedArray01IR`, 3910 }, 3911 }, 3912 // load expectations for parameters in operation get_nested_ref_no_validation01_parameters.go 3913 "getNestedRefNoValidation01": { // fixture index 3914 "serverParameter": { // executed template 3915 // expected code lines 3916 `func NewGetNestedRefNoValidation01Params() GetNestedRefNoValidation01Params {`, 3917 ` return GetNestedRefNoValidation01Params{`, 3918 `type GetNestedRefNoValidation01Params struct {`, 3919 " HTTPRequest *http.Request `json:\"-\"`", 3920 ` NestedRefNovalidation01 map[string]models.NestedRefNoValidation`, 3921 `func (o *GetNestedRefNoValidation01Params) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 3922 ` o.HTTPRequest = r`, 3923 ` if runtime.HasBody(r) {`, 3924 ` defer r.Body.Close(`, 3925 ` var body map[string]models.NestedRefNoValidation`, 3926 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 3927 ` res = append(res, errors.NewParseError("nestedRefNovalidation01", "body", "", err)`, 3928 ` } else {`, 3929 ` for k := range body {`, 3930 ` if val, ok := body[k]; ok {`, 3931 ` if err := val.Validate(route.Formats); err != nil {`, 3932 ` break`, 3933 ` if len(res) == 0 {`, 3934 ` o.NestedRefNovalidation01 = body`, 3935 ` return errors.CompositeValidationError(res...`, 3936 }, 3937 }, 3938 // load expectations for parameters in operation get_nested_ref_no_validation02_parameters.go 3939 "getNestedRefNoValidation02": { // fixture index 3940 "serverParameter": { // executed template 3941 // expected code lines 3942 `func NewGetNestedRefNoValidation02Params() GetNestedRefNoValidation02Params {`, 3943 ` return GetNestedRefNoValidation02Params{`, 3944 `type GetNestedRefNoValidation02Params struct {`, 3945 " HTTPRequest *http.Request `json:\"-\"`", 3946 ` NestedRefNovalidation02 map[string]map[string]models.NestedRefNoValidation`, 3947 `func (o *GetNestedRefNoValidation02Params) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 3948 ` o.HTTPRequest = r`, 3949 ` if runtime.HasBody(r) {`, 3950 ` defer r.Body.Close(`, 3951 ` var body map[string]map[string]models.NestedRefNoValidation`, 3952 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 3953 ` res = append(res, errors.NewParseError("nestedRefNovalidation02", "body", "", err)`, 3954 ` } else {`, 3955 ` o.NestedRefNovalidation02 = body`, 3956 ` if err := o.validateNestedRefNovalidation02Body(route.Formats); err != nil {`, 3957 ` return errors.CompositeValidationError(res...`, 3958 `func (o *GetNestedRefNoValidation02Params) validateNestedRefNovalidation02Body(formats strfmt.Registry) error {`, 3959 ` nestedRefNovalidation02IC := o.NestedRefNovalidation02`, 3960 ` nestedRefNovalidation02IR := make(map[string]map[string]models.NestedRefNoValidation, len(nestedRefNovalidation02IC)`, 3961 ` for k, nestedRefNovalidation02IV := range nestedRefNovalidation02IC {`, 3962 ` nestedRefNovalidation02IIC := nestedRefNovalidation02IV`, 3963 ` nestedRefNovalidation02IIR := make(map[string]models.NestedRefNoValidation, len(nestedRefNovalidation02IIC)`, 3964 ` for kk, nestedRefNovalidation02IIV := range nestedRefNovalidation02IIC {`, 3965 ` nestedRefNovalidation02II := nestedRefNovalidation02IIV`, 3966 ` if err := nestedRefNovalidation02II.Validate(formats); err != nil {`, 3967 ` if ve, ok := err.(*errors.Validation); ok {`, 3968 ` return ve.ValidateName(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "nestedRefNovalidation02", k), kk)`, 3969 ` nestedRefNovalidation02IIR[kk] = nestedRefNovalidation02II`, 3970 ` nestedRefNovalidation02IR[k] = nestedRefNovalidation02IIR`, 3971 ` o.NestedRefNovalidation02 = nestedRefNovalidation02IR`, 3972 }, 3973 }, 3974 } 3975 3976 assertParams(t, fixtureConfig, filepath.Join("..", "fixtures", "bugs", "1536", "fixture-1536-4.yaml"), false, false) 3977 } 3978 3979 func TestGenParameter_Issue15362_WithExpand(t *testing.T) { 3980 log.SetOutput(ioutil.Discard) 3981 defer func() { 3982 log.SetOutput(os.Stdout) 3983 }() 3984 3985 fixtureConfig := map[string]map[string][]string{ 3986 // load expectations for parameters in operation get_nested_required_parameters.go 3987 "getNestedRequired": { // fixture index 3988 "serverParameter": { // executed template 3989 // expected code lines 3990 `func NewGetNestedRequiredParams() GetNestedRequiredParams {`, 3991 ` return GetNestedRequiredParams{`, 3992 `type GetNestedRequiredParams struct {`, 3993 " HTTPRequest *http.Request `json:\"-\"`", 3994 ` ObjectNestedRequired [][][][]*GetNestedRequiredParamsBodyItems0`, 3995 `func (o *GetNestedRequiredParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 3996 ` o.HTTPRequest = r`, 3997 ` if runtime.HasBody(r) {`, 3998 ` defer r.Body.Close(`, 3999 ` var body [][][][]*GetNestedRequiredParamsBodyItems0`, 4000 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 4001 ` res = append(res, errors.NewParseError("objectNestedRequired", "body", "", err)`, 4002 ` } else {`, 4003 ` o.ObjectNestedRequired = body`, 4004 ` if err := o.validateObjectNestedRequiredBody(route.Formats); err != nil {`, 4005 ` return errors.CompositeValidationError(res...`, 4006 `func (o *GetNestedRequiredParams) validateObjectNestedRequiredBody(formats strfmt.Registry) error {`, 4007 ` objectNestedRequiredIC := o.ObjectNestedRequired`, 4008 ` var objectNestedRequiredIR [][][][]*GetNestedRequiredParamsBodyItems0`, 4009 ` for i, objectNestedRequiredIV := range objectNestedRequiredIC {`, 4010 ` objectNestedRequiredIIC := objectNestedRequiredIV`, 4011 ` if len(objectNestedRequiredIIC) > 0 {`, 4012 ` var objectNestedRequiredIIR [][][]*GetNestedRequiredParamsBodyItems0`, 4013 ` for ii, objectNestedRequiredIIV := range objectNestedRequiredIIC {`, 4014 ` objectNestedRequiredIIIC := objectNestedRequiredIIV`, 4015 ` if len(objectNestedRequiredIIIC) > 0 {`, 4016 ` var objectNestedRequiredIIIR [][]*GetNestedRequiredParamsBodyItems0`, 4017 ` for iii, objectNestedRequiredIIIV := range objectNestedRequiredIIIC {`, 4018 ` objectNestedRequiredIIIIC := objectNestedRequiredIIIV`, 4019 ` if len(objectNestedRequiredIIIIC) > 0 {`, 4020 ` var objectNestedRequiredIIIIR []*GetNestedRequiredParamsBodyItems0`, 4021 ` for iiii, objectNestedRequiredIIIIV := range objectNestedRequiredIIIIC {`, 4022 ` objectNestedRequiredIIII := objectNestedRequiredIIIIV`, 4023 ` if err := objectNestedRequiredIIII.Validate(formats); err != nil {`, 4024 ` if ve, ok := err.(*errors.Validation); ok {`, 4025 ` return ve.ValidateName(fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", fmt.Sprintf("%s.%v", "objectNestedRequired", i), ii), iii), iiii)`, 4026 ` objectNestedRequiredIIIIR = append(objectNestedRequiredIIIIR, objectNestedRequiredIIII`, 4027 ` objectNestedRequiredIIIR = append(objectNestedRequiredIIIR, objectNestedRequiredIIIIR`, 4028 ` objectNestedRequiredIIR = append(objectNestedRequiredIIR, objectNestedRequiredIIIR`, 4029 ` objectNestedRequiredIR = append(objectNestedRequiredIR, objectNestedRequiredIIR`, 4030 ` o.ObjectNestedRequired = objectNestedRequiredIR`, 4031 }, 4032 "serverOperation": { // executed template 4033 // expected code lines 4034 `type GetNestedRequiredParamsBodyItems0 struct {`, 4035 " Pkcs *string `json:\"pkcs\"`", 4036 `func (o *GetNestedRequiredParamsBodyItems0) Validate(formats strfmt.Registry) error {`, 4037 ` if err := o.validatePkcs(formats); err != nil {`, 4038 ` return errors.CompositeValidationError(res...`, 4039 `func (o *GetNestedRequiredParamsBodyItems0) validatePkcs(formats strfmt.Registry) error {`, 4040 ` if err := validate.Required("pkcs", "body", o.Pkcs); err != nil {`, 4041 }, 4042 }, 4043 } 4044 4045 assertParams(t, fixtureConfig, filepath.Join("..", "fixtures", "bugs", "1536", "fixture-1536-2.yaml"), true, false) 4046 } 4047 4048 func TestGenParameter_Issue1548_base64(t *testing.T) { 4049 // testing fixture-1548.yaml with flatten 4050 // My App API 4051 fixtureConfig := map[string]map[string][]string{ 4052 4053 // load expectations for parameters in operation my_method_parameters.go 4054 "MyMethod": { // fixture index 4055 "serverParameter": { // executed template 4056 // expected code lines 4057 `func NewMyMethodParams() MyMethodParams {`, 4058 ` return MyMethodParams{`, 4059 `type MyMethodParams struct {`, 4060 " HTTPRequest *http.Request `json:\"-\"`", 4061 ` ByteInQuery strfmt.Base64`, 4062 ` Data strfmt.Base64`, 4063 `func (o *MyMethodParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 4064 ` o.HTTPRequest = r`, 4065 ` qs := runtime.Values(r.URL.Query()`, 4066 ` qByteInQuery, qhkByteInQuery, _ := qs.GetOK("byteInQuery"`, 4067 ` if err := o.bindByteInQuery(qByteInQuery, qhkByteInQuery, route.Formats); err != nil {`, 4068 ` if runtime.HasBody(r) {`, 4069 ` defer r.Body.Close(`, 4070 ` var body strfmt.Base64`, 4071 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 4072 ` res = append(res, errors.NewParseError("data", "body", "", err)`, 4073 ` } else {`, 4074 ` o.Data = body`, 4075 ` if err := o.validateDataBody(route.Formats); err != nil {`, 4076 ` return errors.CompositeValidationError(res...`, 4077 `func (o *MyMethodParams) bindByteInQuery(rawData []string, hasKey bool, formats strfmt.Registry) error {`, 4078 ` if !hasKey {`, 4079 ` return errors.Required("byteInQuery", "query"`, 4080 ` var raw string`, 4081 ` if len(rawData) > 0 {`, 4082 ` raw = rawData[len(rawData)-1]`, 4083 ` if err := validate.RequiredString("byteInQuery", "query", raw); err != nil {`, 4084 ` value, err := formats.Parse("byte", raw`, 4085 ` if err != nil {`, 4086 ` return errors.InvalidType("byteInQuery", "query", "strfmt.Base64", raw`, 4087 ` o.ByteInQuery = *(value.(*strfmt.Base64)`, 4088 ` if err := o.validateByteInQuery(formats); err != nil {`, 4089 `func (o *MyMethodParams) validateByteInQuery(formats strfmt.Registry) error {`, 4090 ` if err := validate.MaxLength("byteInQuery", "query", o.ByteInQuery.String(), 100); err != nil {`, 4091 `func (o *MyMethodParams) validateDataBody(formats strfmt.Registry) error {`, 4092 }, 4093 }, 4094 4095 // load expectations for parameters in operation my_model_method_parameters.go 4096 "MyModelMethod": { // fixture index 4097 "serverParameter": { // executed template 4098 // expected code lines 4099 `func NewMyModelMethodParams() MyModelMethodParams {`, 4100 ` return MyModelMethodParams{`, 4101 `type MyModelMethodParams struct {`, 4102 " HTTPRequest *http.Request `json:\"-\"`", 4103 ` Data *models.Base64Model`, 4104 `func (o *MyModelMethodParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 4105 ` o.HTTPRequest = r`, 4106 ` if runtime.HasBody(r) {`, 4107 ` defer r.Body.Close(`, 4108 ` var body models.Base64Model`, 4109 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 4110 ` res = append(res, errors.NewParseError("data", "body", "", err)`, 4111 ` } else {`, 4112 ` if err := body.Validate(route.Formats); err != nil {`, 4113 ` if len(res) == 0 {`, 4114 ` o.Data = &body`, 4115 ` return errors.CompositeValidationError(res...`, 4116 }, 4117 }, 4118 } 4119 4120 assertParams(t, fixtureConfig, filepath.Join("..", "fixtures", "bugs", "1548", "fixture-1548.yaml"), true, false) 4121 } 4122 4123 func TestGenParameter_1572(t *testing.T) { 4124 log.SetOutput(ioutil.Discard) 4125 defer func() { 4126 log.SetOutput(os.Stdout) 4127 }() 4128 // testing fixture-1572.yaml with minimal flatten 4129 // edge cases for operations schemas 4130 4131 /* 4132 Run the following test caes and exercise the minimal flatten mode: 4133 - [x] nil schema in body param / response 4134 - [x] interface{} in body param /response 4135 - [x] additional schema reused from model (body param and response) (with maps or arrays) 4136 - [x] primitive body / response 4137 - [x] $ref'ed response and param (check that minimal flatten expands it) 4138 4139 */ 4140 4141 fixtureConfig := map[string]map[string][]string{ 4142 4143 // load expectations for parameters in operation get_interface_parameters.go 4144 "getInterface": { // fixture index 4145 "serverParameter": { // executed template 4146 // expected code lines 4147 `func NewGetInterfaceParams() GetInterfaceParams {`, 4148 ` return GetInterfaceParams{`, 4149 `type GetInterfaceParams struct {`, 4150 " HTTPRequest *http.Request `json:\"-\"`", 4151 ` InterfaceBody interface{`, 4152 `func (o *GetInterfaceParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 4153 ` o.HTTPRequest = r`, 4154 ` if runtime.HasBody(r) {`, 4155 ` defer r.Body.Close(`, 4156 ` var body interface{`, 4157 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 4158 ` if err == io.EOF {`, 4159 ` res = append(res, errors.Required("interfaceBody", "body")`, 4160 ` } else {`, 4161 ` res = append(res, errors.NewParseError("interfaceBody", "body", "", err)`, 4162 ` } else {`, 4163 ` o.InterfaceBody = body`, 4164 ` } else {`, 4165 ` res = append(res, errors.Required("interfaceBody", "body")`, 4166 ` return errors.CompositeValidationError(res...`, 4167 }, 4168 }, 4169 4170 // load expectations for parameters in operation get_null_parameters.go 4171 "getNull": { // fixture index 4172 "serverParameter": { // executed template 4173 // expected code lines 4174 `func NewGetNullParams() GetNullParams {`, 4175 ` return GetNullParams{`, 4176 `type GetNullParams struct {`, 4177 " HTTPRequest *http.Request `json:\"-\"`", 4178 ` NullBody interface{`, 4179 `func (o *GetNullParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 4180 ` o.HTTPRequest = r`, 4181 ` if runtime.HasBody(r) {`, 4182 ` defer r.Body.Close(`, 4183 ` var body interface{`, 4184 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 4185 ` if err == io.EOF {`, 4186 ` res = append(res, errors.Required("nullBody", "body")`, 4187 ` } else {`, 4188 ` res = append(res, errors.NewParseError("nullBody", "body", "", err)`, 4189 ` } else {`, 4190 ` o.NullBody = body`, 4191 ` } else {`, 4192 ` res = append(res, errors.Required("nullBody", "body")`, 4193 ` return errors.CompositeValidationError(res...`, 4194 }, 4195 }, 4196 4197 // load expectations for parameters in operation get_primitive_parameters.go 4198 "getPrimitive": { // fixture index 4199 "serverParameter": { // executed template 4200 // expected code lines 4201 `func NewGetPrimitiveParams() GetPrimitiveParams {`, 4202 ` return GetPrimitiveParams{`, 4203 `type GetPrimitiveParams struct {`, 4204 " HTTPRequest *http.Request `json:\"-\"`", 4205 ` PrimitiveBody uint32`, 4206 `func (o *GetPrimitiveParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 4207 ` o.HTTPRequest = r`, 4208 ` if runtime.HasBody(r) {`, 4209 ` defer r.Body.Close(`, 4210 ` var body uint32`, 4211 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 4212 ` if err == io.EOF {`, 4213 ` res = append(res, errors.Required("primitiveBody", "body")`, 4214 ` } else {`, 4215 ` res = append(res, errors.NewParseError("primitiveBody", "body", "", err)`, 4216 ` } else {`, 4217 ` o.PrimitiveBody = body`, 4218 ` if err := o.validatePrimitiveBodyBody(route.Formats); err != nil {`, 4219 ` } else {`, 4220 ` res = append(res, errors.Required("primitiveBody", "body")`, 4221 ` return errors.CompositeValidationError(res...`, 4222 `func (o *GetPrimitiveParams) validatePrimitiveBodyBody(formats strfmt.Registry) error {`, 4223 ` if err := validate.MaximumInt("primitiveBody", "body", int64(o.PrimitiveBody), 100, false); err != nil {`, 4224 }, 4225 }, 4226 4227 // load expectations for parameters in operation get_model_interface_parameters.go 4228 "getModelInterface": { // fixture index 4229 "serverParameter": { // executed template 4230 // expected code lines 4231 `func NewGetModelInterfaceParams() GetModelInterfaceParams {`, 4232 ` return GetModelInterfaceParams{`, 4233 `type GetModelInterfaceParams struct {`, 4234 " HTTPRequest *http.Request `json:\"-\"`", 4235 ` InterfaceBody map[string]models.ModelInterface`, 4236 `func (o *GetModelInterfaceParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {`, 4237 ` o.HTTPRequest = r`, 4238 ` if runtime.HasBody(r) {`, 4239 ` defer r.Body.Close(`, 4240 ` var body map[string]models.ModelInterface`, 4241 ` if err := route.Consumer.Consume(r.Body, &body); err != nil {`, 4242 ` if err == io.EOF {`, 4243 ` res = append(res, errors.Required("interfaceBody", "body")`, 4244 ` } else {`, 4245 ` res = append(res, errors.NewParseError("interfaceBody", "body", "", err)`, 4246 ` } else {`, 4247 ` o.InterfaceBody = body`, 4248 ` } else {`, 4249 ` res = append(res, errors.Required("interfaceBody", "body")`, 4250 ` return errors.CompositeValidationError(res...`, 4251 }, 4252 }, 4253 } 4254 assertParams(t, fixtureConfig, filepath.Join("..", "fixtures", "enhancements", "1572", "fixture-1572.yaml"), true, false) 4255 } 4256 4257 func TestGenParameter_1637(t *testing.T) { 4258 log.SetOutput(ioutil.Discard) 4259 defer func() { 4260 log.SetOutput(os.Stdout) 4261 }() 4262 // testing fixture-1637.yaml with minimal flatten 4263 // slice of polymorphic type in body param 4264 4265 fixtureConfig := map[string]map[string][]string{ 4266 4267 // load expectations for parameters 4268 "test": { // fixture index 4269 "serverParameter": { // executed template 4270 `body, err := models.UnmarshalValueSlice(r.Body, route.Consumer)`, 4271 }, 4272 }, 4273 } 4274 assertParams(t, fixtureConfig, filepath.Join("..", "fixtures", "bugs", "1637", "fixture-1637.yaml"), true, false) 4275 } 4276 4277 func TestGenParameter_1755(t *testing.T) { 4278 log.SetOutput(ioutil.Discard) 4279 defer func() { 4280 log.SetOutput(os.Stdout) 4281 }() 4282 // testing fixture-1755.yaml with minimal flatten 4283 // body param is array with slice validation (e.g. minItems): initialize array with body 4284 4285 fixtureConfig := map[string]map[string][]string{ 4286 4287 // load expectations for parameters 4288 "registerAsset": { // fixture index (operation name) 4289 "serverParameter": { // executed template 4290 `o.AssetProperties = body`, 4291 `assetPropertiesSize := int64(len(o.AssetProperties))`, 4292 }, 4293 }, 4294 } 4295 assertParams(t, fixtureConfig, filepath.Join("..", "fixtures", "bugs", "1755", "fixture-1755.yaml"), true, false) 4296 } 4297 4298 func TestGenClientParameter_1490(t *testing.T) { 4299 log.SetOutput(ioutil.Discard) 4300 defer func() { 4301 log.SetOutput(os.Stdout) 4302 }() 4303 // testing fixture-1490.yaml with minimal flatten 4304 // body param is interface 4305 4306 fixtureConfig := map[string]map[string][]string{ 4307 4308 // load expectations for parameters 4309 "getRecords": { // fixture index 4310 "clientParameter": { // executed template 4311 `if err := r.SetBodyParam(o.Records); err != nil {`, 4312 }, 4313 }, 4314 "getMoreRecords": { // fixture index 4315 "clientParameter": { // executed template 4316 `if err := r.SetBodyParam(o.Records); err != nil {`, 4317 }, 4318 }, 4319 "getRecordsNonRequired": { // fixture index 4320 "clientParameter": { // executed template 4321 `if err := r.SetBodyParam(o.RecordsNonRequired); err != nil {`, 4322 }, 4323 }, 4324 } 4325 assertParams(t, fixtureConfig, filepath.Join("..", "fixtures", "bugs", "1490", "fixture-1490.yaml"), true, false) 4326 } 4327 4328 func TestGenClientParameter_973(t *testing.T) { 4329 log.SetOutput(ioutil.Discard) 4330 defer func() { 4331 log.SetOutput(os.Stdout) 4332 }() 4333 // testing fixture-973.yaml with minimal flatten 4334 // header param is UUID, with or without required constraint 4335 4336 fixtureConfig := map[string]map[string][]string{ 4337 4338 // load expectations for parameters 4339 "getResourceRecords": { // fixture index 4340 "clientParameter": { // executed template 4341 `if err := r.SetHeaderParam("profile", o.Profile.String()); err != nil {`, 4342 `if err := r.SetHeaderParam("profileRequired", o.ProfileRequired.String()); err != nil {`, 4343 }, 4344 }, 4345 } 4346 assertParams(t, fixtureConfig, filepath.Join("..", "fixtures", "bugs", "973", "fixture-973.yaml"), true, false) 4347 } 4348 4349 func TestGenClientParameter_1020(t *testing.T) { 4350 log.SetOutput(ioutil.Discard) 4351 defer func() { 4352 log.SetOutput(os.Stdout) 4353 }() 4354 // testing fixture-1020.yaml with minimal flatten 4355 // param is File 4356 4357 fixtureConfig := map[string]map[string][]string{ 4358 4359 // load expectations for parameters 4360 "someTest": { // fixture index 4361 "clientParameter": { // executed template 4362 `File runtime.NamedReadCloser`, 4363 }, 4364 }, 4365 } 4366 assertParams(t, fixtureConfig, filepath.Join("..", "fixtures", "bugs", "1020", "fixture-1020.yaml"), true, false) 4367 } 4368 4369 func TestGenClientParameter_1339(t *testing.T) { 4370 log.SetOutput(ioutil.Discard) 4371 defer func() { 4372 log.SetOutput(os.Stdout) 4373 }() 4374 // testing fixture-1339.yaml with minimal flatten 4375 // param is binary 4376 4377 fixtureConfig := map[string]map[string][]string{ 4378 4379 // load expectations for parameters 4380 "postBin": { // fixture index 4381 "clientParameter": { // executed template 4382 `if err := r.SetBodyParam(o.Body); err != nil {`, 4383 }, 4384 }, 4385 } 4386 assertParams(t, fixtureConfig, filepath.Join("..", "fixtures", "bugs", "1339", "fixture-1339.yaml"), true, false) 4387 } 4388 4389 func TestGenClientParameter_1937(t *testing.T) { 4390 // names starting with a number 4391 log.SetOutput(ioutil.Discard) 4392 defer func() { 4393 log.SetOutput(os.Stdout) 4394 }() 4395 // testing fixture-1339.yaml with minimal flatten 4396 // param is binary 4397 4398 fixtureConfig := map[string]map[string][]string{ 4399 4400 // load expectations for parameters 4401 "getRecords": { // fixture index 4402 "serverParameter": { // executed template 4403 `Nr101param *string`, 4404 `Records models.Nr400Schema`, 4405 }, 4406 }, 4407 } 4408 assertParams(t, fixtureConfig, filepath.Join("..", "fixtures", "bugs", "1937", "fixture-1937.yaml"), true, false) 4409 }