github.com/emreu/go-swagger@v0.22.1/generator/typeresolver_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 "fmt" 19 "testing" 20 21 "github.com/go-openapi/loads" 22 "github.com/go-openapi/spec" 23 "github.com/stretchr/testify/assert" 24 ) 25 26 var schTypeVals = []struct{ Type, Format, Expected string }{ 27 {"boolean", "", "bool"}, 28 {"string", "", "string"}, 29 {"integer", "int8", "int8"}, 30 {"integer", "int16", "int16"}, 31 {"integer", "int32", "int32"}, 32 {"integer", "int64", "int64"}, 33 {"integer", "", "int64"}, 34 {"integer", "uint8", "uint8"}, 35 {"integer", "uint16", "uint16"}, 36 {"integer", "uint32", "uint32"}, 37 {"integer", "uint64", "uint64"}, 38 {"number", "float", "float32"}, 39 {"number", "double", "float64"}, 40 {"number", "", "float64"}, 41 {"string", "byte", "strfmt.Base64"}, 42 {"string", "date", "strfmt.Date"}, 43 {"string", "date-time", "strfmt.DateTime"}, 44 {"string", "uri", "strfmt.URI"}, 45 {"string", "email", "strfmt.Email"}, 46 {"string", "hostname", "strfmt.Hostname"}, 47 {"string", "ipv4", "strfmt.IPv4"}, 48 {"string", "ipv6", "strfmt.IPv6"}, 49 {"string", "mac", "strfmt.MAC"}, 50 {"string", "uuid", "strfmt.UUID"}, 51 {"string", "uuid3", "strfmt.UUID3"}, 52 {"string", "uuid4", "strfmt.UUID4"}, 53 {"string", "uuid5", "strfmt.UUID5"}, 54 {"string", "isbn", "strfmt.ISBN"}, 55 {"string", "isbn10", "strfmt.ISBN10"}, 56 {"string", "isbn13", "strfmt.ISBN13"}, 57 {"string", "creditcard", "strfmt.CreditCard"}, 58 {"string", "ssn", "strfmt.SSN"}, 59 {"string", "hexcolor", "strfmt.HexColor"}, 60 {"string", "rgbcolor", "strfmt.RGBColor"}, 61 {"string", "duration", "strfmt.Duration"}, 62 {"string", "ObjectId", "strfmt.ObjectId"}, 63 {"string", "password", "strfmt.Password"}, 64 {"string", "uint8", "string"}, 65 {"string", "uint16", "string"}, 66 {"string", "uint32", "string"}, 67 {"string", "uint64", "string"}, 68 {"string", "int8", "string"}, 69 {"string", "int16", "string"}, 70 {"string", "int32", "string"}, 71 {"string", "int64", "string"}, 72 {"file", "", "io.ReadCloser"}, 73 } 74 75 var schRefVals = []struct{ Type, GoType, Expected string }{ 76 {"Comment", "", "models.Comment"}, 77 {"UserCard", "UserItem", "models.UserItem"}, 78 } 79 80 func TestTypeResolver_AdditionalItems(t *testing.T) { 81 _, resolver, err := basicTaskListResolver(t) 82 tpe := spec.StringProperty() 83 if assert.NoError(t, err) { 84 // arrays of primitives and string formats with additional formats 85 for _, val := range schTypeVals { 86 var sch spec.Schema 87 sch.Typed(val.Type, val.Format) 88 var coll spec.Schema 89 coll.Type = []string{"array"} 90 coll.Items = new(spec.SchemaOrArray) 91 coll.Items.Schema = tpe 92 coll.AdditionalItems = new(spec.SchemaOrBool) 93 coll.AdditionalItems.Schema = &sch 94 95 rt, err := resolver.ResolveSchema(&coll, true, true) 96 if assert.NoError(t, err) && assert.True(t, rt.IsArray) { 97 assert.True(t, rt.HasAdditionalItems) 98 assert.False(t, rt.IsNullable) 99 //if assert.NotNil(t, rt.ElementType) { 100 //assertPrimitiveResolve(t, "string", "", "string", *rt.ElementType) 101 //} 102 } 103 } 104 } 105 } 106 107 func TestTypeResolver_BasicTypes(t *testing.T) { 108 109 _, resolver, err := basicTaskListResolver(t) 110 if assert.NoError(t, err) { 111 112 // primitives and string formats 113 for _, val := range schTypeVals { 114 sch := new(spec.Schema) 115 sch.Typed(val.Type, val.Format) 116 117 rt, err := resolver.ResolveSchema(sch, true, false) 118 if assert.NoError(t, err) { 119 assert.False(t, rt.IsNullable, "expected %s with format %q to not be nullable", val.Type, val.Format) 120 assertPrimitiveResolve(t, val.Type, val.Format, val.Expected, rt) 121 } 122 } 123 124 // arrays of primitives and string formats 125 for _, val := range schTypeVals { 126 var sch spec.Schema 127 sch.Typed(val.Type, val.Format) 128 rt, err := resolver.ResolveSchema(new(spec.Schema).CollectionOf(sch), true, true) 129 if assert.NoError(t, err) { 130 assert.True(t, rt.IsArray) 131 assert.False(t, rt.IsEmptyOmitted) 132 } 133 134 s := new(spec.Schema).CollectionOf(sch) 135 s.AddExtension(xOmitEmpty, false) 136 rt, err = resolver.ResolveSchema(s, true, true) 137 if assert.NoError(t, err) { 138 assert.True(t, rt.IsArray) 139 assert.False(t, rt.IsEmptyOmitted) 140 } 141 142 s = new(spec.Schema).CollectionOf(sch) 143 s.AddExtension(xOmitEmpty, true) 144 rt, err = resolver.ResolveSchema(s, true, true) 145 if assert.NoError(t, err) { 146 assert.True(t, rt.IsArray) 147 assert.True(t, rt.IsEmptyOmitted) 148 } 149 } 150 151 // primitives and string formats 152 for _, val := range schTypeVals { 153 sch := new(spec.Schema) 154 sch.Typed(val.Type, val.Format) 155 sch.Extensions = make(spec.Extensions) 156 sch.Extensions[xIsNullable] = true 157 158 rt, err := resolver.ResolveSchema(sch, true, false) 159 if assert.NoError(t, err) { 160 if val.Type == "file" { 161 assert.False(t, rt.IsNullable, "expected %q (%q) to not be nullable", val.Type, val.Format) 162 } else { 163 assert.True(t, rt.IsNullable, "expected %q (%q) to be nullable", val.Type, val.Format) 164 } 165 assertPrimitiveResolve(t, val.Type, val.Format, val.Expected, rt) 166 } 167 168 // Test x-nullable overrides x-isnullable 169 sch.Extensions[xIsNullable] = false 170 sch.Extensions[xNullable] = true 171 rt, err = resolver.ResolveSchema(sch, true, true) 172 if assert.NoError(t, err) { 173 if val.Type == "file" { 174 assert.False(t, rt.IsNullable, "expected %q (%q) to not be nullable", val.Type, val.Format) 175 } else { 176 assert.True(t, rt.IsNullable, "expected %q (%q) to be nullable", val.Type, val.Format) 177 } 178 assertPrimitiveResolve(t, val.Type, val.Format, val.Expected, rt) 179 } 180 181 // Test x-nullable without x-isnullable 182 delete(sch.Extensions, xIsNullable) 183 sch.Extensions[xNullable] = true 184 rt, err = resolver.ResolveSchema(sch, true, true) 185 if assert.NoError(t, err) { 186 if val.Type == "file" { 187 assert.False(t, rt.IsNullable, "expected %q (%q) to not be nullable", val.Type, val.Format) 188 } else { 189 assert.True(t, rt.IsNullable, "expected %q (%q) to be nullable", val.Type, val.Format) 190 } 191 assertPrimitiveResolve(t, val.Type, val.Format, val.Expected, rt) 192 } 193 } 194 195 // arrays of primitives and string formats 196 for _, val := range schTypeVals { 197 var sch spec.Schema 198 sch.Typed(val.Type, val.Format) 199 sch.AddExtension(xIsNullable, true) 200 201 rt, err := resolver.ResolveSchema(new(spec.Schema).CollectionOf(sch), true, true) 202 if assert.NoError(t, err) { 203 assert.True(t, rt.IsArray) 204 } 205 } 206 207 } 208 209 } 210 211 func TestTypeResolver_Refs(t *testing.T) { 212 213 _, resolver, err := basicTaskListResolver(t) 214 if assert.NoError(t, err) { 215 216 // referenced objects 217 for _, val := range schRefVals { 218 sch := new(spec.Schema) 219 sch.Ref, _ = spec.NewRef("#/definitions/" + val.Type) 220 221 rt, err := resolver.ResolveSchema(sch, true, true) 222 if assert.NoError(t, err) { 223 assert.Equal(t, val.Expected, rt.GoType) 224 assert.False(t, rt.IsAnonymous) 225 assert.True(t, rt.IsNullable) 226 assert.Equal(t, "object", rt.SwaggerType) 227 } 228 } 229 230 // referenced array objects 231 for _, val := range schRefVals { 232 sch := new(spec.Schema) 233 sch.Ref, _ = spec.NewRef("#/definitions/" + val.Type) 234 235 rt, err := resolver.ResolveSchema(new(spec.Schema).CollectionOf(*sch), true, true) 236 if assert.NoError(t, err) { 237 assert.True(t, rt.IsArray) 238 assert.Equal(t, "[]"+val.Expected, rt.GoType) 239 } 240 } 241 // for named objects 242 // referenced objects 243 for _, val := range schRefVals { 244 sch := new(spec.Schema) 245 sch.Ref, _ = spec.NewRef("#/definitions/" + val.Type) 246 247 rt, err := resolver.ResolveSchema(sch, false, true) 248 if assert.NoError(t, err) { 249 assert.Equal(t, val.Expected, rt.GoType) 250 assert.False(t, rt.IsAnonymous) 251 assert.True(t, rt.IsNullable) 252 assert.Equal(t, "object", rt.SwaggerType) 253 } 254 } 255 256 // referenced array objects 257 for _, val := range schRefVals { 258 sch := new(spec.Schema) 259 sch.Ref, _ = spec.NewRef("#/definitions/" + val.Type) 260 261 rt, err := resolver.ResolveSchema(new(spec.Schema).CollectionOf(*sch), false, true) 262 if assert.NoError(t, err) { 263 assert.True(t, rt.IsArray) 264 assert.Equal(t, "[]"+val.Expected, rt.GoType) 265 } 266 } 267 } 268 } 269 270 func TestTypeResolver_AdditionalProperties(t *testing.T) { 271 _, resolver, err := basicTaskListResolver(t) 272 if assert.NoError(t, err) { 273 274 // primitives as additional properties 275 for _, val := range schTypeVals { 276 sch := new(spec.Schema) 277 278 sch.Typed(val.Type, val.Format) 279 parent := new(spec.Schema) 280 parent.AdditionalProperties = new(spec.SchemaOrBool) 281 parent.AdditionalProperties.Schema = sch 282 283 rt, err := resolver.ResolveSchema(parent, true, false) 284 if assert.NoError(t, err) { 285 assert.True(t, rt.IsMap) 286 assert.False(t, rt.IsComplexObject) 287 assert.Equal(t, "map[string]"+val.Expected, rt.GoType) 288 assert.Equal(t, "object", rt.SwaggerType) 289 } 290 } 291 292 // array of primitives as additional properties 293 for _, val := range schTypeVals { 294 sch := new(spec.Schema) 295 296 sch.Typed(val.Type, val.Format) 297 parent := new(spec.Schema) 298 parent.AdditionalProperties = new(spec.SchemaOrBool) 299 parent.AdditionalProperties.Schema = new(spec.Schema).CollectionOf(*sch) 300 301 rt, err := resolver.ResolveSchema(parent, true, false) 302 if assert.NoError(t, err) { 303 assert.True(t, rt.IsMap) 304 assert.False(t, rt.IsComplexObject) 305 assert.Equal(t, "map[string][]"+val.Expected, rt.GoType) 306 assert.Equal(t, "object", rt.SwaggerType) 307 } 308 } 309 310 // refs as additional properties 311 for _, val := range schRefVals { 312 sch := new(spec.Schema) 313 sch.Ref, _ = spec.NewRef("#/definitions/" + val.Type) 314 parent := new(spec.Schema) 315 parent.AdditionalProperties = new(spec.SchemaOrBool) 316 parent.AdditionalProperties.Schema = sch 317 318 rt, err := resolver.ResolveSchema(parent, true, true) 319 if assert.NoError(t, err) { 320 assert.True(t, rt.IsMap) 321 assert.False(t, rt.IsComplexObject) 322 assert.Equal(t, "map[string]"+val.Expected, rt.GoType) 323 assert.Equal(t, "object", rt.SwaggerType) 324 } 325 } 326 327 // when additional properties and properties present, it's a complex object 328 329 // primitives as additional properties 330 for _, val := range schTypeVals { 331 sch := new(spec.Schema) 332 333 sch.Typed(val.Type, val.Format) 334 parent := new(spec.Schema) 335 parent.Properties = make(map[string]spec.Schema) 336 parent.Properties["id"] = *spec.Int32Property() 337 parent.AdditionalProperties = new(spec.SchemaOrBool) 338 parent.AdditionalProperties.Schema = sch 339 340 rt, err := resolver.ResolveSchema(parent, true, true) 341 if assert.NoError(t, err) { 342 assert.True(t, rt.IsComplexObject) 343 assert.False(t, rt.IsMap) 344 assert.Equal(t, "map[string]"+val.Expected, rt.GoType) 345 assert.Equal(t, "object", rt.SwaggerType) 346 } 347 } 348 349 // array of primitives as additional properties 350 for _, val := range schTypeVals { 351 sch := new(spec.Schema) 352 353 sch.Typed(val.Type, val.Format) 354 parent := new(spec.Schema) 355 parent.Properties = make(map[string]spec.Schema) 356 parent.Properties["id"] = *spec.Int32Property() 357 parent.AdditionalProperties = new(spec.SchemaOrBool) 358 parent.AdditionalProperties.Schema = new(spec.Schema).CollectionOf(*sch) 359 360 rt, err := resolver.ResolveSchema(parent, true, true) 361 if assert.NoError(t, err) { 362 assert.True(t, rt.IsComplexObject) 363 assert.False(t, rt.IsMap) 364 assert.Equal(t, "map[string][]"+val.Expected, rt.GoType) 365 assert.Equal(t, "object", rt.SwaggerType) 366 } 367 } 368 369 // refs as additional properties 370 for _, val := range schRefVals { 371 sch := new(spec.Schema) 372 sch.Ref, _ = spec.NewRef("#/definitions/" + val.Type) 373 parent := new(spec.Schema) 374 parent.Properties = make(map[string]spec.Schema) 375 parent.Properties["id"] = *spec.Int32Property() 376 parent.AdditionalProperties = new(spec.SchemaOrBool) 377 parent.AdditionalProperties.Schema = sch 378 379 rt, err := resolver.ResolveSchema(parent, true, true) 380 if assert.NoError(t, err) { 381 assert.True(t, rt.IsComplexObject) 382 assert.False(t, rt.IsMap) 383 assert.Equal(t, "map[string]"+val.Expected, rt.GoType) 384 assert.Equal(t, "object", rt.SwaggerType) 385 } 386 } 387 388 } 389 } 390 391 func TestTypeResolver_Notables(t *testing.T) { 392 doc, resolver, err := specResolver(t, "../fixtures/codegen/todolist.models.yml") 393 if assert.NoError(t, err) { 394 def := doc.Spec().Definitions["Notables"] 395 rest, err := resolver.ResolveSchema(&def, false, true) 396 if assert.NoError(t, err) { 397 assert.True(t, rest.IsArray) 398 assert.False(t, rest.IsAnonymous) 399 assert.False(t, rest.IsNullable) 400 assert.Equal(t, "[]models.Notable", rest.GoType) 401 } 402 } 403 } 404 405 func specResolver(t testing.TB, path string) (*loads.Document, *typeResolver, error) { 406 tlb, err := loads.Spec(path) 407 if err != nil { 408 return nil, nil, err 409 } 410 resolver := &typeResolver{ 411 Doc: tlb, 412 ModelsPackage: "models", 413 } 414 resolver.KnownDefs = make(map[string]struct{}) 415 for k := range tlb.Spec().Definitions { 416 resolver.KnownDefs[k] = struct{}{} 417 } 418 return tlb, resolver, nil 419 } 420 421 func basicTaskListResolver(t testing.TB) (*loads.Document, *typeResolver, error) { 422 tlb, err := loads.Spec("../fixtures/codegen/tasklist.basic.yml") 423 if err != nil { 424 return nil, nil, err 425 } 426 swsp := tlb.Spec() 427 uc := swsp.Definitions["UserCard"] 428 uc.AddExtension(xGoName, "UserItem") 429 swsp.Definitions["UserCard"] = uc 430 resolver := &typeResolver{ 431 Doc: tlb, 432 ModelsPackage: "models", 433 } 434 435 resolver.KnownDefs = make(map[string]struct{}) 436 for k, sch := range swsp.Definitions { 437 resolver.KnownDefs[k] = struct{}{} 438 if nm, ok := sch.Extensions[xGoName]; ok { 439 resolver.KnownDefs[nm.(string)] = struct{}{} 440 } 441 } 442 return tlb, resolver, nil 443 } 444 445 func TestTypeResolver_TupleTypes(t *testing.T) { 446 _, resolver, err := basicTaskListResolver(t) 447 if assert.NoError(t, err) { 448 // tuple type (items with multiple schemas) 449 parent := new(spec.Schema) 450 parent.Typed("array", "") 451 parent.Items = new(spec.SchemaOrArray) 452 parent.Items.Schemas = append( 453 parent.Items.Schemas, 454 *spec.StringProperty(), 455 *spec.Int64Property(), 456 *spec.Float64Property(), 457 *spec.BoolProperty(), 458 *spec.ArrayProperty(spec.StringProperty()), 459 *spec.RefProperty("#/definitions/Comment"), 460 ) 461 462 rt, err := resolver.ResolveSchema(parent, true, true) 463 if assert.NoError(t, err) { 464 assert.False(t, rt.IsArray) 465 assert.True(t, rt.IsTuple) 466 } 467 } 468 } 469 func TestTypeResolver_AnonymousStructs(t *testing.T) { 470 471 _, resolver, err := basicTaskListResolver(t) 472 if assert.NoError(t, err) { 473 // anonymous structs should be accounted for 474 parent := new(spec.Schema) 475 parent.Typed("object", "") 476 parent.Properties = make(map[string]spec.Schema) 477 parent.Properties["name"] = *spec.StringProperty() 478 parent.Properties["age"] = *spec.Int32Property() 479 480 rt, err := resolver.ResolveSchema(parent, true, true) 481 if assert.NoError(t, err) { 482 assert.True(t, rt.IsNullable) 483 assert.True(t, rt.IsAnonymous) 484 assert.True(t, rt.IsComplexObject) 485 } 486 487 parent.Extensions = make(spec.Extensions) 488 parent.Extensions[xIsNullable] = true 489 490 rt, err = resolver.ResolveSchema(parent, true, true) 491 if assert.NoError(t, err) { 492 assert.True(t, rt.IsNullable) 493 assert.True(t, rt.IsAnonymous) 494 assert.True(t, rt.IsComplexObject) 495 } 496 497 // Also test that it's nullable with just x-nullable 498 parent.Extensions[xIsNullable] = false 499 parent.Extensions[xNullable] = false 500 501 rt, err = resolver.ResolveSchema(parent, true, true) 502 if assert.NoError(t, err) { 503 assert.False(t, rt.IsNullable) 504 assert.True(t, rt.IsAnonymous) 505 assert.True(t, rt.IsComplexObject) 506 } 507 } 508 } 509 func TestTypeResolver_ObjectType(t *testing.T) { 510 _, resolver, err := basicTaskListResolver(t) 511 resolver.ModelName = "TheModel" 512 resolver.KnownDefs["TheModel"] = struct{}{} 513 defer func() { resolver.ModelName = "" }() 514 515 if assert.NoError(t, err) { 516 //very poor schema definitions (as in none) 517 types := []string{"object", ""} 518 for _, tpe := range types { 519 sch := new(spec.Schema) 520 sch.Typed(tpe, "") 521 rt, err := resolver.ResolveSchema(sch, true, true) 522 if assert.NoError(t, err) { 523 assert.True(t, rt.IsMap) 524 assert.False(t, rt.IsComplexObject) 525 assert.Equal(t, "interface{}", rt.GoType) 526 assert.Equal(t, "object", rt.SwaggerType) 527 } 528 529 sch.Properties = make(map[string]spec.Schema) 530 var ss spec.Schema 531 sch.Properties["tags"] = *(&ss).CollectionOf(*spec.StringProperty()) 532 rt, err = resolver.ResolveSchema(sch, false, true) 533 assert.NoError(t, err) 534 assert.True(t, rt.IsComplexObject) 535 assert.False(t, rt.IsMap) 536 assert.Equal(t, "models.TheModel", rt.GoType) 537 assert.Equal(t, "object", rt.SwaggerType) 538 539 sch.Properties = nil 540 nsch := new(spec.Schema) 541 nsch.Typed(tpe, "") 542 nsch.AllOf = []spec.Schema{*sch} 543 rt, err = resolver.ResolveSchema(nsch, false, true) 544 if assert.NoError(t, err) { 545 assert.True(t, rt.IsComplexObject) 546 assert.False(t, rt.IsMap) 547 assert.Equal(t, "models.TheModel", rt.GoType) 548 assert.Equal(t, "object", rt.SwaggerType) 549 } 550 } 551 sch := new(spec.Schema) 552 rt, err := resolver.ResolveSchema(sch, true, true) 553 if assert.NoError(t, err) { 554 assert.True(t, rt.IsMap) 555 assert.False(t, rt.IsComplexObject) 556 assert.Equal(t, "interface{}", rt.GoType) 557 assert.Equal(t, "object", rt.SwaggerType) 558 559 } 560 sch = new(spec.Schema) 561 var sp spec.Schema 562 sp.Typed("object", "") 563 sch.AllOf = []spec.Schema{sp} 564 rt, err = resolver.ResolveSchema(sch, true, true) 565 if assert.NoError(t, err) { 566 assert.True(t, rt.IsComplexObject) 567 assert.False(t, rt.IsMap) 568 assert.Equal(t, "models.TheModel", rt.GoType) 569 assert.Equal(t, "object", rt.SwaggerType) 570 } 571 } 572 } 573 574 func TestTypeResolver_AliasTypes(t *testing.T) { 575 doc, resolver, err := basicTaskListResolver(t) 576 if assert.NoError(t, err) { 577 resolver.ModelsPackage = "" 578 resolver.ModelName = "Currency" 579 defer func() { 580 resolver.ModelName = "" 581 resolver.ModelsPackage = "models" 582 }() 583 defs := doc.Spec().Definitions[resolver.ModelName] 584 rt, err := resolver.ResolveSchema(&defs, false, true) 585 if assert.NoError(t, err) { 586 assert.False(t, rt.IsAnonymous) 587 assert.True(t, rt.IsAliased) 588 assert.True(t, rt.IsPrimitive) 589 assert.Equal(t, "Currency", rt.GoType) 590 assert.Equal(t, "string", rt.AliasedType) 591 } 592 } 593 } 594 595 func assertPrimitiveResolve(t testing.TB, tpe, tfmt, exp string, tr resolvedType) { 596 assert.Equal(t, tpe, tr.SwaggerType, fmt.Sprintf("expected %q (%q, %q) to for the swagger type but got %q", tpe, tfmt, exp, tr.SwaggerType)) 597 assert.Equal(t, tfmt, tr.SwaggerFormat, fmt.Sprintf("expected %q (%q, %q) to for the swagger format but got %q", tfmt, tpe, exp, tr.SwaggerFormat)) 598 assert.Equal(t, exp, tr.GoType, fmt.Sprintf("expected %q (%q, %q) to for the go type but got %q", exp, tpe, tfmt, tr.GoType)) 599 } 600 601 func TestTypeResolver_ExistingModel(t *testing.T) { 602 doc, err := loads.Spec("../fixtures/codegen/existing-model.yml") 603 resolver := newTypeResolver("model", doc) 604 if assert.NoError(t, err) { 605 def := doc.Spec().Definitions["JsonWebKey"] 606 tpe, pkg, alias := knownDefGoType("JsonWebKey", def, nil) 607 assert.Equal(t, "jwk.Key", tpe) 608 assert.Equal(t, "github.com/user/package", pkg) 609 assert.Equal(t, "jwk", alias) 610 rest, err := resolver.ResolveSchema(&def, false, true) 611 if assert.NoError(t, err) { 612 assert.False(t, rest.IsMap) 613 assert.False(t, rest.IsArray) 614 assert.False(t, rest.IsTuple) 615 assert.False(t, rest.IsStream) 616 assert.False(t, rest.IsAliased) 617 assert.False(t, rest.IsBaseType) 618 assert.False(t, rest.IsInterface) 619 assert.True(t, rest.IsNullable) 620 assert.False(t, rest.IsPrimitive) 621 assert.False(t, rest.IsAnonymous) 622 assert.True(t, rest.IsComplexObject) 623 assert.False(t, rest.IsCustomFormatter) 624 assert.Equal(t, "jwk.Key", rest.GoType) 625 assert.Equal(t, "github.com/user/package", rest.Pkg) 626 assert.Equal(t, "jwk", rest.PkgAlias) 627 } 628 def = doc.Spec().Definitions["JsonWebKeySet"].Properties["keys"] 629 rest, err = resolver.ResolveSchema(&def, false, true) 630 if assert.NoError(t, err) { 631 assert.False(t, rest.IsMap) 632 assert.True(t, rest.IsArray) 633 assert.False(t, rest.IsTuple) 634 assert.False(t, rest.IsStream) 635 assert.False(t, rest.IsAliased) 636 assert.False(t, rest.IsBaseType) 637 assert.False(t, rest.IsInterface) 638 assert.False(t, rest.IsNullable) 639 assert.False(t, rest.IsPrimitive) 640 assert.False(t, rest.IsAnonymous) 641 assert.False(t, rest.IsComplexObject) 642 assert.False(t, rest.IsCustomFormatter) 643 assert.Equal(t, "[]jwk.Key", rest.GoType) 644 assert.Equal(t, "", rest.Pkg) 645 assert.Equal(t, "", rest.PkgAlias) 646 } 647 } 648 }