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