How to use New method of compiler Package

Best K6 code snippet using compiler.New

OpenAPIv2.go

Source:OpenAPIv2.go Github

copy

Full Screen

...21)22func Version() string {23 return "openapi_v2"24}25func NewAdditionalPropertiesItem(in interface{}, context *compiler.Context) (*AdditionalPropertiesItem, error) {26 errors := make([]error, 0)27 x := &AdditionalPropertiesItem{}28 matched := false29 // Schema schema = 1;30 {31 m, ok := compiler.UnpackMap(in)32 if ok {33 // errors might be ok here, they mean we just don't have the right subtype34 t, matching_error := NewSchema(m, compiler.NewContext("schema", context))35 if matching_error == nil {36 x.Oneof = &AdditionalPropertiesItem_Schema{Schema: t}37 matched = true38 } else {39 errors = append(errors, matching_error)40 }41 }42 }43 // bool boolean = 2;44 boolValue, ok := in.(bool)45 if ok {46 x.Oneof = &AdditionalPropertiesItem_Boolean{Boolean: boolValue}47 }48 if matched {49 // since the oneof matched one of its possibilities, discard any matching errors50 errors = make([]error, 0)51 }52 return x, compiler.NewErrorGroupOrNil(errors)53}54func NewAny(in interface{}, context *compiler.Context) (*Any, error) {55 errors := make([]error, 0)56 x := &Any{}57 bytes, _ := yaml.Marshal(in)58 x.Yaml = string(bytes)59 return x, compiler.NewErrorGroupOrNil(errors)60}61func NewApiKeySecurity(in interface{}, context *compiler.Context) (*ApiKeySecurity, error) {62 errors := make([]error, 0)63 x := &ApiKeySecurity{}64 m, ok := compiler.UnpackMap(in)65 if !ok {66 message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)67 errors = append(errors, compiler.NewError(context, message))68 } else {69 requiredKeys := []string{"in", "name", "type"}70 missingKeys := compiler.MissingKeysInMap(m, requiredKeys)71 if len(missingKeys) > 0 {72 message := fmt.Sprintf("is missing required %s: %+v", compiler.PluralProperties(len(missingKeys)), strings.Join(missingKeys, ", "))73 errors = append(errors, compiler.NewError(context, message))74 }75 allowedKeys := []string{"description", "in", "name", "type"}76 allowedPatterns := []string{"^x-"}77 invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)78 if len(invalidKeys) > 0 {79 message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))80 errors = append(errors, compiler.NewError(context, message))81 }82 // string type = 1;83 v1 := compiler.MapValueForKey(m, "type")84 if v1 != nil {85 x.Type, ok = v1.(string)86 if !ok {87 message := fmt.Sprintf("has unexpected value for type: %+v (%T)", v1, v1)88 errors = append(errors, compiler.NewError(context, message))89 }90 // check for valid enum values91 // [apiKey]92 if ok && !compiler.StringArrayContainsValue([]string{"apiKey"}, x.Type) {93 message := fmt.Sprintf("has unexpected value for type: %+v (%T)", v1, v1)94 errors = append(errors, compiler.NewError(context, message))95 }96 }97 // string name = 2;98 v2 := compiler.MapValueForKey(m, "name")99 if v2 != nil {100 x.Name, ok = v2.(string)101 if !ok {102 message := fmt.Sprintf("has unexpected value for name: %+v (%T)", v2, v2)103 errors = append(errors, compiler.NewError(context, message))104 }105 }106 // string in = 3;107 v3 := compiler.MapValueForKey(m, "in")108 if v3 != nil {109 x.In, ok = v3.(string)110 if !ok {111 message := fmt.Sprintf("has unexpected value for in: %+v (%T)", v3, v3)112 errors = append(errors, compiler.NewError(context, message))113 }114 // check for valid enum values115 // [header query]116 if ok && !compiler.StringArrayContainsValue([]string{"header", "query"}, x.In) {117 message := fmt.Sprintf("has unexpected value for in: %+v (%T)", v3, v3)118 errors = append(errors, compiler.NewError(context, message))119 }120 }121 // string description = 4;122 v4 := compiler.MapValueForKey(m, "description")123 if v4 != nil {124 x.Description, ok = v4.(string)125 if !ok {126 message := fmt.Sprintf("has unexpected value for description: %+v (%T)", v4, v4)127 errors = append(errors, compiler.NewError(context, message))128 }129 }130 // repeated NamedAny vendor_extension = 5;131 // MAP: Any ^x-132 x.VendorExtension = make([]*NamedAny, 0)133 for _, item := range m {134 k, ok := item.Key.(string)135 if ok {136 v := item.Value137 if compiler.PatternMatches("^x-", k) {138 pair := &NamedAny{}139 pair.Name = k140 result := &Any{}141 handled, resultFromExt, err := compiler.HandleExtension(context, v, k)142 if handled {143 if err != nil {144 errors = append(errors, err)145 } else {146 bytes, _ := yaml.Marshal(v)147 result.Yaml = string(bytes)148 result.Value = resultFromExt149 pair.Value = result150 }151 } else {152 pair.Value, err = NewAny(v, compiler.NewContext(k, context))153 if err != nil {154 errors = append(errors, err)155 }156 }157 x.VendorExtension = append(x.VendorExtension, pair)158 }159 }160 }161 }162 return x, compiler.NewErrorGroupOrNil(errors)163}164func NewBasicAuthenticationSecurity(in interface{}, context *compiler.Context) (*BasicAuthenticationSecurity, error) {165 errors := make([]error, 0)166 x := &BasicAuthenticationSecurity{}167 m, ok := compiler.UnpackMap(in)168 if !ok {169 message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)170 errors = append(errors, compiler.NewError(context, message))171 } else {172 requiredKeys := []string{"type"}173 missingKeys := compiler.MissingKeysInMap(m, requiredKeys)174 if len(missingKeys) > 0 {175 message := fmt.Sprintf("is missing required %s: %+v", compiler.PluralProperties(len(missingKeys)), strings.Join(missingKeys, ", "))176 errors = append(errors, compiler.NewError(context, message))177 }178 allowedKeys := []string{"description", "type"}179 allowedPatterns := []string{"^x-"}180 invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)181 if len(invalidKeys) > 0 {182 message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))183 errors = append(errors, compiler.NewError(context, message))184 }185 // string type = 1;186 v1 := compiler.MapValueForKey(m, "type")187 if v1 != nil {188 x.Type, ok = v1.(string)189 if !ok {190 message := fmt.Sprintf("has unexpected value for type: %+v (%T)", v1, v1)191 errors = append(errors, compiler.NewError(context, message))192 }193 // check for valid enum values194 // [basic]195 if ok && !compiler.StringArrayContainsValue([]string{"basic"}, x.Type) {196 message := fmt.Sprintf("has unexpected value for type: %+v (%T)", v1, v1)197 errors = append(errors, compiler.NewError(context, message))198 }199 }200 // string description = 2;201 v2 := compiler.MapValueForKey(m, "description")202 if v2 != nil {203 x.Description, ok = v2.(string)204 if !ok {205 message := fmt.Sprintf("has unexpected value for description: %+v (%T)", v2, v2)206 errors = append(errors, compiler.NewError(context, message))207 }208 }209 // repeated NamedAny vendor_extension = 3;210 // MAP: Any ^x-211 x.VendorExtension = make([]*NamedAny, 0)212 for _, item := range m {213 k, ok := item.Key.(string)214 if ok {215 v := item.Value216 if compiler.PatternMatches("^x-", k) {217 pair := &NamedAny{}218 pair.Name = k219 result := &Any{}220 handled, resultFromExt, err := compiler.HandleExtension(context, v, k)221 if handled {222 if err != nil {223 errors = append(errors, err)224 } else {225 bytes, _ := yaml.Marshal(v)226 result.Yaml = string(bytes)227 result.Value = resultFromExt228 pair.Value = result229 }230 } else {231 pair.Value, err = NewAny(v, compiler.NewContext(k, context))232 if err != nil {233 errors = append(errors, err)234 }235 }236 x.VendorExtension = append(x.VendorExtension, pair)237 }238 }239 }240 }241 return x, compiler.NewErrorGroupOrNil(errors)242}243func NewBodyParameter(in interface{}, context *compiler.Context) (*BodyParameter, error) {244 errors := make([]error, 0)245 x := &BodyParameter{}246 m, ok := compiler.UnpackMap(in)247 if !ok {248 message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)249 errors = append(errors, compiler.NewError(context, message))250 } else {251 requiredKeys := []string{"in", "name", "schema"}252 missingKeys := compiler.MissingKeysInMap(m, requiredKeys)253 if len(missingKeys) > 0 {254 message := fmt.Sprintf("is missing required %s: %+v", compiler.PluralProperties(len(missingKeys)), strings.Join(missingKeys, ", "))255 errors = append(errors, compiler.NewError(context, message))256 }257 allowedKeys := []string{"description", "in", "name", "required", "schema"}258 allowedPatterns := []string{"^x-"}259 invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)260 if len(invalidKeys) > 0 {261 message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))262 errors = append(errors, compiler.NewError(context, message))263 }264 // string description = 1;265 v1 := compiler.MapValueForKey(m, "description")266 if v1 != nil {267 x.Description, ok = v1.(string)268 if !ok {269 message := fmt.Sprintf("has unexpected value for description: %+v (%T)", v1, v1)270 errors = append(errors, compiler.NewError(context, message))271 }272 }273 // string name = 2;274 v2 := compiler.MapValueForKey(m, "name")275 if v2 != nil {276 x.Name, ok = v2.(string)277 if !ok {278 message := fmt.Sprintf("has unexpected value for name: %+v (%T)", v2, v2)279 errors = append(errors, compiler.NewError(context, message))280 }281 }282 // string in = 3;283 v3 := compiler.MapValueForKey(m, "in")284 if v3 != nil {285 x.In, ok = v3.(string)286 if !ok {287 message := fmt.Sprintf("has unexpected value for in: %+v (%T)", v3, v3)288 errors = append(errors, compiler.NewError(context, message))289 }290 // check for valid enum values291 // [body]292 if ok && !compiler.StringArrayContainsValue([]string{"body"}, x.In) {293 message := fmt.Sprintf("has unexpected value for in: %+v (%T)", v3, v3)294 errors = append(errors, compiler.NewError(context, message))295 }296 }297 // bool required = 4;298 v4 := compiler.MapValueForKey(m, "required")299 if v4 != nil {300 x.Required, ok = v4.(bool)301 if !ok {302 message := fmt.Sprintf("has unexpected value for required: %+v (%T)", v4, v4)303 errors = append(errors, compiler.NewError(context, message))304 }305 }306 // Schema schema = 5;307 v5 := compiler.MapValueForKey(m, "schema")308 if v5 != nil {309 var err error310 x.Schema, err = NewSchema(v5, compiler.NewContext("schema", context))311 if err != nil {312 errors = append(errors, err)313 }314 }315 // repeated NamedAny vendor_extension = 6;316 // MAP: Any ^x-317 x.VendorExtension = make([]*NamedAny, 0)318 for _, item := range m {319 k, ok := item.Key.(string)320 if ok {321 v := item.Value322 if compiler.PatternMatches("^x-", k) {323 pair := &NamedAny{}324 pair.Name = k325 result := &Any{}326 handled, resultFromExt, err := compiler.HandleExtension(context, v, k)327 if handled {328 if err != nil {329 errors = append(errors, err)330 } else {331 bytes, _ := yaml.Marshal(v)332 result.Yaml = string(bytes)333 result.Value = resultFromExt334 pair.Value = result335 }336 } else {337 pair.Value, err = NewAny(v, compiler.NewContext(k, context))338 if err != nil {339 errors = append(errors, err)340 }341 }342 x.VendorExtension = append(x.VendorExtension, pair)343 }344 }345 }346 }347 return x, compiler.NewErrorGroupOrNil(errors)348}349func NewContact(in interface{}, context *compiler.Context) (*Contact, error) {350 errors := make([]error, 0)351 x := &Contact{}352 m, ok := compiler.UnpackMap(in)353 if !ok {354 message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)355 errors = append(errors, compiler.NewError(context, message))356 } else {357 allowedKeys := []string{"email", "name", "url"}358 allowedPatterns := []string{"^x-"}359 invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)360 if len(invalidKeys) > 0 {361 message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))362 errors = append(errors, compiler.NewError(context, message))363 }364 // string name = 1;365 v1 := compiler.MapValueForKey(m, "name")366 if v1 != nil {367 x.Name, ok = v1.(string)368 if !ok {369 message := fmt.Sprintf("has unexpected value for name: %+v (%T)", v1, v1)370 errors = append(errors, compiler.NewError(context, message))371 }372 }373 // string url = 2;374 v2 := compiler.MapValueForKey(m, "url")375 if v2 != nil {376 x.Url, ok = v2.(string)377 if !ok {378 message := fmt.Sprintf("has unexpected value for url: %+v (%T)", v2, v2)379 errors = append(errors, compiler.NewError(context, message))380 }381 }382 // string email = 3;383 v3 := compiler.MapValueForKey(m, "email")384 if v3 != nil {385 x.Email, ok = v3.(string)386 if !ok {387 message := fmt.Sprintf("has unexpected value for email: %+v (%T)", v3, v3)388 errors = append(errors, compiler.NewError(context, message))389 }390 }391 // repeated NamedAny vendor_extension = 4;392 // MAP: Any ^x-393 x.VendorExtension = make([]*NamedAny, 0)394 for _, item := range m {395 k, ok := item.Key.(string)396 if ok {397 v := item.Value398 if compiler.PatternMatches("^x-", k) {399 pair := &NamedAny{}400 pair.Name = k401 result := &Any{}402 handled, resultFromExt, err := compiler.HandleExtension(context, v, k)403 if handled {404 if err != nil {405 errors = append(errors, err)406 } else {407 bytes, _ := yaml.Marshal(v)408 result.Yaml = string(bytes)409 result.Value = resultFromExt410 pair.Value = result411 }412 } else {413 pair.Value, err = NewAny(v, compiler.NewContext(k, context))414 if err != nil {415 errors = append(errors, err)416 }417 }418 x.VendorExtension = append(x.VendorExtension, pair)419 }420 }421 }422 }423 return x, compiler.NewErrorGroupOrNil(errors)424}425func NewDefault(in interface{}, context *compiler.Context) (*Default, error) {426 errors := make([]error, 0)427 x := &Default{}428 m, ok := compiler.UnpackMap(in)429 if !ok {430 message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)431 errors = append(errors, compiler.NewError(context, message))432 } else {433 // repeated NamedAny additional_properties = 1;434 // MAP: Any435 x.AdditionalProperties = make([]*NamedAny, 0)436 for _, item := range m {437 k, ok := item.Key.(string)438 if ok {439 v := item.Value440 pair := &NamedAny{}441 pair.Name = k442 result := &Any{}443 handled, resultFromExt, err := compiler.HandleExtension(context, v, k)444 if handled {445 if err != nil {446 errors = append(errors, err)447 } else {448 bytes, _ := yaml.Marshal(v)449 result.Yaml = string(bytes)450 result.Value = resultFromExt451 pair.Value = result452 }453 } else {454 pair.Value, err = NewAny(v, compiler.NewContext(k, context))455 if err != nil {456 errors = append(errors, err)457 }458 }459 x.AdditionalProperties = append(x.AdditionalProperties, pair)460 }461 }462 }463 return x, compiler.NewErrorGroupOrNil(errors)464}465func NewDefinitions(in interface{}, context *compiler.Context) (*Definitions, error) {466 errors := make([]error, 0)467 x := &Definitions{}468 m, ok := compiler.UnpackMap(in)469 if !ok {470 message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)471 errors = append(errors, compiler.NewError(context, message))472 } else {473 // repeated NamedSchema additional_properties = 1;474 // MAP: Schema475 x.AdditionalProperties = make([]*NamedSchema, 0)476 for _, item := range m {477 k, ok := item.Key.(string)478 if ok {479 v := item.Value480 pair := &NamedSchema{}481 pair.Name = k482 var err error483 pair.Value, err = NewSchema(v, compiler.NewContext(k, context))484 if err != nil {485 errors = append(errors, err)486 }487 x.AdditionalProperties = append(x.AdditionalProperties, pair)488 }489 }490 }491 return x, compiler.NewErrorGroupOrNil(errors)492}493func NewDocument(in interface{}, context *compiler.Context) (*Document, error) {494 errors := make([]error, 0)495 x := &Document{}496 m, ok := compiler.UnpackMap(in)497 if !ok {498 message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)499 errors = append(errors, compiler.NewError(context, message))500 } else {501 requiredKeys := []string{"info", "paths", "swagger"}502 missingKeys := compiler.MissingKeysInMap(m, requiredKeys)503 if len(missingKeys) > 0 {504 message := fmt.Sprintf("is missing required %s: %+v", compiler.PluralProperties(len(missingKeys)), strings.Join(missingKeys, ", "))505 errors = append(errors, compiler.NewError(context, message))506 }507 allowedKeys := []string{"basePath", "consumes", "definitions", "externalDocs", "host", "info", "parameters", "paths", "produces", "responses", "schemes", "security", "securityDefinitions", "swagger", "tags"}508 allowedPatterns := []string{"^x-"}509 invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)510 if len(invalidKeys) > 0 {511 message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))512 errors = append(errors, compiler.NewError(context, message))513 }514 // string swagger = 1;515 v1 := compiler.MapValueForKey(m, "swagger")516 if v1 != nil {517 x.Swagger, ok = v1.(string)518 if !ok {519 message := fmt.Sprintf("has unexpected value for swagger: %+v (%T)", v1, v1)520 errors = append(errors, compiler.NewError(context, message))521 }522 // check for valid enum values523 // [2.0]524 if ok && !compiler.StringArrayContainsValue([]string{"2.0"}, x.Swagger) {525 message := fmt.Sprintf("has unexpected value for swagger: %+v (%T)", v1, v1)526 errors = append(errors, compiler.NewError(context, message))527 }528 }529 // Info info = 2;530 v2 := compiler.MapValueForKey(m, "info")531 if v2 != nil {532 var err error533 x.Info, err = NewInfo(v2, compiler.NewContext("info", context))534 if err != nil {535 errors = append(errors, err)536 }537 }538 // string host = 3;539 v3 := compiler.MapValueForKey(m, "host")540 if v3 != nil {541 x.Host, ok = v3.(string)542 if !ok {543 message := fmt.Sprintf("has unexpected value for host: %+v (%T)", v3, v3)544 errors = append(errors, compiler.NewError(context, message))545 }546 }547 // string base_path = 4;548 v4 := compiler.MapValueForKey(m, "basePath")549 if v4 != nil {550 x.BasePath, ok = v4.(string)551 if !ok {552 message := fmt.Sprintf("has unexpected value for basePath: %+v (%T)", v4, v4)553 errors = append(errors, compiler.NewError(context, message))554 }555 }556 // repeated string schemes = 5;557 v5 := compiler.MapValueForKey(m, "schemes")558 if v5 != nil {559 v, ok := v5.([]interface{})560 if ok {561 x.Schemes = compiler.ConvertInterfaceArrayToStringArray(v)562 } else {563 message := fmt.Sprintf("has unexpected value for schemes: %+v (%T)", v5, v5)564 errors = append(errors, compiler.NewError(context, message))565 }566 // check for valid enum values567 // [http https ws wss]568 if ok && !compiler.StringArrayContainsValues([]string{"http", "https", "ws", "wss"}, x.Schemes) {569 message := fmt.Sprintf("has unexpected value for schemes: %+v", v5)570 errors = append(errors, compiler.NewError(context, message))571 }572 }573 // repeated string consumes = 6;574 v6 := compiler.MapValueForKey(m, "consumes")575 if v6 != nil {576 v, ok := v6.([]interface{})577 if ok {578 x.Consumes = compiler.ConvertInterfaceArrayToStringArray(v)579 } else {580 message := fmt.Sprintf("has unexpected value for consumes: %+v (%T)", v6, v6)581 errors = append(errors, compiler.NewError(context, message))582 }583 }584 // repeated string produces = 7;585 v7 := compiler.MapValueForKey(m, "produces")586 if v7 != nil {587 v, ok := v7.([]interface{})588 if ok {589 x.Produces = compiler.ConvertInterfaceArrayToStringArray(v)590 } else {591 message := fmt.Sprintf("has unexpected value for produces: %+v (%T)", v7, v7)592 errors = append(errors, compiler.NewError(context, message))593 }594 }595 // Paths paths = 8;596 v8 := compiler.MapValueForKey(m, "paths")597 if v8 != nil {598 var err error599 x.Paths, err = NewPaths(v8, compiler.NewContext("paths", context))600 if err != nil {601 errors = append(errors, err)602 }603 }604 // Definitions definitions = 9;605 v9 := compiler.MapValueForKey(m, "definitions")606 if v9 != nil {607 var err error608 x.Definitions, err = NewDefinitions(v9, compiler.NewContext("definitions", context))609 if err != nil {610 errors = append(errors, err)611 }612 }613 // ParameterDefinitions parameters = 10;614 v10 := compiler.MapValueForKey(m, "parameters")615 if v10 != nil {616 var err error617 x.Parameters, err = NewParameterDefinitions(v10, compiler.NewContext("parameters", context))618 if err != nil {619 errors = append(errors, err)620 }621 }622 // ResponseDefinitions responses = 11;623 v11 := compiler.MapValueForKey(m, "responses")624 if v11 != nil {625 var err error626 x.Responses, err = NewResponseDefinitions(v11, compiler.NewContext("responses", context))627 if err != nil {628 errors = append(errors, err)629 }630 }631 // repeated SecurityRequirement security = 12;632 v12 := compiler.MapValueForKey(m, "security")633 if v12 != nil {634 // repeated SecurityRequirement635 x.Security = make([]*SecurityRequirement, 0)636 a, ok := v12.([]interface{})637 if ok {638 for _, item := range a {639 y, err := NewSecurityRequirement(item, compiler.NewContext("security", context))640 if err != nil {641 errors = append(errors, err)642 }643 x.Security = append(x.Security, y)644 }645 }646 }647 // SecurityDefinitions security_definitions = 13;648 v13 := compiler.MapValueForKey(m, "securityDefinitions")649 if v13 != nil {650 var err error651 x.SecurityDefinitions, err = NewSecurityDefinitions(v13, compiler.NewContext("securityDefinitions", context))652 if err != nil {653 errors = append(errors, err)654 }655 }656 // repeated Tag tags = 14;657 v14 := compiler.MapValueForKey(m, "tags")658 if v14 != nil {659 // repeated Tag660 x.Tags = make([]*Tag, 0)661 a, ok := v14.([]interface{})662 if ok {663 for _, item := range a {664 y, err := NewTag(item, compiler.NewContext("tags", context))665 if err != nil {666 errors = append(errors, err)667 }668 x.Tags = append(x.Tags, y)669 }670 }671 }672 // ExternalDocs external_docs = 15;673 v15 := compiler.MapValueForKey(m, "externalDocs")674 if v15 != nil {675 var err error676 x.ExternalDocs, err = NewExternalDocs(v15, compiler.NewContext("externalDocs", context))677 if err != nil {678 errors = append(errors, err)679 }680 }681 // repeated NamedAny vendor_extension = 16;682 // MAP: Any ^x-683 x.VendorExtension = make([]*NamedAny, 0)684 for _, item := range m {685 k, ok := item.Key.(string)686 if ok {687 v := item.Value688 if compiler.PatternMatches("^x-", k) {689 pair := &NamedAny{}690 pair.Name = k691 result := &Any{}692 handled, resultFromExt, err := compiler.HandleExtension(context, v, k)693 if handled {694 if err != nil {695 errors = append(errors, err)696 } else {697 bytes, _ := yaml.Marshal(v)698 result.Yaml = string(bytes)699 result.Value = resultFromExt700 pair.Value = result701 }702 } else {703 pair.Value, err = NewAny(v, compiler.NewContext(k, context))704 if err != nil {705 errors = append(errors, err)706 }707 }708 x.VendorExtension = append(x.VendorExtension, pair)709 }710 }711 }712 }713 return x, compiler.NewErrorGroupOrNil(errors)714}715func NewExamples(in interface{}, context *compiler.Context) (*Examples, error) {716 errors := make([]error, 0)717 x := &Examples{}718 m, ok := compiler.UnpackMap(in)719 if !ok {720 message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)721 errors = append(errors, compiler.NewError(context, message))722 } else {723 // repeated NamedAny additional_properties = 1;724 // MAP: Any725 x.AdditionalProperties = make([]*NamedAny, 0)726 for _, item := range m {727 k, ok := item.Key.(string)728 if ok {729 v := item.Value730 pair := &NamedAny{}731 pair.Name = k732 result := &Any{}733 handled, resultFromExt, err := compiler.HandleExtension(context, v, k)734 if handled {735 if err != nil {736 errors = append(errors, err)737 } else {738 bytes, _ := yaml.Marshal(v)739 result.Yaml = string(bytes)740 result.Value = resultFromExt741 pair.Value = result742 }743 } else {744 pair.Value, err = NewAny(v, compiler.NewContext(k, context))745 if err != nil {746 errors = append(errors, err)747 }748 }749 x.AdditionalProperties = append(x.AdditionalProperties, pair)750 }751 }752 }753 return x, compiler.NewErrorGroupOrNil(errors)754}755func NewExternalDocs(in interface{}, context *compiler.Context) (*ExternalDocs, error) {756 errors := make([]error, 0)757 x := &ExternalDocs{}758 m, ok := compiler.UnpackMap(in)759 if !ok {760 message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)761 errors = append(errors, compiler.NewError(context, message))762 } else {763 requiredKeys := []string{"url"}764 missingKeys := compiler.MissingKeysInMap(m, requiredKeys)765 if len(missingKeys) > 0 {766 message := fmt.Sprintf("is missing required %s: %+v", compiler.PluralProperties(len(missingKeys)), strings.Join(missingKeys, ", "))767 errors = append(errors, compiler.NewError(context, message))768 }769 allowedKeys := []string{"description", "url"}770 allowedPatterns := []string{"^x-"}771 invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)772 if len(invalidKeys) > 0 {773 message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))774 errors = append(errors, compiler.NewError(context, message))775 }776 // string description = 1;777 v1 := compiler.MapValueForKey(m, "description")778 if v1 != nil {779 x.Description, ok = v1.(string)780 if !ok {781 message := fmt.Sprintf("has unexpected value for description: %+v (%T)", v1, v1)782 errors = append(errors, compiler.NewError(context, message))783 }784 }785 // string url = 2;786 v2 := compiler.MapValueForKey(m, "url")787 if v2 != nil {788 x.Url, ok = v2.(string)789 if !ok {790 message := fmt.Sprintf("has unexpected value for url: %+v (%T)", v2, v2)791 errors = append(errors, compiler.NewError(context, message))792 }793 }794 // repeated NamedAny vendor_extension = 3;795 // MAP: Any ^x-796 x.VendorExtension = make([]*NamedAny, 0)797 for _, item := range m {798 k, ok := item.Key.(string)799 if ok {800 v := item.Value801 if compiler.PatternMatches("^x-", k) {802 pair := &NamedAny{}803 pair.Name = k804 result := &Any{}805 handled, resultFromExt, err := compiler.HandleExtension(context, v, k)806 if handled {807 if err != nil {808 errors = append(errors, err)809 } else {810 bytes, _ := yaml.Marshal(v)811 result.Yaml = string(bytes)812 result.Value = resultFromExt813 pair.Value = result814 }815 } else {816 pair.Value, err = NewAny(v, compiler.NewContext(k, context))817 if err != nil {818 errors = append(errors, err)819 }820 }821 x.VendorExtension = append(x.VendorExtension, pair)822 }823 }824 }825 }826 return x, compiler.NewErrorGroupOrNil(errors)827}828func NewFileSchema(in interface{}, context *compiler.Context) (*FileSchema, error) {829 errors := make([]error, 0)830 x := &FileSchema{}831 m, ok := compiler.UnpackMap(in)832 if !ok {833 message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)834 errors = append(errors, compiler.NewError(context, message))835 } else {836 requiredKeys := []string{"type"}837 missingKeys := compiler.MissingKeysInMap(m, requiredKeys)838 if len(missingKeys) > 0 {839 message := fmt.Sprintf("is missing required %s: %+v", compiler.PluralProperties(len(missingKeys)), strings.Join(missingKeys, ", "))840 errors = append(errors, compiler.NewError(context, message))841 }842 allowedKeys := []string{"default", "description", "example", "externalDocs", "format", "readOnly", "required", "title", "type"}843 allowedPatterns := []string{"^x-"}844 invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)845 if len(invalidKeys) > 0 {846 message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))847 errors = append(errors, compiler.NewError(context, message))848 }849 // string format = 1;850 v1 := compiler.MapValueForKey(m, "format")851 if v1 != nil {852 x.Format, ok = v1.(string)853 if !ok {854 message := fmt.Sprintf("has unexpected value for format: %+v (%T)", v1, v1)855 errors = append(errors, compiler.NewError(context, message))856 }857 }858 // string title = 2;859 v2 := compiler.MapValueForKey(m, "title")860 if v2 != nil {861 x.Title, ok = v2.(string)862 if !ok {863 message := fmt.Sprintf("has unexpected value for title: %+v (%T)", v2, v2)864 errors = append(errors, compiler.NewError(context, message))865 }866 }867 // string description = 3;868 v3 := compiler.MapValueForKey(m, "description")869 if v3 != nil {870 x.Description, ok = v3.(string)871 if !ok {872 message := fmt.Sprintf("has unexpected value for description: %+v (%T)", v3, v3)873 errors = append(errors, compiler.NewError(context, message))874 }875 }876 // Any default = 4;877 v4 := compiler.MapValueForKey(m, "default")878 if v4 != nil {879 var err error880 x.Default, err = NewAny(v4, compiler.NewContext("default", context))881 if err != nil {882 errors = append(errors, err)883 }884 }885 // repeated string required = 5;886 v5 := compiler.MapValueForKey(m, "required")887 if v5 != nil {888 v, ok := v5.([]interface{})889 if ok {890 x.Required = compiler.ConvertInterfaceArrayToStringArray(v)891 } else {892 message := fmt.Sprintf("has unexpected value for required: %+v (%T)", v5, v5)893 errors = append(errors, compiler.NewError(context, message))894 }895 }896 // string type = 6;897 v6 := compiler.MapValueForKey(m, "type")898 if v6 != nil {899 x.Type, ok = v6.(string)900 if !ok {901 message := fmt.Sprintf("has unexpected value for type: %+v (%T)", v6, v6)902 errors = append(errors, compiler.NewError(context, message))903 }904 // check for valid enum values905 // [file]906 if ok && !compiler.StringArrayContainsValue([]string{"file"}, x.Type) {907 message := fmt.Sprintf("has unexpected value for type: %+v (%T)", v6, v6)908 errors = append(errors, compiler.NewError(context, message))909 }910 }911 // bool read_only = 7;912 v7 := compiler.MapValueForKey(m, "readOnly")913 if v7 != nil {914 x.ReadOnly, ok = v7.(bool)915 if !ok {916 message := fmt.Sprintf("has unexpected value for readOnly: %+v (%T)", v7, v7)917 errors = append(errors, compiler.NewError(context, message))918 }919 }920 // ExternalDocs external_docs = 8;921 v8 := compiler.MapValueForKey(m, "externalDocs")922 if v8 != nil {923 var err error924 x.ExternalDocs, err = NewExternalDocs(v8, compiler.NewContext("externalDocs", context))925 if err != nil {926 errors = append(errors, err)927 }928 }929 // Any example = 9;930 v9 := compiler.MapValueForKey(m, "example")931 if v9 != nil {932 var err error933 x.Example, err = NewAny(v9, compiler.NewContext("example", context))934 if err != nil {935 errors = append(errors, err)936 }937 }938 // repeated NamedAny vendor_extension = 10;939 // MAP: Any ^x-940 x.VendorExtension = make([]*NamedAny, 0)941 for _, item := range m {942 k, ok := item.Key.(string)943 if ok {944 v := item.Value945 if compiler.PatternMatches("^x-", k) {946 pair := &NamedAny{}947 pair.Name = k948 result := &Any{}949 handled, resultFromExt, err := compiler.HandleExtension(context, v, k)950 if handled {951 if err != nil {952 errors = append(errors, err)953 } else {954 bytes, _ := yaml.Marshal(v)955 result.Yaml = string(bytes)956 result.Value = resultFromExt957 pair.Value = result958 }959 } else {960 pair.Value, err = NewAny(v, compiler.NewContext(k, context))961 if err != nil {962 errors = append(errors, err)963 }964 }965 x.VendorExtension = append(x.VendorExtension, pair)966 }967 }968 }969 }970 return x, compiler.NewErrorGroupOrNil(errors)971}972func NewFormDataParameterSubSchema(in interface{}, context *compiler.Context) (*FormDataParameterSubSchema, error) {973 errors := make([]error, 0)974 x := &FormDataParameterSubSchema{}975 m, ok := compiler.UnpackMap(in)976 if !ok {977 message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)978 errors = append(errors, compiler.NewError(context, message))979 } else {980 allowedKeys := []string{"allowEmptyValue", "collectionFormat", "default", "description", "enum", "exclusiveMaximum", "exclusiveMinimum", "format", "in", "items", "maxItems", "maxLength", "maximum", "minItems", "minLength", "minimum", "multipleOf", "name", "pattern", "required", "type", "uniqueItems"}981 allowedPatterns := []string{"^x-"}982 invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)983 if len(invalidKeys) > 0 {984 message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))985 errors = append(errors, compiler.NewError(context, message))986 }987 // bool required = 1;988 v1 := compiler.MapValueForKey(m, "required")989 if v1 != nil {990 x.Required, ok = v1.(bool)991 if !ok {992 message := fmt.Sprintf("has unexpected value for required: %+v (%T)", v1, v1)993 errors = append(errors, compiler.NewError(context, message))994 }995 }996 // string in = 2;997 v2 := compiler.MapValueForKey(m, "in")998 if v2 != nil {999 x.In, ok = v2.(string)1000 if !ok {1001 message := fmt.Sprintf("has unexpected value for in: %+v (%T)", v2, v2)1002 errors = append(errors, compiler.NewError(context, message))1003 }1004 // check for valid enum values1005 // [formData]1006 if ok && !compiler.StringArrayContainsValue([]string{"formData"}, x.In) {1007 message := fmt.Sprintf("has unexpected value for in: %+v (%T)", v2, v2)1008 errors = append(errors, compiler.NewError(context, message))1009 }1010 }1011 // string description = 3;1012 v3 := compiler.MapValueForKey(m, "description")1013 if v3 != nil {1014 x.Description, ok = v3.(string)1015 if !ok {1016 message := fmt.Sprintf("has unexpected value for description: %+v (%T)", v3, v3)1017 errors = append(errors, compiler.NewError(context, message))1018 }1019 }1020 // string name = 4;1021 v4 := compiler.MapValueForKey(m, "name")1022 if v4 != nil {1023 x.Name, ok = v4.(string)1024 if !ok {1025 message := fmt.Sprintf("has unexpected value for name: %+v (%T)", v4, v4)1026 errors = append(errors, compiler.NewError(context, message))1027 }1028 }1029 // bool allow_empty_value = 5;1030 v5 := compiler.MapValueForKey(m, "allowEmptyValue")1031 if v5 != nil {1032 x.AllowEmptyValue, ok = v5.(bool)1033 if !ok {1034 message := fmt.Sprintf("has unexpected value for allowEmptyValue: %+v (%T)", v5, v5)1035 errors = append(errors, compiler.NewError(context, message))1036 }1037 }1038 // string type = 6;1039 v6 := compiler.MapValueForKey(m, "type")1040 if v6 != nil {1041 x.Type, ok = v6.(string)1042 if !ok {1043 message := fmt.Sprintf("has unexpected value for type: %+v (%T)", v6, v6)1044 errors = append(errors, compiler.NewError(context, message))1045 }1046 // check for valid enum values1047 // [string number boolean integer array file]1048 if ok && !compiler.StringArrayContainsValue([]string{"string", "number", "boolean", "integer", "array", "file"}, x.Type) {1049 message := fmt.Sprintf("has unexpected value for type: %+v (%T)", v6, v6)1050 errors = append(errors, compiler.NewError(context, message))1051 }1052 }1053 // string format = 7;1054 v7 := compiler.MapValueForKey(m, "format")1055 if v7 != nil {1056 x.Format, ok = v7.(string)1057 if !ok {1058 message := fmt.Sprintf("has unexpected value for format: %+v (%T)", v7, v7)1059 errors = append(errors, compiler.NewError(context, message))1060 }1061 }1062 // PrimitivesItems items = 8;1063 v8 := compiler.MapValueForKey(m, "items")1064 if v8 != nil {1065 var err error1066 x.Items, err = NewPrimitivesItems(v8, compiler.NewContext("items", context))1067 if err != nil {1068 errors = append(errors, err)1069 }1070 }1071 // string collection_format = 9;1072 v9 := compiler.MapValueForKey(m, "collectionFormat")1073 if v9 != nil {1074 x.CollectionFormat, ok = v9.(string)1075 if !ok {1076 message := fmt.Sprintf("has unexpected value for collectionFormat: %+v (%T)", v9, v9)1077 errors = append(errors, compiler.NewError(context, message))1078 }1079 // check for valid enum values1080 // [csv ssv tsv pipes multi]1081 if ok && !compiler.StringArrayContainsValue([]string{"csv", "ssv", "tsv", "pipes", "multi"}, x.CollectionFormat) {1082 message := fmt.Sprintf("has unexpected value for collectionFormat: %+v (%T)", v9, v9)1083 errors = append(errors, compiler.NewError(context, message))1084 }1085 }1086 // Any default = 10;1087 v10 := compiler.MapValueForKey(m, "default")1088 if v10 != nil {1089 var err error1090 x.Default, err = NewAny(v10, compiler.NewContext("default", context))1091 if err != nil {1092 errors = append(errors, err)1093 }1094 }1095 // float maximum = 11;1096 v11 := compiler.MapValueForKey(m, "maximum")1097 if v11 != nil {1098 switch v11 := v11.(type) {1099 case float64:1100 x.Maximum = v111101 case float32:1102 x.Maximum = float64(v11)1103 case uint64:1104 x.Maximum = float64(v11)1105 case uint32:1106 x.Maximum = float64(v11)1107 case int64:1108 x.Maximum = float64(v11)1109 case int32:1110 x.Maximum = float64(v11)1111 case int:1112 x.Maximum = float64(v11)1113 default:1114 message := fmt.Sprintf("has unexpected value for maximum: %+v (%T)", v11, v11)1115 errors = append(errors, compiler.NewError(context, message))1116 }1117 }1118 // bool exclusive_maximum = 12;1119 v12 := compiler.MapValueForKey(m, "exclusiveMaximum")1120 if v12 != nil {1121 x.ExclusiveMaximum, ok = v12.(bool)1122 if !ok {1123 message := fmt.Sprintf("has unexpected value for exclusiveMaximum: %+v (%T)", v12, v12)1124 errors = append(errors, compiler.NewError(context, message))1125 }1126 }1127 // float minimum = 13;1128 v13 := compiler.MapValueForKey(m, "minimum")1129 if v13 != nil {1130 switch v13 := v13.(type) {1131 case float64:1132 x.Minimum = v131133 case float32:1134 x.Minimum = float64(v13)1135 case uint64:1136 x.Minimum = float64(v13)1137 case uint32:1138 x.Minimum = float64(v13)1139 case int64:1140 x.Minimum = float64(v13)1141 case int32:1142 x.Minimum = float64(v13)1143 case int:1144 x.Minimum = float64(v13)1145 default:1146 message := fmt.Sprintf("has unexpected value for minimum: %+v (%T)", v13, v13)1147 errors = append(errors, compiler.NewError(context, message))1148 }1149 }1150 // bool exclusive_minimum = 14;1151 v14 := compiler.MapValueForKey(m, "exclusiveMinimum")1152 if v14 != nil {1153 x.ExclusiveMinimum, ok = v14.(bool)1154 if !ok {1155 message := fmt.Sprintf("has unexpected value for exclusiveMinimum: %+v (%T)", v14, v14)1156 errors = append(errors, compiler.NewError(context, message))1157 }1158 }1159 // int64 max_length = 15;1160 v15 := compiler.MapValueForKey(m, "maxLength")1161 if v15 != nil {1162 t, ok := v15.(int)1163 if ok {1164 x.MaxLength = int64(t)1165 } else {1166 message := fmt.Sprintf("has unexpected value for maxLength: %+v (%T)", v15, v15)1167 errors = append(errors, compiler.NewError(context, message))1168 }1169 }1170 // int64 min_length = 16;1171 v16 := compiler.MapValueForKey(m, "minLength")1172 if v16 != nil {1173 t, ok := v16.(int)1174 if ok {1175 x.MinLength = int64(t)1176 } else {1177 message := fmt.Sprintf("has unexpected value for minLength: %+v (%T)", v16, v16)1178 errors = append(errors, compiler.NewError(context, message))1179 }1180 }1181 // string pattern = 17;1182 v17 := compiler.MapValueForKey(m, "pattern")1183 if v17 != nil {1184 x.Pattern, ok = v17.(string)1185 if !ok {1186 message := fmt.Sprintf("has unexpected value for pattern: %+v (%T)", v17, v17)1187 errors = append(errors, compiler.NewError(context, message))1188 }1189 }1190 // int64 max_items = 18;1191 v18 := compiler.MapValueForKey(m, "maxItems")1192 if v18 != nil {1193 t, ok := v18.(int)1194 if ok {1195 x.MaxItems = int64(t)1196 } else {1197 message := fmt.Sprintf("has unexpected value for maxItems: %+v (%T)", v18, v18)1198 errors = append(errors, compiler.NewError(context, message))1199 }1200 }1201 // int64 min_items = 19;1202 v19 := compiler.MapValueForKey(m, "minItems")1203 if v19 != nil {1204 t, ok := v19.(int)1205 if ok {1206 x.MinItems = int64(t)1207 } else {1208 message := fmt.Sprintf("has unexpected value for minItems: %+v (%T)", v19, v19)1209 errors = append(errors, compiler.NewError(context, message))1210 }1211 }1212 // bool unique_items = 20;1213 v20 := compiler.MapValueForKey(m, "uniqueItems")1214 if v20 != nil {1215 x.UniqueItems, ok = v20.(bool)1216 if !ok {1217 message := fmt.Sprintf("has unexpected value for uniqueItems: %+v (%T)", v20, v20)1218 errors = append(errors, compiler.NewError(context, message))1219 }1220 }1221 // repeated Any enum = 21;1222 v21 := compiler.MapValueForKey(m, "enum")1223 if v21 != nil {1224 // repeated Any1225 x.Enum = make([]*Any, 0)1226 a, ok := v21.([]interface{})1227 if ok {1228 for _, item := range a {1229 y, err := NewAny(item, compiler.NewContext("enum", context))1230 if err != nil {1231 errors = append(errors, err)1232 }1233 x.Enum = append(x.Enum, y)1234 }1235 }1236 }1237 // float multiple_of = 22;1238 v22 := compiler.MapValueForKey(m, "multipleOf")1239 if v22 != nil {1240 switch v22 := v22.(type) {1241 case float64:1242 x.MultipleOf = v221243 case float32:1244 x.MultipleOf = float64(v22)1245 case uint64:1246 x.MultipleOf = float64(v22)1247 case uint32:1248 x.MultipleOf = float64(v22)1249 case int64:1250 x.MultipleOf = float64(v22)1251 case int32:1252 x.MultipleOf = float64(v22)1253 case int:1254 x.MultipleOf = float64(v22)1255 default:1256 message := fmt.Sprintf("has unexpected value for multipleOf: %+v (%T)", v22, v22)1257 errors = append(errors, compiler.NewError(context, message))1258 }1259 }1260 // repeated NamedAny vendor_extension = 23;1261 // MAP: Any ^x-1262 x.VendorExtension = make([]*NamedAny, 0)1263 for _, item := range m {1264 k, ok := item.Key.(string)1265 if ok {1266 v := item.Value1267 if compiler.PatternMatches("^x-", k) {1268 pair := &NamedAny{}1269 pair.Name = k1270 result := &Any{}1271 handled, resultFromExt, err := compiler.HandleExtension(context, v, k)1272 if handled {1273 if err != nil {1274 errors = append(errors, err)1275 } else {1276 bytes, _ := yaml.Marshal(v)1277 result.Yaml = string(bytes)1278 result.Value = resultFromExt1279 pair.Value = result1280 }1281 } else {1282 pair.Value, err = NewAny(v, compiler.NewContext(k, context))1283 if err != nil {1284 errors = append(errors, err)1285 }1286 }1287 x.VendorExtension = append(x.VendorExtension, pair)1288 }1289 }1290 }1291 }1292 return x, compiler.NewErrorGroupOrNil(errors)1293}1294func NewHeader(in interface{}, context *compiler.Context) (*Header, error) {1295 errors := make([]error, 0)1296 x := &Header{}1297 m, ok := compiler.UnpackMap(in)1298 if !ok {1299 message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)1300 errors = append(errors, compiler.NewError(context, message))1301 } else {1302 requiredKeys := []string{"type"}1303 missingKeys := compiler.MissingKeysInMap(m, requiredKeys)1304 if len(missingKeys) > 0 {1305 message := fmt.Sprintf("is missing required %s: %+v", compiler.PluralProperties(len(missingKeys)), strings.Join(missingKeys, ", "))1306 errors = append(errors, compiler.NewError(context, message))1307 }1308 allowedKeys := []string{"collectionFormat", "default", "description", "enum", "exclusiveMaximum", "exclusiveMinimum", "format", "items", "maxItems", "maxLength", "maximum", "minItems", "minLength", "minimum", "multipleOf", "pattern", "type", "uniqueItems"}1309 allowedPatterns := []string{"^x-"}1310 invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)1311 if len(invalidKeys) > 0 {1312 message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))1313 errors = append(errors, compiler.NewError(context, message))1314 }1315 // string type = 1;1316 v1 := compiler.MapValueForKey(m, "type")1317 if v1 != nil {1318 x.Type, ok = v1.(string)1319 if !ok {1320 message := fmt.Sprintf("has unexpected value for type: %+v (%T)", v1, v1)1321 errors = append(errors, compiler.NewError(context, message))1322 }1323 // check for valid enum values1324 // [string number integer boolean array]1325 if ok && !compiler.StringArrayContainsValue([]string{"string", "number", "integer", "boolean", "array"}, x.Type) {1326 message := fmt.Sprintf("has unexpected value for type: %+v (%T)", v1, v1)1327 errors = append(errors, compiler.NewError(context, message))1328 }1329 }1330 // string format = 2;1331 v2 := compiler.MapValueForKey(m, "format")1332 if v2 != nil {1333 x.Format, ok = v2.(string)1334 if !ok {1335 message := fmt.Sprintf("has unexpected value for format: %+v (%T)", v2, v2)1336 errors = append(errors, compiler.NewError(context, message))1337 }1338 }1339 // PrimitivesItems items = 3;1340 v3 := compiler.MapValueForKey(m, "items")1341 if v3 != nil {1342 var err error1343 x.Items, err = NewPrimitivesItems(v3, compiler.NewContext("items", context))1344 if err != nil {1345 errors = append(errors, err)1346 }1347 }1348 // string collection_format = 4;1349 v4 := compiler.MapValueForKey(m, "collectionFormat")1350 if v4 != nil {1351 x.CollectionFormat, ok = v4.(string)1352 if !ok {1353 message := fmt.Sprintf("has unexpected value for collectionFormat: %+v (%T)", v4, v4)1354 errors = append(errors, compiler.NewError(context, message))1355 }1356 // check for valid enum values1357 // [csv ssv tsv pipes]1358 if ok && !compiler.StringArrayContainsValue([]string{"csv", "ssv", "tsv", "pipes"}, x.CollectionFormat) {1359 message := fmt.Sprintf("has unexpected value for collectionFormat: %+v (%T)", v4, v4)1360 errors = append(errors, compiler.NewError(context, message))1361 }1362 }1363 // Any default = 5;1364 v5 := compiler.MapValueForKey(m, "default")1365 if v5 != nil {1366 var err error1367 x.Default, err = NewAny(v5, compiler.NewContext("default", context))1368 if err != nil {1369 errors = append(errors, err)1370 }1371 }1372 // float maximum = 6;1373 v6 := compiler.MapValueForKey(m, "maximum")1374 if v6 != nil {1375 switch v6 := v6.(type) {1376 case float64:1377 x.Maximum = v61378 case float32:1379 x.Maximum = float64(v6)1380 case uint64:1381 x.Maximum = float64(v6)1382 case uint32:1383 x.Maximum = float64(v6)1384 case int64:1385 x.Maximum = float64(v6)1386 case int32:1387 x.Maximum = float64(v6)1388 case int:1389 x.Maximum = float64(v6)1390 default:1391 message := fmt.Sprintf("has unexpected value for maximum: %+v (%T)", v6, v6)1392 errors = append(errors, compiler.NewError(context, message))1393 }1394 }1395 // bool exclusive_maximum = 7;1396 v7 := compiler.MapValueForKey(m, "exclusiveMaximum")1397 if v7 != nil {1398 x.ExclusiveMaximum, ok = v7.(bool)1399 if !ok {1400 message := fmt.Sprintf("has unexpected value for exclusiveMaximum: %+v (%T)", v7, v7)1401 errors = append(errors, compiler.NewError(context, message))1402 }1403 }1404 // float minimum = 8;1405 v8 := compiler.MapValueForKey(m, "minimum")1406 if v8 != nil {1407 switch v8 := v8.(type) {1408 case float64:1409 x.Minimum = v81410 case float32:1411 x.Minimum = float64(v8)1412 case uint64:1413 x.Minimum = float64(v8)1414 case uint32:1415 x.Minimum = float64(v8)1416 case int64:1417 x.Minimum = float64(v8)1418 case int32:1419 x.Minimum = float64(v8)1420 case int:1421 x.Minimum = float64(v8)1422 default:1423 message := fmt.Sprintf("has unexpected value for minimum: %+v (%T)", v8, v8)1424 errors = append(errors, compiler.NewError(context, message))1425 }1426 }1427 // bool exclusive_minimum = 9;1428 v9 := compiler.MapValueForKey(m, "exclusiveMinimum")1429 if v9 != nil {1430 x.ExclusiveMinimum, ok = v9.(bool)1431 if !ok {1432 message := fmt.Sprintf("has unexpected value for exclusiveMinimum: %+v (%T)", v9, v9)1433 errors = append(errors, compiler.NewError(context, message))1434 }1435 }1436 // int64 max_length = 10;1437 v10 := compiler.MapValueForKey(m, "maxLength")1438 if v10 != nil {1439 t, ok := v10.(int)1440 if ok {1441 x.MaxLength = int64(t)1442 } else {1443 message := fmt.Sprintf("has unexpected value for maxLength: %+v (%T)", v10, v10)1444 errors = append(errors, compiler.NewError(context, message))1445 }1446 }1447 // int64 min_length = 11;1448 v11 := compiler.MapValueForKey(m, "minLength")1449 if v11 != nil {1450 t, ok := v11.(int)1451 if ok {1452 x.MinLength = int64(t)1453 } else {1454 message := fmt.Sprintf("has unexpected value for minLength: %+v (%T)", v11, v11)1455 errors = append(errors, compiler.NewError(context, message))1456 }1457 }1458 // string pattern = 12;1459 v12 := compiler.MapValueForKey(m, "pattern")1460 if v12 != nil {1461 x.Pattern, ok = v12.(string)1462 if !ok {1463 message := fmt.Sprintf("has unexpected value for pattern: %+v (%T)", v12, v12)1464 errors = append(errors, compiler.NewError(context, message))1465 }1466 }1467 // int64 max_items = 13;1468 v13 := compiler.MapValueForKey(m, "maxItems")1469 if v13 != nil {1470 t, ok := v13.(int)1471 if ok {1472 x.MaxItems = int64(t)1473 } else {1474 message := fmt.Sprintf("has unexpected value for maxItems: %+v (%T)", v13, v13)1475 errors = append(errors, compiler.NewError(context, message))1476 }1477 }1478 // int64 min_items = 14;1479 v14 := compiler.MapValueForKey(m, "minItems")1480 if v14 != nil {1481 t, ok := v14.(int)1482 if ok {1483 x.MinItems = int64(t)1484 } else {1485 message := fmt.Sprintf("has unexpected value for minItems: %+v (%T)", v14, v14)1486 errors = append(errors, compiler.NewError(context, message))1487 }1488 }1489 // bool unique_items = 15;1490 v15 := compiler.MapValueForKey(m, "uniqueItems")1491 if v15 != nil {1492 x.UniqueItems, ok = v15.(bool)1493 if !ok {1494 message := fmt.Sprintf("has unexpected value for uniqueItems: %+v (%T)", v15, v15)1495 errors = append(errors, compiler.NewError(context, message))1496 }1497 }1498 // repeated Any enum = 16;1499 v16 := compiler.MapValueForKey(m, "enum")1500 if v16 != nil {1501 // repeated Any1502 x.Enum = make([]*Any, 0)1503 a, ok := v16.([]interface{})1504 if ok {1505 for _, item := range a {1506 y, err := NewAny(item, compiler.NewContext("enum", context))1507 if err != nil {1508 errors = append(errors, err)1509 }1510 x.Enum = append(x.Enum, y)1511 }1512 }1513 }1514 // float multiple_of = 17;1515 v17 := compiler.MapValueForKey(m, "multipleOf")1516 if v17 != nil {1517 switch v17 := v17.(type) {1518 case float64:1519 x.MultipleOf = v171520 case float32:1521 x.MultipleOf = float64(v17)1522 case uint64:1523 x.MultipleOf = float64(v17)1524 case uint32:1525 x.MultipleOf = float64(v17)1526 case int64:1527 x.MultipleOf = float64(v17)1528 case int32:1529 x.MultipleOf = float64(v17)1530 case int:1531 x.MultipleOf = float64(v17)1532 default:1533 message := fmt.Sprintf("has unexpected value for multipleOf: %+v (%T)", v17, v17)1534 errors = append(errors, compiler.NewError(context, message))1535 }1536 }1537 // string description = 18;1538 v18 := compiler.MapValueForKey(m, "description")1539 if v18 != nil {1540 x.Description, ok = v18.(string)1541 if !ok {1542 message := fmt.Sprintf("has unexpected value for description: %+v (%T)", v18, v18)1543 errors = append(errors, compiler.NewError(context, message))1544 }1545 }1546 // repeated NamedAny vendor_extension = 19;1547 // MAP: Any ^x-1548 x.VendorExtension = make([]*NamedAny, 0)1549 for _, item := range m {1550 k, ok := item.Key.(string)1551 if ok {1552 v := item.Value1553 if compiler.PatternMatches("^x-", k) {1554 pair := &NamedAny{}1555 pair.Name = k1556 result := &Any{}1557 handled, resultFromExt, err := compiler.HandleExtension(context, v, k)1558 if handled {1559 if err != nil {1560 errors = append(errors, err)1561 } else {1562 bytes, _ := yaml.Marshal(v)1563 result.Yaml = string(bytes)1564 result.Value = resultFromExt1565 pair.Value = result1566 }1567 } else {1568 pair.Value, err = NewAny(v, compiler.NewContext(k, context))1569 if err != nil {1570 errors = append(errors, err)1571 }1572 }1573 x.VendorExtension = append(x.VendorExtension, pair)1574 }1575 }1576 }1577 }1578 return x, compiler.NewErrorGroupOrNil(errors)1579}1580func NewHeaderParameterSubSchema(in interface{}, context *compiler.Context) (*HeaderParameterSubSchema, error) {1581 errors := make([]error, 0)1582 x := &HeaderParameterSubSchema{}1583 m, ok := compiler.UnpackMap(in)1584 if !ok {1585 message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)1586 errors = append(errors, compiler.NewError(context, message))1587 } else {1588 allowedKeys := []string{"collectionFormat", "default", "description", "enum", "exclusiveMaximum", "exclusiveMinimum", "format", "in", "items", "maxItems", "maxLength", "maximum", "minItems", "minLength", "minimum", "multipleOf", "name", "pattern", "required", "type", "uniqueItems"}1589 allowedPatterns := []string{"^x-"}1590 invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)1591 if len(invalidKeys) > 0 {1592 message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))1593 errors = append(errors, compiler.NewError(context, message))1594 }1595 // bool required = 1;1596 v1 := compiler.MapValueForKey(m, "required")1597 if v1 != nil {1598 x.Required, ok = v1.(bool)1599 if !ok {1600 message := fmt.Sprintf("has unexpected value for required: %+v (%T)", v1, v1)1601 errors = append(errors, compiler.NewError(context, message))1602 }1603 }1604 // string in = 2;1605 v2 := compiler.MapValueForKey(m, "in")1606 if v2 != nil {1607 x.In, ok = v2.(string)1608 if !ok {1609 message := fmt.Sprintf("has unexpected value for in: %+v (%T)", v2, v2)1610 errors = append(errors, compiler.NewError(context, message))1611 }1612 // check for valid enum values1613 // [header]1614 if ok && !compiler.StringArrayContainsValue([]string{"header"}, x.In) {1615 message := fmt.Sprintf("has unexpected value for in: %+v (%T)", v2, v2)1616 errors = append(errors, compiler.NewError(context, message))1617 }1618 }1619 // string description = 3;1620 v3 := compiler.MapValueForKey(m, "description")1621 if v3 != nil {1622 x.Description, ok = v3.(string)1623 if !ok {1624 message := fmt.Sprintf("has unexpected value for description: %+v (%T)", v3, v3)1625 errors = append(errors, compiler.NewError(context, message))1626 }1627 }1628 // string name = 4;1629 v4 := compiler.MapValueForKey(m, "name")1630 if v4 != nil {1631 x.Name, ok = v4.(string)1632 if !ok {1633 message := fmt.Sprintf("has unexpected value for name: %+v (%T)", v4, v4)1634 errors = append(errors, compiler.NewError(context, message))1635 }1636 }1637 // string type = 5;1638 v5 := compiler.MapValueForKey(m, "type")1639 if v5 != nil {1640 x.Type, ok = v5.(string)1641 if !ok {1642 message := fmt.Sprintf("has unexpected value for type: %+v (%T)", v5, v5)1643 errors = append(errors, compiler.NewError(context, message))1644 }1645 // check for valid enum values1646 // [string number boolean integer array]1647 if ok && !compiler.StringArrayContainsValue([]string{"string", "number", "boolean", "integer", "array"}, x.Type) {1648 message := fmt.Sprintf("has unexpected value for type: %+v (%T)", v5, v5)1649 errors = append(errors, compiler.NewError(context, message))1650 }1651 }1652 // string format = 6;1653 v6 := compiler.MapValueForKey(m, "format")1654 if v6 != nil {1655 x.Format, ok = v6.(string)1656 if !ok {1657 message := fmt.Sprintf("has unexpected value for format: %+v (%T)", v6, v6)1658 errors = append(errors, compiler.NewError(context, message))1659 }1660 }1661 // PrimitivesItems items = 7;1662 v7 := compiler.MapValueForKey(m, "items")1663 if v7 != nil {1664 var err error1665 x.Items, err = NewPrimitivesItems(v7, compiler.NewContext("items", context))1666 if err != nil {1667 errors = append(errors, err)1668 }1669 }1670 // string collection_format = 8;1671 v8 := compiler.MapValueForKey(m, "collectionFormat")1672 if v8 != nil {1673 x.CollectionFormat, ok = v8.(string)1674 if !ok {1675 message := fmt.Sprintf("has unexpected value for collectionFormat: %+v (%T)", v8, v8)1676 errors = append(errors, compiler.NewError(context, message))1677 }1678 // check for valid enum values1679 // [csv ssv tsv pipes]1680 if ok && !compiler.StringArrayContainsValue([]string{"csv", "ssv", "tsv", "pipes"}, x.CollectionFormat) {1681 message := fmt.Sprintf("has unexpected value for collectionFormat: %+v (%T)", v8, v8)1682 errors = append(errors, compiler.NewError(context, message))1683 }1684 }1685 // Any default = 9;1686 v9 := compiler.MapValueForKey(m, "default")1687 if v9 != nil {1688 var err error1689 x.Default, err = NewAny(v9, compiler.NewContext("default", context))1690 if err != nil {1691 errors = append(errors, err)1692 }1693 }1694 // float maximum = 10;1695 v10 := compiler.MapValueForKey(m, "maximum")1696 if v10 != nil {1697 switch v10 := v10.(type) {1698 case float64:1699 x.Maximum = v101700 case float32:1701 x.Maximum = float64(v10)1702 case uint64:1703 x.Maximum = float64(v10)1704 case uint32:1705 x.Maximum = float64(v10)1706 case int64:1707 x.Maximum = float64(v10)1708 case int32:1709 x.Maximum = float64(v10)1710 case int:1711 x.Maximum = float64(v10)1712 default:1713 message := fmt.Sprintf("has unexpected value for maximum: %+v (%T)", v10, v10)1714 errors = append(errors, compiler.NewError(context, message))1715 }1716 }1717 // bool exclusive_maximum = 11;1718 v11 := compiler.MapValueForKey(m, "exclusiveMaximum")1719 if v11 != nil {1720 x.ExclusiveMaximum, ok = v11.(bool)1721 if !ok {1722 message := fmt.Sprintf("has unexpected value for exclusiveMaximum: %+v (%T)", v11, v11)1723 errors = append(errors, compiler.NewError(context, message))1724 }1725 }1726 // float minimum = 12;1727 v12 := compiler.MapValueForKey(m, "minimum")1728 if v12 != nil {1729 switch v12 := v12.(type) {1730 case float64:1731 x.Minimum = v121732 case float32:1733 x.Minimum = float64(v12)1734 case uint64:1735 x.Minimum = float64(v12)1736 case uint32:1737 x.Minimum = float64(v12)1738 case int64:1739 x.Minimum = float64(v12)1740 case int32:1741 x.Minimum = float64(v12)1742 case int:1743 x.Minimum = float64(v12)1744 default:1745 message := fmt.Sprintf("has unexpected value for minimum: %+v (%T)", v12, v12)1746 errors = append(errors, compiler.NewError(context, message))1747 }1748 }1749 // bool exclusive_minimum = 13;1750 v13 := compiler.MapValueForKey(m, "exclusiveMinimum")1751 if v13 != nil {1752 x.ExclusiveMinimum, ok = v13.(bool)1753 if !ok {1754 message := fmt.Sprintf("has unexpected value for exclusiveMinimum: %+v (%T)", v13, v13)1755 errors = append(errors, compiler.NewError(context, message))1756 }1757 }1758 // int64 max_length = 14;1759 v14 := compiler.MapValueForKey(m, "maxLength")1760 if v14 != nil {1761 t, ok := v14.(int)1762 if ok {1763 x.MaxLength = int64(t)1764 } else {1765 message := fmt.Sprintf("has unexpected value for maxLength: %+v (%T)", v14, v14)1766 errors = append(errors, compiler.NewError(context, message))1767 }1768 }1769 // int64 min_length = 15;1770 v15 := compiler.MapValueForKey(m, "minLength")1771 if v15 != nil {1772 t, ok := v15.(int)1773 if ok {1774 x.MinLength = int64(t)1775 } else {1776 message := fmt.Sprintf("has unexpected value for minLength: %+v (%T)", v15, v15)1777 errors = append(errors, compiler.NewError(context, message))1778 }1779 }1780 // string pattern = 16;1781 v16 := compiler.MapValueForKey(m, "pattern")1782 if v16 != nil {1783 x.Pattern, ok = v16.(string)1784 if !ok {1785 message := fmt.Sprintf("has unexpected value for pattern: %+v (%T)", v16, v16)1786 errors = append(errors, compiler.NewError(context, message))1787 }1788 }1789 // int64 max_items = 17;1790 v17 := compiler.MapValueForKey(m, "maxItems")1791 if v17 != nil {1792 t, ok := v17.(int)1793 if ok {1794 x.MaxItems = int64(t)1795 } else {1796 message := fmt.Sprintf("has unexpected value for maxItems: %+v (%T)", v17, v17)1797 errors = append(errors, compiler.NewError(context, message))1798 }1799 }1800 // int64 min_items = 18;1801 v18 := compiler.MapValueForKey(m, "minItems")1802 if v18 != nil {1803 t, ok := v18.(int)1804 if ok {1805 x.MinItems = int64(t)1806 } else {1807 message := fmt.Sprintf("has unexpected value for minItems: %+v (%T)", v18, v18)1808 errors = append(errors, compiler.NewError(context, message))1809 }1810 }1811 // bool unique_items = 19;1812 v19 := compiler.MapValueForKey(m, "uniqueItems")1813 if v19 != nil {1814 x.UniqueItems, ok = v19.(bool)1815 if !ok {1816 message := fmt.Sprintf("has unexpected value for uniqueItems: %+v (%T)", v19, v19)1817 errors = append(errors, compiler.NewError(context, message))1818 }1819 }1820 // repeated Any enum = 20;1821 v20 := compiler.MapValueForKey(m, "enum")1822 if v20 != nil {1823 // repeated Any1824 x.Enum = make([]*Any, 0)1825 a, ok := v20.([]interface{})1826 if ok {1827 for _, item := range a {1828 y, err := NewAny(item, compiler.NewContext("enum", context))1829 if err != nil {1830 errors = append(errors, err)1831 }1832 x.Enum = append(x.Enum, y)1833 }1834 }1835 }1836 // float multiple_of = 21;1837 v21 := compiler.MapValueForKey(m, "multipleOf")1838 if v21 != nil {1839 switch v21 := v21.(type) {1840 case float64:1841 x.MultipleOf = v211842 case float32:1843 x.MultipleOf = float64(v21)1844 case uint64:1845 x.MultipleOf = float64(v21)1846 case uint32:1847 x.MultipleOf = float64(v21)1848 case int64:1849 x.MultipleOf = float64(v21)1850 case int32:1851 x.MultipleOf = float64(v21)1852 case int:1853 x.MultipleOf = float64(v21)1854 default:1855 message := fmt.Sprintf("has unexpected value for multipleOf: %+v (%T)", v21, v21)1856 errors = append(errors, compiler.NewError(context, message))1857 }1858 }1859 // repeated NamedAny vendor_extension = 22;1860 // MAP: Any ^x-1861 x.VendorExtension = make([]*NamedAny, 0)1862 for _, item := range m {1863 k, ok := item.Key.(string)1864 if ok {1865 v := item.Value1866 if compiler.PatternMatches("^x-", k) {1867 pair := &NamedAny{}1868 pair.Name = k1869 result := &Any{}1870 handled, resultFromExt, err := compiler.HandleExtension(context, v, k)1871 if handled {1872 if err != nil {1873 errors = append(errors, err)1874 } else {1875 bytes, _ := yaml.Marshal(v)1876 result.Yaml = string(bytes)1877 result.Value = resultFromExt1878 pair.Value = result1879 }1880 } else {1881 pair.Value, err = NewAny(v, compiler.NewContext(k, context))1882 if err != nil {1883 errors = append(errors, err)1884 }1885 }1886 x.VendorExtension = append(x.VendorExtension, pair)1887 }1888 }1889 }1890 }1891 return x, compiler.NewErrorGroupOrNil(errors)1892}1893func NewHeaders(in interface{}, context *compiler.Context) (*Headers, error) {1894 errors := make([]error, 0)1895 x := &Headers{}1896 m, ok := compiler.UnpackMap(in)1897 if !ok {1898 message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)1899 errors = append(errors, compiler.NewError(context, message))1900 } else {1901 // repeated NamedHeader additional_properties = 1;1902 // MAP: Header1903 x.AdditionalProperties = make([]*NamedHeader, 0)1904 for _, item := range m {1905 k, ok := item.Key.(string)1906 if ok {1907 v := item.Value1908 pair := &NamedHeader{}1909 pair.Name = k1910 var err error1911 pair.Value, err = NewHeader(v, compiler.NewContext(k, context))1912 if err != nil {1913 errors = append(errors, err)1914 }1915 x.AdditionalProperties = append(x.AdditionalProperties, pair)1916 }1917 }1918 }1919 return x, compiler.NewErrorGroupOrNil(errors)1920}1921func NewInfo(in interface{}, context *compiler.Context) (*Info, error) {1922 errors := make([]error, 0)1923 x := &Info{}1924 m, ok := compiler.UnpackMap(in)1925 if !ok {1926 message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)1927 errors = append(errors, compiler.NewError(context, message))1928 } else {1929 requiredKeys := []string{"title", "version"}1930 missingKeys := compiler.MissingKeysInMap(m, requiredKeys)1931 if len(missingKeys) > 0 {1932 message := fmt.Sprintf("is missing required %s: %+v", compiler.PluralProperties(len(missingKeys)), strings.Join(missingKeys, ", "))1933 errors = append(errors, compiler.NewError(context, message))1934 }1935 allowedKeys := []string{"contact", "description", "license", "termsOfService", "title", "version"}1936 allowedPatterns := []string{"^x-"}1937 invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)1938 if len(invalidKeys) > 0 {1939 message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))1940 errors = append(errors, compiler.NewError(context, message))1941 }1942 // string title = 1;1943 v1 := compiler.MapValueForKey(m, "title")1944 if v1 != nil {1945 x.Title, ok = v1.(string)1946 if !ok {1947 message := fmt.Sprintf("has unexpected value for title: %+v (%T)", v1, v1)1948 errors = append(errors, compiler.NewError(context, message))1949 }1950 }1951 // string version = 2;1952 v2 := compiler.MapValueForKey(m, "version")1953 if v2 != nil {1954 x.Version, ok = v2.(string)1955 if !ok {1956 message := fmt.Sprintf("has unexpected value for version: %+v (%T)", v2, v2)1957 errors = append(errors, compiler.NewError(context, message))1958 }1959 }1960 // string description = 3;1961 v3 := compiler.MapValueForKey(m, "description")1962 if v3 != nil {1963 x.Description, ok = v3.(string)1964 if !ok {1965 message := fmt.Sprintf("has unexpected value for description: %+v (%T)", v3, v3)1966 errors = append(errors, compiler.NewError(context, message))1967 }1968 }1969 // string terms_of_service = 4;1970 v4 := compiler.MapValueForKey(m, "termsOfService")1971 if v4 != nil {1972 x.TermsOfService, ok = v4.(string)1973 if !ok {1974 message := fmt.Sprintf("has unexpected value for termsOfService: %+v (%T)", v4, v4)1975 errors = append(errors, compiler.NewError(context, message))1976 }1977 }1978 // Contact contact = 5;1979 v5 := compiler.MapValueForKey(m, "contact")1980 if v5 != nil {1981 var err error1982 x.Contact, err = NewContact(v5, compiler.NewContext("contact", context))1983 if err != nil {1984 errors = append(errors, err)1985 }1986 }1987 // License license = 6;1988 v6 := compiler.MapValueForKey(m, "license")1989 if v6 != nil {1990 var err error1991 x.License, err = NewLicense(v6, compiler.NewContext("license", context))1992 if err != nil {1993 errors = append(errors, err)1994 }1995 }1996 // repeated NamedAny vendor_extension = 7;1997 // MAP: Any ^x-1998 x.VendorExtension = make([]*NamedAny, 0)1999 for _, item := range m {2000 k, ok := item.Key.(string)2001 if ok {2002 v := item.Value2003 if compiler.PatternMatches("^x-", k) {2004 pair := &NamedAny{}2005 pair.Name = k2006 result := &Any{}2007 handled, resultFromExt, err := compiler.HandleExtension(context, v, k)2008 if handled {2009 if err != nil {2010 errors = append(errors, err)2011 } else {2012 bytes, _ := yaml.Marshal(v)2013 result.Yaml = string(bytes)2014 result.Value = resultFromExt2015 pair.Value = result2016 }2017 } else {2018 pair.Value, err = NewAny(v, compiler.NewContext(k, context))2019 if err != nil {2020 errors = append(errors, err)2021 }2022 }2023 x.VendorExtension = append(x.VendorExtension, pair)2024 }2025 }2026 }2027 }2028 return x, compiler.NewErrorGroupOrNil(errors)2029}2030func NewItemsItem(in interface{}, context *compiler.Context) (*ItemsItem, error) {2031 errors := make([]error, 0)2032 x := &ItemsItem{}2033 m, ok := compiler.UnpackMap(in)2034 if !ok {2035 message := fmt.Sprintf("has unexpected value for item array: %+v (%T)", in, in)2036 errors = append(errors, compiler.NewError(context, message))2037 } else {2038 x.Schema = make([]*Schema, 0)2039 y, err := NewSchema(m, compiler.NewContext("<array>", context))2040 if err != nil {2041 return nil, err2042 }2043 x.Schema = append(x.Schema, y)2044 }2045 return x, compiler.NewErrorGroupOrNil(errors)2046}2047func NewJsonReference(in interface{}, context *compiler.Context) (*JsonReference, error) {2048 errors := make([]error, 0)2049 x := &JsonReference{}2050 m, ok := compiler.UnpackMap(in)2051 if !ok {2052 message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)2053 errors = append(errors, compiler.NewError(context, message))2054 } else {2055 requiredKeys := []string{"$ref"}2056 missingKeys := compiler.MissingKeysInMap(m, requiredKeys)2057 if len(missingKeys) > 0 {2058 message := fmt.Sprintf("is missing required %s: %+v", compiler.PluralProperties(len(missingKeys)), strings.Join(missingKeys, ", "))2059 errors = append(errors, compiler.NewError(context, message))2060 }2061 allowedKeys := []string{"$ref", "description"}2062 allowedPatterns := []string{}2063 invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)2064 if len(invalidKeys) > 0 {2065 message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))2066 errors = append(errors, compiler.NewError(context, message))2067 }2068 // string _ref = 1;2069 v1 := compiler.MapValueForKey(m, "$ref")2070 if v1 != nil {2071 x.XRef, ok = v1.(string)2072 if !ok {2073 message := fmt.Sprintf("has unexpected value for $ref: %+v (%T)", v1, v1)2074 errors = append(errors, compiler.NewError(context, message))2075 }2076 }2077 // string description = 2;2078 v2 := compiler.MapValueForKey(m, "description")2079 if v2 != nil {2080 x.Description, ok = v2.(string)2081 if !ok {2082 message := fmt.Sprintf("has unexpected value for description: %+v (%T)", v2, v2)2083 errors = append(errors, compiler.NewError(context, message))2084 }2085 }2086 }2087 return x, compiler.NewErrorGroupOrNil(errors)2088}2089func NewLicense(in interface{}, context *compiler.Context) (*License, error) {2090 errors := make([]error, 0)2091 x := &License{}2092 m, ok := compiler.UnpackMap(in)2093 if !ok {2094 message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)2095 errors = append(errors, compiler.NewError(context, message))2096 } else {2097 requiredKeys := []string{"name"}2098 missingKeys := compiler.MissingKeysInMap(m, requiredKeys)2099 if len(missingKeys) > 0 {2100 message := fmt.Sprintf("is missing required %s: %+v", compiler.PluralProperties(len(missingKeys)), strings.Join(missingKeys, ", "))2101 errors = append(errors, compiler.NewError(context, message))2102 }2103 allowedKeys := []string{"name", "url"}2104 allowedPatterns := []string{"^x-"}2105 invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)2106 if len(invalidKeys) > 0 {2107 message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))2108 errors = append(errors, compiler.NewError(context, message))2109 }2110 // string name = 1;2111 v1 := compiler.MapValueForKey(m, "name")2112 if v1 != nil {2113 x.Name, ok = v1.(string)2114 if !ok {2115 message := fmt.Sprintf("has unexpected value for name: %+v (%T)", v1, v1)2116 errors = append(errors, compiler.NewError(context, message))2117 }2118 }2119 // string url = 2;2120 v2 := compiler.MapValueForKey(m, "url")2121 if v2 != nil {2122 x.Url, ok = v2.(string)2123 if !ok {2124 message := fmt.Sprintf("has unexpected value for url: %+v (%T)", v2, v2)2125 errors = append(errors, compiler.NewError(context, message))2126 }2127 }2128 // repeated NamedAny vendor_extension = 3;2129 // MAP: Any ^x-2130 x.VendorExtension = make([]*NamedAny, 0)2131 for _, item := range m {2132 k, ok := item.Key.(string)2133 if ok {2134 v := item.Value2135 if compiler.PatternMatches("^x-", k) {2136 pair := &NamedAny{}2137 pair.Name = k2138 result := &Any{}2139 handled, resultFromExt, err := compiler.HandleExtension(context, v, k)2140 if handled {2141 if err != nil {2142 errors = append(errors, err)2143 } else {2144 bytes, _ := yaml.Marshal(v)2145 result.Yaml = string(bytes)2146 result.Value = resultFromExt2147 pair.Value = result2148 }2149 } else {2150 pair.Value, err = NewAny(v, compiler.NewContext(k, context))2151 if err != nil {2152 errors = append(errors, err)2153 }2154 }2155 x.VendorExtension = append(x.VendorExtension, pair)2156 }2157 }2158 }2159 }2160 return x, compiler.NewErrorGroupOrNil(errors)2161}2162func NewNamedAny(in interface{}, context *compiler.Context) (*NamedAny, error) {2163 errors := make([]error, 0)2164 x := &NamedAny{}2165 m, ok := compiler.UnpackMap(in)2166 if !ok {2167 message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)2168 errors = append(errors, compiler.NewError(context, message))2169 } else {2170 allowedKeys := []string{"name", "value"}2171 allowedPatterns := []string{}2172 invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)2173 if len(invalidKeys) > 0 {2174 message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))2175 errors = append(errors, compiler.NewError(context, message))2176 }2177 // string name = 1;2178 v1 := compiler.MapValueForKey(m, "name")2179 if v1 != nil {2180 x.Name, ok = v1.(string)2181 if !ok {2182 message := fmt.Sprintf("has unexpected value for name: %+v (%T)", v1, v1)2183 errors = append(errors, compiler.NewError(context, message))2184 }2185 }2186 // Any value = 2;2187 v2 := compiler.MapValueForKey(m, "value")2188 if v2 != nil {2189 var err error2190 x.Value, err = NewAny(v2, compiler.NewContext("value", context))2191 if err != nil {2192 errors = append(errors, err)2193 }2194 }2195 }2196 return x, compiler.NewErrorGroupOrNil(errors)2197}2198func NewNamedHeader(in interface{}, context *compiler.Context) (*NamedHeader, error) {2199 errors := make([]error, 0)2200 x := &NamedHeader{}2201 m, ok := compiler.UnpackMap(in)2202 if !ok {2203 message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)2204 errors = append(errors, compiler.NewError(context, message))2205 } else {2206 allowedKeys := []string{"name", "value"}2207 allowedPatterns := []string{}2208 invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)2209 if len(invalidKeys) > 0 {2210 message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))2211 errors = append(errors, compiler.NewError(context, message))2212 }2213 // string name = 1;2214 v1 := compiler.MapValueForKey(m, "name")2215 if v1 != nil {2216 x.Name, ok = v1.(string)2217 if !ok {2218 message := fmt.Sprintf("has unexpected value for name: %+v (%T)", v1, v1)2219 errors = append(errors, compiler.NewError(context, message))2220 }2221 }2222 // Header value = 2;2223 v2 := compiler.MapValueForKey(m, "value")2224 if v2 != nil {2225 var err error2226 x.Value, err = NewHeader(v2, compiler.NewContext("value", context))2227 if err != nil {2228 errors = append(errors, err)2229 }2230 }2231 }2232 return x, compiler.NewErrorGroupOrNil(errors)2233}2234func NewNamedParameter(in interface{}, context *compiler.Context) (*NamedParameter, error) {2235 errors := make([]error, 0)2236 x := &NamedParameter{}2237 m, ok := compiler.UnpackMap(in)2238 if !ok {2239 message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)2240 errors = append(errors, compiler.NewError(context, message))2241 } else {2242 allowedKeys := []string{"name", "value"}2243 allowedPatterns := []string{}2244 invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)2245 if len(invalidKeys) > 0 {2246 message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))2247 errors = append(errors, compiler.NewError(context, message))2248 }2249 // string name = 1;2250 v1 := compiler.MapValueForKey(m, "name")2251 if v1 != nil {2252 x.Name, ok = v1.(string)2253 if !ok {2254 message := fmt.Sprintf("has unexpected value for name: %+v (%T)", v1, v1)2255 errors = append(errors, compiler.NewError(context, message))2256 }2257 }2258 // Parameter value = 2;2259 v2 := compiler.MapValueForKey(m, "value")2260 if v2 != nil {2261 var err error2262 x.Value, err = NewParameter(v2, compiler.NewContext("value", context))2263 if err != nil {2264 errors = append(errors, err)2265 }2266 }2267 }2268 return x, compiler.NewErrorGroupOrNil(errors)2269}2270func NewNamedPathItem(in interface{}, context *compiler.Context) (*NamedPathItem, error) {2271 errors := make([]error, 0)2272 x := &NamedPathItem{}2273 m, ok := compiler.UnpackMap(in)2274 if !ok {2275 message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)2276 errors = append(errors, compiler.NewError(context, message))2277 } else {2278 allowedKeys := []string{"name", "value"}2279 allowedPatterns := []string{}2280 invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)2281 if len(invalidKeys) > 0 {2282 message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))2283 errors = append(errors, compiler.NewError(context, message))2284 }2285 // string name = 1;2286 v1 := compiler.MapValueForKey(m, "name")2287 if v1 != nil {2288 x.Name, ok = v1.(string)2289 if !ok {2290 message := fmt.Sprintf("has unexpected value for name: %+v (%T)", v1, v1)2291 errors = append(errors, compiler.NewError(context, message))2292 }2293 }2294 // PathItem value = 2;2295 v2 := compiler.MapValueForKey(m, "value")2296 if v2 != nil {2297 var err error2298 x.Value, err = NewPathItem(v2, compiler.NewContext("value", context))2299 if err != nil {2300 errors = append(errors, err)2301 }2302 }2303 }2304 return x, compiler.NewErrorGroupOrNil(errors)2305}2306func NewNamedResponse(in interface{}, context *compiler.Context) (*NamedResponse, error) {2307 errors := make([]error, 0)2308 x := &NamedResponse{}2309 m, ok := compiler.UnpackMap(in)2310 if !ok {2311 message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)2312 errors = append(errors, compiler.NewError(context, message))2313 } else {2314 allowedKeys := []string{"name", "value"}2315 allowedPatterns := []string{}2316 invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)2317 if len(invalidKeys) > 0 {2318 message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))2319 errors = append(errors, compiler.NewError(context, message))2320 }2321 // string name = 1;2322 v1 := compiler.MapValueForKey(m, "name")2323 if v1 != nil {2324 x.Name, ok = v1.(string)2325 if !ok {2326 message := fmt.Sprintf("has unexpected value for name: %+v (%T)", v1, v1)2327 errors = append(errors, compiler.NewError(context, message))2328 }2329 }2330 // Response value = 2;2331 v2 := compiler.MapValueForKey(m, "value")2332 if v2 != nil {2333 var err error2334 x.Value, err = NewResponse(v2, compiler.NewContext("value", context))2335 if err != nil {2336 errors = append(errors, err)2337 }2338 }2339 }2340 return x, compiler.NewErrorGroupOrNil(errors)2341}2342func NewNamedResponseValue(in interface{}, context *compiler.Context) (*NamedResponseValue, error) {2343 errors := make([]error, 0)2344 x := &NamedResponseValue{}2345 m, ok := compiler.UnpackMap(in)2346 if !ok {2347 message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)2348 errors = append(errors, compiler.NewError(context, message))2349 } else {2350 allowedKeys := []string{"name", "value"}2351 allowedPatterns := []string{}2352 invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)2353 if len(invalidKeys) > 0 {2354 message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))2355 errors = append(errors, compiler.NewError(context, message))2356 }2357 // string name = 1;2358 v1 := compiler.MapValueForKey(m, "name")2359 if v1 != nil {2360 x.Name, ok = v1.(string)2361 if !ok {2362 message := fmt.Sprintf("has unexpected value for name: %+v (%T)", v1, v1)2363 errors = append(errors, compiler.NewError(context, message))2364 }2365 }2366 // ResponseValue value = 2;2367 v2 := compiler.MapValueForKey(m, "value")2368 if v2 != nil {2369 var err error2370 x.Value, err = NewResponseValue(v2, compiler.NewContext("value", context))2371 if err != nil {2372 errors = append(errors, err)2373 }2374 }2375 }2376 return x, compiler.NewErrorGroupOrNil(errors)2377}2378func NewNamedSchema(in interface{}, context *compiler.Context) (*NamedSchema, error) {2379 errors := make([]error, 0)2380 x := &NamedSchema{}2381 m, ok := compiler.UnpackMap(in)2382 if !ok {2383 message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)2384 errors = append(errors, compiler.NewError(context, message))2385 } else {2386 allowedKeys := []string{"name", "value"}2387 allowedPatterns := []string{}2388 invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)2389 if len(invalidKeys) > 0 {2390 message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))2391 errors = append(errors, compiler.NewError(context, message))2392 }2393 // string name = 1;2394 v1 := compiler.MapValueForKey(m, "name")2395 if v1 != nil {2396 x.Name, ok = v1.(string)2397 if !ok {2398 message := fmt.Sprintf("has unexpected value for name: %+v (%T)", v1, v1)2399 errors = append(errors, compiler.NewError(context, message))2400 }2401 }2402 // Schema value = 2;2403 v2 := compiler.MapValueForKey(m, "value")2404 if v2 != nil {2405 var err error2406 x.Value, err = NewSchema(v2, compiler.NewContext("value", context))2407 if err != nil {2408 errors = append(errors, err)2409 }2410 }2411 }2412 return x, compiler.NewErrorGroupOrNil(errors)2413}2414func NewNamedSecurityDefinitionsItem(in interface{}, context *compiler.Context) (*NamedSecurityDefinitionsItem, error) {2415 errors := make([]error, 0)2416 x := &NamedSecurityDefinitionsItem{}2417 m, ok := compiler.UnpackMap(in)2418 if !ok {2419 message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)2420 errors = append(errors, compiler.NewError(context, message))2421 } else {2422 allowedKeys := []string{"name", "value"}2423 allowedPatterns := []string{}2424 invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)2425 if len(invalidKeys) > 0 {2426 message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))2427 errors = append(errors, compiler.NewError(context, message))2428 }2429 // string name = 1;2430 v1 := compiler.MapValueForKey(m, "name")2431 if v1 != nil {2432 x.Name, ok = v1.(string)2433 if !ok {2434 message := fmt.Sprintf("has unexpected value for name: %+v (%T)", v1, v1)2435 errors = append(errors, compiler.NewError(context, message))2436 }2437 }2438 // SecurityDefinitionsItem value = 2;2439 v2 := compiler.MapValueForKey(m, "value")2440 if v2 != nil {2441 var err error2442 x.Value, err = NewSecurityDefinitionsItem(v2, compiler.NewContext("value", context))2443 if err != nil {2444 errors = append(errors, err)2445 }2446 }2447 }2448 return x, compiler.NewErrorGroupOrNil(errors)2449}2450func NewNamedString(in interface{}, context *compiler.Context) (*NamedString, error) {2451 errors := make([]error, 0)2452 x := &NamedString{}2453 m, ok := compiler.UnpackMap(in)2454 if !ok {2455 message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)2456 errors = append(errors, compiler.NewError(context, message))2457 } else {2458 allowedKeys := []string{"name", "value"}2459 allowedPatterns := []string{}2460 invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)2461 if len(invalidKeys) > 0 {2462 message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))2463 errors = append(errors, compiler.NewError(context, message))2464 }2465 // string name = 1;2466 v1 := compiler.MapValueForKey(m, "name")2467 if v1 != nil {2468 x.Name, ok = v1.(string)2469 if !ok {2470 message := fmt.Sprintf("has unexpected value for name: %+v (%T)", v1, v1)2471 errors = append(errors, compiler.NewError(context, message))2472 }2473 }2474 // string value = 2;2475 v2 := compiler.MapValueForKey(m, "value")2476 if v2 != nil {2477 x.Value, ok = v2.(string)2478 if !ok {2479 message := fmt.Sprintf("has unexpected value for value: %+v (%T)", v2, v2)2480 errors = append(errors, compiler.NewError(context, message))2481 }2482 }2483 }2484 return x, compiler.NewErrorGroupOrNil(errors)2485}2486func NewNamedStringArray(in interface{}, context *compiler.Context) (*NamedStringArray, error) {2487 errors := make([]error, 0)2488 x := &NamedStringArray{}2489 m, ok := compiler.UnpackMap(in)2490 if !ok {2491 message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)2492 errors = append(errors, compiler.NewError(context, message))2493 } else {2494 allowedKeys := []string{"name", "value"}2495 allowedPatterns := []string{}2496 invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)2497 if len(invalidKeys) > 0 {2498 message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))2499 errors = append(errors, compiler.NewError(context, message))2500 }2501 // string name = 1;2502 v1 := compiler.MapValueForKey(m, "name")2503 if v1 != nil {2504 x.Name, ok = v1.(string)2505 if !ok {2506 message := fmt.Sprintf("has unexpected value for name: %+v (%T)", v1, v1)2507 errors = append(errors, compiler.NewError(context, message))2508 }2509 }2510 // StringArray value = 2;2511 v2 := compiler.MapValueForKey(m, "value")2512 if v2 != nil {2513 var err error2514 x.Value, err = NewStringArray(v2, compiler.NewContext("value", context))2515 if err != nil {2516 errors = append(errors, err)2517 }2518 }2519 }2520 return x, compiler.NewErrorGroupOrNil(errors)2521}2522func NewNonBodyParameter(in interface{}, context *compiler.Context) (*NonBodyParameter, error) {2523 errors := make([]error, 0)2524 x := &NonBodyParameter{}2525 matched := false2526 m, ok := compiler.UnpackMap(in)2527 if !ok {2528 message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)2529 errors = append(errors, compiler.NewError(context, message))2530 } else {2531 requiredKeys := []string{"in", "name", "type"}2532 missingKeys := compiler.MissingKeysInMap(m, requiredKeys)2533 if len(missingKeys) > 0 {2534 message := fmt.Sprintf("is missing required %s: %+v", compiler.PluralProperties(len(missingKeys)), strings.Join(missingKeys, ", "))2535 errors = append(errors, compiler.NewError(context, message))2536 }2537 // HeaderParameterSubSchema header_parameter_sub_schema = 1;2538 {2539 // errors might be ok here, they mean we just don't have the right subtype2540 t, matching_error := NewHeaderParameterSubSchema(m, compiler.NewContext("headerParameterSubSchema", context))2541 if matching_error == nil {2542 x.Oneof = &NonBodyParameter_HeaderParameterSubSchema{HeaderParameterSubSchema: t}2543 matched = true2544 } else {2545 errors = append(errors, matching_error)2546 }2547 }2548 // FormDataParameterSubSchema form_data_parameter_sub_schema = 2;2549 {2550 // errors might be ok here, they mean we just don't have the right subtype2551 t, matching_error := NewFormDataParameterSubSchema(m, compiler.NewContext("formDataParameterSubSchema", context))2552 if matching_error == nil {2553 x.Oneof = &NonBodyParameter_FormDataParameterSubSchema{FormDataParameterSubSchema: t}2554 matched = true2555 } else {2556 errors = append(errors, matching_error)2557 }2558 }2559 // QueryParameterSubSchema query_parameter_sub_schema = 3;2560 {2561 // errors might be ok here, they mean we just don't have the right subtype2562 t, matching_error := NewQueryParameterSubSchema(m, compiler.NewContext("queryParameterSubSchema", context))2563 if matching_error == nil {2564 x.Oneof = &NonBodyParameter_QueryParameterSubSchema{QueryParameterSubSchema: t}2565 matched = true2566 } else {2567 errors = append(errors, matching_error)2568 }2569 }2570 // PathParameterSubSchema path_parameter_sub_schema = 4;2571 {2572 // errors might be ok here, they mean we just don't have the right subtype2573 t, matching_error := NewPathParameterSubSchema(m, compiler.NewContext("pathParameterSubSchema", context))2574 if matching_error == nil {2575 x.Oneof = &NonBodyParameter_PathParameterSubSchema{PathParameterSubSchema: t}2576 matched = true2577 } else {2578 errors = append(errors, matching_error)2579 }2580 }2581 }2582 if matched {2583 // since the oneof matched one of its possibilities, discard any matching errors2584 errors = make([]error, 0)2585 }2586 return x, compiler.NewErrorGroupOrNil(errors)2587}2588func NewOauth2AccessCodeSecurity(in interface{}, context *compiler.Context) (*Oauth2AccessCodeSecurity, error) {2589 errors := make([]error, 0)2590 x := &Oauth2AccessCodeSecurity{}2591 m, ok := compiler.UnpackMap(in)2592 if !ok {2593 message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)2594 errors = append(errors, compiler.NewError(context, message))2595 } else {2596 requiredKeys := []string{"authorizationUrl", "flow", "tokenUrl", "type"}2597 missingKeys := compiler.MissingKeysInMap(m, requiredKeys)2598 if len(missingKeys) > 0 {2599 message := fmt.Sprintf("is missing required %s: %+v", compiler.PluralProperties(len(missingKeys)), strings.Join(missingKeys, ", "))2600 errors = append(errors, compiler.NewError(context, message))2601 }2602 allowedKeys := []string{"authorizationUrl", "description", "flow", "scopes", "tokenUrl", "type"}2603 allowedPatterns := []string{"^x-"}2604 invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)2605 if len(invalidKeys) > 0 {2606 message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))2607 errors = append(errors, compiler.NewError(context, message))2608 }2609 // string type = 1;2610 v1 := compiler.MapValueForKey(m, "type")2611 if v1 != nil {2612 x.Type, ok = v1.(string)2613 if !ok {2614 message := fmt.Sprintf("has unexpected value for type: %+v (%T)", v1, v1)2615 errors = append(errors, compiler.NewError(context, message))2616 }2617 // check for valid enum values2618 // [oauth2]2619 if ok && !compiler.StringArrayContainsValue([]string{"oauth2"}, x.Type) {2620 message := fmt.Sprintf("has unexpected value for type: %+v (%T)", v1, v1)2621 errors = append(errors, compiler.NewError(context, message))2622 }2623 }2624 // string flow = 2;2625 v2 := compiler.MapValueForKey(m, "flow")2626 if v2 != nil {2627 x.Flow, ok = v2.(string)2628 if !ok {2629 message := fmt.Sprintf("has unexpected value for flow: %+v (%T)", v2, v2)2630 errors = append(errors, compiler.NewError(context, message))2631 }2632 // check for valid enum values2633 // [accessCode]2634 if ok && !compiler.StringArrayContainsValue([]string{"accessCode"}, x.Flow) {2635 message := fmt.Sprintf("has unexpected value for flow: %+v (%T)", v2, v2)2636 errors = append(errors, compiler.NewError(context, message))2637 }2638 }2639 // Oauth2Scopes scopes = 3;2640 v3 := compiler.MapValueForKey(m, "scopes")2641 if v3 != nil {2642 var err error2643 x.Scopes, err = NewOauth2Scopes(v3, compiler.NewContext("scopes", context))2644 if err != nil {2645 errors = append(errors, err)2646 }2647 }2648 // string authorization_url = 4;2649 v4 := compiler.MapValueForKey(m, "authorizationUrl")2650 if v4 != nil {2651 x.AuthorizationUrl, ok = v4.(string)2652 if !ok {2653 message := fmt.Sprintf("has unexpected value for authorizationUrl: %+v (%T)", v4, v4)2654 errors = append(errors, compiler.NewError(context, message))2655 }2656 }2657 // string token_url = 5;2658 v5 := compiler.MapValueForKey(m, "tokenUrl")2659 if v5 != nil {2660 x.TokenUrl, ok = v5.(string)2661 if !ok {2662 message := fmt.Sprintf("has unexpected value for tokenUrl: %+v (%T)", v5, v5)2663 errors = append(errors, compiler.NewError(context, message))2664 }2665 }2666 // string description = 6;2667 v6 := compiler.MapValueForKey(m, "description")2668 if v6 != nil {2669 x.Description, ok = v6.(string)2670 if !ok {2671 message := fmt.Sprintf("has unexpected value for description: %+v (%T)", v6, v6)2672 errors = append(errors, compiler.NewError(context, message))2673 }2674 }2675 // repeated NamedAny vendor_extension = 7;2676 // MAP: Any ^x-2677 x.VendorExtension = make([]*NamedAny, 0)2678 for _, item := range m {2679 k, ok := item.Key.(string)2680 if ok {2681 v := item.Value2682 if compiler.PatternMatches("^x-", k) {2683 pair := &NamedAny{}2684 pair.Name = k2685 result := &Any{}2686 handled, resultFromExt, err := compiler.HandleExtension(context, v, k)2687 if handled {2688 if err != nil {2689 errors = append(errors, err)2690 } else {2691 bytes, _ := yaml.Marshal(v)2692 result.Yaml = string(bytes)2693 result.Value = resultFromExt2694 pair.Value = result2695 }2696 } else {2697 pair.Value, err = NewAny(v, compiler.NewContext(k, context))2698 if err != nil {2699 errors = append(errors, err)2700 }2701 }2702 x.VendorExtension = append(x.VendorExtension, pair)2703 }2704 }2705 }2706 }2707 return x, compiler.NewErrorGroupOrNil(errors)2708}2709func NewOauth2ApplicationSecurity(in interface{}, context *compiler.Context) (*Oauth2ApplicationSecurity, error) {2710 errors := make([]error, 0)2711 x := &Oauth2ApplicationSecurity{}2712 m, ok := compiler.UnpackMap(in)2713 if !ok {2714 message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)2715 errors = append(errors, compiler.NewError(context, message))2716 } else {2717 requiredKeys := []string{"flow", "tokenUrl", "type"}2718 missingKeys := compiler.MissingKeysInMap(m, requiredKeys)2719 if len(missingKeys) > 0 {2720 message := fmt.Sprintf("is missing required %s: %+v", compiler.PluralProperties(len(missingKeys)), strings.Join(missingKeys, ", "))2721 errors = append(errors, compiler.NewError(context, message))2722 }2723 allowedKeys := []string{"description", "flow", "scopes", "tokenUrl", "type"}2724 allowedPatterns := []string{"^x-"}2725 invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)2726 if len(invalidKeys) > 0 {2727 message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))2728 errors = append(errors, compiler.NewError(context, message))2729 }2730 // string type = 1;2731 v1 := compiler.MapValueForKey(m, "type")2732 if v1 != nil {2733 x.Type, ok = v1.(string)2734 if !ok {2735 message := fmt.Sprintf("has unexpected value for type: %+v (%T)", v1, v1)2736 errors = append(errors, compiler.NewError(context, message))2737 }2738 // check for valid enum values2739 // [oauth2]2740 if ok && !compiler.StringArrayContainsValue([]string{"oauth2"}, x.Type) {2741 message := fmt.Sprintf("has unexpected value for type: %+v (%T)", v1, v1)2742 errors = append(errors, compiler.NewError(context, message))2743 }2744 }2745 // string flow = 2;2746 v2 := compiler.MapValueForKey(m, "flow")2747 if v2 != nil {2748 x.Flow, ok = v2.(string)2749 if !ok {2750 message := fmt.Sprintf("has unexpected value for flow: %+v (%T)", v2, v2)2751 errors = append(errors, compiler.NewError(context, message))2752 }2753 // check for valid enum values2754 // [application]2755 if ok && !compiler.StringArrayContainsValue([]string{"application"}, x.Flow) {2756 message := fmt.Sprintf("has unexpected value for flow: %+v (%T)", v2, v2)2757 errors = append(errors, compiler.NewError(context, message))2758 }2759 }2760 // Oauth2Scopes scopes = 3;2761 v3 := compiler.MapValueForKey(m, "scopes")2762 if v3 != nil {2763 var err error2764 x.Scopes, err = NewOauth2Scopes(v3, compiler.NewContext("scopes", context))2765 if err != nil {2766 errors = append(errors, err)2767 }2768 }2769 // string token_url = 4;2770 v4 := compiler.MapValueForKey(m, "tokenUrl")2771 if v4 != nil {2772 x.TokenUrl, ok = v4.(string)2773 if !ok {2774 message := fmt.Sprintf("has unexpected value for tokenUrl: %+v (%T)", v4, v4)2775 errors = append(errors, compiler.NewError(context, message))2776 }2777 }2778 // string description = 5;2779 v5 := compiler.MapValueForKey(m, "description")2780 if v5 != nil {2781 x.Description, ok = v5.(string)2782 if !ok {2783 message := fmt.Sprintf("has unexpected value for description: %+v (%T)", v5, v5)2784 errors = append(errors, compiler.NewError(context, message))2785 }2786 }2787 // repeated NamedAny vendor_extension = 6;2788 // MAP: Any ^x-2789 x.VendorExtension = make([]*NamedAny, 0)2790 for _, item := range m {2791 k, ok := item.Key.(string)2792 if ok {2793 v := item.Value2794 if compiler.PatternMatches("^x-", k) {2795 pair := &NamedAny{}2796 pair.Name = k2797 result := &Any{}2798 handled, resultFromExt, err := compiler.HandleExtension(context, v, k)2799 if handled {2800 if err != nil {2801 errors = append(errors, err)2802 } else {2803 bytes, _ := yaml.Marshal(v)2804 result.Yaml = string(bytes)2805 result.Value = resultFromExt2806 pair.Value = result2807 }2808 } else {2809 pair.Value, err = NewAny(v, compiler.NewContext(k, context))2810 if err != nil {2811 errors = append(errors, err)2812 }2813 }2814 x.VendorExtension = append(x.VendorExtension, pair)2815 }2816 }2817 }2818 }2819 return x, compiler.NewErrorGroupOrNil(errors)2820}2821func NewOauth2ImplicitSecurity(in interface{}, context *compiler.Context) (*Oauth2ImplicitSecurity, error) {2822 errors := make([]error, 0)2823 x := &Oauth2ImplicitSecurity{}2824 m, ok := compiler.UnpackMap(in)2825 if !ok {2826 message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)2827 errors = append(errors, compiler.NewError(context, message))2828 } else {2829 requiredKeys := []string{"authorizationUrl", "flow", "type"}2830 missingKeys := compiler.MissingKeysInMap(m, requiredKeys)2831 if len(missingKeys) > 0 {2832 message := fmt.Sprintf("is missing required %s: %+v", compiler.PluralProperties(len(missingKeys)), strings.Join(missingKeys, ", "))2833 errors = append(errors, compiler.NewError(context, message))2834 }2835 allowedKeys := []string{"authorizationUrl", "description", "flow", "scopes", "type"}2836 allowedPatterns := []string{"^x-"}2837 invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)2838 if len(invalidKeys) > 0 {2839 message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))2840 errors = append(errors, compiler.NewError(context, message))2841 }2842 // string type = 1;2843 v1 := compiler.MapValueForKey(m, "type")2844 if v1 != nil {2845 x.Type, ok = v1.(string)2846 if !ok {2847 message := fmt.Sprintf("has unexpected value for type: %+v (%T)", v1, v1)2848 errors = append(errors, compiler.NewError(context, message))2849 }2850 // check for valid enum values2851 // [oauth2]2852 if ok && !compiler.StringArrayContainsValue([]string{"oauth2"}, x.Type) {2853 message := fmt.Sprintf("has unexpected value for type: %+v (%T)", v1, v1)2854 errors = append(errors, compiler.NewError(context, message))2855 }2856 }2857 // string flow = 2;2858 v2 := compiler.MapValueForKey(m, "flow")2859 if v2 != nil {2860 x.Flow, ok = v2.(string)2861 if !ok {2862 message := fmt.Sprintf("has unexpected value for flow: %+v (%T)", v2, v2)2863 errors = append(errors, compiler.NewError(context, message))2864 }2865 // check for valid enum values2866 // [implicit]2867 if ok && !compiler.StringArrayContainsValue([]string{"implicit"}, x.Flow) {2868 message := fmt.Sprintf("has unexpected value for flow: %+v (%T)", v2, v2)2869 errors = append(errors, compiler.NewError(context, message))2870 }2871 }2872 // Oauth2Scopes scopes = 3;2873 v3 := compiler.MapValueForKey(m, "scopes")2874 if v3 != nil {2875 var err error2876 x.Scopes, err = NewOauth2Scopes(v3, compiler.NewContext("scopes", context))2877 if err != nil {2878 errors = append(errors, err)2879 }2880 }2881 // string authorization_url = 4;2882 v4 := compiler.MapValueForKey(m, "authorizationUrl")2883 if v4 != nil {2884 x.AuthorizationUrl, ok = v4.(string)2885 if !ok {2886 message := fmt.Sprintf("has unexpected value for authorizationUrl: %+v (%T)", v4, v4)2887 errors = append(errors, compiler.NewError(context, message))2888 }2889 }2890 // string description = 5;2891 v5 := compiler.MapValueForKey(m, "description")2892 if v5 != nil {2893 x.Description, ok = v5.(string)2894 if !ok {2895 message := fmt.Sprintf("has unexpected value for description: %+v (%T)", v5, v5)2896 errors = append(errors, compiler.NewError(context, message))2897 }2898 }2899 // repeated NamedAny vendor_extension = 6;2900 // MAP: Any ^x-2901 x.VendorExtension = make([]*NamedAny, 0)2902 for _, item := range m {2903 k, ok := item.Key.(string)2904 if ok {2905 v := item.Value2906 if compiler.PatternMatches("^x-", k) {2907 pair := &NamedAny{}2908 pair.Name = k2909 result := &Any{}2910 handled, resultFromExt, err := compiler.HandleExtension(context, v, k)2911 if handled {2912 if err != nil {2913 errors = append(errors, err)2914 } else {2915 bytes, _ := yaml.Marshal(v)2916 result.Yaml = string(bytes)2917 result.Value = resultFromExt2918 pair.Value = result2919 }2920 } else {2921 pair.Value, err = NewAny(v, compiler.NewContext(k, context))2922 if err != nil {2923 errors = append(errors, err)2924 }2925 }2926 x.VendorExtension = append(x.VendorExtension, pair)2927 }2928 }2929 }2930 }2931 return x, compiler.NewErrorGroupOrNil(errors)2932}2933func NewOauth2PasswordSecurity(in interface{}, context *compiler.Context) (*Oauth2PasswordSecurity, error) {2934 errors := make([]error, 0)2935 x := &Oauth2PasswordSecurity{}2936 m, ok := compiler.UnpackMap(in)2937 if !ok {2938 message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)2939 errors = append(errors, compiler.NewError(context, message))2940 } else {2941 requiredKeys := []string{"flow", "tokenUrl", "type"}2942 missingKeys := compiler.MissingKeysInMap(m, requiredKeys)2943 if len(missingKeys) > 0 {2944 message := fmt.Sprintf("is missing required %s: %+v", compiler.PluralProperties(len(missingKeys)), strings.Join(missingKeys, ", "))2945 errors = append(errors, compiler.NewError(context, message))2946 }2947 allowedKeys := []string{"description", "flow", "scopes", "tokenUrl", "type"}2948 allowedPatterns := []string{"^x-"}2949 invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)2950 if len(invalidKeys) > 0 {2951 message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))2952 errors = append(errors, compiler.NewError(context, message))2953 }2954 // string type = 1;2955 v1 := compiler.MapValueForKey(m, "type")2956 if v1 != nil {2957 x.Type, ok = v1.(string)2958 if !ok {2959 message := fmt.Sprintf("has unexpected value for type: %+v (%T)", v1, v1)2960 errors = append(errors, compiler.NewError(context, message))2961 }2962 // check for valid enum values2963 // [oauth2]2964 if ok && !compiler.StringArrayContainsValue([]string{"oauth2"}, x.Type) {2965 message := fmt.Sprintf("has unexpected value for type: %+v (%T)", v1, v1)2966 errors = append(errors, compiler.NewError(context, message))2967 }2968 }2969 // string flow = 2;2970 v2 := compiler.MapValueForKey(m, "flow")2971 if v2 != nil {2972 x.Flow, ok = v2.(string)2973 if !ok {2974 message := fmt.Sprintf("has unexpected value for flow: %+v (%T)", v2, v2)2975 errors = append(errors, compiler.NewError(context, message))2976 }2977 // check for valid enum values2978 // [password]2979 if ok && !compiler.StringArrayContainsValue([]string{"password"}, x.Flow) {2980 message := fmt.Sprintf("has unexpected value for flow: %+v (%T)", v2, v2)2981 errors = append(errors, compiler.NewError(context, message))2982 }2983 }2984 // Oauth2Scopes scopes = 3;2985 v3 := compiler.MapValueForKey(m, "scopes")2986 if v3 != nil {2987 var err error2988 x.Scopes, err = NewOauth2Scopes(v3, compiler.NewContext("scopes", context))2989 if err != nil {2990 errors = append(errors, err)2991 }2992 }2993 // string token_url = 4;2994 v4 := compiler.MapValueForKey(m, "tokenUrl")2995 if v4 != nil {2996 x.TokenUrl, ok = v4.(string)2997 if !ok {2998 message := fmt.Sprintf("has unexpected value for tokenUrl: %+v (%T)", v4, v4)2999 errors = append(errors, compiler.NewError(context, message))3000 }3001 }3002 // string description = 5;3003 v5 := compiler.MapValueForKey(m, "description")3004 if v5 != nil {3005 x.Description, ok = v5.(string)3006 if !ok {3007 message := fmt.Sprintf("has unexpected value for description: %+v (%T)", v5, v5)3008 errors = append(errors, compiler.NewError(context, message))3009 }3010 }3011 // repeated NamedAny vendor_extension = 6;3012 // MAP: Any ^x-3013 x.VendorExtension = make([]*NamedAny, 0)3014 for _, item := range m {3015 k, ok := item.Key.(string)3016 if ok {3017 v := item.Value3018 if compiler.PatternMatches("^x-", k) {3019 pair := &NamedAny{}3020 pair.Name = k3021 result := &Any{}3022 handled, resultFromExt, err := compiler.HandleExtension(context, v, k)3023 if handled {3024 if err != nil {3025 errors = append(errors, err)3026 } else {3027 bytes, _ := yaml.Marshal(v)3028 result.Yaml = string(bytes)3029 result.Value = resultFromExt3030 pair.Value = result3031 }3032 } else {3033 pair.Value, err = NewAny(v, compiler.NewContext(k, context))3034 if err != nil {3035 errors = append(errors, err)3036 }3037 }3038 x.VendorExtension = append(x.VendorExtension, pair)3039 }3040 }3041 }3042 }3043 return x, compiler.NewErrorGroupOrNil(errors)3044}3045func NewOauth2Scopes(in interface{}, context *compiler.Context) (*Oauth2Scopes, error) {3046 errors := make([]error, 0)3047 x := &Oauth2Scopes{}3048 m, ok := compiler.UnpackMap(in)3049 if !ok {3050 message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)3051 errors = append(errors, compiler.NewError(context, message))3052 } else {3053 // repeated NamedString additional_properties = 1;3054 // MAP: string3055 x.AdditionalProperties = make([]*NamedString, 0)3056 for _, item := range m {3057 k, ok := item.Key.(string)3058 if ok {3059 v := item.Value3060 pair := &NamedString{}3061 pair.Name = k3062 pair.Value = v.(string)3063 x.AdditionalProperties = append(x.AdditionalProperties, pair)3064 }3065 }3066 }3067 return x, compiler.NewErrorGroupOrNil(errors)3068}3069func NewOperation(in interface{}, context *compiler.Context) (*Operation, error) {3070 errors := make([]error, 0)3071 x := &Operation{}3072 m, ok := compiler.UnpackMap(in)3073 if !ok {3074 message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)3075 errors = append(errors, compiler.NewError(context, message))3076 } else {3077 requiredKeys := []string{"responses"}3078 missingKeys := compiler.MissingKeysInMap(m, requiredKeys)3079 if len(missingKeys) > 0 {3080 message := fmt.Sprintf("is missing required %s: %+v", compiler.PluralProperties(len(missingKeys)), strings.Join(missingKeys, ", "))3081 errors = append(errors, compiler.NewError(context, message))3082 }3083 allowedKeys := []string{"consumes", "deprecated", "description", "externalDocs", "operationId", "parameters", "produces", "responses", "schemes", "security", "summary", "tags"}3084 allowedPatterns := []string{"^x-"}3085 invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)3086 if len(invalidKeys) > 0 {3087 message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))3088 errors = append(errors, compiler.NewError(context, message))3089 }3090 // repeated string tags = 1;3091 v1 := compiler.MapValueForKey(m, "tags")3092 if v1 != nil {3093 v, ok := v1.([]interface{})3094 if ok {3095 x.Tags = compiler.ConvertInterfaceArrayToStringArray(v)3096 } else {3097 message := fmt.Sprintf("has unexpected value for tags: %+v (%T)", v1, v1)3098 errors = append(errors, compiler.NewError(context, message))3099 }3100 }3101 // string summary = 2;3102 v2 := compiler.MapValueForKey(m, "summary")3103 if v2 != nil {3104 x.Summary, ok = v2.(string)3105 if !ok {3106 message := fmt.Sprintf("has unexpected value for summary: %+v (%T)", v2, v2)3107 errors = append(errors, compiler.NewError(context, message))3108 }3109 }3110 // string description = 3;3111 v3 := compiler.MapValueForKey(m, "description")3112 if v3 != nil {3113 x.Description, ok = v3.(string)3114 if !ok {3115 message := fmt.Sprintf("has unexpected value for description: %+v (%T)", v3, v3)3116 errors = append(errors, compiler.NewError(context, message))3117 }3118 }3119 // ExternalDocs external_docs = 4;3120 v4 := compiler.MapValueForKey(m, "externalDocs")3121 if v4 != nil {3122 var err error3123 x.ExternalDocs, err = NewExternalDocs(v4, compiler.NewContext("externalDocs", context))3124 if err != nil {3125 errors = append(errors, err)3126 }3127 }3128 // string operation_id = 5;3129 v5 := compiler.MapValueForKey(m, "operationId")3130 if v5 != nil {3131 x.OperationId, ok = v5.(string)3132 if !ok {3133 message := fmt.Sprintf("has unexpected value for operationId: %+v (%T)", v5, v5)3134 errors = append(errors, compiler.NewError(context, message))3135 }3136 }3137 // repeated string produces = 6;3138 v6 := compiler.MapValueForKey(m, "produces")3139 if v6 != nil {3140 v, ok := v6.([]interface{})3141 if ok {3142 x.Produces = compiler.ConvertInterfaceArrayToStringArray(v)3143 } else {3144 message := fmt.Sprintf("has unexpected value for produces: %+v (%T)", v6, v6)3145 errors = append(errors, compiler.NewError(context, message))3146 }3147 }3148 // repeated string consumes = 7;3149 v7 := compiler.MapValueForKey(m, "consumes")3150 if v7 != nil {3151 v, ok := v7.([]interface{})3152 if ok {3153 x.Consumes = compiler.ConvertInterfaceArrayToStringArray(v)3154 } else {3155 message := fmt.Sprintf("has unexpected value for consumes: %+v (%T)", v7, v7)3156 errors = append(errors, compiler.NewError(context, message))3157 }3158 }3159 // repeated ParametersItem parameters = 8;3160 v8 := compiler.MapValueForKey(m, "parameters")3161 if v8 != nil {3162 // repeated ParametersItem3163 x.Parameters = make([]*ParametersItem, 0)3164 a, ok := v8.([]interface{})3165 if ok {3166 for _, item := range a {3167 y, err := NewParametersItem(item, compiler.NewContext("parameters", context))3168 if err != nil {3169 errors = append(errors, err)3170 }3171 x.Parameters = append(x.Parameters, y)3172 }3173 }3174 }3175 // Responses responses = 9;3176 v9 := compiler.MapValueForKey(m, "responses")3177 if v9 != nil {3178 var err error3179 x.Responses, err = NewResponses(v9, compiler.NewContext("responses", context))3180 if err != nil {3181 errors = append(errors, err)3182 }3183 }3184 // repeated string schemes = 10;3185 v10 := compiler.MapValueForKey(m, "schemes")3186 if v10 != nil {3187 v, ok := v10.([]interface{})3188 if ok {3189 x.Schemes = compiler.ConvertInterfaceArrayToStringArray(v)3190 } else {3191 message := fmt.Sprintf("has unexpected value for schemes: %+v (%T)", v10, v10)3192 errors = append(errors, compiler.NewError(context, message))3193 }3194 // check for valid enum values3195 // [http https ws wss]3196 if ok && !compiler.StringArrayContainsValues([]string{"http", "https", "ws", "wss"}, x.Schemes) {3197 message := fmt.Sprintf("has unexpected value for schemes: %+v", v10)3198 errors = append(errors, compiler.NewError(context, message))3199 }3200 }3201 // bool deprecated = 11;3202 v11 := compiler.MapValueForKey(m, "deprecated")3203 if v11 != nil {3204 x.Deprecated, ok = v11.(bool)3205 if !ok {3206 message := fmt.Sprintf("has unexpected value for deprecated: %+v (%T)", v11, v11)3207 errors = append(errors, compiler.NewError(context, message))3208 }3209 }3210 // repeated SecurityRequirement security = 12;3211 v12 := compiler.MapValueForKey(m, "security")3212 if v12 != nil {3213 // repeated SecurityRequirement3214 x.Security = make([]*SecurityRequirement, 0)3215 a, ok := v12.([]interface{})3216 if ok {3217 for _, item := range a {3218 y, err := NewSecurityRequirement(item, compiler.NewContext("security", context))3219 if err != nil {3220 errors = append(errors, err)3221 }3222 x.Security = append(x.Security, y)3223 }3224 }3225 }3226 // repeated NamedAny vendor_extension = 13;3227 // MAP: Any ^x-3228 x.VendorExtension = make([]*NamedAny, 0)3229 for _, item := range m {3230 k, ok := item.Key.(string)3231 if ok {3232 v := item.Value3233 if compiler.PatternMatches("^x-", k) {3234 pair := &NamedAny{}3235 pair.Name = k3236 result := &Any{}3237 handled, resultFromExt, err := compiler.HandleExtension(context, v, k)3238 if handled {3239 if err != nil {3240 errors = append(errors, err)3241 } else {3242 bytes, _ := yaml.Marshal(v)3243 result.Yaml = string(bytes)3244 result.Value = resultFromExt3245 pair.Value = result3246 }3247 } else {3248 pair.Value, err = NewAny(v, compiler.NewContext(k, context))3249 if err != nil {3250 errors = append(errors, err)3251 }3252 }3253 x.VendorExtension = append(x.VendorExtension, pair)3254 }3255 }3256 }3257 }3258 return x, compiler.NewErrorGroupOrNil(errors)3259}3260func NewParameter(in interface{}, context *compiler.Context) (*Parameter, error) {3261 errors := make([]error, 0)3262 x := &Parameter{}3263 matched := false3264 // BodyParameter body_parameter = 1;3265 {3266 m, ok := compiler.UnpackMap(in)3267 if ok {3268 // errors might be ok here, they mean we just don't have the right subtype3269 t, matching_error := NewBodyParameter(m, compiler.NewContext("bodyParameter", context))3270 if matching_error == nil {3271 x.Oneof = &Parameter_BodyParameter{BodyParameter: t}3272 matched = true3273 } else {3274 errors = append(errors, matching_error)3275 }3276 }3277 }3278 // NonBodyParameter non_body_parameter = 2;3279 {3280 m, ok := compiler.UnpackMap(in)3281 if ok {3282 // errors might be ok here, they mean we just don't have the right subtype3283 t, matching_error := NewNonBodyParameter(m, compiler.NewContext("nonBodyParameter", context))3284 if matching_error == nil {3285 x.Oneof = &Parameter_NonBodyParameter{NonBodyParameter: t}3286 matched = true3287 } else {3288 errors = append(errors, matching_error)3289 }3290 }3291 }3292 if matched {3293 // since the oneof matched one of its possibilities, discard any matching errors3294 errors = make([]error, 0)3295 }3296 return x, compiler.NewErrorGroupOrNil(errors)3297}3298func NewParameterDefinitions(in interface{}, context *compiler.Context) (*ParameterDefinitions, error) {3299 errors := make([]error, 0)3300 x := &ParameterDefinitions{}3301 m, ok := compiler.UnpackMap(in)3302 if !ok {3303 message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)3304 errors = append(errors, compiler.NewError(context, message))3305 } else {3306 // repeated NamedParameter additional_properties = 1;3307 // MAP: Parameter3308 x.AdditionalProperties = make([]*NamedParameter, 0)3309 for _, item := range m {3310 k, ok := item.Key.(string)3311 if ok {3312 v := item.Value3313 pair := &NamedParameter{}3314 pair.Name = k3315 var err error3316 pair.Value, err = NewParameter(v, compiler.NewContext(k, context))3317 if err != nil {3318 errors = append(errors, err)3319 }3320 x.AdditionalProperties = append(x.AdditionalProperties, pair)3321 }3322 }3323 }3324 return x, compiler.NewErrorGroupOrNil(errors)3325}3326func NewParametersItem(in interface{}, context *compiler.Context) (*ParametersItem, error) {3327 errors := make([]error, 0)3328 x := &ParametersItem{}3329 matched := false3330 // Parameter parameter = 1;3331 {3332 m, ok := compiler.UnpackMap(in)3333 if ok {3334 // errors might be ok here, they mean we just don't have the right subtype3335 t, matching_error := NewParameter(m, compiler.NewContext("parameter", context))3336 if matching_error == nil {3337 x.Oneof = &ParametersItem_Parameter{Parameter: t}3338 matched = true3339 } else {3340 errors = append(errors, matching_error)3341 }3342 }3343 }3344 // JsonReference json_reference = 2;3345 {3346 m, ok := compiler.UnpackMap(in)3347 if ok {3348 // errors might be ok here, they mean we just don't have the right subtype3349 t, matching_error := NewJsonReference(m, compiler.NewContext("jsonReference", context))3350 if matching_error == nil {3351 x.Oneof = &ParametersItem_JsonReference{JsonReference: t}3352 matched = true3353 } else {3354 errors = append(errors, matching_error)3355 }3356 }3357 }3358 if matched {3359 // since the oneof matched one of its possibilities, discard any matching errors3360 errors = make([]error, 0)3361 }3362 return x, compiler.NewErrorGroupOrNil(errors)3363}3364func NewPathItem(in interface{}, context *compiler.Context) (*PathItem, error) {3365 errors := make([]error, 0)3366 x := &PathItem{}3367 m, ok := compiler.UnpackMap(in)3368 if !ok {3369 message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)3370 errors = append(errors, compiler.NewError(context, message))3371 } else {3372 allowedKeys := []string{"$ref", "delete", "get", "head", "options", "parameters", "patch", "post", "put"}3373 allowedPatterns := []string{"^x-"}3374 invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)3375 if len(invalidKeys) > 0 {3376 message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))3377 errors = append(errors, compiler.NewError(context, message))3378 }3379 // string _ref = 1;3380 v1 := compiler.MapValueForKey(m, "$ref")3381 if v1 != nil {3382 x.XRef, ok = v1.(string)3383 if !ok {3384 message := fmt.Sprintf("has unexpected value for $ref: %+v (%T)", v1, v1)3385 errors = append(errors, compiler.NewError(context, message))3386 }3387 }3388 // Operation get = 2;3389 v2 := compiler.MapValueForKey(m, "get")3390 if v2 != nil {3391 var err error3392 x.Get, err = NewOperation(v2, compiler.NewContext("get", context))3393 if err != nil {3394 errors = append(errors, err)3395 }3396 }3397 // Operation put = 3;3398 v3 := compiler.MapValueForKey(m, "put")3399 if v3 != nil {3400 var err error3401 x.Put, err = NewOperation(v3, compiler.NewContext("put", context))3402 if err != nil {3403 errors = append(errors, err)3404 }3405 }3406 // Operation post = 4;3407 v4 := compiler.MapValueForKey(m, "post")3408 if v4 != nil {3409 var err error3410 x.Post, err = NewOperation(v4, compiler.NewContext("post", context))3411 if err != nil {3412 errors = append(errors, err)3413 }3414 }3415 // Operation delete = 5;3416 v5 := compiler.MapValueForKey(m, "delete")3417 if v5 != nil {3418 var err error3419 x.Delete, err = NewOperation(v5, compiler.NewContext("delete", context))3420 if err != nil {3421 errors = append(errors, err)3422 }3423 }3424 // Operation options = 6;3425 v6 := compiler.MapValueForKey(m, "options")3426 if v6 != nil {3427 var err error3428 x.Options, err = NewOperation(v6, compiler.NewContext("options", context))3429 if err != nil {3430 errors = append(errors, err)3431 }3432 }3433 // Operation head = 7;3434 v7 := compiler.MapValueForKey(m, "head")3435 if v7 != nil {3436 var err error3437 x.Head, err = NewOperation(v7, compiler.NewContext("head", context))3438 if err != nil {3439 errors = append(errors, err)3440 }3441 }3442 // Operation patch = 8;3443 v8 := compiler.MapValueForKey(m, "patch")3444 if v8 != nil {3445 var err error3446 x.Patch, err = NewOperation(v8, compiler.NewContext("patch", context))3447 if err != nil {3448 errors = append(errors, err)3449 }3450 }3451 // repeated ParametersItem parameters = 9;3452 v9 := compiler.MapValueForKey(m, "parameters")3453 if v9 != nil {3454 // repeated ParametersItem3455 x.Parameters = make([]*ParametersItem, 0)3456 a, ok := v9.([]interface{})3457 if ok {3458 for _, item := range a {3459 y, err := NewParametersItem(item, compiler.NewContext("parameters", context))3460 if err != nil {3461 errors = append(errors, err)3462 }3463 x.Parameters = append(x.Parameters, y)3464 }3465 }3466 }3467 // repeated NamedAny vendor_extension = 10;3468 // MAP: Any ^x-3469 x.VendorExtension = make([]*NamedAny, 0)3470 for _, item := range m {3471 k, ok := item.Key.(string)3472 if ok {3473 v := item.Value3474 if compiler.PatternMatches("^x-", k) {3475 pair := &NamedAny{}3476 pair.Name = k3477 result := &Any{}3478 handled, resultFromExt, err := compiler.HandleExtension(context, v, k)3479 if handled {3480 if err != nil {3481 errors = append(errors, err)3482 } else {3483 bytes, _ := yaml.Marshal(v)3484 result.Yaml = string(bytes)3485 result.Value = resultFromExt3486 pair.Value = result3487 }3488 } else {3489 pair.Value, err = NewAny(v, compiler.NewContext(k, context))3490 if err != nil {3491 errors = append(errors, err)3492 }3493 }3494 x.VendorExtension = append(x.VendorExtension, pair)3495 }3496 }3497 }3498 }3499 return x, compiler.NewErrorGroupOrNil(errors)3500}3501func NewPathParameterSubSchema(in interface{}, context *compiler.Context) (*PathParameterSubSchema, error) {3502 errors := make([]error, 0)3503 x := &PathParameterSubSchema{}3504 m, ok := compiler.UnpackMap(in)3505 if !ok {3506 message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)3507 errors = append(errors, compiler.NewError(context, message))3508 } else {3509 requiredKeys := []string{"required"}3510 missingKeys := compiler.MissingKeysInMap(m, requiredKeys)3511 if len(missingKeys) > 0 {3512 message := fmt.Sprintf("is missing required %s: %+v", compiler.PluralProperties(len(missingKeys)), strings.Join(missingKeys, ", "))3513 errors = append(errors, compiler.NewError(context, message))3514 }3515 allowedKeys := []string{"collectionFormat", "default", "description", "enum", "exclusiveMaximum", "exclusiveMinimum", "format", "in", "items", "maxItems", "maxLength", "maximum", "minItems", "minLength", "minimum", "multipleOf", "name", "pattern", "required", "type", "uniqueItems"}3516 allowedPatterns := []string{"^x-"}3517 invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)3518 if len(invalidKeys) > 0 {3519 message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))3520 errors = append(errors, compiler.NewError(context, message))3521 }3522 // bool required = 1;3523 v1 := compiler.MapValueForKey(m, "required")3524 if v1 != nil {3525 x.Required, ok = v1.(bool)3526 if !ok {3527 message := fmt.Sprintf("has unexpected value for required: %+v (%T)", v1, v1)3528 errors = append(errors, compiler.NewError(context, message))3529 }3530 }3531 // string in = 2;3532 v2 := compiler.MapValueForKey(m, "in")3533 if v2 != nil {3534 x.In, ok = v2.(string)3535 if !ok {3536 message := fmt.Sprintf("has unexpected value for in: %+v (%T)", v2, v2)3537 errors = append(errors, compiler.NewError(context, message))3538 }3539 // check for valid enum values3540 // [path]3541 if ok && !compiler.StringArrayContainsValue([]string{"path"}, x.In) {3542 message := fmt.Sprintf("has unexpected value for in: %+v (%T)", v2, v2)3543 errors = append(errors, compiler.NewError(context, message))3544 }3545 }3546 // string description = 3;3547 v3 := compiler.MapValueForKey(m, "description")3548 if v3 != nil {3549 x.Description, ok = v3.(string)3550 if !ok {3551 message := fmt.Sprintf("has unexpected value for description: %+v (%T)", v3, v3)3552 errors = append(errors, compiler.NewError(context, message))3553 }3554 }3555 // string name = 4;3556 v4 := compiler.MapValueForKey(m, "name")3557 if v4 != nil {3558 x.Name, ok = v4.(string)3559 if !ok {3560 message := fmt.Sprintf("has unexpected value for name: %+v (%T)", v4, v4)3561 errors = append(errors, compiler.NewError(context, message))3562 }3563 }3564 // string type = 5;3565 v5 := compiler.MapValueForKey(m, "type")3566 if v5 != nil {3567 x.Type, ok = v5.(string)3568 if !ok {3569 message := fmt.Sprintf("has unexpected value for type: %+v (%T)", v5, v5)3570 errors = append(errors, compiler.NewError(context, message))3571 }3572 // check for valid enum values3573 // [string number boolean integer array]3574 if ok && !compiler.StringArrayContainsValue([]string{"string", "number", "boolean", "integer", "array"}, x.Type) {3575 message := fmt.Sprintf("has unexpected value for type: %+v (%T)", v5, v5)3576 errors = append(errors, compiler.NewError(context, message))3577 }3578 }3579 // string format = 6;3580 v6 := compiler.MapValueForKey(m, "format")3581 if v6 != nil {3582 x.Format, ok = v6.(string)3583 if !ok {3584 message := fmt.Sprintf("has unexpected value for format: %+v (%T)", v6, v6)3585 errors = append(errors, compiler.NewError(context, message))3586 }3587 }3588 // PrimitivesItems items = 7;3589 v7 := compiler.MapValueForKey(m, "items")3590 if v7 != nil {3591 var err error3592 x.Items, err = NewPrimitivesItems(v7, compiler.NewContext("items", context))3593 if err != nil {3594 errors = append(errors, err)3595 }3596 }3597 // string collection_format = 8;3598 v8 := compiler.MapValueForKey(m, "collectionFormat")3599 if v8 != nil {3600 x.CollectionFormat, ok = v8.(string)3601 if !ok {3602 message := fmt.Sprintf("has unexpected value for collectionFormat: %+v (%T)", v8, v8)3603 errors = append(errors, compiler.NewError(context, message))3604 }3605 // check for valid enum values3606 // [csv ssv tsv pipes]3607 if ok && !compiler.StringArrayContainsValue([]string{"csv", "ssv", "tsv", "pipes"}, x.CollectionFormat) {3608 message := fmt.Sprintf("has unexpected value for collectionFormat: %+v (%T)", v8, v8)3609 errors = append(errors, compiler.NewError(context, message))3610 }3611 }3612 // Any default = 9;3613 v9 := compiler.MapValueForKey(m, "default")3614 if v9 != nil {3615 var err error3616 x.Default, err = NewAny(v9, compiler.NewContext("default", context))3617 if err != nil {3618 errors = append(errors, err)3619 }3620 }3621 // float maximum = 10;3622 v10 := compiler.MapValueForKey(m, "maximum")3623 if v10 != nil {3624 switch v10 := v10.(type) {3625 case float64:3626 x.Maximum = v103627 case float32:3628 x.Maximum = float64(v10)3629 case uint64:3630 x.Maximum = float64(v10)3631 case uint32:3632 x.Maximum = float64(v10)3633 case int64:3634 x.Maximum = float64(v10)3635 case int32:3636 x.Maximum = float64(v10)3637 case int:3638 x.Maximum = float64(v10)3639 default:3640 message := fmt.Sprintf("has unexpected value for maximum: %+v (%T)", v10, v10)3641 errors = append(errors, compiler.NewError(context, message))3642 }3643 }3644 // bool exclusive_maximum = 11;3645 v11 := compiler.MapValueForKey(m, "exclusiveMaximum")3646 if v11 != nil {3647 x.ExclusiveMaximum, ok = v11.(bool)3648 if !ok {3649 message := fmt.Sprintf("has unexpected value for exclusiveMaximum: %+v (%T)", v11, v11)3650 errors = append(errors, compiler.NewError(context, message))3651 }3652 }3653 // float minimum = 12;3654 v12 := compiler.MapValueForKey(m, "minimum")3655 if v12 != nil {3656 switch v12 := v12.(type) {3657 case float64:3658 x.Minimum = v123659 case float32:3660 x.Minimum = float64(v12)3661 case uint64:3662 x.Minimum = float64(v12)3663 case uint32:3664 x.Minimum = float64(v12)3665 case int64:3666 x.Minimum = float64(v12)3667 case int32:3668 x.Minimum = float64(v12)3669 case int:3670 x.Minimum = float64(v12)3671 default:3672 message := fmt.Sprintf("has unexpected value for minimum: %+v (%T)", v12, v12)3673 errors = append(errors, compiler.NewError(context, message))3674 }3675 }3676 // bool exclusive_minimum = 13;3677 v13 := compiler.MapValueForKey(m, "exclusiveMinimum")3678 if v13 != nil {3679 x.ExclusiveMinimum, ok = v13.(bool)3680 if !ok {3681 message := fmt.Sprintf("has unexpected value for exclusiveMinimum: %+v (%T)", v13, v13)3682 errors = append(errors, compiler.NewError(context, message))3683 }3684 }3685 // int64 max_length = 14;3686 v14 := compiler.MapValueForKey(m, "maxLength")3687 if v14 != nil {3688 t, ok := v14.(int)3689 if ok {3690 x.MaxLength = int64(t)3691 } else {3692 message := fmt.Sprintf("has unexpected value for maxLength: %+v (%T)", v14, v14)3693 errors = append(errors, compiler.NewError(context, message))3694 }3695 }3696 // int64 min_length = 15;3697 v15 := compiler.MapValueForKey(m, "minLength")3698 if v15 != nil {3699 t, ok := v15.(int)3700 if ok {3701 x.MinLength = int64(t)3702 } else {3703 message := fmt.Sprintf("has unexpected value for minLength: %+v (%T)", v15, v15)3704 errors = append(errors, compiler.NewError(context, message))3705 }3706 }3707 // string pattern = 16;3708 v16 := compiler.MapValueForKey(m, "pattern")3709 if v16 != nil {3710 x.Pattern, ok = v16.(string)3711 if !ok {3712 message := fmt.Sprintf("has unexpected value for pattern: %+v (%T)", v16, v16)3713 errors = append(errors, compiler.NewError(context, message))3714 }3715 }3716 // int64 max_items = 17;3717 v17 := compiler.MapValueForKey(m, "maxItems")3718 if v17 != nil {3719 t, ok := v17.(int)3720 if ok {3721 x.MaxItems = int64(t)3722 } else {3723 message := fmt.Sprintf("has unexpected value for maxItems: %+v (%T)", v17, v17)3724 errors = append(errors, compiler.NewError(context, message))3725 }3726 }3727 // int64 min_items = 18;3728 v18 := compiler.MapValueForKey(m, "minItems")3729 if v18 != nil {3730 t, ok := v18.(int)3731 if ok {3732 x.MinItems = int64(t)3733 } else {3734 message := fmt.Sprintf("has unexpected value for minItems: %+v (%T)", v18, v18)3735 errors = append(errors, compiler.NewError(context, message))3736 }3737 }3738 // bool unique_items = 19;3739 v19 := compiler.MapValueForKey(m, "uniqueItems")3740 if v19 != nil {3741 x.UniqueItems, ok = v19.(bool)3742 if !ok {3743 message := fmt.Sprintf("has unexpected value for uniqueItems: %+v (%T)", v19, v19)3744 errors = append(errors, compiler.NewError(context, message))3745 }3746 }3747 // repeated Any enum = 20;3748 v20 := compiler.MapValueForKey(m, "enum")3749 if v20 != nil {3750 // repeated Any3751 x.Enum = make([]*Any, 0)3752 a, ok := v20.([]interface{})3753 if ok {3754 for _, item := range a {3755 y, err := NewAny(item, compiler.NewContext("enum", context))3756 if err != nil {3757 errors = append(errors, err)3758 }3759 x.Enum = append(x.Enum, y)3760 }3761 }3762 }3763 // float multiple_of = 21;3764 v21 := compiler.MapValueForKey(m, "multipleOf")3765 if v21 != nil {3766 switch v21 := v21.(type) {3767 case float64:3768 x.MultipleOf = v213769 case float32:3770 x.MultipleOf = float64(v21)3771 case uint64:3772 x.MultipleOf = float64(v21)3773 case uint32:3774 x.MultipleOf = float64(v21)3775 case int64:3776 x.MultipleOf = float64(v21)3777 case int32:3778 x.MultipleOf = float64(v21)3779 case int:3780 x.MultipleOf = float64(v21)3781 default:3782 message := fmt.Sprintf("has unexpected value for multipleOf: %+v (%T)", v21, v21)3783 errors = append(errors, compiler.NewError(context, message))3784 }3785 }3786 // repeated NamedAny vendor_extension = 22;3787 // MAP: Any ^x-3788 x.VendorExtension = make([]*NamedAny, 0)3789 for _, item := range m {3790 k, ok := item.Key.(string)3791 if ok {3792 v := item.Value3793 if compiler.PatternMatches("^x-", k) {3794 pair := &NamedAny{}3795 pair.Name = k3796 result := &Any{}3797 handled, resultFromExt, err := compiler.HandleExtension(context, v, k)3798 if handled {3799 if err != nil {3800 errors = append(errors, err)3801 } else {3802 bytes, _ := yaml.Marshal(v)3803 result.Yaml = string(bytes)3804 result.Value = resultFromExt3805 pair.Value = result3806 }3807 } else {3808 pair.Value, err = NewAny(v, compiler.NewContext(k, context))3809 if err != nil {3810 errors = append(errors, err)3811 }3812 }3813 x.VendorExtension = append(x.VendorExtension, pair)3814 }3815 }3816 }3817 }3818 return x, compiler.NewErrorGroupOrNil(errors)3819}3820func NewPaths(in interface{}, context *compiler.Context) (*Paths, error) {3821 errors := make([]error, 0)3822 x := &Paths{}3823 m, ok := compiler.UnpackMap(in)3824 if !ok {3825 message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)3826 errors = append(errors, compiler.NewError(context, message))3827 } else {3828 allowedKeys := []string{}3829 allowedPatterns := []string{"^x-", "^/"}3830 invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)3831 if len(invalidKeys) > 0 {3832 message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))3833 errors = append(errors, compiler.NewError(context, message))3834 }3835 // repeated NamedAny vendor_extension = 1;3836 // MAP: Any ^x-3837 x.VendorExtension = make([]*NamedAny, 0)3838 for _, item := range m {3839 k, ok := item.Key.(string)3840 if ok {3841 v := item.Value3842 if compiler.PatternMatches("^x-", k) {3843 pair := &NamedAny{}3844 pair.Name = k3845 result := &Any{}3846 handled, resultFromExt, err := compiler.HandleExtension(context, v, k)3847 if handled {3848 if err != nil {3849 errors = append(errors, err)3850 } else {3851 bytes, _ := yaml.Marshal(v)3852 result.Yaml = string(bytes)3853 result.Value = resultFromExt3854 pair.Value = result3855 }3856 } else {3857 pair.Value, err = NewAny(v, compiler.NewContext(k, context))3858 if err != nil {3859 errors = append(errors, err)3860 }3861 }3862 x.VendorExtension = append(x.VendorExtension, pair)3863 }3864 }3865 }3866 // repeated NamedPathItem path = 2;3867 // MAP: PathItem ^/3868 x.Path = make([]*NamedPathItem, 0)3869 for _, item := range m {3870 k, ok := item.Key.(string)3871 if ok {3872 v := item.Value3873 if compiler.PatternMatches("^/", k) {3874 pair := &NamedPathItem{}3875 pair.Name = k3876 var err error3877 pair.Value, err = NewPathItem(v, compiler.NewContext(k, context))3878 if err != nil {3879 errors = append(errors, err)3880 }3881 x.Path = append(x.Path, pair)3882 }3883 }3884 }3885 }3886 return x, compiler.NewErrorGroupOrNil(errors)3887}3888func NewPrimitivesItems(in interface{}, context *compiler.Context) (*PrimitivesItems, error) {3889 errors := make([]error, 0)3890 x := &PrimitivesItems{}3891 m, ok := compiler.UnpackMap(in)3892 if !ok {3893 message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)3894 errors = append(errors, compiler.NewError(context, message))3895 } else {3896 allowedKeys := []string{"collectionFormat", "default", "enum", "exclusiveMaximum", "exclusiveMinimum", "format", "items", "maxItems", "maxLength", "maximum", "minItems", "minLength", "minimum", "multipleOf", "pattern", "type", "uniqueItems"}3897 allowedPatterns := []string{"^x-"}3898 invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)3899 if len(invalidKeys) > 0 {3900 message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))3901 errors = append(errors, compiler.NewError(context, message))3902 }3903 // string type = 1;3904 v1 := compiler.MapValueForKey(m, "type")3905 if v1 != nil {3906 x.Type, ok = v1.(string)3907 if !ok {3908 message := fmt.Sprintf("has unexpected value for type: %+v (%T)", v1, v1)3909 errors = append(errors, compiler.NewError(context, message))3910 }3911 // check for valid enum values3912 // [string number integer boolean array]3913 if ok && !compiler.StringArrayContainsValue([]string{"string", "number", "integer", "boolean", "array"}, x.Type) {3914 message := fmt.Sprintf("has unexpected value for type: %+v (%T)", v1, v1)3915 errors = append(errors, compiler.NewError(context, message))3916 }3917 }3918 // string format = 2;3919 v2 := compiler.MapValueForKey(m, "format")3920 if v2 != nil {3921 x.Format, ok = v2.(string)3922 if !ok {3923 message := fmt.Sprintf("has unexpected value for format: %+v (%T)", v2, v2)3924 errors = append(errors, compiler.NewError(context, message))3925 }3926 }3927 // PrimitivesItems items = 3;3928 v3 := compiler.MapValueForKey(m, "items")3929 if v3 != nil {3930 var err error3931 x.Items, err = NewPrimitivesItems(v3, compiler.NewContext("items", context))3932 if err != nil {3933 errors = append(errors, err)3934 }3935 }3936 // string collection_format = 4;3937 v4 := compiler.MapValueForKey(m, "collectionFormat")3938 if v4 != nil {3939 x.CollectionFormat, ok = v4.(string)3940 if !ok {3941 message := fmt.Sprintf("has unexpected value for collectionFormat: %+v (%T)", v4, v4)3942 errors = append(errors, compiler.NewError(context, message))3943 }3944 // check for valid enum values3945 // [csv ssv tsv pipes]3946 if ok && !compiler.StringArrayContainsValue([]string{"csv", "ssv", "tsv", "pipes"}, x.CollectionFormat) {3947 message := fmt.Sprintf("has unexpected value for collectionFormat: %+v (%T)", v4, v4)3948 errors = append(errors, compiler.NewError(context, message))3949 }3950 }3951 // Any default = 5;3952 v5 := compiler.MapValueForKey(m, "default")3953 if v5 != nil {3954 var err error3955 x.Default, err = NewAny(v5, compiler.NewContext("default", context))3956 if err != nil {3957 errors = append(errors, err)3958 }3959 }3960 // float maximum = 6;3961 v6 := compiler.MapValueForKey(m, "maximum")3962 if v6 != nil {3963 switch v6 := v6.(type) {3964 case float64:3965 x.Maximum = v63966 case float32:3967 x.Maximum = float64(v6)3968 case uint64:3969 x.Maximum = float64(v6)3970 case uint32:3971 x.Maximum = float64(v6)3972 case int64:3973 x.Maximum = float64(v6)3974 case int32:3975 x.Maximum = float64(v6)3976 case int:3977 x.Maximum = float64(v6)3978 default:3979 message := fmt.Sprintf("has unexpected value for maximum: %+v (%T)", v6, v6)3980 errors = append(errors, compiler.NewError(context, message))3981 }3982 }3983 // bool exclusive_maximum = 7;3984 v7 := compiler.MapValueForKey(m, "exclusiveMaximum")3985 if v7 != nil {3986 x.ExclusiveMaximum, ok = v7.(bool)3987 if !ok {3988 message := fmt.Sprintf("has unexpected value for exclusiveMaximum: %+v (%T)", v7, v7)3989 errors = append(errors, compiler.NewError(context, message))3990 }3991 }3992 // float minimum = 8;3993 v8 := compiler.MapValueForKey(m, "minimum")3994 if v8 != nil {3995 switch v8 := v8.(type) {3996 case float64:3997 x.Minimum = v83998 case float32:3999 x.Minimum = float64(v8)4000 case uint64:4001 x.Minimum = float64(v8)4002 case uint32:4003 x.Minimum = float64(v8)4004 case int64:4005 x.Minimum = float64(v8)4006 case int32:4007 x.Minimum = float64(v8)4008 case int:4009 x.Minimum = float64(v8)4010 default:4011 message := fmt.Sprintf("has unexpected value for minimum: %+v (%T)", v8, v8)4012 errors = append(errors, compiler.NewError(context, message))4013 }4014 }4015 // bool exclusive_minimum = 9;4016 v9 := compiler.MapValueForKey(m, "exclusiveMinimum")4017 if v9 != nil {4018 x.ExclusiveMinimum, ok = v9.(bool)4019 if !ok {4020 message := fmt.Sprintf("has unexpected value for exclusiveMinimum: %+v (%T)", v9, v9)4021 errors = append(errors, compiler.NewError(context, message))4022 }4023 }4024 // int64 max_length = 10;4025 v10 := compiler.MapValueForKey(m, "maxLength")4026 if v10 != nil {4027 t, ok := v10.(int)4028 if ok {4029 x.MaxLength = int64(t)4030 } else {4031 message := fmt.Sprintf("has unexpected value for maxLength: %+v (%T)", v10, v10)4032 errors = append(errors, compiler.NewError(context, message))4033 }4034 }4035 // int64 min_length = 11;4036 v11 := compiler.MapValueForKey(m, "minLength")4037 if v11 != nil {4038 t, ok := v11.(int)4039 if ok {4040 x.MinLength = int64(t)4041 } else {4042 message := fmt.Sprintf("has unexpected value for minLength: %+v (%T)", v11, v11)4043 errors = append(errors, compiler.NewError(context, message))4044 }4045 }4046 // string pattern = 12;4047 v12 := compiler.MapValueForKey(m, "pattern")4048 if v12 != nil {4049 x.Pattern, ok = v12.(string)4050 if !ok {4051 message := fmt.Sprintf("has unexpected value for pattern: %+v (%T)", v12, v12)4052 errors = append(errors, compiler.NewError(context, message))4053 }4054 }4055 // int64 max_items = 13;4056 v13 := compiler.MapValueForKey(m, "maxItems")4057 if v13 != nil {4058 t, ok := v13.(int)4059 if ok {4060 x.MaxItems = int64(t)4061 } else {4062 message := fmt.Sprintf("has unexpected value for maxItems: %+v (%T)", v13, v13)4063 errors = append(errors, compiler.NewError(context, message))4064 }4065 }4066 // int64 min_items = 14;4067 v14 := compiler.MapValueForKey(m, "minItems")4068 if v14 != nil {4069 t, ok := v14.(int)4070 if ok {4071 x.MinItems = int64(t)4072 } else {4073 message := fmt.Sprintf("has unexpected value for minItems: %+v (%T)", v14, v14)4074 errors = append(errors, compiler.NewError(context, message))4075 }4076 }4077 // bool unique_items = 15;4078 v15 := compiler.MapValueForKey(m, "uniqueItems")4079 if v15 != nil {4080 x.UniqueItems, ok = v15.(bool)4081 if !ok {4082 message := fmt.Sprintf("has unexpected value for uniqueItems: %+v (%T)", v15, v15)4083 errors = append(errors, compiler.NewError(context, message))4084 }4085 }4086 // repeated Any enum = 16;4087 v16 := compiler.MapValueForKey(m, "enum")4088 if v16 != nil {4089 // repeated Any4090 x.Enum = make([]*Any, 0)4091 a, ok := v16.([]interface{})4092 if ok {4093 for _, item := range a {4094 y, err := NewAny(item, compiler.NewContext("enum", context))4095 if err != nil {4096 errors = append(errors, err)4097 }4098 x.Enum = append(x.Enum, y)4099 }4100 }4101 }4102 // float multiple_of = 17;4103 v17 := compiler.MapValueForKey(m, "multipleOf")4104 if v17 != nil {4105 switch v17 := v17.(type) {4106 case float64:4107 x.MultipleOf = v174108 case float32:4109 x.MultipleOf = float64(v17)4110 case uint64:4111 x.MultipleOf = float64(v17)4112 case uint32:4113 x.MultipleOf = float64(v17)4114 case int64:4115 x.MultipleOf = float64(v17)4116 case int32:4117 x.MultipleOf = float64(v17)4118 case int:4119 x.MultipleOf = float64(v17)4120 default:4121 message := fmt.Sprintf("has unexpected value for multipleOf: %+v (%T)", v17, v17)4122 errors = append(errors, compiler.NewError(context, message))4123 }4124 }4125 // repeated NamedAny vendor_extension = 18;4126 // MAP: Any ^x-4127 x.VendorExtension = make([]*NamedAny, 0)4128 for _, item := range m {4129 k, ok := item.Key.(string)4130 if ok {4131 v := item.Value4132 if compiler.PatternMatches("^x-", k) {4133 pair := &NamedAny{}4134 pair.Name = k4135 result := &Any{}4136 handled, resultFromExt, err := compiler.HandleExtension(context, v, k)4137 if handled {4138 if err != nil {4139 errors = append(errors, err)4140 } else {4141 bytes, _ := yaml.Marshal(v)4142 result.Yaml = string(bytes)4143 result.Value = resultFromExt4144 pair.Value = result4145 }4146 } else {4147 pair.Value, err = NewAny(v, compiler.NewContext(k, context))4148 if err != nil {4149 errors = append(errors, err)4150 }4151 }4152 x.VendorExtension = append(x.VendorExtension, pair)4153 }4154 }4155 }4156 }4157 return x, compiler.NewErrorGroupOrNil(errors)4158}4159func NewProperties(in interface{}, context *compiler.Context) (*Properties, error) {4160 errors := make([]error, 0)4161 x := &Properties{}4162 m, ok := compiler.UnpackMap(in)4163 if !ok {4164 message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)4165 errors = append(errors, compiler.NewError(context, message))4166 } else {4167 // repeated NamedSchema additional_properties = 1;4168 // MAP: Schema4169 x.AdditionalProperties = make([]*NamedSchema, 0)4170 for _, item := range m {4171 k, ok := item.Key.(string)4172 if ok {4173 v := item.Value4174 pair := &NamedSchema{}4175 pair.Name = k4176 var err error4177 pair.Value, err = NewSchema(v, compiler.NewContext(k, context))4178 if err != nil {4179 errors = append(errors, err)4180 }4181 x.AdditionalProperties = append(x.AdditionalProperties, pair)4182 }4183 }4184 }4185 return x, compiler.NewErrorGroupOrNil(errors)4186}4187func NewQueryParameterSubSchema(in interface{}, context *compiler.Context) (*QueryParameterSubSchema, error) {4188 errors := make([]error, 0)4189 x := &QueryParameterSubSchema{}4190 m, ok := compiler.UnpackMap(in)4191 if !ok {4192 message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)4193 errors = append(errors, compiler.NewError(context, message))4194 } else {4195 allowedKeys := []string{"allowEmptyValue", "collectionFormat", "default", "description", "enum", "exclusiveMaximum", "exclusiveMinimum", "format", "in", "items", "maxItems", "maxLength", "maximum", "minItems", "minLength", "minimum", "multipleOf", "name", "pattern", "required", "type", "uniqueItems"}4196 allowedPatterns := []string{"^x-"}4197 invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)4198 if len(invalidKeys) > 0 {4199 message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))4200 errors = append(errors, compiler.NewError(context, message))4201 }4202 // bool required = 1;4203 v1 := compiler.MapValueForKey(m, "required")4204 if v1 != nil {4205 x.Required, ok = v1.(bool)4206 if !ok {4207 message := fmt.Sprintf("has unexpected value for required: %+v (%T)", v1, v1)4208 errors = append(errors, compiler.NewError(context, message))4209 }4210 }4211 // string in = 2;4212 v2 := compiler.MapValueForKey(m, "in")4213 if v2 != nil {4214 x.In, ok = v2.(string)4215 if !ok {4216 message := fmt.Sprintf("has unexpected value for in: %+v (%T)", v2, v2)4217 errors = append(errors, compiler.NewError(context, message))4218 }4219 // check for valid enum values4220 // [query]4221 if ok && !compiler.StringArrayContainsValue([]string{"query"}, x.In) {4222 message := fmt.Sprintf("has unexpected value for in: %+v (%T)", v2, v2)4223 errors = append(errors, compiler.NewError(context, message))4224 }4225 }4226 // string description = 3;4227 v3 := compiler.MapValueForKey(m, "description")4228 if v3 != nil {4229 x.Description, ok = v3.(string)4230 if !ok {4231 message := fmt.Sprintf("has unexpected value for description: %+v (%T)", v3, v3)4232 errors = append(errors, compiler.NewError(context, message))4233 }4234 }4235 // string name = 4;4236 v4 := compiler.MapValueForKey(m, "name")4237 if v4 != nil {4238 x.Name, ok = v4.(string)4239 if !ok {4240 message := fmt.Sprintf("has unexpected value for name: %+v (%T)", v4, v4)4241 errors = append(errors, compiler.NewError(context, message))4242 }4243 }4244 // bool allow_empty_value = 5;4245 v5 := compiler.MapValueForKey(m, "allowEmptyValue")4246 if v5 != nil {4247 x.AllowEmptyValue, ok = v5.(bool)4248 if !ok {4249 message := fmt.Sprintf("has unexpected value for allowEmptyValue: %+v (%T)", v5, v5)4250 errors = append(errors, compiler.NewError(context, message))4251 }4252 }4253 // string type = 6;4254 v6 := compiler.MapValueForKey(m, "type")4255 if v6 != nil {4256 x.Type, ok = v6.(string)4257 if !ok {4258 message := fmt.Sprintf("has unexpected value for type: %+v (%T)", v6, v6)4259 errors = append(errors, compiler.NewError(context, message))4260 }4261 // check for valid enum values4262 // [string number boolean integer array]4263 if ok && !compiler.StringArrayContainsValue([]string{"string", "number", "boolean", "integer", "array"}, x.Type) {4264 message := fmt.Sprintf("has unexpected value for type: %+v (%T)", v6, v6)4265 errors = append(errors, compiler.NewError(context, message))4266 }4267 }4268 // string format = 7;4269 v7 := compiler.MapValueForKey(m, "format")4270 if v7 != nil {4271 x.Format, ok = v7.(string)4272 if !ok {4273 message := fmt.Sprintf("has unexpected value for format: %+v (%T)", v7, v7)4274 errors = append(errors, compiler.NewError(context, message))4275 }4276 }4277 // PrimitivesItems items = 8;4278 v8 := compiler.MapValueForKey(m, "items")4279 if v8 != nil {4280 var err error4281 x.Items, err = NewPrimitivesItems(v8, compiler.NewContext("items", context))4282 if err != nil {4283 errors = append(errors, err)4284 }4285 }4286 // string collection_format = 9;4287 v9 := compiler.MapValueForKey(m, "collectionFormat")4288 if v9 != nil {4289 x.CollectionFormat, ok = v9.(string)4290 if !ok {4291 message := fmt.Sprintf("has unexpected value for collectionFormat: %+v (%T)", v9, v9)4292 errors = append(errors, compiler.NewError(context, message))4293 }4294 // check for valid enum values4295 // [csv ssv tsv pipes multi]4296 if ok && !compiler.StringArrayContainsValue([]string{"csv", "ssv", "tsv", "pipes", "multi"}, x.CollectionFormat) {4297 message := fmt.Sprintf("has unexpected value for collectionFormat: %+v (%T)", v9, v9)4298 errors = append(errors, compiler.NewError(context, message))4299 }4300 }4301 // Any default = 10;4302 v10 := compiler.MapValueForKey(m, "default")4303 if v10 != nil {4304 var err error4305 x.Default, err = NewAny(v10, compiler.NewContext("default", context))4306 if err != nil {4307 errors = append(errors, err)4308 }4309 }4310 // float maximum = 11;4311 v11 := compiler.MapValueForKey(m, "maximum")4312 if v11 != nil {4313 switch v11 := v11.(type) {4314 case float64:4315 x.Maximum = v114316 case float32:4317 x.Maximum = float64(v11)4318 case uint64:4319 x.Maximum = float64(v11)4320 case uint32:4321 x.Maximum = float64(v11)4322 case int64:4323 x.Maximum = float64(v11)4324 case int32:4325 x.Maximum = float64(v11)4326 case int:4327 x.Maximum = float64(v11)4328 default:4329 message := fmt.Sprintf("has unexpected value for maximum: %+v (%T)", v11, v11)4330 errors = append(errors, compiler.NewError(context, message))4331 }4332 }4333 // bool exclusive_maximum = 12;4334 v12 := compiler.MapValueForKey(m, "exclusiveMaximum")4335 if v12 != nil {4336 x.ExclusiveMaximum, ok = v12.(bool)4337 if !ok {4338 message := fmt.Sprintf("has unexpected value for exclusiveMaximum: %+v (%T)", v12, v12)4339 errors = append(errors, compiler.NewError(context, message))4340 }4341 }4342 // float minimum = 13;4343 v13 := compiler.MapValueForKey(m, "minimum")4344 if v13 != nil {4345 switch v13 := v13.(type) {4346 case float64:4347 x.Minimum = v134348 case float32:4349 x.Minimum = float64(v13)4350 case uint64:4351 x.Minimum = float64(v13)4352 case uint32:4353 x.Minimum = float64(v13)4354 case int64:4355 x.Minimum = float64(v13)4356 case int32:4357 x.Minimum = float64(v13)4358 case int:4359 x.Minimum = float64(v13)4360 default:4361 message := fmt.Sprintf("has unexpected value for minimum: %+v (%T)", v13, v13)4362 errors = append(errors, compiler.NewError(context, message))4363 }4364 }4365 // bool exclusive_minimum = 14;4366 v14 := compiler.MapValueForKey(m, "exclusiveMinimum")4367 if v14 != nil {4368 x.ExclusiveMinimum, ok = v14.(bool)4369 if !ok {4370 message := fmt.Sprintf("has unexpected value for exclusiveMinimum: %+v (%T)", v14, v14)4371 errors = append(errors, compiler.NewError(context, message))4372 }4373 }4374 // int64 max_length = 15;4375 v15 := compiler.MapValueForKey(m, "maxLength")4376 if v15 != nil {4377 t, ok := v15.(int)4378 if ok {4379 x.MaxLength = int64(t)4380 } else {4381 message := fmt.Sprintf("has unexpected value for maxLength: %+v (%T)", v15, v15)4382 errors = append(errors, compiler.NewError(context, message))4383 }4384 }4385 // int64 min_length = 16;4386 v16 := compiler.MapValueForKey(m, "minLength")4387 if v16 != nil {4388 t, ok := v16.(int)4389 if ok {4390 x.MinLength = int64(t)4391 } else {4392 message := fmt.Sprintf("has unexpected value for minLength: %+v (%T)", v16, v16)4393 errors = append(errors, compiler.NewError(context, message))4394 }4395 }4396 // string pattern = 17;4397 v17 := compiler.MapValueForKey(m, "pattern")4398 if v17 != nil {4399 x.Pattern, ok = v17.(string)4400 if !ok {4401 message := fmt.Sprintf("has unexpected value for pattern: %+v (%T)", v17, v17)4402 errors = append(errors, compiler.NewError(context, message))4403 }4404 }4405 // int64 max_items = 18;4406 v18 := compiler.MapValueForKey(m, "maxItems")4407 if v18 != nil {4408 t, ok := v18.(int)4409 if ok {4410 x.MaxItems = int64(t)4411 } else {4412 message := fmt.Sprintf("has unexpected value for maxItems: %+v (%T)", v18, v18)4413 errors = append(errors, compiler.NewError(context, message))4414 }4415 }4416 // int64 min_items = 19;4417 v19 := compiler.MapValueForKey(m, "minItems")4418 if v19 != nil {4419 t, ok := v19.(int)4420 if ok {4421 x.MinItems = int64(t)4422 } else {4423 message := fmt.Sprintf("has unexpected value for minItems: %+v (%T)", v19, v19)4424 errors = append(errors, compiler.NewError(context, message))4425 }4426 }4427 // bool unique_items = 20;4428 v20 := compiler.MapValueForKey(m, "uniqueItems")4429 if v20 != nil {4430 x.UniqueItems, ok = v20.(bool)4431 if !ok {4432 message := fmt.Sprintf("has unexpected value for uniqueItems: %+v (%T)", v20, v20)4433 errors = append(errors, compiler.NewError(context, message))4434 }4435 }4436 // repeated Any enum = 21;4437 v21 := compiler.MapValueForKey(m, "enum")4438 if v21 != nil {4439 // repeated Any4440 x.Enum = make([]*Any, 0)4441 a, ok := v21.([]interface{})4442 if ok {4443 for _, item := range a {4444 y, err := NewAny(item, compiler.NewContext("enum", context))4445 if err != nil {4446 errors = append(errors, err)4447 }4448 x.Enum = append(x.Enum, y)4449 }4450 }4451 }4452 // float multiple_of = 22;4453 v22 := compiler.MapValueForKey(m, "multipleOf")4454 if v22 != nil {4455 switch v22 := v22.(type) {4456 case float64:4457 x.MultipleOf = v224458 case float32:4459 x.MultipleOf = float64(v22)4460 case uint64:4461 x.MultipleOf = float64(v22)4462 case uint32:4463 x.MultipleOf = float64(v22)4464 case int64:4465 x.MultipleOf = float64(v22)4466 case int32:4467 x.MultipleOf = float64(v22)4468 case int:4469 x.MultipleOf = float64(v22)4470 default:4471 message := fmt.Sprintf("has unexpected value for multipleOf: %+v (%T)", v22, v22)4472 errors = append(errors, compiler.NewError(context, message))4473 }4474 }4475 // repeated NamedAny vendor_extension = 23;4476 // MAP: Any ^x-4477 x.VendorExtension = make([]*NamedAny, 0)4478 for _, item := range m {4479 k, ok := item.Key.(string)4480 if ok {4481 v := item.Value4482 if compiler.PatternMatches("^x-", k) {4483 pair := &NamedAny{}4484 pair.Name = k4485 result := &Any{}4486 handled, resultFromExt, err := compiler.HandleExtension(context, v, k)4487 if handled {4488 if err != nil {4489 errors = append(errors, err)4490 } else {4491 bytes, _ := yaml.Marshal(v)4492 result.Yaml = string(bytes)4493 result.Value = resultFromExt4494 pair.Value = result4495 }4496 } else {4497 pair.Value, err = NewAny(v, compiler.NewContext(k, context))4498 if err != nil {4499 errors = append(errors, err)4500 }4501 }4502 x.VendorExtension = append(x.VendorExtension, pair)4503 }4504 }4505 }4506 }4507 return x, compiler.NewErrorGroupOrNil(errors)4508}4509func NewResponse(in interface{}, context *compiler.Context) (*Response, error) {4510 errors := make([]error, 0)4511 x := &Response{}4512 m, ok := compiler.UnpackMap(in)4513 if !ok {4514 message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)4515 errors = append(errors, compiler.NewError(context, message))4516 } else {4517 requiredKeys := []string{"description"}4518 missingKeys := compiler.MissingKeysInMap(m, requiredKeys)4519 if len(missingKeys) > 0 {4520 message := fmt.Sprintf("is missing required %s: %+v", compiler.PluralProperties(len(missingKeys)), strings.Join(missingKeys, ", "))4521 errors = append(errors, compiler.NewError(context, message))4522 }4523 allowedKeys := []string{"description", "examples", "headers", "schema"}4524 allowedPatterns := []string{"^x-"}4525 invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)4526 if len(invalidKeys) > 0 {4527 message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))4528 errors = append(errors, compiler.NewError(context, message))4529 }4530 // string description = 1;4531 v1 := compiler.MapValueForKey(m, "description")4532 if v1 != nil {4533 x.Description, ok = v1.(string)4534 if !ok {4535 message := fmt.Sprintf("has unexpected value for description: %+v (%T)", v1, v1)4536 errors = append(errors, compiler.NewError(context, message))4537 }4538 }4539 // SchemaItem schema = 2;4540 v2 := compiler.MapValueForKey(m, "schema")4541 if v2 != nil {4542 var err error4543 x.Schema, err = NewSchemaItem(v2, compiler.NewContext("schema", context))4544 if err != nil {4545 errors = append(errors, err)4546 }4547 }4548 // Headers headers = 3;4549 v3 := compiler.MapValueForKey(m, "headers")4550 if v3 != nil {4551 var err error4552 x.Headers, err = NewHeaders(v3, compiler.NewContext("headers", context))4553 if err != nil {4554 errors = append(errors, err)4555 }4556 }4557 // Examples examples = 4;4558 v4 := compiler.MapValueForKey(m, "examples")4559 if v4 != nil {4560 var err error4561 x.Examples, err = NewExamples(v4, compiler.NewContext("examples", context))4562 if err != nil {4563 errors = append(errors, err)4564 }4565 }4566 // repeated NamedAny vendor_extension = 5;4567 // MAP: Any ^x-4568 x.VendorExtension = make([]*NamedAny, 0)4569 for _, item := range m {4570 k, ok := item.Key.(string)4571 if ok {4572 v := item.Value4573 if compiler.PatternMatches("^x-", k) {4574 pair := &NamedAny{}4575 pair.Name = k4576 result := &Any{}4577 handled, resultFromExt, err := compiler.HandleExtension(context, v, k)4578 if handled {4579 if err != nil {4580 errors = append(errors, err)4581 } else {4582 bytes, _ := yaml.Marshal(v)4583 result.Yaml = string(bytes)4584 result.Value = resultFromExt4585 pair.Value = result4586 }4587 } else {4588 pair.Value, err = NewAny(v, compiler.NewContext(k, context))4589 if err != nil {4590 errors = append(errors, err)4591 }4592 }4593 x.VendorExtension = append(x.VendorExtension, pair)4594 }4595 }4596 }4597 }4598 return x, compiler.NewErrorGroupOrNil(errors)4599}4600func NewResponseDefinitions(in interface{}, context *compiler.Context) (*ResponseDefinitions, error) {4601 errors := make([]error, 0)4602 x := &ResponseDefinitions{}4603 m, ok := compiler.UnpackMap(in)4604 if !ok {4605 message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)4606 errors = append(errors, compiler.NewError(context, message))4607 } else {4608 // repeated NamedResponse additional_properties = 1;4609 // MAP: Response4610 x.AdditionalProperties = make([]*NamedResponse, 0)4611 for _, item := range m {4612 k, ok := item.Key.(string)4613 if ok {4614 v := item.Value4615 pair := &NamedResponse{}4616 pair.Name = k4617 var err error4618 pair.Value, err = NewResponse(v, compiler.NewContext(k, context))4619 if err != nil {4620 errors = append(errors, err)4621 }4622 x.AdditionalProperties = append(x.AdditionalProperties, pair)4623 }4624 }4625 }4626 return x, compiler.NewErrorGroupOrNil(errors)4627}4628func NewResponseValue(in interface{}, context *compiler.Context) (*ResponseValue, error) {4629 errors := make([]error, 0)4630 x := &ResponseValue{}4631 matched := false4632 // Response response = 1;4633 {4634 m, ok := compiler.UnpackMap(in)4635 if ok {4636 // errors might be ok here, they mean we just don't have the right subtype4637 t, matching_error := NewResponse(m, compiler.NewContext("response", context))4638 if matching_error == nil {4639 x.Oneof = &ResponseValue_Response{Response: t}4640 matched = true4641 } else {4642 errors = append(errors, matching_error)4643 }4644 }4645 }4646 // JsonReference json_reference = 2;4647 {4648 m, ok := compiler.UnpackMap(in)4649 if ok {4650 // errors might be ok here, they mean we just don't have the right subtype4651 t, matching_error := NewJsonReference(m, compiler.NewContext("jsonReference", context))4652 if matching_error == nil {4653 x.Oneof = &ResponseValue_JsonReference{JsonReference: t}4654 matched = true4655 } else {4656 errors = append(errors, matching_error)4657 }4658 }4659 }4660 if matched {4661 // since the oneof matched one of its possibilities, discard any matching errors4662 errors = make([]error, 0)4663 }4664 return x, compiler.NewErrorGroupOrNil(errors)4665}4666func NewResponses(in interface{}, context *compiler.Context) (*Responses, error) {4667 errors := make([]error, 0)4668 x := &Responses{}4669 m, ok := compiler.UnpackMap(in)4670 if !ok {4671 message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)4672 errors = append(errors, compiler.NewError(context, message))4673 } else {4674 allowedKeys := []string{}4675 allowedPatterns := []string{"^([0-9]{3})$|^(default)$", "^x-"}4676 invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)4677 if len(invalidKeys) > 0 {4678 message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))4679 errors = append(errors, compiler.NewError(context, message))4680 }4681 // repeated NamedResponseValue response_code = 1;4682 // MAP: ResponseValue ^([0-9]{3})$|^(default)$4683 x.ResponseCode = make([]*NamedResponseValue, 0)4684 for _, item := range m {4685 k, ok := item.Key.(string)4686 if ok {4687 v := item.Value4688 if compiler.PatternMatches("^([0-9]{3})$|^(default)$", k) {4689 pair := &NamedResponseValue{}4690 pair.Name = k4691 var err error4692 pair.Value, err = NewResponseValue(v, compiler.NewContext(k, context))4693 if err != nil {4694 errors = append(errors, err)4695 }4696 x.ResponseCode = append(x.ResponseCode, pair)4697 }4698 }4699 }4700 // repeated NamedAny vendor_extension = 2;4701 // MAP: Any ^x-4702 x.VendorExtension = make([]*NamedAny, 0)4703 for _, item := range m {4704 k, ok := item.Key.(string)4705 if ok {4706 v := item.Value4707 if compiler.PatternMatches("^x-", k) {4708 pair := &NamedAny{}4709 pair.Name = k4710 result := &Any{}4711 handled, resultFromExt, err := compiler.HandleExtension(context, v, k)4712 if handled {4713 if err != nil {4714 errors = append(errors, err)4715 } else {4716 bytes, _ := yaml.Marshal(v)4717 result.Yaml = string(bytes)4718 result.Value = resultFromExt4719 pair.Value = result4720 }4721 } else {4722 pair.Value, err = NewAny(v, compiler.NewContext(k, context))4723 if err != nil {4724 errors = append(errors, err)4725 }4726 }4727 x.VendorExtension = append(x.VendorExtension, pair)4728 }4729 }4730 }4731 }4732 return x, compiler.NewErrorGroupOrNil(errors)4733}4734func NewSchema(in interface{}, context *compiler.Context) (*Schema, error) {4735 errors := make([]error, 0)4736 x := &Schema{}4737 m, ok := compiler.UnpackMap(in)4738 if !ok {4739 message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)4740 errors = append(errors, compiler.NewError(context, message))4741 } else {4742 allowedKeys := []string{"$ref", "additionalProperties", "allOf", "default", "description", "discriminator", "enum", "example", "exclusiveMaximum", "exclusiveMinimum", "externalDocs", "format", "items", "maxItems", "maxLength", "maxProperties", "maximum", "minItems", "minLength", "minProperties", "minimum", "multipleOf", "pattern", "properties", "readOnly", "required", "title", "type", "uniqueItems", "xml"}4743 allowedPatterns := []string{"^x-"}4744 invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)4745 if len(invalidKeys) > 0 {4746 message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))4747 errors = append(errors, compiler.NewError(context, message))4748 }4749 // string _ref = 1;4750 v1 := compiler.MapValueForKey(m, "$ref")4751 if v1 != nil {4752 x.XRef, ok = v1.(string)4753 if !ok {4754 message := fmt.Sprintf("has unexpected value for $ref: %+v (%T)", v1, v1)4755 errors = append(errors, compiler.NewError(context, message))4756 }4757 }4758 // string format = 2;4759 v2 := compiler.MapValueForKey(m, "format")4760 if v2 != nil {4761 x.Format, ok = v2.(string)4762 if !ok {4763 message := fmt.Sprintf("has unexpected value for format: %+v (%T)", v2, v2)4764 errors = append(errors, compiler.NewError(context, message))4765 }4766 }4767 // string title = 3;4768 v3 := compiler.MapValueForKey(m, "title")4769 if v3 != nil {4770 x.Title, ok = v3.(string)4771 if !ok {4772 message := fmt.Sprintf("has unexpected value for title: %+v (%T)", v3, v3)4773 errors = append(errors, compiler.NewError(context, message))4774 }4775 }4776 // string description = 4;4777 v4 := compiler.MapValueForKey(m, "description")4778 if v4 != nil {4779 x.Description, ok = v4.(string)4780 if !ok {4781 message := fmt.Sprintf("has unexpected value for description: %+v (%T)", v4, v4)4782 errors = append(errors, compiler.NewError(context, message))4783 }4784 }4785 // Any default = 5;4786 v5 := compiler.MapValueForKey(m, "default")4787 if v5 != nil {4788 var err error4789 x.Default, err = NewAny(v5, compiler.NewContext("default", context))4790 if err != nil {4791 errors = append(errors, err)4792 }4793 }4794 // float multiple_of = 6;4795 v6 := compiler.MapValueForKey(m, "multipleOf")4796 if v6 != nil {4797 switch v6 := v6.(type) {4798 case float64:4799 x.MultipleOf = v64800 case float32:4801 x.MultipleOf = float64(v6)4802 case uint64:4803 x.MultipleOf = float64(v6)4804 case uint32:4805 x.MultipleOf = float64(v6)4806 case int64:4807 x.MultipleOf = float64(v6)4808 case int32:4809 x.MultipleOf = float64(v6)4810 case int:4811 x.MultipleOf = float64(v6)4812 default:4813 message := fmt.Sprintf("has unexpected value for multipleOf: %+v (%T)", v6, v6)4814 errors = append(errors, compiler.NewError(context, message))4815 }4816 }4817 // float maximum = 7;4818 v7 := compiler.MapValueForKey(m, "maximum")4819 if v7 != nil {4820 switch v7 := v7.(type) {4821 case float64:4822 x.Maximum = v74823 case float32:4824 x.Maximum = float64(v7)4825 case uint64:4826 x.Maximum = float64(v7)4827 case uint32:4828 x.Maximum = float64(v7)4829 case int64:4830 x.Maximum = float64(v7)4831 case int32:4832 x.Maximum = float64(v7)4833 case int:4834 x.Maximum = float64(v7)4835 default:4836 message := fmt.Sprintf("has unexpected value for maximum: %+v (%T)", v7, v7)4837 errors = append(errors, compiler.NewError(context, message))4838 }4839 }4840 // bool exclusive_maximum = 8;4841 v8 := compiler.MapValueForKey(m, "exclusiveMaximum")4842 if v8 != nil {4843 x.ExclusiveMaximum, ok = v8.(bool)4844 if !ok {4845 message := fmt.Sprintf("has unexpected value for exclusiveMaximum: %+v (%T)", v8, v8)4846 errors = append(errors, compiler.NewError(context, message))4847 }4848 }4849 // float minimum = 9;4850 v9 := compiler.MapValueForKey(m, "minimum")4851 if v9 != nil {4852 switch v9 := v9.(type) {4853 case float64:4854 x.Minimum = v94855 case float32:4856 x.Minimum = float64(v9)4857 case uint64:4858 x.Minimum = float64(v9)4859 case uint32:4860 x.Minimum = float64(v9)4861 case int64:4862 x.Minimum = float64(v9)4863 case int32:4864 x.Minimum = float64(v9)4865 case int:4866 x.Minimum = float64(v9)4867 default:4868 message := fmt.Sprintf("has unexpected value for minimum: %+v (%T)", v9, v9)4869 errors = append(errors, compiler.NewError(context, message))4870 }4871 }4872 // bool exclusive_minimum = 10;4873 v10 := compiler.MapValueForKey(m, "exclusiveMinimum")4874 if v10 != nil {4875 x.ExclusiveMinimum, ok = v10.(bool)4876 if !ok {4877 message := fmt.Sprintf("has unexpected value for exclusiveMinimum: %+v (%T)", v10, v10)4878 errors = append(errors, compiler.NewError(context, message))4879 }4880 }4881 // int64 max_length = 11;4882 v11 := compiler.MapValueForKey(m, "maxLength")4883 if v11 != nil {4884 t, ok := v11.(int)4885 if ok {4886 x.MaxLength = int64(t)4887 } else {4888 message := fmt.Sprintf("has unexpected value for maxLength: %+v (%T)", v11, v11)4889 errors = append(errors, compiler.NewError(context, message))4890 }4891 }4892 // int64 min_length = 12;4893 v12 := compiler.MapValueForKey(m, "minLength")4894 if v12 != nil {4895 t, ok := v12.(int)4896 if ok {4897 x.MinLength = int64(t)4898 } else {4899 message := fmt.Sprintf("has unexpected value for minLength: %+v (%T)", v12, v12)4900 errors = append(errors, compiler.NewError(context, message))4901 }4902 }4903 // string pattern = 13;4904 v13 := compiler.MapValueForKey(m, "pattern")4905 if v13 != nil {4906 x.Pattern, ok = v13.(string)4907 if !ok {4908 message := fmt.Sprintf("has unexpected value for pattern: %+v (%T)", v13, v13)4909 errors = append(errors, compiler.NewError(context, message))4910 }4911 }4912 // int64 max_items = 14;4913 v14 := compiler.MapValueForKey(m, "maxItems")4914 if v14 != nil {4915 t, ok := v14.(int)4916 if ok {4917 x.MaxItems = int64(t)4918 } else {4919 message := fmt.Sprintf("has unexpected value for maxItems: %+v (%T)", v14, v14)4920 errors = append(errors, compiler.NewError(context, message))4921 }4922 }4923 // int64 min_items = 15;4924 v15 := compiler.MapValueForKey(m, "minItems")4925 if v15 != nil {4926 t, ok := v15.(int)4927 if ok {4928 x.MinItems = int64(t)4929 } else {4930 message := fmt.Sprintf("has unexpected value for minItems: %+v (%T)", v15, v15)4931 errors = append(errors, compiler.NewError(context, message))4932 }4933 }4934 // bool unique_items = 16;4935 v16 := compiler.MapValueForKey(m, "uniqueItems")4936 if v16 != nil {4937 x.UniqueItems, ok = v16.(bool)4938 if !ok {4939 message := fmt.Sprintf("has unexpected value for uniqueItems: %+v (%T)", v16, v16)4940 errors = append(errors, compiler.NewError(context, message))4941 }4942 }4943 // int64 max_properties = 17;4944 v17 := compiler.MapValueForKey(m, "maxProperties")4945 if v17 != nil {4946 t, ok := v17.(int)4947 if ok {4948 x.MaxProperties = int64(t)4949 } else {4950 message := fmt.Sprintf("has unexpected value for maxProperties: %+v (%T)", v17, v17)4951 errors = append(errors, compiler.NewError(context, message))4952 }4953 }4954 // int64 min_properties = 18;4955 v18 := compiler.MapValueForKey(m, "minProperties")4956 if v18 != nil {4957 t, ok := v18.(int)4958 if ok {4959 x.MinProperties = int64(t)4960 } else {4961 message := fmt.Sprintf("has unexpected value for minProperties: %+v (%T)", v18, v18)4962 errors = append(errors, compiler.NewError(context, message))4963 }4964 }4965 // repeated string required = 19;4966 v19 := compiler.MapValueForKey(m, "required")4967 if v19 != nil {4968 v, ok := v19.([]interface{})4969 if ok {4970 x.Required = compiler.ConvertInterfaceArrayToStringArray(v)4971 } else {4972 message := fmt.Sprintf("has unexpected value for required: %+v (%T)", v19, v19)4973 errors = append(errors, compiler.NewError(context, message))4974 }4975 }4976 // repeated Any enum = 20;4977 v20 := compiler.MapValueForKey(m, "enum")4978 if v20 != nil {4979 // repeated Any4980 x.Enum = make([]*Any, 0)4981 a, ok := v20.([]interface{})4982 if ok {4983 for _, item := range a {4984 y, err := NewAny(item, compiler.NewContext("enum", context))4985 if err != nil {4986 errors = append(errors, err)4987 }4988 x.Enum = append(x.Enum, y)4989 }4990 }4991 }4992 // AdditionalPropertiesItem additional_properties = 21;4993 v21 := compiler.MapValueForKey(m, "additionalProperties")4994 if v21 != nil {4995 var err error4996 x.AdditionalProperties, err = NewAdditionalPropertiesItem(v21, compiler.NewContext("additionalProperties", context))4997 if err != nil {4998 errors = append(errors, err)4999 }5000 }5001 // TypeItem type = 22;5002 v22 := compiler.MapValueForKey(m, "type")5003 if v22 != nil {5004 var err error5005 x.Type, err = NewTypeItem(v22, compiler.NewContext("type", context))5006 if err != nil {5007 errors = append(errors, err)5008 }5009 }5010 // ItemsItem items = 23;5011 v23 := compiler.MapValueForKey(m, "items")5012 if v23 != nil {5013 var err error5014 x.Items, err = NewItemsItem(v23, compiler.NewContext("items", context))5015 if err != nil {5016 errors = append(errors, err)5017 }5018 }5019 // repeated Schema all_of = 24;5020 v24 := compiler.MapValueForKey(m, "allOf")5021 if v24 != nil {5022 // repeated Schema5023 x.AllOf = make([]*Schema, 0)5024 a, ok := v24.([]interface{})5025 if ok {5026 for _, item := range a {5027 y, err := NewSchema(item, compiler.NewContext("allOf", context))5028 if err != nil {5029 errors = append(errors, err)5030 }5031 x.AllOf = append(x.AllOf, y)5032 }5033 }5034 }5035 // Properties properties = 25;5036 v25 := compiler.MapValueForKey(m, "properties")5037 if v25 != nil {5038 var err error5039 x.Properties, err = NewProperties(v25, compiler.NewContext("properties", context))5040 if err != nil {5041 errors = append(errors, err)5042 }5043 }5044 // string discriminator = 26;5045 v26 := compiler.MapValueForKey(m, "discriminator")5046 if v26 != nil {5047 x.Discriminator, ok = v26.(string)5048 if !ok {5049 message := fmt.Sprintf("has unexpected value for discriminator: %+v (%T)", v26, v26)5050 errors = append(errors, compiler.NewError(context, message))5051 }5052 }5053 // bool read_only = 27;5054 v27 := compiler.MapValueForKey(m, "readOnly")5055 if v27 != nil {5056 x.ReadOnly, ok = v27.(bool)5057 if !ok {5058 message := fmt.Sprintf("has unexpected value for readOnly: %+v (%T)", v27, v27)5059 errors = append(errors, compiler.NewError(context, message))5060 }5061 }5062 // Xml xml = 28;5063 v28 := compiler.MapValueForKey(m, "xml")5064 if v28 != nil {5065 var err error5066 x.Xml, err = NewXml(v28, compiler.NewContext("xml", context))5067 if err != nil {5068 errors = append(errors, err)5069 }5070 }5071 // ExternalDocs external_docs = 29;5072 v29 := compiler.MapValueForKey(m, "externalDocs")5073 if v29 != nil {5074 var err error5075 x.ExternalDocs, err = NewExternalDocs(v29, compiler.NewContext("externalDocs", context))5076 if err != nil {5077 errors = append(errors, err)5078 }5079 }5080 // Any example = 30;5081 v30 := compiler.MapValueForKey(m, "example")5082 if v30 != nil {5083 var err error5084 x.Example, err = NewAny(v30, compiler.NewContext("example", context))5085 if err != nil {5086 errors = append(errors, err)5087 }5088 }5089 // repeated NamedAny vendor_extension = 31;5090 // MAP: Any ^x-5091 x.VendorExtension = make([]*NamedAny, 0)5092 for _, item := range m {5093 k, ok := item.Key.(string)5094 if ok {5095 v := item.Value5096 if compiler.PatternMatches("^x-", k) {5097 pair := &NamedAny{}5098 pair.Name = k5099 result := &Any{}5100 handled, resultFromExt, err := compiler.HandleExtension(context, v, k)5101 if handled {5102 if err != nil {5103 errors = append(errors, err)5104 } else {5105 bytes, _ := yaml.Marshal(v)5106 result.Yaml = string(bytes)5107 result.Value = resultFromExt5108 pair.Value = result5109 }5110 } else {5111 pair.Value, err = NewAny(v, compiler.NewContext(k, context))5112 if err != nil {5113 errors = append(errors, err)5114 }5115 }5116 x.VendorExtension = append(x.VendorExtension, pair)5117 }5118 }5119 }5120 }5121 return x, compiler.NewErrorGroupOrNil(errors)5122}5123func NewSchemaItem(in interface{}, context *compiler.Context) (*SchemaItem, error) {5124 errors := make([]error, 0)5125 x := &SchemaItem{}5126 matched := false5127 // Schema schema = 1;5128 {5129 m, ok := compiler.UnpackMap(in)5130 if ok {5131 // errors might be ok here, they mean we just don't have the right subtype5132 t, matching_error := NewSchema(m, compiler.NewContext("schema", context))5133 if matching_error == nil {5134 x.Oneof = &SchemaItem_Schema{Schema: t}5135 matched = true5136 } else {5137 errors = append(errors, matching_error)5138 }5139 }5140 }5141 // FileSchema file_schema = 2;5142 {5143 m, ok := compiler.UnpackMap(in)5144 if ok {5145 // errors might be ok here, they mean we just don't have the right subtype5146 t, matching_error := NewFileSchema(m, compiler.NewContext("fileSchema", context))5147 if matching_error == nil {5148 x.Oneof = &SchemaItem_FileSchema{FileSchema: t}5149 matched = true5150 } else {5151 errors = append(errors, matching_error)5152 }5153 }5154 }5155 if matched {5156 // since the oneof matched one of its possibilities, discard any matching errors5157 errors = make([]error, 0)5158 }5159 return x, compiler.NewErrorGroupOrNil(errors)5160}5161func NewSecurityDefinitions(in interface{}, context *compiler.Context) (*SecurityDefinitions, error) {5162 errors := make([]error, 0)5163 x := &SecurityDefinitions{}5164 m, ok := compiler.UnpackMap(in)5165 if !ok {5166 message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)5167 errors = append(errors, compiler.NewError(context, message))5168 } else {5169 // repeated NamedSecurityDefinitionsItem additional_properties = 1;5170 // MAP: SecurityDefinitionsItem5171 x.AdditionalProperties = make([]*NamedSecurityDefinitionsItem, 0)5172 for _, item := range m {5173 k, ok := item.Key.(string)5174 if ok {5175 v := item.Value5176 pair := &NamedSecurityDefinitionsItem{}5177 pair.Name = k5178 var err error5179 pair.Value, err = NewSecurityDefinitionsItem(v, compiler.NewContext(k, context))5180 if err != nil {5181 errors = append(errors, err)5182 }5183 x.AdditionalProperties = append(x.AdditionalProperties, pair)5184 }5185 }5186 }5187 return x, compiler.NewErrorGroupOrNil(errors)5188}5189func NewSecurityDefinitionsItem(in interface{}, context *compiler.Context) (*SecurityDefinitionsItem, error) {5190 errors := make([]error, 0)5191 x := &SecurityDefinitionsItem{}5192 matched := false5193 // BasicAuthenticationSecurity basic_authentication_security = 1;5194 {5195 m, ok := compiler.UnpackMap(in)5196 if ok {5197 // errors might be ok here, they mean we just don't have the right subtype5198 t, matching_error := NewBasicAuthenticationSecurity(m, compiler.NewContext("basicAuthenticationSecurity", context))5199 if matching_error == nil {5200 x.Oneof = &SecurityDefinitionsItem_BasicAuthenticationSecurity{BasicAuthenticationSecurity: t}5201 matched = true5202 } else {5203 errors = append(errors, matching_error)5204 }5205 }5206 }5207 // ApiKeySecurity api_key_security = 2;5208 {5209 m, ok := compiler.UnpackMap(in)5210 if ok {5211 // errors might be ok here, they mean we just don't have the right subtype5212 t, matching_error := NewApiKeySecurity(m, compiler.NewContext("apiKeySecurity", context))5213 if matching_error == nil {5214 x.Oneof = &SecurityDefinitionsItem_ApiKeySecurity{ApiKeySecurity: t}5215 matched = true5216 } else {5217 errors = append(errors, matching_error)5218 }5219 }5220 }5221 // Oauth2ImplicitSecurity oauth2_implicit_security = 3;5222 {5223 m, ok := compiler.UnpackMap(in)5224 if ok {5225 // errors might be ok here, they mean we just don't have the right subtype5226 t, matching_error := NewOauth2ImplicitSecurity(m, compiler.NewContext("oauth2ImplicitSecurity", context))5227 if matching_error == nil {5228 x.Oneof = &SecurityDefinitionsItem_Oauth2ImplicitSecurity{Oauth2ImplicitSecurity: t}5229 matched = true5230 } else {5231 errors = append(errors, matching_error)5232 }5233 }5234 }5235 // Oauth2PasswordSecurity oauth2_password_security = 4;5236 {5237 m, ok := compiler.UnpackMap(in)5238 if ok {5239 // errors might be ok here, they mean we just don't have the right subtype5240 t, matching_error := NewOauth2PasswordSecurity(m, compiler.NewContext("oauth2PasswordSecurity", context))5241 if matching_error == nil {5242 x.Oneof = &SecurityDefinitionsItem_Oauth2PasswordSecurity{Oauth2PasswordSecurity: t}5243 matched = true5244 } else {5245 errors = append(errors, matching_error)5246 }5247 }5248 }5249 // Oauth2ApplicationSecurity oauth2_application_security = 5;5250 {5251 m, ok := compiler.UnpackMap(in)5252 if ok {5253 // errors might be ok here, they mean we just don't have the right subtype5254 t, matching_error := NewOauth2ApplicationSecurity(m, compiler.NewContext("oauth2ApplicationSecurity", context))5255 if matching_error == nil {5256 x.Oneof = &SecurityDefinitionsItem_Oauth2ApplicationSecurity{Oauth2ApplicationSecurity: t}5257 matched = true5258 } else {5259 errors = append(errors, matching_error)5260 }5261 }5262 }5263 // Oauth2AccessCodeSecurity oauth2_access_code_security = 6;5264 {5265 m, ok := compiler.UnpackMap(in)5266 if ok {5267 // errors might be ok here, they mean we just don't have the right subtype5268 t, matching_error := NewOauth2AccessCodeSecurity(m, compiler.NewContext("oauth2AccessCodeSecurity", context))5269 if matching_error == nil {5270 x.Oneof = &SecurityDefinitionsItem_Oauth2AccessCodeSecurity{Oauth2AccessCodeSecurity: t}5271 matched = true5272 } else {5273 errors = append(errors, matching_error)5274 }5275 }5276 }5277 if matched {5278 // since the oneof matched one of its possibilities, discard any matching errors5279 errors = make([]error, 0)5280 }5281 return x, compiler.NewErrorGroupOrNil(errors)5282}5283func NewSecurityRequirement(in interface{}, context *compiler.Context) (*SecurityRequirement, error) {5284 errors := make([]error, 0)5285 x := &SecurityRequirement{}5286 m, ok := compiler.UnpackMap(in)5287 if !ok {5288 message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)5289 errors = append(errors, compiler.NewError(context, message))5290 } else {5291 // repeated NamedStringArray additional_properties = 1;5292 // MAP: StringArray5293 x.AdditionalProperties = make([]*NamedStringArray, 0)5294 for _, item := range m {5295 k, ok := item.Key.(string)5296 if ok {5297 v := item.Value5298 pair := &NamedStringArray{}5299 pair.Name = k5300 var err error5301 pair.Value, err = NewStringArray(v, compiler.NewContext(k, context))5302 if err != nil {5303 errors = append(errors, err)5304 }5305 x.AdditionalProperties = append(x.AdditionalProperties, pair)5306 }5307 }5308 }5309 return x, compiler.NewErrorGroupOrNil(errors)5310}5311func NewStringArray(in interface{}, context *compiler.Context) (*StringArray, error) {5312 errors := make([]error, 0)5313 x := &StringArray{}5314 a, ok := in.([]interface{})5315 if !ok {5316 message := fmt.Sprintf("has unexpected value for StringArray: %+v (%T)", in, in)5317 errors = append(errors, compiler.NewError(context, message))5318 } else {5319 x.Value = make([]string, 0)5320 for _, s := range a {5321 x.Value = append(x.Value, s.(string))5322 }5323 }5324 return x, compiler.NewErrorGroupOrNil(errors)5325}5326func NewTag(in interface{}, context *compiler.Context) (*Tag, error) {5327 errors := make([]error, 0)5328 x := &Tag{}5329 m, ok := compiler.UnpackMap(in)5330 if !ok {5331 message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)5332 errors = append(errors, compiler.NewError(context, message))5333 } else {5334 requiredKeys := []string{"name"}5335 missingKeys := compiler.MissingKeysInMap(m, requiredKeys)5336 if len(missingKeys) > 0 {5337 message := fmt.Sprintf("is missing required %s: %+v", compiler.PluralProperties(len(missingKeys)), strings.Join(missingKeys, ", "))5338 errors = append(errors, compiler.NewError(context, message))5339 }5340 allowedKeys := []string{"description", "externalDocs", "name"}5341 allowedPatterns := []string{"^x-"}5342 invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)5343 if len(invalidKeys) > 0 {5344 message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))5345 errors = append(errors, compiler.NewError(context, message))5346 }5347 // string name = 1;5348 v1 := compiler.MapValueForKey(m, "name")5349 if v1 != nil {5350 x.Name, ok = v1.(string)5351 if !ok {5352 message := fmt.Sprintf("has unexpected value for name: %+v (%T)", v1, v1)5353 errors = append(errors, compiler.NewError(context, message))5354 }5355 }5356 // string description = 2;5357 v2 := compiler.MapValueForKey(m, "description")5358 if v2 != nil {5359 x.Description, ok = v2.(string)5360 if !ok {5361 message := fmt.Sprintf("has unexpected value for description: %+v (%T)", v2, v2)5362 errors = append(errors, compiler.NewError(context, message))5363 }5364 }5365 // ExternalDocs external_docs = 3;5366 v3 := compiler.MapValueForKey(m, "externalDocs")5367 if v3 != nil {5368 var err error5369 x.ExternalDocs, err = NewExternalDocs(v3, compiler.NewContext("externalDocs", context))5370 if err != nil {5371 errors = append(errors, err)5372 }5373 }5374 // repeated NamedAny vendor_extension = 4;5375 // MAP: Any ^x-5376 x.VendorExtension = make([]*NamedAny, 0)5377 for _, item := range m {5378 k, ok := item.Key.(string)5379 if ok {5380 v := item.Value5381 if compiler.PatternMatches("^x-", k) {5382 pair := &NamedAny{}5383 pair.Name = k5384 result := &Any{}5385 handled, resultFromExt, err := compiler.HandleExtension(context, v, k)5386 if handled {5387 if err != nil {5388 errors = append(errors, err)5389 } else {5390 bytes, _ := yaml.Marshal(v)5391 result.Yaml = string(bytes)5392 result.Value = resultFromExt5393 pair.Value = result5394 }5395 } else {5396 pair.Value, err = NewAny(v, compiler.NewContext(k, context))5397 if err != nil {5398 errors = append(errors, err)5399 }5400 }5401 x.VendorExtension = append(x.VendorExtension, pair)5402 }5403 }5404 }5405 }5406 return x, compiler.NewErrorGroupOrNil(errors)5407}5408func NewTypeItem(in interface{}, context *compiler.Context) (*TypeItem, error) {5409 errors := make([]error, 0)5410 x := &TypeItem{}5411 switch in := in.(type) {5412 case string:5413 x.Value = make([]string, 0)5414 x.Value = append(x.Value, in)5415 case []interface{}:5416 x.Value = make([]string, 0)5417 for _, v := range in {5418 value, ok := v.(string)5419 if ok {5420 x.Value = append(x.Value, value)5421 } else {5422 message := fmt.Sprintf("has unexpected value for string array element: %+v (%T)", value, value)5423 errors = append(errors, compiler.NewError(context, message))5424 }5425 }5426 default:5427 message := fmt.Sprintf("has unexpected value for string array: %+v (%T)", in, in)5428 errors = append(errors, compiler.NewError(context, message))5429 }5430 return x, compiler.NewErrorGroupOrNil(errors)5431}5432func NewVendorExtension(in interface{}, context *compiler.Context) (*VendorExtension, error) {5433 errors := make([]error, 0)5434 x := &VendorExtension{}5435 m, ok := compiler.UnpackMap(in)5436 if !ok {5437 message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)5438 errors = append(errors, compiler.NewError(context, message))5439 } else {5440 // repeated NamedAny additional_properties = 1;5441 // MAP: Any5442 x.AdditionalProperties = make([]*NamedAny, 0)5443 for _, item := range m {5444 k, ok := item.Key.(string)5445 if ok {5446 v := item.Value5447 pair := &NamedAny{}5448 pair.Name = k5449 result := &Any{}5450 handled, resultFromExt, err := compiler.HandleExtension(context, v, k)5451 if handled {5452 if err != nil {5453 errors = append(errors, err)5454 } else {5455 bytes, _ := yaml.Marshal(v)5456 result.Yaml = string(bytes)5457 result.Value = resultFromExt5458 pair.Value = result5459 }5460 } else {5461 pair.Value, err = NewAny(v, compiler.NewContext(k, context))5462 if err != nil {5463 errors = append(errors, err)5464 }5465 }5466 x.AdditionalProperties = append(x.AdditionalProperties, pair)5467 }5468 }5469 }5470 return x, compiler.NewErrorGroupOrNil(errors)5471}5472func NewXml(in interface{}, context *compiler.Context) (*Xml, error) {5473 errors := make([]error, 0)5474 x := &Xml{}5475 m, ok := compiler.UnpackMap(in)5476 if !ok {5477 message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)5478 errors = append(errors, compiler.NewError(context, message))5479 } else {5480 allowedKeys := []string{"attribute", "name", "namespace", "prefix", "wrapped"}5481 allowedPatterns := []string{"^x-"}5482 invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)5483 if len(invalidKeys) > 0 {5484 message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))5485 errors = append(errors, compiler.NewError(context, message))5486 }5487 // string name = 1;5488 v1 := compiler.MapValueForKey(m, "name")5489 if v1 != nil {5490 x.Name, ok = v1.(string)5491 if !ok {5492 message := fmt.Sprintf("has unexpected value for name: %+v (%T)", v1, v1)5493 errors = append(errors, compiler.NewError(context, message))5494 }5495 }5496 // string namespace = 2;5497 v2 := compiler.MapValueForKey(m, "namespace")5498 if v2 != nil {5499 x.Namespace, ok = v2.(string)5500 if !ok {5501 message := fmt.Sprintf("has unexpected value for namespace: %+v (%T)", v2, v2)5502 errors = append(errors, compiler.NewError(context, message))5503 }5504 }5505 // string prefix = 3;5506 v3 := compiler.MapValueForKey(m, "prefix")5507 if v3 != nil {5508 x.Prefix, ok = v3.(string)5509 if !ok {5510 message := fmt.Sprintf("has unexpected value for prefix: %+v (%T)", v3, v3)5511 errors = append(errors, compiler.NewError(context, message))5512 }5513 }5514 // bool attribute = 4;5515 v4 := compiler.MapValueForKey(m, "attribute")5516 if v4 != nil {5517 x.Attribute, ok = v4.(bool)5518 if !ok {5519 message := fmt.Sprintf("has unexpected value for attribute: %+v (%T)", v4, v4)5520 errors = append(errors, compiler.NewError(context, message))5521 }5522 }5523 // bool wrapped = 5;5524 v5 := compiler.MapValueForKey(m, "wrapped")5525 if v5 != nil {5526 x.Wrapped, ok = v5.(bool)5527 if !ok {5528 message := fmt.Sprintf("has unexpected value for wrapped: %+v (%T)", v5, v5)5529 errors = append(errors, compiler.NewError(context, message))5530 }5531 }5532 // repeated NamedAny vendor_extension = 6;5533 // MAP: Any ^x-5534 x.VendorExtension = make([]*NamedAny, 0)5535 for _, item := range m {5536 k, ok := item.Key.(string)5537 if ok {5538 v := item.Value5539 if compiler.PatternMatches("^x-", k) {5540 pair := &NamedAny{}5541 pair.Name = k5542 result := &Any{}5543 handled, resultFromExt, err := compiler.HandleExtension(context, v, k)5544 if handled {5545 if err != nil {5546 errors = append(errors, err)5547 } else {5548 bytes, _ := yaml.Marshal(v)5549 result.Yaml = string(bytes)5550 result.Value = resultFromExt5551 pair.Value = result5552 }5553 } else {5554 pair.Value, err = NewAny(v, compiler.NewContext(k, context))5555 if err != nil {5556 errors = append(errors, err)5557 }5558 }5559 x.VendorExtension = append(x.VendorExtension, pair)5560 }5561 }5562 }5563 }5564 return x, compiler.NewErrorGroupOrNil(errors)5565}5566func (m *AdditionalPropertiesItem) ResolveReferences(root string) (interface{}, error) {5567 errors := make([]error, 0)5568 {5569 p, ok := m.Oneof.(*AdditionalPropertiesItem_Schema)5570 if ok {5571 _, err := p.Schema.ResolveReferences(root)5572 if err != nil {5573 return nil, err5574 }5575 }5576 }5577 return nil, compiler.NewErrorGroupOrNil(errors)5578}5579func (m *Any) ResolveReferences(root string) (interface{}, error) {5580 errors := make([]error, 0)5581 return nil, compiler.NewErrorGroupOrNil(errors)5582}5583func (m *ApiKeySecurity) ResolveReferences(root string) (interface{}, error) {5584 errors := make([]error, 0)5585 for _, item := range m.VendorExtension {5586 if item != nil {5587 _, err := item.ResolveReferences(root)5588 if err != nil {5589 errors = append(errors, err)5590 }5591 }5592 }5593 return nil, compiler.NewErrorGroupOrNil(errors)5594}5595func (m *BasicAuthenticationSecurity) ResolveReferences(root string) (interface{}, error) {5596 errors := make([]error, 0)5597 for _, item := range m.VendorExtension {5598 if item != nil {5599 _, err := item.ResolveReferences(root)5600 if err != nil {5601 errors = append(errors, err)5602 }5603 }5604 }5605 return nil, compiler.NewErrorGroupOrNil(errors)5606}5607func (m *BodyParameter) ResolveReferences(root string) (interface{}, error) {5608 errors := make([]error, 0)5609 if m.Schema != nil {5610 _, err := m.Schema.ResolveReferences(root)5611 if err != nil {5612 errors = append(errors, err)5613 }5614 }5615 for _, item := range m.VendorExtension {5616 if item != nil {5617 _, err := item.ResolveReferences(root)5618 if err != nil {5619 errors = append(errors, err)5620 }5621 }5622 }5623 return nil, compiler.NewErrorGroupOrNil(errors)5624}5625func (m *Contact) ResolveReferences(root string) (interface{}, error) {5626 errors := make([]error, 0)5627 for _, item := range m.VendorExtension {5628 if item != nil {5629 _, err := item.ResolveReferences(root)5630 if err != nil {5631 errors = append(errors, err)5632 }5633 }5634 }5635 return nil, compiler.NewErrorGroupOrNil(errors)5636}5637func (m *Default) ResolveReferences(root string) (interface{}, error) {5638 errors := make([]error, 0)5639 for _, item := range m.AdditionalProperties {5640 if item != nil {5641 _, err := item.ResolveReferences(root)5642 if err != nil {5643 errors = append(errors, err)5644 }5645 }5646 }5647 return nil, compiler.NewErrorGroupOrNil(errors)5648}5649func (m *Definitions) ResolveReferences(root string) (interface{}, error) {5650 errors := make([]error, 0)5651 for _, item := range m.AdditionalProperties {5652 if item != nil {5653 _, err := item.ResolveReferences(root)5654 if err != nil {5655 errors = append(errors, err)5656 }5657 }5658 }5659 return nil, compiler.NewErrorGroupOrNil(errors)5660}5661func (m *Document) ResolveReferences(root string) (interface{}, error) {5662 errors := make([]error, 0)5663 if m.Info != nil {5664 _, err := m.Info.ResolveReferences(root)5665 if err != nil {5666 errors = append(errors, err)5667 }5668 }5669 if m.Paths != nil {5670 _, err := m.Paths.ResolveReferences(root)5671 if err != nil {5672 errors = append(errors, err)5673 }5674 }5675 if m.Definitions != nil {5676 _, err := m.Definitions.ResolveReferences(root)5677 if err != nil {5678 errors = append(errors, err)5679 }5680 }5681 if m.Parameters != nil {5682 _, err := m.Parameters.ResolveReferences(root)5683 if err != nil {5684 errors = append(errors, err)5685 }5686 }5687 if m.Responses != nil {5688 _, err := m.Responses.ResolveReferences(root)5689 if err != nil {5690 errors = append(errors, err)5691 }5692 }5693 for _, item := range m.Security {5694 if item != nil {5695 _, err := item.ResolveReferences(root)5696 if err != nil {5697 errors = append(errors, err)5698 }5699 }5700 }5701 if m.SecurityDefinitions != nil {5702 _, err := m.SecurityDefinitions.ResolveReferences(root)5703 if err != nil {5704 errors = append(errors, err)5705 }5706 }5707 for _, item := range m.Tags {5708 if item != nil {5709 _, err := item.ResolveReferences(root)5710 if err != nil {5711 errors = append(errors, err)5712 }5713 }5714 }5715 if m.ExternalDocs != nil {5716 _, err := m.ExternalDocs.ResolveReferences(root)5717 if err != nil {5718 errors = append(errors, err)5719 }5720 }5721 for _, item := range m.VendorExtension {5722 if item != nil {5723 _, err := item.ResolveReferences(root)5724 if err != nil {5725 errors = append(errors, err)5726 }5727 }5728 }5729 return nil, compiler.NewErrorGroupOrNil(errors)5730}5731func (m *Examples) ResolveReferences(root string) (interface{}, error) {5732 errors := make([]error, 0)5733 for _, item := range m.AdditionalProperties {5734 if item != nil {5735 _, err := item.ResolveReferences(root)5736 if err != nil {5737 errors = append(errors, err)5738 }5739 }5740 }5741 return nil, compiler.NewErrorGroupOrNil(errors)5742}5743func (m *ExternalDocs) ResolveReferences(root string) (interface{}, error) {5744 errors := make([]error, 0)5745 for _, item := range m.VendorExtension {5746 if item != nil {5747 _, err := item.ResolveReferences(root)5748 if err != nil {5749 errors = append(errors, err)5750 }5751 }5752 }5753 return nil, compiler.NewErrorGroupOrNil(errors)5754}5755func (m *FileSchema) ResolveReferences(root string) (interface{}, error) {5756 errors := make([]error, 0)5757 if m.Default != nil {5758 _, err := m.Default.ResolveReferences(root)5759 if err != nil {5760 errors = append(errors, err)5761 }5762 }5763 if m.ExternalDocs != nil {5764 _, err := m.ExternalDocs.ResolveReferences(root)5765 if err != nil {5766 errors = append(errors, err)5767 }5768 }5769 if m.Example != nil {5770 _, err := m.Example.ResolveReferences(root)5771 if err != nil {5772 errors = append(errors, err)5773 }5774 }5775 for _, item := range m.VendorExtension {5776 if item != nil {5777 _, err := item.ResolveReferences(root)5778 if err != nil {5779 errors = append(errors, err)5780 }5781 }5782 }5783 return nil, compiler.NewErrorGroupOrNil(errors)5784}5785func (m *FormDataParameterSubSchema) ResolveReferences(root string) (interface{}, error) {5786 errors := make([]error, 0)5787 if m.Items != nil {5788 _, err := m.Items.ResolveReferences(root)5789 if err != nil {5790 errors = append(errors, err)5791 }5792 }5793 if m.Default != nil {5794 _, err := m.Default.ResolveReferences(root)5795 if err != nil {5796 errors = append(errors, err)5797 }5798 }5799 for _, item := range m.Enum {5800 if item != nil {5801 _, err := item.ResolveReferences(root)5802 if err != nil {5803 errors = append(errors, err)5804 }5805 }5806 }5807 for _, item := range m.VendorExtension {5808 if item != nil {5809 _, err := item.ResolveReferences(root)5810 if err != nil {5811 errors = append(errors, err)5812 }5813 }5814 }5815 return nil, compiler.NewErrorGroupOrNil(errors)5816}5817func (m *Header) ResolveReferences(root string) (interface{}, error) {5818 errors := make([]error, 0)5819 if m.Items != nil {5820 _, err := m.Items.ResolveReferences(root)5821 if err != nil {5822 errors = append(errors, err)5823 }5824 }5825 if m.Default != nil {5826 _, err := m.Default.ResolveReferences(root)5827 if err != nil {5828 errors = append(errors, err)5829 }5830 }5831 for _, item := range m.Enum {5832 if item != nil {5833 _, err := item.ResolveReferences(root)5834 if err != nil {5835 errors = append(errors, err)5836 }5837 }5838 }5839 for _, item := range m.VendorExtension {5840 if item != nil {5841 _, err := item.ResolveReferences(root)5842 if err != nil {5843 errors = append(errors, err)5844 }5845 }5846 }5847 return nil, compiler.NewErrorGroupOrNil(errors)5848}5849func (m *HeaderParameterSubSchema) ResolveReferences(root string) (interface{}, error) {5850 errors := make([]error, 0)5851 if m.Items != nil {5852 _, err := m.Items.ResolveReferences(root)5853 if err != nil {5854 errors = append(errors, err)5855 }5856 }5857 if m.Default != nil {5858 _, err := m.Default.ResolveReferences(root)5859 if err != nil {5860 errors = append(errors, err)5861 }5862 }5863 for _, item := range m.Enum {5864 if item != nil {5865 _, err := item.ResolveReferences(root)5866 if err != nil {5867 errors = append(errors, err)5868 }5869 }5870 }5871 for _, item := range m.VendorExtension {5872 if item != nil {5873 _, err := item.ResolveReferences(root)5874 if err != nil {5875 errors = append(errors, err)5876 }5877 }5878 }5879 return nil, compiler.NewErrorGroupOrNil(errors)5880}5881func (m *Headers) ResolveReferences(root string) (interface{}, error) {5882 errors := make([]error, 0)5883 for _, item := range m.AdditionalProperties {5884 if item != nil {5885 _, err := item.ResolveReferences(root)5886 if err != nil {5887 errors = append(errors, err)5888 }5889 }5890 }5891 return nil, compiler.NewErrorGroupOrNil(errors)5892}5893func (m *Info) ResolveReferences(root string) (interface{}, error) {5894 errors := make([]error, 0)5895 if m.Contact != nil {5896 _, err := m.Contact.ResolveReferences(root)5897 if err != nil {5898 errors = append(errors, err)5899 }5900 }5901 if m.License != nil {5902 _, err := m.License.ResolveReferences(root)5903 if err != nil {5904 errors = append(errors, err)5905 }5906 }5907 for _, item := range m.VendorExtension {5908 if item != nil {5909 _, err := item.ResolveReferences(root)5910 if err != nil {5911 errors = append(errors, err)5912 }5913 }5914 }5915 return nil, compiler.NewErrorGroupOrNil(errors)5916}5917func (m *ItemsItem) ResolveReferences(root string) (interface{}, error) {5918 errors := make([]error, 0)5919 for _, item := range m.Schema {5920 if item != nil {5921 _, err := item.ResolveReferences(root)5922 if err != nil {5923 errors = append(errors, err)5924 }5925 }5926 }5927 return nil, compiler.NewErrorGroupOrNil(errors)5928}5929func (m *JsonReference) ResolveReferences(root string) (interface{}, error) {5930 errors := make([]error, 0)5931 if m.XRef != "" {5932 info, err := compiler.ReadInfoForRef(root, m.XRef)5933 if err != nil {5934 return nil, err5935 }5936 if info != nil {5937 replacement, err := NewJsonReference(info, nil)5938 if err == nil {5939 *m = *replacement5940 return m.ResolveReferences(root)5941 }5942 }5943 return info, nil5944 }5945 return nil, compiler.NewErrorGroupOrNil(errors)5946}5947func (m *License) ResolveReferences(root string) (interface{}, error) {5948 errors := make([]error, 0)5949 for _, item := range m.VendorExtension {5950 if item != nil {5951 _, err := item.ResolveReferences(root)5952 if err != nil {5953 errors = append(errors, err)5954 }5955 }5956 }5957 return nil, compiler.NewErrorGroupOrNil(errors)5958}5959func (m *NamedAny) ResolveReferences(root string) (interface{}, error) {5960 errors := make([]error, 0)5961 if m.Value != nil {5962 _, err := m.Value.ResolveReferences(root)5963 if err != nil {5964 errors = append(errors, err)5965 }5966 }5967 return nil, compiler.NewErrorGroupOrNil(errors)5968}5969func (m *NamedHeader) ResolveReferences(root string) (interface{}, error) {5970 errors := make([]error, 0)5971 if m.Value != nil {5972 _, err := m.Value.ResolveReferences(root)5973 if err != nil {5974 errors = append(errors, err)5975 }5976 }5977 return nil, compiler.NewErrorGroupOrNil(errors)5978}5979func (m *NamedParameter) ResolveReferences(root string) (interface{}, error) {5980 errors := make([]error, 0)5981 if m.Value != nil {5982 _, err := m.Value.ResolveReferences(root)5983 if err != nil {5984 errors = append(errors, err)5985 }5986 }5987 return nil, compiler.NewErrorGroupOrNil(errors)5988}5989func (m *NamedPathItem) ResolveReferences(root string) (interface{}, error) {5990 errors := make([]error, 0)5991 if m.Value != nil {5992 _, err := m.Value.ResolveReferences(root)5993 if err != nil {5994 errors = append(errors, err)5995 }5996 }5997 return nil, compiler.NewErrorGroupOrNil(errors)5998}5999func (m *NamedResponse) ResolveReferences(root string) (interface{}, error) {6000 errors := make([]error, 0)6001 if m.Value != nil {6002 _, err := m.Value.ResolveReferences(root)6003 if err != nil {6004 errors = append(errors, err)6005 }6006 }6007 return nil, compiler.NewErrorGroupOrNil(errors)6008}6009func (m *NamedResponseValue) ResolveReferences(root string) (interface{}, error) {6010 errors := make([]error, 0)6011 if m.Value != nil {6012 _, err := m.Value.ResolveReferences(root)6013 if err != nil {6014 errors = append(errors, err)6015 }6016 }6017 return nil, compiler.NewErrorGroupOrNil(errors)6018}6019func (m *NamedSchema) ResolveReferences(root string) (interface{}, error) {6020 errors := make([]error, 0)6021 if m.Value != nil {6022 _, err := m.Value.ResolveReferences(root)6023 if err != nil {6024 errors = append(errors, err)6025 }6026 }6027 return nil, compiler.NewErrorGroupOrNil(errors)6028}6029func (m *NamedSecurityDefinitionsItem) ResolveReferences(root string) (interface{}, error) {6030 errors := make([]error, 0)6031 if m.Value != nil {6032 _, err := m.Value.ResolveReferences(root)6033 if err != nil {6034 errors = append(errors, err)6035 }6036 }6037 return nil, compiler.NewErrorGroupOrNil(errors)6038}6039func (m *NamedString) ResolveReferences(root string) (interface{}, error) {6040 errors := make([]error, 0)6041 return nil, compiler.NewErrorGroupOrNil(errors)6042}6043func (m *NamedStringArray) ResolveReferences(root string) (interface{}, error) {6044 errors := make([]error, 0)6045 if m.Value != nil {6046 _, err := m.Value.ResolveReferences(root)6047 if err != nil {6048 errors = append(errors, err)6049 }6050 }6051 return nil, compiler.NewErrorGroupOrNil(errors)6052}6053func (m *NonBodyParameter) ResolveReferences(root string) (interface{}, error) {6054 errors := make([]error, 0)6055 {6056 p, ok := m.Oneof.(*NonBodyParameter_HeaderParameterSubSchema)6057 if ok {6058 _, err := p.HeaderParameterSubSchema.ResolveReferences(root)6059 if err != nil {6060 return nil, err6061 }6062 }6063 }6064 {6065 p, ok := m.Oneof.(*NonBodyParameter_FormDataParameterSubSchema)6066 if ok {6067 _, err := p.FormDataParameterSubSchema.ResolveReferences(root)6068 if err != nil {6069 return nil, err6070 }6071 }6072 }6073 {6074 p, ok := m.Oneof.(*NonBodyParameter_QueryParameterSubSchema)6075 if ok {6076 _, err := p.QueryParameterSubSchema.ResolveReferences(root)6077 if err != nil {6078 return nil, err6079 }6080 }6081 }6082 {6083 p, ok := m.Oneof.(*NonBodyParameter_PathParameterSubSchema)6084 if ok {6085 _, err := p.PathParameterSubSchema.ResolveReferences(root)6086 if err != nil {6087 return nil, err6088 }6089 }6090 }6091 return nil, compiler.NewErrorGroupOrNil(errors)6092}6093func (m *Oauth2AccessCodeSecurity) ResolveReferences(root string) (interface{}, error) {6094 errors := make([]error, 0)6095 if m.Scopes != nil {6096 _, err := m.Scopes.ResolveReferences(root)6097 if err != nil {6098 errors = append(errors, err)6099 }6100 }6101 for _, item := range m.VendorExtension {6102 if item != nil {6103 _, err := item.ResolveReferences(root)6104 if err != nil {6105 errors = append(errors, err)6106 }6107 }6108 }6109 return nil, compiler.NewErrorGroupOrNil(errors)6110}6111func (m *Oauth2ApplicationSecurity) ResolveReferences(root string) (interface{}, error) {6112 errors := make([]error, 0)6113 if m.Scopes != nil {6114 _, err := m.Scopes.ResolveReferences(root)6115 if err != nil {6116 errors = append(errors, err)6117 }6118 }6119 for _, item := range m.VendorExtension {6120 if item != nil {6121 _, err := item.ResolveReferences(root)6122 if err != nil {6123 errors = append(errors, err)6124 }6125 }6126 }6127 return nil, compiler.NewErrorGroupOrNil(errors)6128}6129func (m *Oauth2ImplicitSecurity) ResolveReferences(root string) (interface{}, error) {6130 errors := make([]error, 0)6131 if m.Scopes != nil {6132 _, err := m.Scopes.ResolveReferences(root)6133 if err != nil {6134 errors = append(errors, err)6135 }6136 }6137 for _, item := range m.VendorExtension {6138 if item != nil {6139 _, err := item.ResolveReferences(root)6140 if err != nil {6141 errors = append(errors, err)6142 }6143 }6144 }6145 return nil, compiler.NewErrorGroupOrNil(errors)6146}6147func (m *Oauth2PasswordSecurity) ResolveReferences(root string) (interface{}, error) {6148 errors := make([]error, 0)6149 if m.Scopes != nil {6150 _, err := m.Scopes.ResolveReferences(root)6151 if err != nil {6152 errors = append(errors, err)6153 }6154 }6155 for _, item := range m.VendorExtension {6156 if item != nil {6157 _, err := item.ResolveReferences(root)6158 if err != nil {6159 errors = append(errors, err)6160 }6161 }6162 }6163 return nil, compiler.NewErrorGroupOrNil(errors)6164}6165func (m *Oauth2Scopes) ResolveReferences(root string) (interface{}, error) {6166 errors := make([]error, 0)6167 for _, item := range m.AdditionalProperties {6168 if item != nil {6169 _, err := item.ResolveReferences(root)6170 if err != nil {6171 errors = append(errors, err)6172 }6173 }6174 }6175 return nil, compiler.NewErrorGroupOrNil(errors)6176}6177func (m *Operation) ResolveReferences(root string) (interface{}, error) {6178 errors := make([]error, 0)6179 if m.ExternalDocs != nil {6180 _, err := m.ExternalDocs.ResolveReferences(root)6181 if err != nil {6182 errors = append(errors, err)6183 }6184 }6185 for _, item := range m.Parameters {6186 if item != nil {6187 _, err := item.ResolveReferences(root)6188 if err != nil {6189 errors = append(errors, err)6190 }6191 }6192 }6193 if m.Responses != nil {6194 _, err := m.Responses.ResolveReferences(root)6195 if err != nil {6196 errors = append(errors, err)6197 }6198 }6199 for _, item := range m.Security {6200 if item != nil {6201 _, err := item.ResolveReferences(root)6202 if err != nil {6203 errors = append(errors, err)6204 }6205 }6206 }6207 for _, item := range m.VendorExtension {6208 if item != nil {6209 _, err := item.ResolveReferences(root)6210 if err != nil {6211 errors = append(errors, err)6212 }6213 }6214 }6215 return nil, compiler.NewErrorGroupOrNil(errors)6216}6217func (m *Parameter) ResolveReferences(root string) (interface{}, error) {6218 errors := make([]error, 0)6219 {6220 p, ok := m.Oneof.(*Parameter_BodyParameter)6221 if ok {6222 _, err := p.BodyParameter.ResolveReferences(root)6223 if err != nil {6224 return nil, err6225 }6226 }6227 }6228 {6229 p, ok := m.Oneof.(*Parameter_NonBodyParameter)6230 if ok {6231 _, err := p.NonBodyParameter.ResolveReferences(root)6232 if err != nil {6233 return nil, err6234 }6235 }6236 }6237 return nil, compiler.NewErrorGroupOrNil(errors)6238}6239func (m *ParameterDefinitions) ResolveReferences(root string) (interface{}, error) {6240 errors := make([]error, 0)6241 for _, item := range m.AdditionalProperties {6242 if item != nil {6243 _, err := item.ResolveReferences(root)6244 if err != nil {6245 errors = append(errors, err)6246 }6247 }6248 }6249 return nil, compiler.NewErrorGroupOrNil(errors)6250}6251func (m *ParametersItem) ResolveReferences(root string) (interface{}, error) {6252 errors := make([]error, 0)6253 {6254 p, ok := m.Oneof.(*ParametersItem_Parameter)6255 if ok {6256 _, err := p.Parameter.ResolveReferences(root)6257 if err != nil {6258 return nil, err6259 }6260 }6261 }6262 {6263 p, ok := m.Oneof.(*ParametersItem_JsonReference)6264 if ok {6265 info, err := p.JsonReference.ResolveReferences(root)6266 if err != nil {6267 return nil, err6268 } else if info != nil {6269 n, err := NewParametersItem(info, nil)6270 if err != nil {6271 return nil, err6272 } else if n != nil {6273 *m = *n6274 return nil, nil6275 }6276 }6277 }6278 }6279 return nil, compiler.NewErrorGroupOrNil(errors)6280}6281func (m *PathItem) ResolveReferences(root string) (interface{}, error) {6282 errors := make([]error, 0)6283 if m.XRef != "" {6284 info, err := compiler.ReadInfoForRef(root, m.XRef)6285 if err != nil {6286 return nil, err6287 }6288 if info != nil {6289 replacement, err := NewPathItem(info, nil)6290 if err == nil {6291 *m = *replacement6292 return m.ResolveReferences(root)6293 }6294 }6295 return info, nil6296 }6297 if m.Get != nil {6298 _, err := m.Get.ResolveReferences(root)6299 if err != nil {6300 errors = append(errors, err)6301 }6302 }6303 if m.Put != nil {6304 _, err := m.Put.ResolveReferences(root)6305 if err != nil {6306 errors = append(errors, err)6307 }6308 }6309 if m.Post != nil {6310 _, err := m.Post.ResolveReferences(root)6311 if err != nil {6312 errors = append(errors, err)6313 }6314 }6315 if m.Delete != nil {6316 _, err := m.Delete.ResolveReferences(root)6317 if err != nil {6318 errors = append(errors, err)6319 }6320 }6321 if m.Options != nil {6322 _, err := m.Options.ResolveReferences(root)6323 if err != nil {6324 errors = append(errors, err)6325 }6326 }6327 if m.Head != nil {6328 _, err := m.Head.ResolveReferences(root)6329 if err != nil {6330 errors = append(errors, err)6331 }6332 }6333 if m.Patch != nil {6334 _, err := m.Patch.ResolveReferences(root)6335 if err != nil {6336 errors = append(errors, err)6337 }6338 }6339 for _, item := range m.Parameters {6340 if item != nil {6341 _, err := item.ResolveReferences(root)6342 if err != nil {6343 errors = append(errors, err)6344 }6345 }6346 }6347 for _, item := range m.VendorExtension {6348 if item != nil {6349 _, err := item.ResolveReferences(root)6350 if err != nil {6351 errors = append(errors, err)6352 }6353 }6354 }6355 return nil, compiler.NewErrorGroupOrNil(errors)6356}6357func (m *PathParameterSubSchema) ResolveReferences(root string) (interface{}, error) {6358 errors := make([]error, 0)6359 if m.Items != nil {6360 _, err := m.Items.ResolveReferences(root)6361 if err != nil {6362 errors = append(errors, err)6363 }6364 }6365 if m.Default != nil {6366 _, err := m.Default.ResolveReferences(root)6367 if err != nil {6368 errors = append(errors, err)6369 }6370 }6371 for _, item := range m.Enum {6372 if item != nil {6373 _, err := item.ResolveReferences(root)6374 if err != nil {6375 errors = append(errors, err)6376 }6377 }6378 }6379 for _, item := range m.VendorExtension {6380 if item != nil {6381 _, err := item.ResolveReferences(root)6382 if err != nil {6383 errors = append(errors, err)6384 }6385 }6386 }6387 return nil, compiler.NewErrorGroupOrNil(errors)6388}6389func (m *Paths) ResolveReferences(root string) (interface{}, error) {6390 errors := make([]error, 0)6391 for _, item := range m.VendorExtension {6392 if item != nil {6393 _, err := item.ResolveReferences(root)6394 if err != nil {6395 errors = append(errors, err)6396 }6397 }6398 }6399 for _, item := range m.Path {6400 if item != nil {6401 _, err := item.ResolveReferences(root)6402 if err != nil {6403 errors = append(errors, err)6404 }6405 }6406 }6407 return nil, compiler.NewErrorGroupOrNil(errors)6408}6409func (m *PrimitivesItems) ResolveReferences(root string) (interface{}, error) {6410 errors := make([]error, 0)6411 if m.Items != nil {6412 _, err := m.Items.ResolveReferences(root)6413 if err != nil {6414 errors = append(errors, err)6415 }6416 }6417 if m.Default != nil {6418 _, err := m.Default.ResolveReferences(root)6419 if err != nil {6420 errors = append(errors, err)6421 }6422 }6423 for _, item := range m.Enum {6424 if item != nil {6425 _, err := item.ResolveReferences(root)6426 if err != nil {6427 errors = append(errors, err)6428 }6429 }6430 }6431 for _, item := range m.VendorExtension {6432 if item != nil {6433 _, err := item.ResolveReferences(root)6434 if err != nil {6435 errors = append(errors, err)6436 }6437 }6438 }6439 return nil, compiler.NewErrorGroupOrNil(errors)6440}6441func (m *Properties) ResolveReferences(root string) (interface{}, error) {6442 errors := make([]error, 0)6443 for _, item := range m.AdditionalProperties {6444 if item != nil {6445 _, err := item.ResolveReferences(root)6446 if err != nil {6447 errors = append(errors, err)6448 }6449 }6450 }6451 return nil, compiler.NewErrorGroupOrNil(errors)6452}6453func (m *QueryParameterSubSchema) ResolveReferences(root string) (interface{}, error) {6454 errors := make([]error, 0)6455 if m.Items != nil {6456 _, err := m.Items.ResolveReferences(root)6457 if err != nil {6458 errors = append(errors, err)6459 }6460 }6461 if m.Default != nil {6462 _, err := m.Default.ResolveReferences(root)6463 if err != nil {6464 errors = append(errors, err)6465 }6466 }6467 for _, item := range m.Enum {6468 if item != nil {6469 _, err := item.ResolveReferences(root)6470 if err != nil {6471 errors = append(errors, err)6472 }6473 }6474 }6475 for _, item := range m.VendorExtension {6476 if item != nil {6477 _, err := item.ResolveReferences(root)6478 if err != nil {6479 errors = append(errors, err)6480 }6481 }6482 }6483 return nil, compiler.NewErrorGroupOrNil(errors)6484}6485func (m *Response) ResolveReferences(root string) (interface{}, error) {6486 errors := make([]error, 0)6487 if m.Schema != nil {6488 _, err := m.Schema.ResolveReferences(root)6489 if err != nil {6490 errors = append(errors, err)6491 }6492 }6493 if m.Headers != nil {6494 _, err := m.Headers.ResolveReferences(root)6495 if err != nil {6496 errors = append(errors, err)6497 }6498 }6499 if m.Examples != nil {6500 _, err := m.Examples.ResolveReferences(root)6501 if err != nil {6502 errors = append(errors, err)6503 }6504 }6505 for _, item := range m.VendorExtension {6506 if item != nil {6507 _, err := item.ResolveReferences(root)6508 if err != nil {6509 errors = append(errors, err)6510 }6511 }6512 }6513 return nil, compiler.NewErrorGroupOrNil(errors)6514}6515func (m *ResponseDefinitions) ResolveReferences(root string) (interface{}, error) {6516 errors := make([]error, 0)6517 for _, item := range m.AdditionalProperties {6518 if item != nil {6519 _, err := item.ResolveReferences(root)6520 if err != nil {6521 errors = append(errors, err)6522 }6523 }6524 }6525 return nil, compiler.NewErrorGroupOrNil(errors)6526}6527func (m *ResponseValue) ResolveReferences(root string) (interface{}, error) {6528 errors := make([]error, 0)6529 {6530 p, ok := m.Oneof.(*ResponseValue_Response)6531 if ok {6532 _, err := p.Response.ResolveReferences(root)6533 if err != nil {6534 return nil, err6535 }6536 }6537 }6538 {6539 p, ok := m.Oneof.(*ResponseValue_JsonReference)6540 if ok {6541 info, err := p.JsonReference.ResolveReferences(root)6542 if err != nil {6543 return nil, err6544 } else if info != nil {6545 n, err := NewResponseValue(info, nil)6546 if err != nil {6547 return nil, err6548 } else if n != nil {6549 *m = *n6550 return nil, nil6551 }6552 }6553 }6554 }6555 return nil, compiler.NewErrorGroupOrNil(errors)6556}6557func (m *Responses) ResolveReferences(root string) (interface{}, error) {6558 errors := make([]error, 0)6559 for _, item := range m.ResponseCode {6560 if item != nil {6561 _, err := item.ResolveReferences(root)6562 if err != nil {6563 errors = append(errors, err)6564 }6565 }6566 }6567 for _, item := range m.VendorExtension {6568 if item != nil {6569 _, err := item.ResolveReferences(root)6570 if err != nil {6571 errors = append(errors, err)6572 }6573 }6574 }6575 return nil, compiler.NewErrorGroupOrNil(errors)6576}6577func (m *Schema) ResolveReferences(root string) (interface{}, error) {6578 errors := make([]error, 0)6579 if m.XRef != "" {6580 info, err := compiler.ReadInfoForRef(root, m.XRef)6581 if err != nil {6582 return nil, err6583 }6584 if info != nil {6585 replacement, err := NewSchema(info, nil)6586 if err == nil {6587 *m = *replacement6588 return m.ResolveReferences(root)6589 }6590 }6591 return info, nil6592 }6593 if m.Default != nil {6594 _, err := m.Default.ResolveReferences(root)6595 if err != nil {6596 errors = append(errors, err)6597 }6598 }6599 for _, item := range m.Enum {6600 if item != nil {6601 _, err := item.ResolveReferences(root)6602 if err != nil {6603 errors = append(errors, err)6604 }6605 }6606 }6607 if m.AdditionalProperties != nil {6608 _, err := m.AdditionalProperties.ResolveReferences(root)6609 if err != nil {6610 errors = append(errors, err)6611 }6612 }6613 if m.Type != nil {6614 _, err := m.Type.ResolveReferences(root)6615 if err != nil {6616 errors = append(errors, err)6617 }6618 }6619 if m.Items != nil {6620 _, err := m.Items.ResolveReferences(root)6621 if err != nil {6622 errors = append(errors, err)6623 }6624 }6625 for _, item := range m.AllOf {6626 if item != nil {6627 _, err := item.ResolveReferences(root)6628 if err != nil {6629 errors = append(errors, err)6630 }6631 }6632 }6633 if m.Properties != nil {6634 _, err := m.Properties.ResolveReferences(root)6635 if err != nil {6636 errors = append(errors, err)6637 }6638 }6639 if m.Xml != nil {6640 _, err := m.Xml.ResolveReferences(root)6641 if err != nil {6642 errors = append(errors, err)6643 }6644 }6645 if m.ExternalDocs != nil {6646 _, err := m.ExternalDocs.ResolveReferences(root)6647 if err != nil {6648 errors = append(errors, err)6649 }6650 }6651 if m.Example != nil {6652 _, err := m.Example.ResolveReferences(root)6653 if err != nil {6654 errors = append(errors, err)6655 }6656 }6657 for _, item := range m.VendorExtension {6658 if item != nil {6659 _, err := item.ResolveReferences(root)6660 if err != nil {6661 errors = append(errors, err)6662 }6663 }6664 }6665 return nil, compiler.NewErrorGroupOrNil(errors)6666}6667func (m *SchemaItem) ResolveReferences(root string) (interface{}, error) {6668 errors := make([]error, 0)6669 {6670 p, ok := m.Oneof.(*SchemaItem_Schema)6671 if ok {6672 _, err := p.Schema.ResolveReferences(root)6673 if err != nil {6674 return nil, err6675 }6676 }6677 }6678 {6679 p, ok := m.Oneof.(*SchemaItem_FileSchema)6680 if ok {6681 _, err := p.FileSchema.ResolveReferences(root)6682 if err != nil {6683 return nil, err6684 }6685 }6686 }6687 return nil, compiler.NewErrorGroupOrNil(errors)6688}6689func (m *SecurityDefinitions) ResolveReferences(root string) (interface{}, error) {6690 errors := make([]error, 0)6691 for _, item := range m.AdditionalProperties {6692 if item != nil {6693 _, err := item.ResolveReferences(root)6694 if err != nil {6695 errors = append(errors, err)6696 }6697 }6698 }6699 return nil, compiler.NewErrorGroupOrNil(errors)6700}6701func (m *SecurityDefinitionsItem) ResolveReferences(root string) (interface{}, error) {6702 errors := make([]error, 0)6703 {6704 p, ok := m.Oneof.(*SecurityDefinitionsItem_BasicAuthenticationSecurity)6705 if ok {6706 _, err := p.BasicAuthenticationSecurity.ResolveReferences(root)6707 if err != nil {6708 return nil, err6709 }6710 }6711 }6712 {6713 p, ok := m.Oneof.(*SecurityDefinitionsItem_ApiKeySecurity)6714 if ok {6715 _, err := p.ApiKeySecurity.ResolveReferences(root)6716 if err != nil {6717 return nil, err6718 }6719 }6720 }6721 {6722 p, ok := m.Oneof.(*SecurityDefinitionsItem_Oauth2ImplicitSecurity)6723 if ok {6724 _, err := p.Oauth2ImplicitSecurity.ResolveReferences(root)6725 if err != nil {6726 return nil, err6727 }6728 }6729 }6730 {6731 p, ok := m.Oneof.(*SecurityDefinitionsItem_Oauth2PasswordSecurity)6732 if ok {6733 _, err := p.Oauth2PasswordSecurity.ResolveReferences(root)6734 if err != nil {6735 return nil, err6736 }6737 }6738 }6739 {6740 p, ok := m.Oneof.(*SecurityDefinitionsItem_Oauth2ApplicationSecurity)6741 if ok {6742 _, err := p.Oauth2ApplicationSecurity.ResolveReferences(root)6743 if err != nil {6744 return nil, err6745 }6746 }6747 }6748 {6749 p, ok := m.Oneof.(*SecurityDefinitionsItem_Oauth2AccessCodeSecurity)6750 if ok {6751 _, err := p.Oauth2AccessCodeSecurity.ResolveReferences(root)6752 if err != nil {6753 return nil, err6754 }6755 }6756 }6757 return nil, compiler.NewErrorGroupOrNil(errors)6758}6759func (m *SecurityRequirement) ResolveReferences(root string) (interface{}, error) {6760 errors := make([]error, 0)6761 for _, item := range m.AdditionalProperties {6762 if item != nil {6763 _, err := item.ResolveReferences(root)6764 if err != nil {6765 errors = append(errors, err)6766 }6767 }6768 }6769 return nil, compiler.NewErrorGroupOrNil(errors)6770}6771func (m *StringArray) ResolveReferences(root string) (interface{}, error) {6772 errors := make([]error, 0)6773 return nil, compiler.NewErrorGroupOrNil(errors)6774}6775func (m *Tag) ResolveReferences(root string) (interface{}, error) {6776 errors := make([]error, 0)6777 if m.ExternalDocs != nil {6778 _, err := m.ExternalDocs.ResolveReferences(root)6779 if err != nil {6780 errors = append(errors, err)6781 }6782 }6783 for _, item := range m.VendorExtension {6784 if item != nil {6785 _, err := item.ResolveReferences(root)6786 if err != nil {6787 errors = append(errors, err)6788 }6789 }6790 }6791 return nil, compiler.NewErrorGroupOrNil(errors)6792}6793func (m *TypeItem) ResolveReferences(root string) (interface{}, error) {6794 errors := make([]error, 0)6795 return nil, compiler.NewErrorGroupOrNil(errors)6796}6797func (m *VendorExtension) ResolveReferences(root string) (interface{}, error) {6798 errors := make([]error, 0)6799 for _, item := range m.AdditionalProperties {6800 if item != nil {6801 _, err := item.ResolveReferences(root)6802 if err != nil {6803 errors = append(errors, err)6804 }6805 }6806 }6807 return nil, compiler.NewErrorGroupOrNil(errors)6808}6809func (m *Xml) ResolveReferences(root string) (interface{}, error) {6810 errors := make([]error, 0)6811 for _, item := range m.VendorExtension {6812 if item != nil {6813 _, err := item.ResolveReferences(root)6814 if err != nil {6815 errors = append(errors, err)6816 }6817 }6818 }6819 return nil, compiler.NewErrorGroupOrNil(errors)6820}...

Full Screen

Full Screen

compiler.go

Source:compiler.go Github

copy

Full Screen

...87type Compiler struct {88 opts CompilerOptions89 dataLayout string90}91func NewCompiler(opts CompilerOptions) (*Compiler, error) {92 compiler := &Compiler{opts: opts}93 dataLayout, err := llvmDataLayout(compiler.opts.TargetTriple)94 if err != nil {95 return nil, err96 }97 compiler.dataLayout = dataLayout98 return compiler, nil99}100func (c *Compiler) Compile(fset *token.FileSet, astFiles []*ast.File, importpath string) (m *Module, err error) {101 target := llvm.NewTargetData(c.dataLayout)102 compiler := &compiler{103 CompilerOptions: c.opts,104 dataLayout: c.dataLayout,105 target: target,106 llvmtypes: NewLLVMTypeMap(llvm.GlobalContext(), target),107 }108 return compiler.compile(fset, astFiles, importpath)109}110type compiler struct {111 CompilerOptions112 module *Module113 dataLayout string114 target llvm.TargetData115 fileset *token.FileSet116 runtime *runtimeInterface117 llvmtypes *llvmTypeMap118 types *TypeMap119 debug *debug.DIBuilder120}121func (c *compiler) logf(format string, v ...interface{}) {122 if c.Logger != nil {123 c.Logger.Printf(format, v...)124 }125}126func (c *compiler) addCommonFunctionAttrs(fn llvm.Value) {127 fn.AddTargetDependentFunctionAttr("disable-tail-calls", "true")128 fn.AddTargetDependentFunctionAttr("split-stack", "")129 if c.SanitizerAttribute.GetEnumKind() != 0 {130 fn.AddFunctionAttr(c.SanitizerAttribute)131 }132}133// MakeImporter sets CompilerOptions.Importer to an appropriate importer134// for the search paths given in CompilerOptions.ImportPaths, and sets135// CompilerOptions.InitMap to an init map belonging to that importer.136// If CompilerOptions.GccgoPath is non-empty, the importer will also use137// the search paths for that gccgo installation.138func (opts *CompilerOptions) MakeImporter() error {139 opts.InitMap = make(map[*types.Package]gccgoimporter.InitData)140 if opts.GccgoPath == "" {141 paths := append(append([]string{}, opts.ImportPaths...), ".")142 opts.Importer = gccgoimporter.GetImporter(paths, opts.InitMap)143 } else {144 var inst gccgoimporter.GccgoInstallation145 err := inst.InitFromDriver(opts.GccgoPath)146 if err != nil {147 return err148 }149 opts.Importer = inst.GetImporter(opts.ImportPaths, opts.InitMap)150 }151 return nil152}153func (compiler *compiler) compile(fset *token.FileSet, astFiles []*ast.File, importpath string) (m *Module, err error) {154 buildctx, err := llgobuild.ContextFromTriple(compiler.TargetTriple)155 if err != nil {156 return nil, err157 }158 if compiler.Importer == nil {159 err = compiler.MakeImporter()160 if err != nil {161 return nil, err162 }163 }164 impcfg := &loader.Config{165 Fset: fset,166 TypeChecker: types.Config{167 Packages: compiler.Packages,168 Import: compiler.Importer,169 Sizes: compiler.llvmtypes,170 DisableUnusedImportCheck: compiler.DisableUnusedImportCheck,171 },172 ImportFromBinary: true,173 Build: &buildctx.Context,174 PackageCreated: compiler.PackageCreated,175 }176 // If no import path is specified, then set the import177 // path to be the same as the package's name.178 if importpath == "" {179 importpath = astFiles[0].Name.String()180 }181 impcfg.CreateFromFiles(importpath, astFiles...)182 iprog, err := impcfg.Load()183 if err != nil {184 return nil, err185 }186 program := ssa.Create(iprog, ssa.BareInits)187 mainPkginfo := iprog.InitialPackages()[0]188 mainPkg := program.CreatePackage(mainPkginfo)189 // Create a Module, which contains the LLVM module.190 modulename := importpath191 compiler.module = &Module{Module: llvm.NewModule(modulename), Path: modulename, Package: mainPkg.Object}192 compiler.module.SetTarget(compiler.TargetTriple)193 compiler.module.SetDataLayout(compiler.dataLayout)194 // Create a new translation unit.195 unit := newUnit(compiler, mainPkg)196 // Create the runtime interface.197 compiler.runtime, err = newRuntimeInterface(compiler.module.Module, compiler.llvmtypes)198 if err != nil {199 return nil, err200 }201 mainPkg.Build()202 // Create a struct responsible for mapping static types to LLVM types,203 // and to runtime/dynamic type values.204 compiler.types = NewTypeMap(205 mainPkg,206 compiler.llvmtypes,207 compiler.module.Module,208 compiler.runtime,209 MethodResolver(unit),210 )211 if compiler.GenerateDebug {212 compiler.debug = debug.NewDIBuilder(213 types.Sizes(compiler.llvmtypes),214 compiler.module.Module,215 impcfg.Fset,216 compiler.DebugPrefixMaps,217 )218 defer compiler.debug.Destroy()219 defer compiler.debug.Finalize()220 }221 unit.translatePackage(mainPkg)222 compiler.processAnnotations(unit, mainPkginfo)223 if importpath == "main" {224 compiler.createInitMainFunction(mainPkg)225 } else {226 compiler.module.ExportData = compiler.buildExportData(mainPkg)227 }228 return compiler.module, nil229}230type byPriorityThenFunc []gccgoimporter.PackageInit231func (a byPriorityThenFunc) Len() int { return len(a) }232func (a byPriorityThenFunc) Swap(i, j int) { a[i], a[j] = a[j], a[i] }233func (a byPriorityThenFunc) Less(i, j int) bool {234 switch {235 case a[i].Priority < a[j].Priority:236 return true237 case a[i].Priority > a[j].Priority:238 return false239 case a[i].InitFunc < a[j].InitFunc:240 return true241 default:242 return false243 }244}245func (c *compiler) buildPackageInitData(mainPkg *ssa.Package) gccgoimporter.InitData {246 var inits []gccgoimporter.PackageInit247 for _, imp := range mainPkg.Object.Imports() {248 inits = append(inits, c.InitMap[imp].Inits...)249 }250 sort.Sort(byPriorityThenFunc(inits))251 // Deduplicate init entries. We want to preserve the entry with the highest priority.252 // Normally a package's priorities will be consistent among its dependencies, but it is253 // possible for them to be different. For example, if a standard library test augments a254 // package which is a dependency of 'regexp' (which is imported by every test main package)255 // with additional dependencies, those dependencies may cause the package under test to256 // receive a higher priority than indicated by its init clause in 'regexp'.257 uniqinits := make([]gccgoimporter.PackageInit, len(inits))258 uniqinitpos := len(inits)259 uniqinitnames := make(map[string]struct{})260 for i, _ := range inits {261 init := inits[len(inits)-1-i]262 if _, ok := uniqinitnames[init.InitFunc]; !ok {263 uniqinitnames[init.InitFunc] = struct{}{}264 uniqinitpos--265 uniqinits[uniqinitpos] = init266 }267 }268 uniqinits = uniqinits[uniqinitpos:]269 ourprio := 1270 if len(uniqinits) != 0 {271 ourprio = uniqinits[len(uniqinits)-1].Priority + 1272 }273 if imp := mainPkg.Func("init"); imp != nil {274 impname := c.types.mc.mangleFunctionName(imp)275 uniqinits = append(uniqinits, gccgoimporter.PackageInit{mainPkg.Object.Name(), impname, ourprio})276 }277 return gccgoimporter.InitData{ourprio, uniqinits}278}279func (c *compiler) createInitMainFunction(mainPkg *ssa.Package) {280 int8ptr := llvm.PointerType(c.types.ctx.Int8Type(), 0)281 ftyp := llvm.FunctionType(llvm.VoidType(), []llvm.Type{int8ptr}, false)282 initMain := llvm.AddFunction(c.module.Module, "__go_init_main", ftyp)283 c.addCommonFunctionAttrs(initMain)284 entry := llvm.AddBasicBlock(initMain, "entry")285 builder := llvm.GlobalContext().NewBuilder()286 defer builder.Dispose()287 builder.SetInsertPointAtEnd(entry)288 args := []llvm.Value{llvm.Undef(int8ptr)}289 if !c.GccgoABI {290 initfn := c.module.Module.NamedFunction("main..import")291 if !initfn.IsNil() {292 builder.CreateCall(initfn, args, "")293 }294 builder.CreateRetVoid()295 return296 }297 initdata := c.buildPackageInitData(mainPkg)298 for _, init := range initdata.Inits {299 initfn := c.module.Module.NamedFunction(init.InitFunc)300 if initfn.IsNil() {301 initfn = llvm.AddFunction(c.module.Module, init.InitFunc, ftyp)302 }303 builder.CreateCall(initfn, args, "")304 }305 builder.CreateRetVoid()306}307func (c *compiler) buildExportData(mainPkg *ssa.Package) []byte {308 exportData := importer.ExportData(mainPkg.Object)309 b := bytes.NewBuffer(exportData)310 b.WriteString("v1;\n")311 if !c.GccgoABI {312 return b.Bytes()313 }314 initdata := c.buildPackageInitData(mainPkg)315 b.WriteString("priority ")316 b.WriteString(strconv.Itoa(initdata.Priority))317 b.WriteString(";\n")318 if len(initdata.Inits) != 0 {319 b.WriteString("init")320 for _, init := range initdata.Inits {321 b.WriteRune(' ')322 b.WriteString(init.Name)323 b.WriteRune(' ')...

Full Screen

Full Screen

compiler_contract_test.go

Source:compiler_contract_test.go Github

copy

Full Screen

...50 t.Logf("Compilation time: %d ms", compilationTimeMs)51 require.NoError(t, err, "compilation of multiple files should succeed")52 require.NotNil(t, contractInfo, "loaded object should not be nil")53 // instantiate the "start()" function of the contract and call it54 contractInstance, err := types.NewContractInstance(contractInfo)55 require.NoError(t, err, "create contract instance should succeed")56 res := reflect.ValueOf(contractInstance.PublicMethods["start"]).Call([]reflect.Value{})57 require.Equal(t, contracts.MOCK_COUNTER_CONTRACT_START_FROM, res[0].Interface().(uint64), "result of calling start() should match")58 t.Log("Compiling an invalid contract")59 invalidCode := "invalid code example"60 _, err = h.compiler.Compile(ctx, invalidCode)61 require.Error(t, err, "compile should fail")62 })63 }64}65type compilerContractHarness struct {66 compiler adapter.Compiler67 cleanup func()68}69func aNativeCompiler(t *testing.T, logger log.Logger) *compilerContractHarness {70 cfg, cleanup := NewConfigWithTempDir(t)71 compiler := adapter.NewNativeCompiler(cfg, logger, metric.NewRegistry())72 return &compilerContractHarness{73 compiler: compiler,74 cleanup: cleanup,75 }76}77func aFakeCompiler(t *testing.T, logger log.Logger) *compilerContractHarness {78 compiler := fake.NewCompiler()79 code := string(contracts.NativeSourceCodeForCounter(contracts.MOCK_COUNTER_CONTRACT_START_FROM))80 compiler.ProvideFakeContract(contracts.MockForCounter(), code)81 codePart1 := string(contracts.NativeSourceCodeForCounterPart1(contracts.MOCK_COUNTER_CONTRACT_START_FROM))82 compiler.ProvideFakeContract(contracts.MockForCounter(), codePart1)83 return &compilerContractHarness{84 compiler: compiler,85 cleanup: func() {},86 }87}...

Full Screen

Full Screen

New

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fset := token.NewFileSet()4 f, err := parser.ParseFile(fset, "test.go", nil, parser.ParseComments)5 if err != nil {6 panic(err)7 }8 ast.Print(fset, f)9 fmt.Println("Hello, playground")10}11import (12func main() {13 fset := token.NewFileSet()14 f, err := parser.ParseFile(fset, "test.go", nil, parser.ParseComments)15 if err != nil {16 panic(err)17 }18 ast.Print(fset, f)19 fmt.Println("Hello, playground")20}21import (22func main() {23 fset := token.NewFileSet()24 f, err := parser.ParseFiles(fset, "test.go")25 if err != nil {26 panic(err)27 }28 ast.Print(fset, f["test.go"])29 fmt.Println("Hello, playground")30}31import (32func main() {33 fset := token.NewFileSet()34 f, err := parser.ParseDir(fset, ".", nil, parser.ParseComments)35 if err != nil {36 panic(err)37 }38 ast.Print(fset, f["test.go"])39 fmt.Println("Hello, playground")40}41import (42func main() {43 fset := token.NewFileSet()44 f, err := parser.ParseExpr("1 + 1")45 if err != nil {46 panic(err)47 }48 ast.Print(fset, f)

Full Screen

Full Screen

New

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 f, err := parser.ParseFile(fset, "1.go", nil, parser.ImportsOnly)4 if err != nil {5 fmt.Println(err)6 }7 for _, s := range f.Imports {8 fmt.Println(s.Path.Value)9 }10}11func ParseFile(fset *token.FileSet, filename string, src interface{}, mode Mode) (f *File, err error)12import (13func main() {14 f, err := parser.ParseFile(fset, "1.go", nil, parser.ImportsOnly)15 if err != nil {16 fmt.Println(err)17 }18 for _, s := range f.Imports {19 fmt.Println(s.Path.Value)20 }21}

Full Screen

Full Screen

New

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 var src = []byte(`4import "fmt"5func main() {6 fmt.Println("Hello, World!")7}8 fset := token.NewFileSet()9 f, err := parser.ParseFile(fset, "", src, 0)10 if err != nil {11 panic(err)12 }13 ast.Print(fset, f)14}15(package main (import "fmt" (func main () (call (selector (ident fmt) Println) (string "Hello, World!")))))16import (17func main() {18 var src = []byte(`19import "fmt"20func main() {21 fmt.Println("Hello, World!")22}23 fset := token.NewFileSet()24 f, err := parser.ParseFile(fset, "", src, 0)25 if err != nil {26 panic(err)27 }28 ast.Inspect(f, func(n ast.Node) bool {29 fmt.Printf("%T30 })31}

Full Screen

Full Screen

New

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 vm := otto.New()4 vm.Set("name", "otto")5 vm.Run(`6 console.log("Hello " + name);7}8import (9func main() {10 vm := otto.New()11 vm.Set("name", "otto")12 vm.Run(`13 console.log("Hello " + name);14}15import (16func main() {17 vm := otto.New()18 vm.Set("name", "otto")19 vm.Run(`20 console.log("Hello " + name);21}22import (23func main() {24 vm := otto.New()25 vm.Set("name", "otto")26 vm.Run(`27 console.log("Hello " + name);28}29import (30func main() {

Full Screen

Full Screen

New

Using AI Code Generation

copy

Full Screen

1func main() {2 c := compiler.New()3 fmt.Println(c.Compile("Hello, World!"))4}5func main() {6 c := compiler.compiler{}7 fmt.Println(c.Compile("Hello, World!"))8}

Full Screen

Full Screen

New

Using AI Code Generation

copy

Full Screen

1c := compiler.New()2c.Compile("program.go")3c := compiler.New()4c.Compile("program.go")5c := compiler.New()6c.Compile("program.go")7c := compiler.New()8c.Compile("program.go")9c := compiler.New()10c.Compile("program.go")11c := compiler.New()12c.Compile("program.go")13c := compiler.New()14c.Compile("program.go")15c := compiler.New()16c.Compile("program.go")17c := compiler.New()18c.Compile("program.go")19c := compiler.New()

Full Screen

Full Screen

New

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 c := compiler.New()4 c.Compile("1.go")5}6import "fmt"7func main() {8 c := compiler.New()9 c.Compile("2.go")10}11import "fmt"12func main() {13 c := compiler.New()14 c.Compile("3.go")15}16import "fmt"17func main() {18 c := compiler.New()19 c.Compile("4.go")20}21import "fmt"22func main() {23 c := compiler.New()24 c.Compile("5.go")25}26import "fmt"27func main() {28 c := compiler.New()29 c.Compile("6.go")30}31import "fmt"32func main() {33 c := compiler.New()34 c.Compile("7.go")35}36import "fmt"37func main() {38 c := compiler.New()39 c.Compile("8.go")40}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful