blob: 5351f36f36c7d6ee5fe6df166281cece518c8e20 [file] [log] [blame]
// Copyright 2017 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// THIS FILE IS AUTOMATICALLY GENERATED.
package openapi_v2
import (
"fmt"
"github.com/googleapis/gnostic/compiler"
"gopkg.in/yaml.v2"
"regexp"
"strings"
)
// Version returns the package name (and OpenAPI version).
func Version() string {
return "openapi_v2"
}
// NewAdditionalPropertiesItem creates an object of type AdditionalPropertiesItem if possible, returning an error if not.
func NewAdditionalPropertiesItem(in interface{}, context *compiler.Context) (*AdditionalPropertiesItem, error) {
errors := make([]error, 0)
x := &AdditionalPropertiesItem{}
matched := false
// Schema schema = 1;
{
m, ok := compiler.UnpackMap(in)
if ok {
// errors might be ok here, they mean we just don't have the right subtype
t, matchingError := NewSchema(m, compiler.NewContext("schema", context))
if matchingError == nil {
x.Oneof = &AdditionalPropertiesItem_Schema{Schema: t}
matched = true
} else {
errors = append(errors, matchingError)
}
}
}
// bool boolean = 2;
boolValue, ok := in.(bool)
if ok {
x.Oneof = &AdditionalPropertiesItem_Boolean{Boolean: boolValue}
}
if matched {
// since the oneof matched one of its possibilities, discard any matching errors
errors = make([]error, 0)
}
return x, compiler.NewErrorGroupOrNil(errors)
}
// NewAny creates an object of type Any if possible, returning an error if not.
func NewAny(in interface{}, context *compiler.Context) (*Any, error) {
errors := make([]error, 0)
x := &Any{}
bytes, _ := yaml.Marshal(in)
x.Yaml = string(bytes)
return x, compiler.NewErrorGroupOrNil(errors)
}
// NewApiKeySecurity creates an object of type ApiKeySecurity if possible, returning an error if not.
func NewApiKeySecurity(in interface{}, context *compiler.Context) (*ApiKeySecurity, error) {
errors := make([]error, 0)
x := &ApiKeySecurity{}
m, ok := compiler.UnpackMap(in)
if !ok {
message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)
errors = append(errors, compiler.NewError(context, message))
} else {
requiredKeys := []string{"in", "name", "type"}
missingKeys := compiler.MissingKeysInMap(m, requiredKeys)
if len(missingKeys) > 0 {
message := fmt.Sprintf("is missing required %s: %+v", compiler.PluralProperties(len(missingKeys)), strings.Join(missingKeys, ", "))
errors = append(errors, compiler.NewError(context, message))
}
allowedKeys := []string{"description", "in", "name", "type"}
allowedPatterns := []*regexp.Regexp{pattern0}
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
errors = append(errors, compiler.NewError(context, message))
}
// string type = 1;
v1 := compiler.MapValueForKey(m, "type")
if v1 != nil {
x.Type, ok = v1.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for type: %+v (%T)", v1, v1)
errors = append(errors, compiler.NewError(context, message))
}
// check for valid enum values
// [apiKey]
if ok && !compiler.StringArrayContainsValue([]string{"apiKey"}, x.Type) {
message := fmt.Sprintf("has unexpected value for type: %+v (%T)", v1, v1)
errors = append(errors, compiler.NewError(context, message))
}
}
// string name = 2;
v2 := compiler.MapValueForKey(m, "name")
if v2 != nil {
x.Name, ok = v2.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for name: %+v (%T)", v2, v2)
errors = append(errors, compiler.NewError(context, message))
}
}
// string in = 3;
v3 := compiler.MapValueForKey(m, "in")
if v3 != nil {
x.In, ok = v3.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for in: %+v (%T)", v3, v3)
errors = append(errors, compiler.NewError(context, message))
}
// check for valid enum values
// [header query]
if ok && !compiler.StringArrayContainsValue([]string{"header", "query"}, x.In) {
message := fmt.Sprintf("has unexpected value for in: %+v (%T)", v3, v3)
errors = append(errors, compiler.NewError(context, message))
}
}
// string description = 4;
v4 := compiler.MapValueForKey(m, "description")
if v4 != nil {
x.Description, ok = v4.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for description: %+v (%T)", v4, v4)
errors = append(errors, compiler.NewError(context, message))
}
}
// repeated NamedAny vendor_extension = 5;
// MAP: Any ^x-
x.VendorExtension = make([]*NamedAny, 0)
for _, item := range m {
k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
if strings.HasPrefix(k, "x-") {
pair := &NamedAny{}
pair.Name = k
result := &Any{}
handled, resultFromExt, err := compiler.HandleExtension(context, v, k)
if handled {
if err != nil {
errors = append(errors, err)
} else {
bytes, _ := yaml.Marshal(v)
result.Yaml = string(bytes)
result.Value = resultFromExt
pair.Value = result
}
} else {
pair.Value, err = NewAny(v, compiler.NewContext(k, context))
if err != nil {
errors = append(errors, err)
}
}
x.VendorExtension = append(x.VendorExtension, pair)
}
}
}
}
return x, compiler.NewErrorGroupOrNil(errors)
}
// NewBasicAuthenticationSecurity creates an object of type BasicAuthenticationSecurity if possible, returning an error if not.
func NewBasicAuthenticationSecurity(in interface{}, context *compiler.Context) (*BasicAuthenticationSecurity, error) {
errors := make([]error, 0)
x := &BasicAuthenticationSecurity{}
m, ok := compiler.UnpackMap(in)
if !ok {
message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)
errors = append(errors, compiler.NewError(context, message))
} else {
requiredKeys := []string{"type"}
missingKeys := compiler.MissingKeysInMap(m, requiredKeys)
if len(missingKeys) > 0 {
message := fmt.Sprintf("is missing required %s: %+v", compiler.PluralProperties(len(missingKeys)), strings.Join(missingKeys, ", "))
errors = append(errors, compiler.NewError(context, message))
}
allowedKeys := []string{"description", "type"}
allowedPatterns := []*regexp.Regexp{pattern0}
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
errors = append(errors, compiler.NewError(context, message))
}
// string type = 1;
v1 := compiler.MapValueForKey(m, "type")
if v1 != nil {
x.Type, ok = v1.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for type: %+v (%T)", v1, v1)
errors = append(errors, compiler.NewError(context, message))
}
// check for valid enum values
// [basic]
if ok && !compiler.StringArrayContainsValue([]string{"basic"}, x.Type) {
message := fmt.Sprintf("has unexpected value for type: %+v (%T)", v1, v1)
errors = append(errors, compiler.NewError(context, message))
}
}
// string description = 2;
v2 := compiler.MapValueForKey(m, "description")
if v2 != nil {
x.Description, ok = v2.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for description: %+v (%T)", v2, v2)
errors = append(errors, compiler.NewError(context, message))
}
}
// repeated NamedAny vendor_extension = 3;
// MAP: Any ^x-
x.VendorExtension = make([]*NamedAny, 0)
for _, item := range m {
k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
if strings.HasPrefix(k, "x-") {
pair := &NamedAny{}
pair.Name = k
result := &Any{}
handled, resultFromExt, err := compiler.HandleExtension(context, v, k)
if handled {
if err != nil {
errors = append(errors, err)
} else {
bytes, _ := yaml.Marshal(v)
result.Yaml = string(bytes)
result.Value = resultFromExt
pair.Value = result
}
} else {
pair.Value, err = NewAny(v, compiler.NewContext(k, context))
if err != nil {
errors = append(errors, err)
}
}
x.VendorExtension = append(x.VendorExtension, pair)
}
}
}
}
return x, compiler.NewErrorGroupOrNil(errors)
}
// NewBodyParameter creates an object of type BodyParameter if possible, returning an error if not.
func NewBodyParameter(in interface{}, context *compiler.Context) (*BodyParameter, error) {
errors := make([]error, 0)
x := &BodyParameter{}
m, ok := compiler.UnpackMap(in)
if !ok {
message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)
errors = append(errors, compiler.NewError(context, message))
} else {
requiredKeys := []string{"in", "name", "schema"}
missingKeys := compiler.MissingKeysInMap(m, requiredKeys)
if len(missingKeys) > 0 {
message := fmt.Sprintf("is missing required %s: %+v", compiler.PluralProperties(len(missingKeys)), strings.Join(missingKeys, ", "))
errors = append(errors, compiler.NewError(context, message))
}
allowedKeys := []string{"description", "in", "name", "required", "schema"}
allowedPatterns := []*regexp.Regexp{pattern0}
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
errors = append(errors, compiler.NewError(context, message))
}
// string description = 1;
v1 := compiler.MapValueForKey(m, "description")
if v1 != nil {
x.Description, ok = v1.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for description: %+v (%T)", v1, v1)
errors = append(errors, compiler.NewError(context, message))
}
}
// string name = 2;
v2 := compiler.MapValueForKey(m, "name")
if v2 != nil {
x.Name, ok = v2.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for name: %+v (%T)", v2, v2)
errors = append(errors, compiler.NewError(context, message))
}
}
// string in = 3;
v3 := compiler.MapValueForKey(m, "in")
if v3 != nil {
x.In, ok = v3.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for in: %+v (%T)", v3, v3)
errors = append(errors, compiler.NewError(context, message))
}
// check for valid enum values
// [body]
if ok && !compiler.StringArrayContainsValue([]string{"body"}, x.In) {
message := fmt.Sprintf("has unexpected value for in: %+v (%T)", v3, v3)
errors = append(errors, compiler.NewError(context, message))
}
}
// bool required = 4;
v4 := compiler.MapValueForKey(m, "required")
if v4 != nil {
x.Required, ok = v4.(bool)
if !ok {
message := fmt.Sprintf("has unexpected value for required: %+v (%T)", v4, v4)
errors = append(errors, compiler.NewError(context, message))
}
}
// Schema schema = 5;
v5 := compiler.MapValueForKey(m, "schema")
if v5 != nil {
var err error
x.Schema, err = NewSchema(v5, compiler.NewContext("schema", context))
if err != nil {
errors = append(errors, err)
}
}
// repeated NamedAny vendor_extension = 6;
// MAP: Any ^x-
x.VendorExtension = make([]*NamedAny, 0)
for _, item := range m {
k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
if strings.HasPrefix(k, "x-") {
pair := &NamedAny{}
pair.Name = k
result := &Any{}
handled, resultFromExt, err := compiler.HandleExtension(context, v, k)
if handled {
if err != nil {
errors = append(errors, err)
} else {
bytes, _ := yaml.Marshal(v)
result.Yaml = string(bytes)
result.Value = resultFromExt
pair.Value = result
}
} else {
pair.Value, err = NewAny(v, compiler.NewContext(k, context))
if err != nil {
errors = append(errors, err)
}
}
x.VendorExtension = append(x.VendorExtension, pair)
}
}
}
}
return x, compiler.NewErrorGroupOrNil(errors)
}
// NewContact creates an object of type Contact if possible, returning an error if not.
func NewContact(in interface{}, context *compiler.Context) (*Contact, error) {
errors := make([]error, 0)
x := &Contact{}
m, ok := compiler.UnpackMap(in)
if !ok {
message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)
errors = append(errors, compiler.NewError(context, message))
} else {
allowedKeys := []string{"email", "name", "url"}
allowedPatterns := []*regexp.Regexp{pattern0}
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
errors = append(errors, compiler.NewError(context, message))
}
// string name = 1;
v1 := compiler.MapValueForKey(m, "name")
if v1 != nil {
x.Name, ok = v1.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for name: %+v (%T)", v1, v1)
errors = append(errors, compiler.NewError(context, message))
}
}
// string url = 2;
v2 := compiler.MapValueForKey(m, "url")
if v2 != nil {
x.Url, ok = v2.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for url: %+v (%T)", v2, v2)
errors = append(errors, compiler.NewError(context, message))
}
}
// string email = 3;
v3 := compiler.MapValueForKey(m, "email")
if v3 != nil {
x.Email, ok = v3.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for email: %+v (%T)", v3, v3)
errors = append(errors, compiler.NewError(context, message))
}
}
// repeated NamedAny vendor_extension = 4;
// MAP: Any ^x-
x.VendorExtension = make([]*NamedAny, 0)
for _, item := range m {
k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
if strings.HasPrefix(k, "x-") {
pair := &NamedAny{}
pair.Name = k
result := &Any{}
handled, resultFromExt, err := compiler.HandleExtension(context, v, k)
if handled {
if err != nil {
errors = append(errors, err)
} else {
bytes, _ := yaml.Marshal(v)
result.Yaml = string(bytes)
result.Value = resultFromExt
pair.Value = result
}
} else {
pair.Value, err = NewAny(v, compiler.NewContext(k, context))
if err != nil {
errors = append(errors, err)
}
}
x.VendorExtension = append(x.VendorExtension, pair)
}
}
}
}
return x, compiler.NewErrorGroupOrNil(errors)
}
// NewDefault creates an object of type Default if possible, returning an error if not.
func NewDefault(in interface{}, context *compiler.Context) (*Default, error) {
errors := make([]error, 0)
x := &Default{}
m, ok := compiler.UnpackMap(in)
if !ok {
message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)
errors = append(errors, compiler.NewError(context, message))
} else {
// repeated NamedAny additional_properties = 1;
// MAP: Any
x.AdditionalProperties = make([]*NamedAny, 0)
for _, item := range m {
k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
pair := &NamedAny{}
pair.Name = k
result := &Any{}
handled, resultFromExt, err := compiler.HandleExtension(context, v, k)
if handled {
if err != nil {
errors = append(errors, err)
} else {
bytes, _ := yaml.Marshal(v)
result.Yaml = string(bytes)
result.Value = resultFromExt
pair.Value = result
}
} else {
pair.Value, err = NewAny(v, compiler.NewContext(k, context))
if err != nil {
errors = append(errors, err)
}
}
x.AdditionalProperties = append(x.AdditionalProperties, pair)
}
}
}
return x, compiler.NewErrorGroupOrNil(errors)
}
// NewDefinitions creates an object of type Definitions if possible, returning an error if not.
func NewDefinitions(in interface{}, context *compiler.Context) (*Definitions, error) {
errors := make([]error, 0)
x := &Definitions{}
m, ok := compiler.UnpackMap(in)
if !ok {
message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)
errors = append(errors, compiler.NewError(context, message))
} else {
// repeated NamedSchema additional_properties = 1;
// MAP: Schema
x.AdditionalProperties = make([]*NamedSchema, 0)
for _, item := range m {
k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
pair := &NamedSchema{}
pair.Name = k
var err error
pair.Value, err = NewSchema(v, compiler.NewContext(k, context))
if err != nil {
errors = append(errors, err)
}
x.AdditionalProperties = append(x.AdditionalProperties, pair)
}
}
}
return x, compiler.NewErrorGroupOrNil(errors)
}
// NewDocument creates an object of type Document if possible, returning an error if not.
func NewDocument(in interface{}, context *compiler.Context) (*Document, error) {
errors := make([]error, 0)
x := &Document{}
m, ok := compiler.UnpackMap(in)
if !ok {
message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)
errors = append(errors, compiler.NewError(context, message))
} else {
requiredKeys := []string{"info", "paths", "swagger"}
missingKeys := compiler.MissingKeysInMap(m, requiredKeys)
if len(missingKeys) > 0 {
message := fmt.Sprintf("is missing required %s: %+v", compiler.PluralProperties(len(missingKeys)), strings.Join(missingKeys, ", "))
errors = append(errors, compiler.NewError(context, message))
}
allowedKeys := []string{"basePath", "consumes", "definitions", "externalDocs", "host", "info", "parameters", "paths", "produces", "responses", "schemes", "security", "securityDefinitions", "swagger", "tags"}
allowedPatterns := []*regexp.Regexp{pattern0}
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
errors = append(errors, compiler.NewError(context, message))
}
// string swagger = 1;
v1 := compiler.MapValueForKey(m, "swagger")
if v1 != nil {
x.Swagger, ok = v1.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for swagger: %+v (%T)", v1, v1)
errors = append(errors, compiler.NewError(context, message))
}
// check for valid enum values
// [2.0]
if ok && !compiler.StringArrayContainsValue([]string{"2.0"}, x.Swagger) {
message := fmt.Sprintf("has unexpected value for swagger: %+v (%T)", v1, v1)
errors = append(errors, compiler.NewError(context, message))
}
}
// Info info = 2;
v2 := compiler.MapValueForKey(m, "info")
if v2 != nil {
var err error
x.Info, err = NewInfo(v2, compiler.NewContext("info", context))
if err != nil {
errors = append(errors, err)
}
}
// string host = 3;
v3 := compiler.MapValueForKey(m, "host")
if v3 != nil {
x.Host, ok = v3.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for host: %+v (%T)", v3, v3)
errors = append(errors, compiler.NewError(context, message))
}
}
// string base_path = 4;
v4 := compiler.MapValueForKey(m, "basePath")
if v4 != nil {
x.BasePath, ok = v4.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for basePath: %+v (%T)", v4, v4)
errors = append(errors, compiler.NewError(context, message))
}
}
// repeated string schemes = 5;
v5 := compiler.MapValueForKey(m, "schemes")
if v5 != nil {
v, ok := v5.([]interface{})
if ok {
x.Schemes = compiler.ConvertInterfaceArrayToStringArray(v)
} else {
message := fmt.Sprintf("has unexpected value for schemes: %+v (%T)", v5, v5)
errors = append(errors, compiler.NewError(context, message))
}
// check for valid enum values
// [http https ws wss]
if ok && !compiler.StringArrayContainsValues([]string{"http", "https", "ws", "wss"}, x.Schemes) {
message := fmt.Sprintf("has unexpected value for schemes: %+v", v5)
errors = append(errors, compiler.NewError(context, message))
}
}
// repeated string consumes = 6;
v6 := compiler.MapValueForKey(m, "consumes")
if v6 != nil {
v, ok := v6.([]interface{})
if ok {
x.Consumes = compiler.ConvertInterfaceArrayToStringArray(v)
} else {
message := fmt.Sprintf("has unexpected value for consumes: %+v (%T)", v6, v6)
errors = append(errors, compiler.NewError(context, message))
}
}
// repeated string produces = 7;
v7 := compiler.MapValueForKey(m, "produces")
if v7 != nil {
v, ok := v7.([]interface{})
if ok {
x.Produces = compiler.ConvertInterfaceArrayToStringArray(v)
} else {
message := fmt.Sprintf("has unexpected value for produces: %+v (%T)", v7, v7)
errors = append(errors, compiler.NewError(context, message))
}
}
// Paths paths = 8;
v8 := compiler.MapValueForKey(m, "paths")
if v8 != nil {
var err error
x.Paths, err = NewPaths(v8, compiler.NewContext("paths", context))
if err != nil {
errors = append(errors, err)
}
}
// Definitions definitions = 9;
v9 := compiler.MapValueForKey(m, "definitions")
if v9 != nil {
var err error
x.Definitions, err = NewDefinitions(v9, compiler.NewContext("definitions", context))
if err != nil {
errors = append(errors, err)
}
}
// ParameterDefinitions parameters = 10;
v10 := compiler.MapValueForKey(m, "parameters")
if v10 != nil {
var err error
x.Parameters, err = NewParameterDefinitions(v10, compiler.NewContext("parameters", context))
if err != nil {
errors = append(errors, err)
}
}
// ResponseDefinitions responses = 11;
v11 := compiler.MapValueForKey(m, "responses")
if v11 != nil {
var err error
x.Responses, err = NewResponseDefinitions(v11, compiler.NewContext("responses", context))
if err != nil {
errors = append(errors, err)
}
}
// repeated SecurityRequirement security = 12;
v12 := compiler.MapValueForKey(m, "security")
if v12 != nil {
// repeated SecurityRequirement
x.Security = make([]*SecurityRequirement, 0)
a, ok := v12.([]interface{})
if ok {
for _, item := range a {
y, err := NewSecurityRequirement(item, compiler.NewContext("security", context))
if err != nil {
errors = append(errors, err)
}
x.Security = append(x.Security, y)
}
}
}
// SecurityDefinitions security_definitions = 13;
v13 := compiler.MapValueForKey(m, "securityDefinitions")
if v13 != nil {
var err error
x.SecurityDefinitions, err = NewSecurityDefinitions(v13, compiler.NewContext("securityDefinitions", context))
if err != nil {
errors = append(errors, err)
}
}
// repeated Tag tags = 14;
v14 := compiler.MapValueForKey(m, "tags")
if v14 != nil {
// repeated Tag
x.Tags = make([]*Tag, 0)
a, ok := v14.([]interface{})
if ok {
for _, item := range a {
y, err := NewTag(item, compiler.NewContext("tags", context))
if err != nil {
errors = append(errors, err)
}
x.Tags = append(x.Tags, y)
}
}
}
// ExternalDocs external_docs = 15;
v15 := compiler.MapValueForKey(m, "externalDocs")
if v15 != nil {
var err error
x.ExternalDocs, err = NewExternalDocs(v15, compiler.NewContext("externalDocs", context))
if err != nil {
errors = append(errors, err)
}
}
// repeated NamedAny vendor_extension = 16;
// MAP: Any ^x-
x.VendorExtension = make([]*NamedAny, 0)
for _, item := range m {
k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
if strings.HasPrefix(k, "x-") {
pair := &NamedAny{}
pair.Name = k
result := &Any{}
handled, resultFromExt, err := compiler.HandleExtension(context, v, k)
if handled {
if err != nil {
errors = append(errors, err)
} else {
bytes, _ := yaml.Marshal(v)
result.Yaml = string(bytes)
result.Value = resultFromExt
pair.Value = result
}
} else {
pair.Value, err = NewAny(v, compiler.NewContext(k, context))
if err != nil {
errors = append(errors, err)
}
}
x.VendorExtension = append(x.VendorExtension, pair)
}
}
}
}
return x, compiler.NewErrorGroupOrNil(errors)
}
// NewExamples creates an object of type Examples if possible, returning an error if not.
func NewExamples(in interface{}, context *compiler.Context) (*Examples, error) {
errors := make([]error, 0)
x := &Examples{}
m, ok := compiler.UnpackMap(in)
if !ok {
message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)
errors = append(errors, compiler.NewError(context, message))
} else {
// repeated NamedAny additional_properties = 1;
// MAP: Any
x.AdditionalProperties = make([]*NamedAny, 0)
for _, item := range m {
k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
pair := &NamedAny{}
pair.Name = k
result := &Any{}
handled, resultFromExt, err := compiler.HandleExtension(context, v, k)
if handled {
if err != nil {
errors = append(errors, err)
} else {
bytes, _ := yaml.Marshal(v)
result.Yaml = string(bytes)
result.Value = resultFromExt
pair.Value = result
}
} else {
pair.Value, err = NewAny(v, compiler.NewContext(k, context))
if err != nil {
errors = append(errors, err)
}
}
x.AdditionalProperties = append(x.AdditionalProperties, pair)
}
}
}
return x, compiler.NewErrorGroupOrNil(errors)
}
// NewExternalDocs creates an object of type ExternalDocs if possible, returning an error if not.
func NewExternalDocs(in interface{}, context *compiler.Context) (*ExternalDocs, error) {
errors := make([]error, 0)
x := &ExternalDocs{}
m, ok := compiler.UnpackMap(in)
if !ok {
message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)
errors = append(errors, compiler.NewError(context, message))
} else {
requiredKeys := []string{"url"}
missingKeys := compiler.MissingKeysInMap(m, requiredKeys)
if len(missingKeys) > 0 {
message := fmt.Sprintf("is missing required %s: %+v", compiler.PluralProperties(len(missingKeys)), strings.Join(missingKeys, ", "))
errors = append(errors, compiler.NewError(context, message))
}
allowedKeys := []string{"description", "url"}
allowedPatterns := []*regexp.Regexp{pattern0}
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
errors = append(errors, compiler.NewError(context, message))
}
// string description = 1;
v1 := compiler.MapValueForKey(m, "description")
if v1 != nil {
x.Description, ok = v1.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for description: %+v (%T)", v1, v1)
errors = append(errors, compiler.NewError(context, message))
}
}
// string url = 2;
v2 := compiler.MapValueForKey(m, "url")
if v2 != nil {
x.Url, ok = v2.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for url: %+v (%T)", v2, v2)
errors = append(errors, compiler.NewError(context, message))
}
}
// repeated NamedAny vendor_extension = 3;
// MAP: Any ^x-
x.VendorExtension = make([]*NamedAny, 0)
for _, item := range m {
k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
if strings.HasPrefix(k, "x-") {
pair := &NamedAny{}
pair.Name = k
result := &Any{}
handled, resultFromExt, err := compiler.HandleExtension(context, v, k)
if handled {
if err != nil {
errors = append(errors, err)
} else {
bytes, _ := yaml.Marshal(v)
result.Yaml = string(bytes)
result.Value = resultFromExt
pair.Value = result
}
} else {
pair.Value, err = NewAny(v, compiler.NewContext(k, context))
if err != nil {
errors = append(errors, err)
}
}
x.VendorExtension = append(x.VendorExtension, pair)
}
}
}
}
return x, compiler.NewErrorGroupOrNil(errors)
}
// NewFileSchema creates an object of type FileSchema if possible, returning an error if not.
func NewFileSchema(in interface{}, context *compiler.Context) (*FileSchema, error) {
errors := make([]error, 0)
x := &FileSchema{}
m, ok := compiler.UnpackMap(in)
if !ok {
message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)
errors = append(errors, compiler.NewError(context, message))
} else {
requiredKeys := []string{"type"}
missingKeys := compiler.MissingKeysInMap(m, requiredKeys)
if len(missingKeys) > 0 {
message := fmt.Sprintf("is missing required %s: %+v", compiler.PluralProperties(len(missingKeys)), strings.Join(missingKeys, ", "))
errors = append(errors, compiler.NewError(context, message))
}
allowedKeys := []string{"default", "description", "example", "externalDocs", "format", "readOnly", "required", "title", "type"}
allowedPatterns := []*regexp.Regexp{pattern0}
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
errors = append(errors, compiler.NewError(context, message))
}
// string format = 1;
v1 := compiler.MapValueForKey(m, "format")
if v1 != nil {
x.Format, ok = v1.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for format: %+v (%T)", v1, v1)
errors = append(errors, compiler.NewError(context, message))
}
}
// string title = 2;
v2 := compiler.MapValueForKey(m, "title")
if v2 != nil {
x.Title, ok = v2.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for title: %+v (%T)", v2, v2)
errors = append(errors, compiler.NewError(context, message))
}
}
// string description = 3;
v3 := compiler.MapValueForKey(m, "description")
if v3 != nil {
x.Description, ok = v3.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for description: %+v (%T)", v3, v3)
errors = append(errors, compiler.NewError(context, message))
}
}
// Any default = 4;
v4 := compiler.MapValueForKey(m, "default")
if v4 != nil {
var err error
x.Default, err = NewAny(v4, compiler.NewContext("default", context))
if err != nil {
errors = append(errors, err)
}
}
// repeated string required = 5;
v5 := compiler.MapValueForKey(m, "required")
if v5 != nil {
v, ok := v5.([]interface{})
if ok {
x.Required = compiler.ConvertInterfaceArrayToStringArray(v)
} else {
message := fmt.Sprintf("has unexpected value for required: %+v (%T)", v5, v5)
errors = append(errors, compiler.NewError(context, message))
}
}
// string type = 6;
v6 := compiler.MapValueForKey(m, "type")
if v6 != nil {
x.Type, ok = v6.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for type: %+v (%T)", v6, v6)
errors = append(errors, compiler.NewError(context, message))
}
// check for valid enum values
// [file]
if ok && !compiler.StringArrayContainsValue([]string{"file"}, x.Type) {
message := fmt.Sprintf("has unexpected value for type: %+v (%T)", v6, v6)
errors = append(errors, compiler.NewError(context, message))
}
}
// bool read_only = 7;
v7 := compiler.MapValueForKey(m, "readOnly")
if v7 != nil {
x.ReadOnly, ok = v7.(bool)
if !ok {
message := fmt.Sprintf("has unexpected value for readOnly: %+v (%T)", v7, v7)
errors = append(errors, compiler.NewError(context, message))
}
}
// ExternalDocs external_docs = 8;
v8 := compiler.MapValueForKey(m, "externalDocs")
if v8 != nil {
var err error
x.ExternalDocs, err = NewExternalDocs(v8, compiler.NewContext("externalDocs", context))
if err != nil {
errors = append(errors, err)
}
}
// Any example = 9;
v9 := compiler.MapValueForKey(m, "example")
if v9 != nil {
var err error
x.Example, err = NewAny(v9, compiler.NewContext("example", context))
if err != nil {
errors = append(errors, err)
}
}
// repeated NamedAny vendor_extension = 10;
// MAP: Any ^x-
x.VendorExtension = make([]*NamedAny, 0)
for _, item := range m {
k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
if strings.HasPrefix(k, "x-") {
pair := &NamedAny{}
pair.Name = k
result := &Any{}
handled, resultFromExt, err := compiler.HandleExtension(context, v, k)
if handled {
if err != nil {
errors = append(errors, err)
} else {
bytes, _ := yaml.Marshal(v)
result.Yaml = string(bytes)
result.Value = resultFromExt
pair.Value = result
}
} else {
pair.Value, err = NewAny(v, compiler.NewContext(k, context))
if err != nil {
errors = append(errors, err)
}
}
x.VendorExtension = append(x.VendorExtension, pair)
}
}
}
}
return x, compiler.NewErrorGroupOrNil(errors)
}
// NewFormDataParameterSubSchema creates an object of type FormDataParameterSubSchema if possible, returning an error if not.
func NewFormDataParameterSubSchema(in interface{}, context *compiler.Context) (*FormDataParameterSubSchema, error) {
errors := make([]error, 0)
x := &FormDataParameterSubSchema{}
m, ok := compiler.UnpackMap(in)
if !ok {
message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)
errors = append(errors, compiler.NewError(context, message))
} else {
allowedKeys := []string{"allowEmptyValue", "collectionFormat", "default", "description", "enum", "exclusiveMaximum", "exclusiveMinimum", "format", "in", "items", "maxItems", "maxLength", "maximum", "minItems", "minLength", "minimum", "multipleOf", "name", "pattern", "required", "type", "uniqueItems"}
allowedPatterns := []*regexp.Regexp{pattern0}
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
errors = append(errors, compiler.NewError(context, message))
}
// bool required = 1;
v1 := compiler.MapValueForKey(m, "required")
if v1 != nil {
x.Required, ok = v1.(bool)
if !ok {
message := fmt.Sprintf("has unexpected value for required: %+v (%T)", v1, v1)
errors = append(errors, compiler.NewError(context, message))
}
}
// string in = 2;
v2 := compiler.MapValueForKey(m, "in")
if v2 != nil {
x.In, ok = v2.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for in: %+v (%T)", v2, v2)
errors = append(errors, compiler.NewError(context, message))
}
// check for valid enum values
// [formData]
if ok && !compiler.StringArrayContainsValue([]string{"formData"}, x.In) {
message := fmt.Sprintf("has unexpected value for in: %+v (%T)", v2, v2)
errors = append(errors, compiler.NewError(context, message))
}
}
// string description = 3;
v3 := compiler.MapValueForKey(m, "description")
if v3 != nil {
x.Description, ok = v3.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for description: %+v (%T)", v3, v3)
errors = append(errors, compiler.NewError(context, message))
}
}
// string name = 4;
v4 := compiler.MapValueForKey(m, "name")
if v4 != nil {
x.Name, ok = v4.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for name: %+v (%T)", v4, v4)
errors = append(errors, compiler.NewError(context, message))
}
}
// bool allow_empty_value = 5;
v5 := compiler.MapValueForKey(m, "allowEmptyValue")
if v5 != nil {
x.AllowEmptyValue, ok = v5.(bool)
if !ok {
message := fmt.Sprintf("has unexpected value for allowEmptyValue: %+v (%T)", v5, v5)
errors = append(errors, compiler.NewError(context, message))
}
}
// string type = 6;
v6 := compiler.MapValueForKey(m, "type")
if v6 != nil {
x.Type, ok = v6.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for type: %+v (%T)", v6, v6)
errors = append(errors, compiler.NewError(context, message))
}
// check for valid enum values
// [string number boolean integer array file]
if ok && !compiler.StringArrayContainsValue([]string{"string", "number", "boolean", "integer", "array", "file"}, x.Type) {
message := fmt.Sprintf("has unexpected value for type: %+v (%T)", v6, v6)
errors = append(errors, compiler.NewError(context, message))
}
}
// string format = 7;
v7 := compiler.MapValueForKey(m, "format")
if v7 != nil {
x.Format, ok = v7.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for format: %+v (%T)", v7, v7)
errors = append(errors, compiler.NewError(context, message))
}
}
// PrimitivesItems items = 8;
v8 := compiler.MapValueForKey(m, "items")
if v8 != nil {
var err error
x.Items, err = NewPrimitivesItems(v8, compiler.NewContext("items", context))
if err != nil {
errors = append(errors, err)
}
}
// string collection_format = 9;
v9 := compiler.MapValueForKey(m, "collectionFormat")
if v9 != nil {
x.CollectionFormat, ok = v9.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for collectionFormat: %+v (%T)", v9, v9)
errors = append(errors, compiler.NewError(context, message))
}
// check for valid enum values
// [csv ssv tsv pipes multi]
if ok && !compiler.StringArrayContainsValue([]string{"csv", "ssv", "tsv", "pipes", "multi"}, x.CollectionFormat) {
message := fmt.Sprintf("has unexpected value for collectionFormat: %+v (%T)", v9, v9)
errors = append(errors, compiler.NewError(context, message))
}
}
// Any default = 10;
v10 := compiler.MapValueForKey(m, "default")
if v10 != nil {
var err error
x.Default, err = NewAny(v10, compiler.NewContext("default", context))
if err != nil {
errors = append(errors, err)
}
}
// float maximum = 11;
v11 := compiler.MapValueForKey(m, "maximum")
if v11 != nil {
switch v11 := v11.(type) {
case float64:
x.Maximum = v11
case float32:
x.Maximum = float64(v11)
case uint64:
x.Maximum = float64(v11)
case uint32:
x.Maximum = float64(v11)
case int64:
x.Maximum = float64(v11)
case int32:
x.Maximum = float64(v11)
case int:
x.Maximum = float64(v11)
default:
message := fmt.Sprintf("has unexpected value for maximum: %+v (%T)", v11, v11)
errors = append(errors, compiler.NewError(context, message))
}
}
// bool exclusive_maximum = 12;
v12 := compiler.MapValueForKey(m, "exclusiveMaximum")
if v12 != nil {
x.ExclusiveMaximum, ok = v12.(bool)
if !ok {
message := fmt.Sprintf("has unexpected value for exclusiveMaximum: %+v (%T)", v12, v12)
errors = append(errors, compiler.NewError(context, message))
}
}
// float minimum = 13;
v13 := compiler.MapValueForKey(m, "minimum")
if v13 != nil {
switch v13 := v13.(type) {
case float64:
x.Minimum = v13
case float32:
x.Minimum = float64(v13)
case uint64:
x.Minimum = float64(v13)
case uint32:
x.Minimum = float64(v13)
case int64:
x.Minimum = float64(v13)
case int32:
x.Minimum = float64(v13)
case int:
x.Minimum = float64(v13)
default:
message := fmt.Sprintf("has unexpected value for minimum: %+v (%T)", v13, v13)
errors = append(errors, compiler.NewError(context, message))
}
}
// bool exclusive_minimum = 14;
v14 := compiler.MapValueForKey(m, "exclusiveMinimum")
if v14 != nil {
x.ExclusiveMinimum, ok = v14.(bool)
if !ok {
message := fmt.Sprintf("has unexpected value for exclusiveMinimum: %+v (%T)", v14, v14)
errors = append(errors, compiler.NewError(context, message))
}
}
// int64 max_length = 15;
v15 := compiler.MapValueForKey(m, "maxLength")
if v15 != nil {
t, ok := v15.(int)
if ok {
x.MaxLength = int64(t)
} else {
message := fmt.Sprintf("has unexpected value for maxLength: %+v (%T)", v15, v15)
errors = append(errors, compiler.NewError(context, message))
}
}
// int64 min_length = 16;
v16 := compiler.MapValueForKey(m, "minLength")
if v16 != nil {
t, ok := v16.(int)
if ok {
x.MinLength = int64(t)
} else {
message := fmt.Sprintf("has unexpected value for minLength: %+v (%T)", v16, v16)
errors = append(errors, compiler.NewError(context, message))
}
}
// string pattern = 17;
v17 := compiler.MapValueForKey(m, "pattern")
if v17 != nil {
x.Pattern, ok = v17.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for pattern: %+v (%T)", v17, v17)
errors = append(errors, compiler.NewError(context, message))
}
}
// int64 max_items = 18;
v18 := compiler.MapValueForKey(m, "maxItems")
if v18 != nil {
t, ok := v18.(int)
if ok {
x.MaxItems = int64(t)
} else {
message := fmt.Sprintf("has unexpected value for maxItems: %+v (%T)", v18, v18)
errors = append(errors, compiler.NewError(context, message))
}
}
// int64 min_items = 19;
v19 := compiler.MapValueForKey(m, "minItems")
if v19 != nil {
t, ok := v19.(int)
if ok {
x.MinItems = int64(t)
} else {
message := fmt.Sprintf("has unexpected value for minItems: %+v (%T)", v19, v19)
errors = append(errors, compiler.NewError(context, message))
}
}
// bool unique_items = 20;
v20 := compiler.MapValueForKey(m, "uniqueItems")
if v20 != nil {
x.UniqueItems, ok = v20.(bool)
if !ok {
message := fmt.Sprintf("has unexpected value for uniqueItems: %+v (%T)", v20, v20)
errors = append(errors, compiler.NewError(context, message))
}
}
// repeated Any enum = 21;
v21 := compiler.MapValueForKey(m, "enum")
if v21 != nil {
// repeated Any
x.Enum = make([]*Any, 0)
a, ok := v21.([]interface{})
if ok {
for _, item := range a {
y, err := NewAny(item, compiler.NewContext("enum", context))
if err != nil {
errors = append(errors, err)
}
x.Enum = append(x.Enum, y)
}
}
}
// float multiple_of = 22;
v22 := compiler.MapValueForKey(m, "multipleOf")
if v22 != nil {
switch v22 := v22.(type) {
case float64:
x.MultipleOf = v22
case float32:
x.MultipleOf = float64(v22)
case uint64:
x.MultipleOf = float64(v22)
case uint32:
x.MultipleOf = float64(v22)
case int64:
x.MultipleOf = float64(v22)
case int32:
x.MultipleOf = float64(v22)
case int:
x.MultipleOf = float64(v22)
default:
message := fmt.Sprintf("has unexpected value for multipleOf: %+v (%T)", v22, v22)
errors = append(errors, compiler.NewError(context, message))
}
}
// repeated NamedAny vendor_extension = 23;
// MAP: Any ^x-
x.VendorExtension = make([]*NamedAny, 0)
for _, item := range m {
k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
if strings.HasPrefix(k, "x-") {
pair := &NamedAny{}
pair.Name = k
result := &Any{}
handled, resultFromExt, err := compiler.HandleExtension(context, v, k)
if handled {
if err != nil {
errors = append(errors, err)
} else {
bytes, _ := yaml.Marshal(v)
result.Yaml = string(bytes)
result.Value = resultFromExt
pair.Value = result
}
} else {
pair.Value, err = NewAny(v, compiler.NewContext(k, context))
if err != nil {
errors = append(errors, err)
}
}
x.VendorExtension = append(x.VendorExtension, pair)
}
}
}
}
return x, compiler.NewErrorGroupOrNil(errors)
}
// NewHeader creates an object of type Header if possible, returning an error if not.
func NewHeader(in interface{}, context *compiler.Context) (*Header, error) {
errors := make([]error, 0)
x := &Header{}
m, ok := compiler.UnpackMap(in)
if !ok {
message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)
errors = append(errors, compiler.NewError(context, message))
} else {
requiredKeys := []string{"type"}
missingKeys := compiler.MissingKeysInMap(m, requiredKeys)
if len(missingKeys) > 0 {
message := fmt.Sprintf("is missing required %s: %+v", compiler.PluralProperties(len(missingKeys)), strings.Join(missingKeys, ", "))
errors = append(errors, compiler.NewError(context, message))
}
allowedKeys := []string{"collectionFormat", "default", "description", "enum", "exclusiveMaximum", "exclusiveMinimum", "format", "items", "maxItems", "maxLength", "maximum", "minItems", "minLength", "minimum", "multipleOf", "pattern", "type", "uniqueItems"}
allowedPatterns := []*regexp.Regexp{pattern0}
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
errors = append(errors, compiler.NewError(context, message))
}
// string type = 1;
v1 := compiler.MapValueForKey(m, "type")
if v1 != nil {
x.Type, ok = v1.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for type: %+v (%T)", v1, v1)
errors = append(errors, compiler.NewError(context, message))
}
// check for valid enum values
// [string number integer boolean array]
if ok && !compiler.StringArrayContainsValue([]string{"string", "number", "integer", "boolean", "array"}, x.Type) {
message := fmt.Sprintf("has unexpected value for type: %+v (%T)", v1, v1)
errors = append(errors, compiler.NewError(context, message))
}
}
// string format = 2;
v2 := compiler.MapValueForKey(m, "format")
if v2 != nil {
x.Format, ok = v2.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for format: %+v (%T)", v2, v2)
errors = append(errors, compiler.NewError(context, message))
}
}
// PrimitivesItems items = 3;
v3 := compiler.MapValueForKey(m, "items")
if v3 != nil {
var err error
x.Items, err = NewPrimitivesItems(v3, compiler.NewContext("items", context))
if err != nil {
errors = append(errors, err)
}
}
// string collection_format = 4;
v4 := compiler.MapValueForKey(m, "collectionFormat")
if v4 != nil {
x.CollectionFormat, ok = v4.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for collectionFormat: %+v (%T)", v4, v4)
errors = append(errors, compiler.NewError(context, message))
}
// check for valid enum values
// [csv ssv tsv pipes]
if ok && !compiler.StringArrayContainsValue([]string{"csv", "ssv", "tsv", "pipes"}, x.CollectionFormat) {
message := fmt.Sprintf("has unexpected value for collectionFormat: %+v (%T)", v4, v4)
errors = append(errors, compiler.NewError(context, message))
}
}
// Any default = 5;
v5 := compiler.MapValueForKey(m, "default")
if v5 != nil {
var err error
x.Default, err = NewAny(v5, compiler.NewContext("default", context))
if err != nil {
errors = append(errors, err)
}
}
// float maximum = 6;
v6 := compiler.MapValueForKey(m, "maximum")
if v6 != nil {
switch v6 := v6.(type) {
case float64:
x.Maximum = v6
case float32:
x.Maximum = float64(v6)
case uint64:
x.Maximum = float64(v6)
case uint32:
x.Maximum = float64(v6)
case int64:
x.Maximum = float64(v6)
case int32:
x.Maximum = float64(v6)
case int:
x.Maximum = float64(v6)
default:
message := fmt.Sprintf("has unexpected value for maximum: %+v (%T)", v6, v6)
errors = append(errors, compiler.NewError(context, message))
}
}
// bool exclusive_maximum = 7;
v7 := compiler.MapValueForKey(m, "exclusiveMaximum")
if v7 != nil {
x.ExclusiveMaximum, ok = v7.(bool)
if !ok {
message := fmt.Sprintf("has unexpected value for exclusiveMaximum: %+v (%T)", v7, v7)
errors = append(errors, compiler.NewError(context, message))
}
}
// float minimum = 8;
v8 := compiler.MapValueForKey(m, "minimum")
if v8 != nil {
switch v8 := v8.(type) {
case float64:
x.Minimum = v8
case float32:
x.Minimum = float64(v8)
case uint64:
x.Minimum = float64(v8)
case uint32:
x.Minimum = float64(v8)
case int64:
x.Minimum = float64(v8)
case int32:
x.Minimum = float64(v8)
case int:
x.Minimum = float64(v8)
default:
message := fmt.Sprintf("has unexpected value for minimum: %+v (%T)", v8, v8)
errors = append(errors, compiler.NewError(context, message))
}
}
// bool exclusive_minimum = 9;
v9 := compiler.MapValueForKey(m, "exclusiveMinimum")
if v9 != nil {
x.ExclusiveMinimum, ok = v9.(bool)
if !ok {
message := fmt.Sprintf("has unexpected value for exclusiveMinimum: %+v (%T)", v9, v9)
errors = append(errors, compiler.NewError(context, message))
}
}
// int64 max_length = 10;
v10 := compiler.MapValueForKey(m, "maxLength")
if v10 != nil {
t, ok := v10.(int)
if ok {
x.MaxLength = int64(t)
} else {
message := fmt.Sprintf("has unexpected value for maxLength: %+v (%T)", v10, v10)
errors = append(errors, compiler.NewError(context, message))
}
}
// int64 min_length = 11;
v11 := compiler.MapValueForKey(m, "minLength")
if v11 != nil {
t, ok := v11.(int)
if ok {
x.MinLength = int64(t)
} else {
message := fmt.Sprintf("has unexpected value for minLength: %+v (%T)", v11, v11)
errors = append(errors, compiler.NewError(context, message))
}
}
// string pattern = 12;
v12 := compiler.MapValueForKey(m, "pattern")
if v12 != nil {
x.Pattern, ok = v12.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for pattern: %+v (%T)", v12, v12)
errors = append(errors, compiler.NewError(context, message))
}
}
// int64 max_items = 13;
v13 := compiler.MapValueForKey(m, "maxItems")
if v13 != nil {
t, ok := v13.(int)
if ok {
x.MaxItems = int64(t)
} else {
message := fmt.Sprintf("has unexpected value for maxItems: %+v (%T)", v13, v13)
errors = append(errors, compiler.NewError(context, message))
}
}
// int64 min_items = 14;
v14 := compiler.MapValueForKey(m, "minItems")
if v14 != nil {
t, ok := v14.(int)
if ok {
x.MinItems = int64(t)
} else {
message := fmt.Sprintf("has unexpected value for minItems: %+v (%T)", v14, v14)
errors = append(errors, compiler.NewError(context, message))
}
}
// bool unique_items = 15;
v15 := compiler.MapValueForKey(m, "uniqueItems")
if v15 != nil {
x.UniqueItems, ok = v15.(bool)
if !ok {
message := fmt.Sprintf("has unexpected value for uniqueItems: %+v (%T)", v15, v15)
errors = append(errors, compiler.NewError(context, message))
}
}
// repeated Any enum = 16;
v16 := compiler.MapValueForKey(m, "enum")
if v16 != nil {
// repeated Any
x.Enum = make([]*Any, 0)
a, ok := v16.([]interface{})
if ok {
for _, item := range a {
y, err := NewAny(item, compiler.NewContext("enum", context))
if err != nil {
errors = append(errors, err)
}
x.Enum = append(x.Enum, y)
}
}
}
// float multiple_of = 17;
v17 := compiler.MapValueForKey(m, "multipleOf")
if v17 != nil {
switch v17 := v17.(type) {
case float64:
x.MultipleOf = v17
case float32:
x.MultipleOf = float64(v17)
case uint64:
x.MultipleOf = float64(v17)
case uint32:
x.MultipleOf = float64(v17)
case int64:
x.MultipleOf = float64(v17)
case int32:
x.MultipleOf = float64(v17)
case int:
x.MultipleOf = float64(v17)
default:
message := fmt.Sprintf("has unexpected value for multipleOf: %+v (%T)", v17, v17)
errors = append(errors, compiler.NewError(context, message))
}
}
// string description = 18;
v18 := compiler.MapValueForKey(m, "description")
if v18 != nil {
x.Description, ok = v18.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for description: %+v (%T)", v18, v18)
errors = append(errors, compiler.NewError(context, message))
}
}
// repeated NamedAny vendor_extension = 19;
// MAP: Any ^x-
x.VendorExtension = make([]*NamedAny, 0)
for _, item := range m {
k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
if strings.HasPrefix(k, "x-") {
pair := &NamedAny{}
pair.Name = k
result := &Any{}
handled, resultFromExt, err := compiler.HandleExtension(context, v, k)
if handled {
if err != nil {
errors = append(errors, err)
} else {
bytes, _ := yaml.Marshal(v)
result.Yaml = string(bytes)
result.Value = resultFromExt
pair.Value = result
}
} else {
pair.Value, err = NewAny(v, compiler.NewContext(k, context))
if err != nil {
errors = append(errors, err)
}
}
x.VendorExtension = append(x.VendorExtension, pair)
}
}
}
}
return x, compiler.NewErrorGroupOrNil(errors)
}
// NewHeaderParameterSubSchema creates an object of type HeaderParameterSubSchema if possible, returning an error if not.
func NewHeaderParameterSubSchema(in interface{}, context *compiler.Context) (*HeaderParameterSubSchema, error) {
errors := make([]error, 0)
x := &HeaderParameterSubSchema{}
m, ok := compiler.UnpackMap(in)
if !ok {
message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)
errors = append(errors, compiler.NewError(context, message))
} else {
allowedKeys := []string{"collectionFormat", "default", "description", "enum", "exclusiveMaximum", "exclusiveMinimum", "format", "in", "items", "maxItems", "maxLength", "maximum", "minItems", "minLength", "minimum", "multipleOf", "name", "pattern", "required", "type", "uniqueItems"}
allowedPatterns := []*regexp.Regexp{pattern0}
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
errors = append(errors, compiler.NewError(context, message))
}
// bool required = 1;
v1 := compiler.MapValueForKey(m, "required")
if v1 != nil {
x.Required, ok = v1.(bool)
if !ok {
message := fmt.Sprintf("has unexpected value for required: %+v (%T)", v1, v1)
errors = append(errors, compiler.NewError(context, message))
}
}
// string in = 2;
v2 := compiler.MapValueForKey(m, "in")
if v2 != nil {
x.In, ok = v2.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for in: %+v (%T)", v2, v2)
errors = append(errors, compiler.NewError(context, message))
}
// check for valid enum values
// [header]
if ok && !compiler.StringArrayContainsValue([]string{"header"}, x.In) {
message := fmt.Sprintf("has unexpected value for in: %+v (%T)", v2, v2)
errors = append(errors, compiler.NewError(context, message))
}
}
// string description = 3;
v3 := compiler.MapValueForKey(m, "description")
if v3 != nil {
x.Description, ok = v3.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for description: %+v (%T)", v3, v3)
errors = append(errors, compiler.NewError(context, message))
}
}
// string name = 4;
v4 := compiler.MapValueForKey(m, "name")
if v4 != nil {
x.Name, ok = v4.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for name: %+v (%T)", v4, v4)
errors = append(errors, compiler.NewError(context, message))
}
}
// string type = 5;
v5 := compiler.MapValueForKey(m, "type")
if v5 != nil {
x.Type, ok = v5.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for type: %+v (%T)", v5, v5)
errors = append(errors, compiler.NewError(context, message))
}
// check for valid enum values
// [string number boolean integer array]
if ok && !compiler.StringArrayContainsValue([]string{"string", "number", "boolean", "integer", "array"}, x.Type) {
message := fmt.Sprintf("has unexpected value for type: %+v (%T)", v5, v5)
errors = append(errors, compiler.NewError(context, message))
}
}
// string format = 6;
v6 := compiler.MapValueForKey(m, "format")
if v6 != nil {
x.Format, ok = v6.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for format: %+v (%T)", v6, v6)
errors = append(errors, compiler.NewError(context, message))
}
}
// PrimitivesItems items = 7;
v7 := compiler.MapValueForKey(m, "items")
if v7 != nil {
var err error
x.Items, err = NewPrimitivesItems(v7, compiler.NewContext("items", context))
if err != nil {
errors = append(errors, err)
}
}
// string collection_format = 8;
v8 := compiler.MapValueForKey(m, "collectionFormat")
if v8 != nil {
x.CollectionFormat, ok = v8.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for collectionFormat: %+v (%T)", v8, v8)
errors = append(errors, compiler.NewError(context, message))
}
// check for valid enum values
// [csv ssv tsv pipes]
if ok && !compiler.StringArrayContainsValue([]string{"csv", "ssv", "tsv", "pipes"}, x.CollectionFormat) {
message := fmt.Sprintf("has unexpected value for collectionFormat: %+v (%T)", v8, v8)
errors = append(errors, compiler.NewError(context, message))
}
}
// Any default = 9;
v9 := compiler.MapValueForKey(m, "default")
if v9 != nil {
var err error
x.Default, err = NewAny(v9, compiler.NewContext("default", context))
if err != nil {
errors = append(errors, err)
}
}
// float maximum = 10;
v10 := compiler.MapValueForKey(m, "maximum")
if v10 != nil {
switch v10 := v10.(type) {
case float64:
x.Maximum = v10
case float32:
x.Maximum = float64(v10)
case uint64:
x.Maximum = float64(v10)
case uint32:
x.Maximum = float64(v10)
case int64:
x.Maximum = float64(v10)
case int32:
x.Maximum = float64(v10)
case int:
x.Maximum = float64(v10)
default:
message := fmt.Sprintf("has unexpected value for maximum: %+v (%T)", v10, v10)
errors = append(errors, compiler.NewError(context, message))
}
}
// bool exclusive_maximum = 11;
v11 := compiler.MapValueForKey(m, "exclusiveMaximum")
if v11 != nil {
x.ExclusiveMaximum, ok = v11.(bool)
if !ok {
message := fmt.Sprintf("has unexpected value for exclusiveMaximum: %+v (%T)", v11, v11)
errors = append(errors, compiler.NewError(context, message))
}
}
// float minimum = 12;
v12 := compiler.MapValueForKey(m, "minimum")
if v12 != nil {
switch v12 := v12.(type) {
case float64:
x.Minimum = v12
case float32:
x.Minimum = float64(v12)
case uint64:
x.Minimum = float64(v12)
case uint32:
x.Minimum = float64(v12)
case int64:
x.Minimum = float64(v12)
case int32:
x.Minimum = float64(v12)
case int:
x.Minimum = float64(v12)
default:
message := fmt.Sprintf("has unexpected value for minimum: %+v (%T)", v12, v12)
errors = append(errors, compiler.NewError(context, message))
}
}
// bool exclusive_minimum = 13;
v13 := compiler.MapValueForKey(m, "exclusiveMinimum")
if v13 != nil {
x.ExclusiveMinimum, ok = v13.(bool)
if !ok {
message := fmt.Sprintf("has unexpected value for exclusiveMinimum: %+v (%T)", v13, v13)
errors = append(errors, compiler.NewError(context, message))
}
}
// int64 max_length = 14;
v14 := compiler.MapValueForKey(m, "maxLength")
if v14 != nil {
t, ok := v14.(int)
if ok {
x.MaxLength = int64(t)
} else {
message := fmt.Sprintf("has unexpected value for maxLength: %+v (%T)", v14, v14)
errors = append(errors, compiler.NewError(context, message))
}
}
// int64 min_length = 15;
v15 := compiler.MapValueForKey(m, "minLength")
if v15 != nil {
t, ok := v15.(int)
if ok {
x.MinLength = int64(t)
} else {
message := fmt.Sprintf("has unexpected value for minLength: %+v (%T)", v15, v15)
errors = append(errors, compiler.NewError(context, message))
}
}
// string pattern = 16;
v16 := compiler.MapValueForKey(m, "pattern")
if v16 != nil {
x.Pattern, ok = v16.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for pattern: %+v (%T)", v16, v16)
errors = append(errors, compiler.NewError(context, message))
}
}
// int64 max_items = 17;
v17 := compiler.MapValueForKey(m, "maxItems")
if v17 != nil {
t, ok := v17.(int)
if ok {
x.MaxItems = int64(t)
} else {
message := fmt.Sprintf("has unexpected value for maxItems: %+v (%T)", v17, v17)
errors = append(errors, compiler.NewError(context, message))
}
}
// int64 min_items = 18;
v18 := compiler.MapValueForKey(m, "minItems")
if v18 != nil {
t, ok := v18.(int)
if ok {
x.MinItems = int64(t)
} else {
message := fmt.Sprintf("has unexpected value for minItems: %+v (%T)", v18, v18)
errors = append(errors, compiler.NewError(context, message))
}
}
// bool unique_items = 19;
v19 := compiler.MapValueForKey(m, "uniqueItems")
if v19 != nil {
x.UniqueItems, ok = v19.(bool)
if !ok {
message := fmt.Sprintf("has unexpected value for uniqueItems: %+v (%T)", v19, v19)
errors = append(errors, compiler.NewError(context, message))
}
}
// repeated Any enum = 20;
v20 := compiler.MapValueForKey(m, "enum")
if v20 != nil {
// repeated Any
x.Enum = make([]*Any, 0)
a, ok := v20.([]interface{})
if ok {
for _, item := range a {
y, err := NewAny(item, compiler.NewContext("enum", context))
if err != nil {
errors = append(errors, err)
}
x.Enum = append(x.Enum, y)
}
}
}
// float multiple_of = 21;
v21 := compiler.MapValueForKey(m, "multipleOf")
if v21 != nil {
switch v21 := v21.(type) {
case float64:
x.MultipleOf = v21
case float32:
x.MultipleOf = float64(v21)
case uint64:
x.MultipleOf = float64(v21)
case uint32:
x.MultipleOf = float64(v21)
case int64:
x.MultipleOf = float64(v21)
case int32:
x.MultipleOf = float64(v21)
case int:
x.MultipleOf = float64(v21)
default:
message := fmt.Sprintf("has unexpected value for multipleOf: %+v (%T)", v21, v21)
errors = append(errors, compiler.NewError(context, message))
}
}
// repeated NamedAny vendor_extension = 22;
// MAP: Any ^x-
x.VendorExtension = make([]*NamedAny, 0)
for _, item := range m {
k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
if strings.HasPrefix(k, "x-") {
pair := &NamedAny{}
pair.Name = k
result := &Any{}
handled, resultFromExt, err := compiler.HandleExtension(context, v, k)
if handled {
if err != nil {
errors = append(errors, err)
} else {
bytes, _ := yaml.Marshal(v)
result.Yaml = string(bytes)
result.Value = resultFromExt
pair.Value = result
}
} else {
pair.Value, err = NewAny(v, compiler.NewContext(k, context))
if err != nil {
errors = append(errors, err)
}
}
x.VendorExtension = append(x.VendorExtension, pair)
}
}
}
}
return x, compiler.NewErrorGroupOrNil(errors)
}
// NewHeaders creates an object of type Headers if possible, returning an error if not.
func NewHeaders(in interface{}, context *compiler.Context) (*Headers, error) {
errors := make([]error, 0)
x := &Headers{}
m, ok := compiler.UnpackMap(in)
if !ok {
message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)
errors = append(errors, compiler.NewError(context, message))
} else {
// repeated NamedHeader additional_properties = 1;
// MAP: Header
x.AdditionalProperties = make([]*NamedHeader, 0)
for _, item := range m {
k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
pair := &NamedHeader{}
pair.Name = k
var err error
pair.Value, err = NewHeader(v, compiler.NewContext(k, context))
if err != nil {
errors = append(errors, err)
}
x.AdditionalProperties = append(x.AdditionalProperties, pair)
}
}
}
return x, compiler.NewErrorGroupOrNil(errors)
}
// NewInfo creates an object of type Info if possible, returning an error if not.
func NewInfo(in interface{}, context *compiler.Context) (*Info, error) {
errors := make([]error, 0)
x := &Info{}
m, ok := compiler.UnpackMap(in)
if !ok {
message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)
errors = append(errors, compiler.NewError(context, message))
} else {
requiredKeys := []string{"title", "version"}
missingKeys := compiler.MissingKeysInMap(m, requiredKeys)
if len(missingKeys) > 0 {
message := fmt.Sprintf("is missing required %s: %+v", compiler.PluralProperties(len(missingKeys)), strings.Join(missingKeys, ", "))
errors = append(errors, compiler.NewError(context, message))
}
allowedKeys := []string{"contact", "description", "license", "termsOfService", "title", "version"}
allowedPatterns := []*regexp.Regexp{pattern0}
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
errors = append(errors, compiler.NewError(context, message))
}
// string title = 1;
v1 := compiler.MapValueForKey(m, "title")
if v1 != nil {
x.Title, ok = v1.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for title: %+v (%T)", v1, v1)
errors = append(errors, compiler.NewError(context, message))
}
}
// string version = 2;
v2 := compiler.MapValueForKey(m, "version")
if v2 != nil {
x.Version, ok = v2.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for version: %+v (%T)", v2, v2)
errors = append(errors, compiler.NewError(context, message))
}
}
// string description = 3;
v3 := compiler.MapValueForKey(m, "description")
if v3 != nil {
x.Description, ok = v3.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for description: %+v (%T)", v3, v3)
errors = append(errors, compiler.NewError(context, message))
}
}
// string terms_of_service = 4;
v4 := compiler.MapValueForKey(m, "termsOfService")
if v4 != nil {
x.TermsOfService, ok = v4.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for termsOfService: %+v (%T)", v4, v4)
errors = append(errors, compiler.NewError(context, message))
}
}
// Contact contact = 5;
v5 := compiler.MapValueForKey(m, "contact")
if v5 != nil {
var err error
x.Contact, err = NewContact(v5, compiler.NewContext("contact", context))
if err != nil {
errors = append(errors, err)
}
}
// License license = 6;
v6 := compiler.MapValueForKey(m, "license")
if v6 != nil {
var err error
x.License, err = NewLicense(v6, compiler.NewContext("license", context))
if err != nil {
errors = append(errors, err)
}
}
// repeated NamedAny vendor_extension = 7;
// MAP: Any ^x-
x.VendorExtension = make([]*NamedAny, 0)
for _, item := range m {
k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
if strings.HasPrefix(k, "x-") {
pair := &NamedAny{}
pair.Name = k
result := &Any{}
handled, resultFromExt, err := compiler.HandleExtension(context, v, k)
if handled {
if err != nil {
errors = append(errors, err)
} else {
bytes, _ := yaml.Marshal(v)
result.Yaml = string(bytes)
result.Value = resultFromExt
pair.Value = result
}
} else {
pair.Value, err = NewAny(v, compiler.NewContext(k, context))
if err != nil {
errors = append(errors, err)
}
}
x.VendorExtension = append(x.VendorExtension, pair)
}
}
}
}
return x, compiler.NewErrorGroupOrNil(errors)
}
// NewItemsItem creates an object of type ItemsItem if possible, returning an error if not.
func NewItemsItem(in interface{}, context *compiler.Context) (*ItemsItem, error) {
errors := make([]error, 0)
x := &ItemsItem{}
m, ok := compiler.UnpackMap(in)
if !ok {
message := fmt.Sprintf("has unexpected value for item array: %+v (%T)", in, in)
errors = append(errors, compiler.NewError(context, message))
} else {
x.Schema = make([]*Schema, 0)
y, err := NewSchema(m, compiler.NewContext("<array>", context))
if err != nil {
return nil, err
}
x.Schema = append(x.Schema, y)
}
return x, compiler.NewErrorGroupOrNil(errors)
}
// NewJsonReference creates an object of type JsonReference if possible, returning an error if not.
func NewJsonReference(in interface{}, context *compiler.Context) (*JsonReference, error) {
errors := make([]error, 0)
x := &JsonReference{}
m, ok := compiler.UnpackMap(in)
if !ok {
message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)
errors = append(errors, compiler.NewError(context, message))
} else {
requiredKeys := []string{"$ref"}
missingKeys := compiler.MissingKeysInMap(m, requiredKeys)
if len(missingKeys) > 0 {
message := fmt.Sprintf("is missing required %s: %+v", compiler.PluralProperties(len(missingKeys)), strings.Join(missingKeys, ", "))
errors = append(errors, compiler.NewError(context, message))
}
allowedKeys := []string{"$ref", "description"}
var allowedPatterns []*regexp.Regexp
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
errors = append(errors, compiler.NewError(context, message))
}
// string _ref = 1;
v1 := compiler.MapValueForKey(m, "$ref")
if v1 != nil {
x.XRef, ok = v1.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for $ref: %+v (%T)", v1, v1)
errors = append(errors, compiler.NewError(context, message))
}
}
// string description = 2;
v2 := compiler.MapValueForKey(m, "description")
if v2 != nil {
x.Description, ok = v2.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for description: %+v (%T)", v2, v2)
errors = append(errors, compiler.NewError(context, message))
}
}
}
return x, compiler.NewErrorGroupOrNil(errors)
}
// NewLicense creates an object of type License if possible, returning an error if not.
func NewLicense(in interface{}, context *compiler.Context) (*License, error) {
errors := make([]error, 0)
x := &License{}
m, ok := compiler.UnpackMap(in)
if !ok {
message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)
errors = append(errors, compiler.NewError(context, message))
} else {
requiredKeys := []string{"name"}
missingKeys := compiler.MissingKeysInMap(m, requiredKeys)
if len(missingKeys) > 0 {
message := fmt.Sprintf("is missing required %s: %+v", compiler.PluralProperties(len(missingKeys)), strings.Join(missingKeys, ", "))
errors = append(errors, compiler.NewError(context, message))
}
allowedKeys := []string{"name", "url"}
allowedPatterns := []*regexp.Regexp{pattern0}
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
errors = append(errors, compiler.NewError(context, message))
}
// string name = 1;
v1 := compiler.MapValueForKey(m, "name")
if v1 != nil {
x.Name, ok = v1.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for name: %+v (%T)", v1, v1)
errors = append(errors, compiler.NewError(context, message))
}
}
// string url = 2;
v2 := compiler.MapValueForKey(m, "url")
if v2 != nil {
x.Url, ok = v2.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for url: %+v (%T)", v2, v2)
errors = append(errors, compiler.NewError(context, message))
}
}
// repeated NamedAny vendor_extension = 3;
// MAP: Any ^x-
x.VendorExtension = make([]*NamedAny, 0)
for _, item := range m {
k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
if strings.HasPrefix(k, "x-") {
pair := &NamedAny{}
pair.Name = k
result := &Any{}
handled, resultFromExt, err := compiler.HandleExtension(context, v, k)
if handled {
if err != nil {
errors = append(errors, err)
} else {
bytes, _ := yaml.Marshal(v)
result.Yaml = string(bytes)
result.Value = resultFromExt
pair.Value = result
}
} else {
pair.Value, err = NewAny(v, compiler.NewContext(k, context))
if err != nil {
errors = append(errors, err)
}
}
x.VendorExtension = append(x.VendorExtension, pair)
}
}
}
}
return x, compiler.NewErrorGroupOrNil(errors)
}
// NewNamedAny creates an object of type NamedAny if possible, returning an error if not.
func NewNamedAny(in interface{}, context *compiler.Context) (*NamedAny, error) {
errors := make([]error, 0)
x := &NamedAny{}
m, ok := compiler.UnpackMap(in)
if !ok {
message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)
errors = append(errors, compiler.NewError(context, message))
} else {
allowedKeys := []string{"name", "value"}
var allowedPatterns []*regexp.Regexp
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
errors = append(errors, compiler.NewError(context, message))
}
// string name = 1;
v1 := compiler.MapValueForKey(m, "name")
if v1 != nil {
x.Name, ok = v1.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for name: %+v (%T)", v1, v1)
errors = append(errors, compiler.NewError(context, message))
}
}
// Any value = 2;
v2 := compiler.MapValueForKey(m, "value")
if v2 != nil {
var err error
x.Value, err = NewAny(v2, compiler.NewContext("value", context))
if err != nil {
errors = append(errors, err)
}
}
}
return x, compiler.NewErrorGroupOrNil(errors)
}
// NewNamedHeader creates an object of type NamedHeader if possible, returning an error if not.
func NewNamedHeader(in interface{}, context *compiler.Context) (*NamedHeader, error) {
errors := make([]error, 0)
x := &NamedHeader{}
m, ok := compiler.UnpackMap(in)
if !ok {
message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)
errors = append(errors, compiler.NewError(context, message))
} else {
allowedKeys := []string{"name", "value"}
var allowedPatterns []*regexp.Regexp
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
errors = append(errors, compiler.NewError(context, message))
}
// string name = 1;
v1 := compiler.MapValueForKey(m, "name")
if v1 != nil {
x.Name, ok = v1.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for name: %+v (%T)", v1, v1)
errors = append(errors, compiler.NewError(context, message))
}
}
// Header value = 2;
v2 := compiler.MapValueForKey(m, "value")
if v2 != nil {
var err error
x.Value, err = NewHeader(v2, compiler.NewContext("value", context))
if err != nil {
errors = append(errors, err)
}
}
}
return x, compiler.NewErrorGroupOrNil(errors)
}
// NewNamedParameter creates an object of type NamedParameter if possible, returning an error if not.
func NewNamedParameter(in interface{}, context *compiler.Context) (*NamedParameter, error) {
errors := make([]error, 0)
x := &NamedParameter{}
m, ok := compiler.UnpackMap(in)
if !ok {
message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)
errors = append(errors, compiler.NewError(context, message))
} else {
allowedKeys := []string{"name", "value"}
var allowedPatterns []*regexp.Regexp
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
errors = append(errors, compiler.NewError(context, message))
}
// string name = 1;
v1 := compiler.MapValueForKey(m, "name")
if v1 != nil {
x.Name, ok = v1.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for name: %+v (%T)", v1, v1)
errors = append(errors, compiler.NewError(context, message))
}
}
// Parameter value = 2;
v2 := compiler.MapValueForKey(m, "value")
if v2 != nil {
var err error
x.Value, err = NewParameter(v2, compiler.NewContext("value", context))
if err != nil {
errors = append(errors, err)
}
}
}
return x, compiler.NewErrorGroupOrNil(errors)
}
// NewNamedPathItem creates an object of type NamedPathItem if possible, returning an error if not.
func NewNamedPathItem(in interface{}, context *compiler.Context) (*NamedPathItem, error) {
errors := make([]error, 0)
x := &NamedPathItem{}
m, ok := compiler.UnpackMap(in)
if !ok {
message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)
errors = append(errors, compiler.NewError(context, message))
} else {
allowedKeys := []string{"name", "value"}
var allowedPatterns []*regexp.Regexp
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
errors = append(errors, compiler.NewError(context, message))
}
// string name = 1;
v1 := compiler.MapValueForKey(m, "name")
if v1 != nil {
x.Name, ok = v1.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for name: %+v (%T)", v1, v1)
errors = append(errors, compiler.NewError(context, message))
}
}
// PathItem value = 2;
v2 := compiler.MapValueForKey(m, "value")
if v2 != nil {
var err error
x.Value, err = NewPathItem(v2, compiler.NewContext("value", context))
if err != nil {
errors = append(errors, err)
}
}
}
return x, compiler.NewErrorGroupOrNil(errors)
}
// NewNamedResponse creates an object of type NamedResponse if possible, returning an error if not.
func NewNamedResponse(in interface{}, context *compiler.Context) (*NamedResponse, error) {
errors := make([]error, 0)
x := &NamedResponse{}
m, ok := compiler.UnpackMap(in)
if !ok {
message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)
errors = append(errors, compiler.NewError(context, message))
} else {
allowedKeys := []string{"name", "value"}
var allowedPatterns []*regexp.Regexp
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
errors = append(errors, compiler.NewError(context, message))
}
// string name = 1;
v1 := compiler.MapValueForKey(m, "name")
if v1 != nil {
x.Name, ok = v1.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for name: %+v (%T)", v1, v1)
errors = append(errors, compiler.NewError(context, message))
}
}
// Response value = 2;
v2 := compiler.MapValueForKey(m, "value")
if v2 != nil {
var err error
x.Value, err = NewResponse(v2, compiler.NewContext("value", context))
if err != nil {
errors = append(errors, err)
}
}
}
return x, compiler.NewErrorGroupOrNil(errors)
}
// NewNamedResponseValue creates an object of type NamedResponseValue if possible, returning an error if not.
func NewNamedResponseValue(in interface{}, context *compiler.Context) (*NamedResponseValue, error) {
errors := make([]error, 0)
x := &NamedResponseValue{}
m, ok := compiler.UnpackMap(in)
if !ok {
message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)
errors = append(errors, compiler.NewError(context, message))
} else {
allowedKeys := []string{"name", "value"}
var allowedPatterns []*regexp.Regexp
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
errors = append(errors, compiler.NewError(context, message))
}
// string name = 1;
v1 := compiler.MapValueForKey(m, "name")
if v1 != nil {
x.Name, ok = v1.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for name: %+v (%T)", v1, v1)
errors = append(errors, compiler.NewError(context, message))
}
}
// ResponseValue value = 2;
v2 := compiler.MapValueForKey(m, "value")
if v2 != nil {
var err error
x.Value, err = NewResponseValue(v2, compiler.NewContext("value", context))
if err != nil {
errors = append(errors, err)
}
}
}
return x, compiler.NewErrorGroupOrNil(errors)
}
// NewNamedSchema creates an object of type NamedSchema if possible, returning an error if not.
func NewNamedSchema(in interface{}, context *compiler.Context) (*NamedSchema, error) {
errors := make([]error, 0)
x := &NamedSchema{}
m, ok := compiler.UnpackMap(in)
if !ok {
message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)
errors = append(errors, compiler.NewError(context, message))
} else {
allowedKeys := []string{"name", "value"}
var allowedPatterns []*regexp.Regexp
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
errors = append(errors, compiler.NewError(context, message))
}
// string name = 1;
v1 := compiler.MapValueForKey(m, "name")
if v1 != nil {
x.Name, ok = v1.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for name: %+v (%T)", v1, v1)
errors = append(errors, compiler.NewError(context, message))
}
}
// Schema value = 2;
v2 := compiler.MapValueForKey(m, "value")
if v2 != nil {
var err error
x.Value, err = NewSchema(v2, compiler.NewContext("value", context))
if err != nil {
errors = append(errors, err)
}
}
}
return x, compiler.NewErrorGroupOrNil(errors)
}
// NewNamedSecurityDefinitionsItem creates an object of type NamedSecurityDefinitionsItem if possible, returning an error if not.
func NewNamedSecurityDefinitionsItem(in interface{}, context *compiler.Context) (*NamedSecurityDefinitionsItem, error) {
errors := make([]error, 0)
x := &NamedSecurityDefinitionsItem{}
m, ok := compiler.UnpackMap(in)
if !ok {
message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)
errors = append(errors, compiler.NewError(context, message))
} else {
allowedKeys := []string{"name", "value"}
var allowedPatterns []*regexp.Regexp
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
errors = append(errors, compiler.NewError(context, message))
}
// string name = 1;
v1 := compiler.MapValueForKey(m, "name")
if v1 != nil {
x.Name, ok = v1.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for name: %+v (%T)", v1, v1)
errors = append(errors, compiler.NewError(context, message))
}
}
// SecurityDefinitionsItem value = 2;
v2 := compiler.MapValueForKey(m, "value")
if v2 != nil {
var err error
x.Value, err = NewSecurityDefinitionsItem(v2, compiler.NewContext("value", context))
if err != nil {
errors = append(errors, err)
}
}
}
return x, compiler.NewErrorGroupOrNil(errors)
}
// NewNamedString creates an object of type NamedString if possible, returning an error if not.
func NewNamedString(in interface{}, context *compiler.Context) (*NamedString, error) {
errors := make([]error, 0)
x := &NamedString{}
m, ok := compiler.UnpackMap(in)
if !ok {
message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)
errors = append(errors, compiler.NewError(context, message))
} else {
allowedKeys := []string{"name", "value"}
var allowedPatterns []*regexp.Regexp
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
errors = append(errors, compiler.NewError(context, message))
}
// string name = 1;
v1 := compiler.MapValueForKey(m, "name")
if v1 != nil {
x.Name, ok = v1.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for name: %+v (%T)", v1, v1)
errors = append(errors, compiler.NewError(context, message))
}
}
// string value = 2;
v2 := compiler.MapValueForKey(m, "value")
if v2 != nil {
x.Value, ok = v2.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for value: %+v (%T)", v2, v2)
errors = append(errors, compiler.NewError(context, message))
}
}
}
return x, compiler.NewErrorGroupOrNil(errors)
}
// NewNamedStringArray creates an object of type NamedStringArray if possible, returning an error if not.
func NewNamedStringArray(in interface{}, context *compiler.Context) (*NamedStringArray, error) {
errors := make([]error, 0)
x := &NamedStringArray{}
m, ok := compiler.UnpackMap(in)
if !ok {
message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)
errors = append(errors, compiler.NewError(context, message))
} else {
allowedKeys := []string{"name", "value"}
var allowedPatterns []*regexp.Regexp
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
errors = append(errors, compiler.NewError(context, message))
}
// string name = 1;
v1 := compiler.MapValueForKey(m, "name")
if v1 != nil {
x.Name, ok = v1.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for name: %+v (%T)", v1, v1)
errors = append(errors, compiler.NewError(context, message))
}
}
// StringArray value = 2;
v2 := compiler.MapValueForKey(m, "value")
if v2 != nil {
var err error
x.Value, err = NewStringArray(v2, compiler.NewContext("value", context))
if err != nil {
errors = append(errors, err)
}
}
}
return x, compiler.NewErrorGroupOrNil(errors)
}
// NewNonBodyParameter creates an object of type NonBodyParameter if possible, returning an error if not.
func NewNonBodyParameter(in interface{}, context *compiler.Context) (*NonBodyParameter, error) {
errors := make([]error, 0)
x := &NonBodyParameter{}
matched := false
m, ok := compiler.UnpackMap(in)
if !ok {
message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)
errors = append(errors, compiler.NewError(context, message))
} else {
requiredKeys := []string{"in", "name", "type"}
missingKeys := compiler.MissingKeysInMap(m, requiredKeys)
if len(missingKeys) > 0 {
message := fmt.Sprintf("is missing required %s: %+v", compiler.PluralProperties(len(missingKeys)), strings.Join(missingKeys, ", "))
errors = append(errors, compiler.NewError(context, message))
}
// HeaderParameterSubSchema header_parameter_sub_schema = 1;
{
// errors might be ok here, they mean we just don't have the right subtype
t, matchingError := NewHeaderParameterSubSchema(m, compiler.NewContext("headerParameterSubSchema", context))
if matchingError == nil {
x.Oneof = &NonBodyParameter_HeaderParameterSubSchema{HeaderParameterSubSchema: t}
matched = true
} else {
errors = append(errors, matchingError)
}
}
// FormDataParameterSubSchema form_data_parameter_sub_schema = 2;
{
// errors might be ok here, they mean we just don't have the right subtype
t, matchingError := NewFormDataParameterSubSchema(m, compiler.NewContext("formDataParameterSubSchema", context))
if matchingError == nil {
x.Oneof = &NonBodyParameter_FormDataParameterSubSchema{FormDataParameterSubSchema: t}
matched = true
} else {
errors = append(errors, matchingError)
}
}
// QueryParameterSubSchema query_parameter_sub_schema = 3;
{
// errors might be ok here, they mean we just don't have the right subtype
t, matchingError := NewQueryParameterSubSchema(m, compiler.NewContext("queryParameterSubSchema", context))
if matchingError == nil {
x.Oneof = &NonBodyParameter_QueryParameterSubSchema{QueryParameterSubSchema: t}
matched = true
} else {
errors = append(errors, matchingError)
}
}
// PathParameterSubSchema path_parameter_sub_schema = 4;
{
// errors might be ok here, they mean we just don't have the right subtype
t, matchingError := NewPathParameterSubSchema(m, compiler.NewContext("pathParameterSubSchema", context))
if matchingError == nil {
x.Oneof = &NonBodyParameter_PathParameterSubSchema{PathParameterSubSchema: t}
matched = true
} else {
errors = append(errors, matchingError)
}
}
}
if matched {
// since the oneof matched one of its possibilities, discard any matching errors
errors = make([]error, 0)
}
return x, compiler.NewErrorGroupOrNil(errors)
}
// NewOauth2AccessCodeSecurity creates an object of type Oauth2AccessCodeSecurity if possible, returning an error if not.
func NewOauth2AccessCodeSecurity(in interface{}, context *compiler.Context) (*Oauth2AccessCodeSecurity, error) {
errors := make([]error, 0)
x := &Oauth2AccessCodeSecurity{}
m, ok := compiler.UnpackMap(in)
if !ok {
message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)
errors = append(errors, compiler.NewError(context, message))
} else {
requiredKeys := []string{"authorizationUrl", "flow", "tokenUrl", "type"}
missingKeys := compiler.MissingKeysInMap(m, requiredKeys)
if len(missingKeys) > 0 {
message := fmt.Sprintf("is missing required %s: %+v", compiler.PluralProperties(len(missingKeys)), strings.Join(missingKeys, ", "))
errors = append(errors, compiler.NewError(context, message))
}
allowedKeys := []string{"authorizationUrl", "description", "flow", "scopes", "tokenUrl", "type"}
allowedPatterns := []*regexp.Regexp{pattern0}
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
errors = append(errors, compiler.NewError(context, message))
}
// string type = 1;
v1 := compiler.MapValueForKey(m, "type")
if v1 != nil {
x.Type, ok = v1.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for type: %+v (%T)", v1, v1)
errors = append(errors, compiler.NewError(context, message))
}
// check for valid enum values
// [oauth2]
if ok && !compiler.StringArrayContainsValue([]string{"oauth2"}, x.Type) {
message := fmt.Sprintf("has unexpected value for type: %+v (%T)", v1, v1)
errors = append(errors, compiler.NewError(context, message))
}
}
// string flow = 2;
v2 := compiler.MapValueForKey(m, "flow")
if v2 != nil {
x.Flow, ok = v2.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for flow: %+v (%T)", v2, v2)
errors = append(errors, compiler.NewError(context, message))
}
// check for valid enum values
// [accessCode]
if ok && !compiler.StringArrayContainsValue([]string{"accessCode"}, x.Flow) {
message := fmt.Sprintf("has unexpected value for flow: %+v (%T)", v2, v2)
errors = append(errors, compiler.NewError(context, message))
}
}
// Oauth2Scopes scopes = 3;
v3 := compiler.MapValueForKey(m, "scopes")
if v3 != nil {
var err error
x.Scopes, err = NewOauth2Scopes(v3, compiler.NewContext("scopes", context))
if err != nil {
errors = append(errors, err)
}
}
// string authorization_url = 4;
v4 := compiler.MapValueForKey(m, "authorizationUrl")
if v4 != nil {
x.AuthorizationUrl, ok = v4.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for authorizationUrl: %+v (%T)", v4, v4)
errors = append(errors, compiler.NewError(context, message))
}
}
// string token_url = 5;
v5 := compiler.MapValueForKey(m, "tokenUrl")
if v5 != nil {
x.TokenUrl, ok = v5.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for tokenUrl: %+v (%T)", v5, v5)
errors = append(errors, compiler.NewError(context, message))
}
}
// string description = 6;
v6 := compiler.MapValueForKey(m, "description")
if v6 != nil {
x.Description, ok = v6.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for description: %+v (%T)", v6, v6)
errors = append(errors, compiler.NewError(context, message))
}
}
// repeated NamedAny vendor_extension = 7;
// MAP: Any ^x-
x.VendorExtension = make([]*NamedAny, 0)
for _, item := range m {
k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
if strings.HasPrefix(k, "x-") {
pair := &NamedAny{}
pair.Name = k
result := &Any{}
handled, resultFromExt, err := compiler.HandleExtension(context, v, k)
if handled {
if err != nil {
errors = append(errors, err)
} else {
bytes, _ := yaml.Marshal(v)
result.Yaml = string(bytes)
result.Value = resultFromExt
pair.Value = result
}
} else {
pair.Value, err = NewAny(v, compiler.NewContext(k, context))
if err != nil {
errors = append(errors, err)
}
}
x.VendorExtension = append(x.VendorExtension, pair)
}
}
}
}
return x, compiler.NewErrorGroupOrNil(errors)
}
// NewOauth2ApplicationSecurity creates an object of type Oauth2ApplicationSecurity if possible, returning an error if not.
func NewOauth2ApplicationSecurity(in interface{}, context *compiler.Context) (*Oauth2ApplicationSecurity, error) {
errors := make([]error, 0)
x := &Oauth2ApplicationSecurity{}
m, ok := compiler.UnpackMap(in)
if !ok {
message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)
errors = append(errors, compiler.NewError(context, message))
} else {
requiredKeys := []string{"flow", "tokenUrl", "type"}
missingKeys := compiler.MissingKeysInMap(m, requiredKeys)
if len(missingKeys) > 0 {
message := fmt.Sprintf("is missing required %s: %+v", compiler.PluralProperties(len(missingKeys)), strings.Join(missingKeys, ", "))
errors = append(errors, compiler.NewError(context, message))
}
allowedKeys := []string{"description", "flow", "scopes", "tokenUrl", "type"}
allowedPatterns := []*regexp.Regexp{pattern0}
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
errors = append(errors, compiler.NewError(context, message))
}
// string type = 1;
v1 := compiler.MapValueForKey(m, "type")
if v1 != nil {
x.Type, ok = v1.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for type: %+v (%T)", v1, v1)
errors = append(errors, compiler.NewError(context, message))
}
// check for valid enum values
// [oauth2]
if ok && !compiler.StringArrayContainsValue([]string{"oauth2"}, x.Type) {
message := fmt.Sprintf("has unexpected value for type: %+v (%T)", v1, v1)
errors = append(errors, compiler.NewError(context, message))
}
}
// string flow = 2;
v2 := compiler.MapValueForKey(m, "flow")
if v2 != nil {
x.Flow, ok = v2.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for flow: %+v (%T)", v2, v2)
errors = append(errors, compiler.NewError(context, message))
}
// check for valid enum values
// [application]
if ok && !compiler.StringArrayContainsValue([]string{"application"}, x.Flow) {
message := fmt.Sprintf("has unexpected value for flow: %+v (%T)", v2, v2)
errors = append(errors, compiler.NewError(context, message))
}
}
// Oauth2Scopes scopes = 3;
v3 := compiler.MapValueForKey(m, "scopes")
if v3 != nil {
var err error
x.Scopes, err = NewOauth2Scopes(v3, compiler.NewContext("scopes", context))
if err != nil {
errors = append(errors, err)
}
}
// string token_url = 4;
v4 := compiler.MapValueForKey(m, "tokenUrl")
if v4 != nil {
x.TokenUrl, ok = v4.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for tokenUrl: %+v (%T)", v4, v4)
errors = append(errors, compiler.NewError(context, message))
}
}
// string description = 5;
v5 := compiler.MapValueForKey(m, "description")
if v5 != nil {
x.Description, ok = v5.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for description: %+v (%T)", v5, v5)
errors = append(errors, compiler.NewError(context, message))
}
}
// repeated NamedAny vendor_extension = 6;
// MAP: Any ^x-
x.VendorExtension = make([]*NamedAny, 0)
for _, item := range m {
k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
if strings.HasPrefix(k, "x-") {
pair := &NamedAny{}
pair.Name = k
result := &Any{}
handled, resultFromExt, err := compiler.HandleExtension(context, v, k)
if handled {
if err != nil {
errors = append(errors, err)
} else {
bytes, _ := yaml.Marshal(v)
result.Yaml = string(bytes)
result.Value = resultFromExt
pair.Value = result
}
} else {
pair.Value, err = NewAny(v, compiler.NewContext(k, context))
if err != nil {
errors = append(errors, err)
}
}
x.VendorExtension = append(x.VendorExtension, pair)
}
}
}
}
return x, compiler.NewErrorGroupOrNil(errors)
}
// NewOauth2ImplicitSecurity creates an object of type Oauth2ImplicitSecurity if possible, returning an error if not.
func NewOauth2ImplicitSecurity(in interface{}, context *compiler.Context) (*Oauth2ImplicitSecurity, error) {
errors := make([]error, 0)
x := &Oauth2ImplicitSecurity{}
m, ok := compiler.UnpackMap(in)
if !ok {
message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)
errors = append(errors, compiler.NewError(context, message))
} else {
requiredKeys := []string{"authorizationUrl", "flow", "type"}
missingKeys := compiler.MissingKeysInMap(m, requiredKeys)
if len(missingKeys) > 0 {
message := fmt.Sprintf("is missing required %s: %+v", compiler.PluralProperties(len(missingKeys)), strings.Join(missingKeys, ", "))
errors = append(errors, compiler.NewError(context, message))
}
allowedKeys := []string{"authorizationUrl", "description", "flow", "scopes", "type"}
allowedPatterns := []*regexp.Regexp{pattern0}
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
errors = append(errors, compiler.NewError(context, message))
}
// string type = 1;
v1 := compiler.MapValueForKey(m, "type")
if v1 != nil {
x.Type, ok = v1.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for type: %+v (%T)", v1, v1)
errors = append(errors, compiler.NewError(context, message))
}
// check for valid enum values
// [oauth2]
if ok && !compiler.StringArrayContainsValue([]string{"oauth2"}, x.Type) {
message := fmt.Sprintf("has unexpected value for type: %+v (%T)", v1, v1)
errors = append(errors, compiler.NewError(context, message))
}
}
// string flow = 2;
v2 := compiler.MapValueForKey(m, "flow")
if v2 != nil {
x.Flow, ok = v2.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for flow: %+v (%T)", v2, v2)
errors = append(errors, compiler.NewError(context, message))
}
// check for valid enum values
// [implicit]
if ok && !compiler.StringArrayContainsValue([]string{"implicit"}, x.Flow) {
message := fmt.Sprintf("has unexpected value for flow: %+v (%T)", v2, v2)
errors = append(errors, compiler.NewError(context, message))
}
}
// Oauth2Scopes scopes = 3;
v3 := compiler.MapValueForKey(m, "scopes")
if v3 != nil {
var err error
x.Scopes, err = NewOauth2Scopes(v3, compiler.NewContext("scopes", context))
if err != nil {
errors = append(errors, err)
}
}
// string authorization_url = 4;
v4 := compiler.MapValueForKey(m, "authorizationUrl")
if v4 != nil {
x.AuthorizationUrl, ok = v4.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for authorizationUrl: %+v (%T)", v4, v4)
errors = append(errors, compiler.NewError(context, message))
}
}
// string description = 5;
v5 := compiler.MapValueForKey(m, "description")
if v5 != nil {
x.Description, ok = v5.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for description: %+v (%T)", v5, v5)
errors = append(errors, compiler.NewError(context, message))
}
}
// repeated NamedAny vendor_extension = 6;
// MAP: Any ^x-
x.VendorExtension = make([]*NamedAny, 0)
for _, item := range m {
k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
if strings.HasPrefix(k, "x-") {
pair := &NamedAny{}
pair.Name = k
result := &Any{}
handled, resultFromExt, err := compiler.HandleExtension(context, v, k)
if handled {
if err != nil {
errors = append(errors, err)
} else {
bytes, _ := yaml.Marshal(v)
result.Yaml = string(bytes)
result.Value = resultFromExt
pair.Value = result
}
} else {
pair.Value, err = NewAny(v, compiler.NewContext(k, context))
if err != nil {
errors = append(errors, err)
}
}
x.VendorExtension = append(x.VendorExtension, pair)
}
}
}
}
return x, compiler.NewErrorGroupOrNil(errors)
}
// NewOauth2PasswordSecurity creates an object of type Oauth2PasswordSecurity if possible, returning an error if not.
func NewOauth2PasswordSecurity(in interface{}, context *compiler.Context) (*Oauth2PasswordSecurity, error) {
errors := make([]error, 0)
x := &Oauth2PasswordSecurity{}
m, ok := compiler.UnpackMap(in)
if !ok {
message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)
errors = append(errors, compiler.NewError(context, message))
} else {
requiredKeys := []string{"flow", "tokenUrl", "type"}
missingKeys := compiler.MissingKeysInMap(m, requiredKeys)
if len(missingKeys) > 0 {
message := fmt.Sprintf("is missing required %s: %+v", compiler.PluralProperties(len(missingKeys)), strings.Join(missingKeys, ", "))
errors = append(errors, compiler.NewError(context, message))
}
allowedKeys := []string{"description", "flow", "scopes", "tokenUrl", "type"}
allowedPatterns := []*regexp.Regexp{pattern0}
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
errors = append(errors, compiler.NewError(context, message))
}
// string type = 1;
v1 := compiler.MapValueForKey(m, "type")
if v1 != nil {
x.Type, ok = v1.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for type: %+v (%T)", v1, v1)
errors = append(errors, compiler.NewError(context, message))
}
// check for valid enum values
// [oauth2]
if ok && !compiler.StringArrayContainsValue([]string{"oauth2"}, x.Type) {
message := fmt.Sprintf("has unexpected value for type: %+v (%T)", v1, v1)
errors = append(errors, compiler.NewError(context, message))
}
}
// string flow = 2;
v2 := compiler.MapValueForKey(m, "flow")
if v2 != nil {
x.Flow, ok = v2.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for flow: %+v (%T)", v2, v2)
errors = append(errors, compiler.NewError(context, message))
}
// check for valid enum values
// [password]
if ok && !compiler.StringArrayContainsValue([]string{"password"}, x.Flow) {
message := fmt.Sprintf("has unexpected value for flow: %+v (%T)", v2, v2)
errors = append(errors, compiler.NewError(context, message))
}
}
// Oauth2Scopes scopes = 3;
v3 := compiler.MapValueForKey(m, "scopes")
if v3 != nil {
var err error
x.Scopes, err = NewOauth2Scopes(v3, compiler.NewContext("scopes", context))
if err != nil {
errors = append(errors, err)
}
}
// string token_url = 4;
v4 := compiler.MapValueForKey(m, "tokenUrl")
if v4 != nil {
x.TokenUrl, ok = v4.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for tokenUrl: %+v (%T)", v4, v4)
errors = append(errors, compiler.NewError(context, message))
}
}
// string description = 5;
v5 := compiler.MapValueForKey(m, "description")
if v5 != nil {
x.Description, ok = v5.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for description: %+v (%T)", v5, v5)
errors = append(errors, compiler.NewError(context, message))
}
}
// repeated NamedAny vendor_extension = 6;
// MAP: Any ^x-
x.VendorExtension = make([]*NamedAny, 0)
for _, item := range m {
k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
if strings.HasPrefix(k, "x-") {
pair := &NamedAny{}
pair.Name = k
result := &Any{}
handled, resultFromExt, err := compiler.HandleExtension(context, v, k)
if handled {
if err != nil {
errors = append(errors, err)
} else {
bytes, _ := yaml.Marshal(v)
result.Yaml = string(bytes)
result.Value = resultFromExt
pair.Value = result
}
} else {
pair.Value, err = NewAny(v, compiler.NewContext(k, context))
if err != nil {
errors = append(errors, err)
}
}
x.VendorExtension = append(x.VendorExtension, pair)
}
}
}
}
return x, compiler.NewErrorGroupOrNil(errors)
}
// NewOauth2Scopes creates an object of type Oauth2Scopes if possible, returning an error if not.
func NewOauth2Scopes(in interface{}, context *compiler.Context) (*Oauth2Scopes, error) {
errors := make([]error, 0)
x := &Oauth2Scopes{}
m, ok := compiler.UnpackMap(in)
if !ok {
message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)
errors = append(errors, compiler.NewError(context, message))
} else {
// repeated NamedString additional_properties = 1;
// MAP: string
x.AdditionalProperties = make([]*NamedString, 0)
for _, item := range m {
k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
pair := &NamedString{}
pair.Name = k
pair.Value = v.(string)
x.AdditionalProperties = append(x.AdditionalProperties, pair)
}
}
}
return x, compiler.NewErrorGroupOrNil(errors)
}
// NewOperation creates an object of type Operation if possible, returning an error if not.
func NewOperation(in interface{}, context *compiler.Context) (*Operation, error) {
errors := make([]error, 0)
x := &Operation{}
m, ok := compiler.UnpackMap(in)
if !ok {
message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)
errors = append(errors, compiler.NewError(context, message))
} else {
requiredKeys := []string{"responses"}
missingKeys := compiler.MissingKeysInMap(m, requiredKeys)
if len(missingKeys) > 0 {
message := fmt.Sprintf("is missing required %s: %+v", compiler.PluralProperties(len(missingKeys)), strings.Join(missingKeys, ", "))
errors = append(errors, compiler.NewError(context, message))
}
allowedKeys := []string{"consumes", "deprecated", "description", "externalDocs", "operationId", "parameters", "produces", "responses", "schemes", "security", "summary", "tags"}
allowedPatterns := []*regexp.Regexp{pattern0}
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
errors = append(errors, compiler.NewError(context, message))
}
// repeated string tags = 1;
v1 := compiler.MapValueForKey(m, "tags")
if v1 != nil {
v, ok := v1.([]interface{})
if ok {
x.Tags = compiler.ConvertInterfaceArrayToStringArray(v)
} else {
message := fmt.Sprintf("has unexpected value for tags: %+v (%T)", v1, v1)
errors = append(errors, compiler.NewError(context, message))
}
}
// string summary = 2;
v2 := compiler.MapValueForKey(m, "summary")
if v2 != nil {
x.Summary, ok = v2.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for summary: %+v (%T)", v2, v2)
errors = append(errors, compiler.NewError(context, message))
}
}
// string description = 3;
v3 := compiler.MapValueForKey(m, "description")
if v3 != nil {
x.Description, ok = v3.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for description: %+v (%T)", v3, v3)
errors = append(errors, compiler.NewError(context, message))
}
}
// ExternalDocs external_docs = 4;
v4 := compiler.MapValueForKey(m, "externalDocs")
if v4 != nil {
var err error
x.ExternalDocs, err = NewExternalDocs(v4, compiler.NewContext("externalDocs", context))
if err != nil {
errors = append(errors, err)
}
}
// string operation_id = 5;
v5 := compiler.MapValueForKey(m, "operationId")
if v5 != nil {
x.OperationId, ok = v5.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for operationId: %+v (%T)", v5, v5)
errors = append(errors, compiler.NewError(context, message))
}
}
// repeated string produces = 6;
v6 := compiler.MapValueForKey(m, "produces")
if v6 != nil {
v, ok := v6.([]interface{})
if ok {
x.Produces = compiler.ConvertInterfaceArrayToStringArray(v)
} else {
message := fmt.Sprintf("has unexpected value for produces: %+v (%T)", v6, v6)
errors = append(errors, compiler.NewError(context, message))
}
}
// repeated string consumes = 7;
v7 := compiler.MapValueForKey(m, "consumes")
if v7 != nil {
v, ok := v7.([]interface{})
if ok {
x.Consumes = compiler.ConvertInterfaceArrayToStringArray(v)
} else {
message := fmt.Sprintf("has unexpected value for consumes: %+v (%T)", v7, v7)
errors = append(errors, compiler.NewError(context, message))
}
}
// repeated ParametersItem parameters = 8;
v8 := compiler.MapValueForKey(m, "parameters")
if v8 != nil {
// repeated ParametersItem
x.Parameters = make([]*ParametersItem, 0)
a, ok := v8.([]interface{})
if ok {
for _, item := range a {
y, err := NewParametersItem(item, compiler.NewContext("parameters", context))
if err != nil {
errors = append(errors, err)
}
x.Parameters = append(x.Parameters, y)
}
}
}
// Responses responses = 9;
v9 := compiler.MapValueForKey(m, "responses")
if v9 != nil {
var err error
x.Responses, err = NewResponses(v9, compiler.NewContext("responses", context))
if err != nil {
errors = append(errors, err)
}
}
// repeated string schemes = 10;
v10 := compiler.MapValueForKey(m, "schemes")
if v10 != nil {
v, ok := v10.([]interface{})
if ok {
x.Schemes = compiler.ConvertInterfaceArrayToStringArray(v)
} else {
message := fmt.Sprintf("has unexpected value for schemes: %+v (%T)", v10, v10)
errors = append(errors, compiler.NewError(context, message))
}
// check for valid enum values
// [http https ws wss]
if ok && !compiler.StringArrayContainsValues([]string{"http", "https", "ws", "wss"}, x.Schemes) {
message := fmt.Sprintf("has unexpected value for schemes: %+v", v10)
errors = append(errors, compiler.NewError(context, message))
}
}
// bool deprecated = 11;
v11 := compiler.MapValueForKey(m, "deprecated")
if v11 != nil {
x.Deprecated, ok = v11.(bool)
if !ok {
message := fmt.Sprintf("has unexpected value for deprecated: %+v (%T)", v11, v11)
errors = append(errors, compiler.NewError(context, message))
}
}
// repeated SecurityRequirement security = 12;
v12 := compiler.MapValueForKey(m, "security")
if v12 != nil {
// repeated SecurityRequirement
x.Security = make([]*SecurityRequirement, 0)
a, ok := v12.([]interface{})
if ok {
for _, item := range a {
y, err := NewSecurityRequirement(item, compiler.NewContext("security", context))
if err != nil {
errors = append(errors, err)
}
x.Security = append(x.Security, y)
}
}
}
// repeated NamedAny vendor_extension = 13;
// MAP: Any ^x-
x.VendorExtension = make([]*NamedAny, 0)
for _, item := range m {
k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
if strings.HasPrefix(k, "x-") {
pair := &NamedAny{}
pair.Name = k
result := &Any{}
handled, resultFromExt, err := compiler.HandleExtension(context, v, k)
if handled {
if err != nil {
errors = append(errors, err)
} else {
bytes, _ := yaml.Marshal(v)
result.Yaml = string(bytes)
result.Value = resultFromExt
pair.Value = result
}
} else {
pair.Value, err = NewAny(v, compiler.NewContext(k, context))
if err != nil {
errors = append(errors, err)
}
}
x.VendorExtension = append(x.VendorExtension, pair)
}
}
}
}
return x, compiler.NewErrorGroupOrNil(errors)
}
// NewParameter creates an object of type Parameter if possible, returning an error if not.
func NewParameter(in interface{}, context *compiler.Context) (*Parameter, error) {
errors := make([]error, 0)
x := &Parameter{}
matched := false
// BodyParameter body_parameter = 1;
{
m, ok := compiler.UnpackMap(in)
if ok {
// errors might be ok here, they mean we just don't have the right subtype
t, matchingError := NewBodyParameter(m, compiler.NewContext("bodyParameter", context))
if matchingError == nil {
x.Oneof = &Parameter_BodyParameter{BodyParameter: t}
matched = true
} else {
errors = append(errors, matchingError)
}
}
}
// NonBodyParameter non_body_parameter = 2;
{
m, ok := compiler.UnpackMap(in)
if ok {
// errors might be ok here, they mean we just don't have the right subtype
t, matchingError := NewNonBodyParameter(m, compiler.NewContext("nonBodyParameter", context))
if matchingError == nil {
x.Oneof = &Parameter_NonBodyParameter{NonBodyParameter: t}
matched = true
} else {
errors = append(errors, matchingError)
}
}
}
if matched {
// since the oneof matched one of its possibilities, discard any matching errors
errors = make([]error, 0)
}
return x, compiler.NewErrorGroupOrNil(errors)
}
// NewParameterDefinitions creates an object of type ParameterDefinitions if possible, returning an error if not.
func NewParameterDefinitions(in interface{}, context *compiler.Context) (*ParameterDefinitions, error) {
errors := make([]error, 0)
x := &ParameterDefinitions{}
m, ok := compiler.UnpackMap(in)
if !ok {
message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)
errors = append(errors, compiler.NewError(context, message))
} else {
// repeated NamedParameter additional_properties = 1;
// MAP: Parameter
x.AdditionalProperties = make([]*NamedParameter, 0)
for _, item := range m {
k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
pair := &NamedParameter{}
pair.Name = k
var err error
pair.Value, err = NewParameter(v, compiler.NewContext(k, context))
if err != nil {
errors = append(errors, err)
}
x.AdditionalProperties = append(x.AdditionalProperties, pair)
}
}
}
return x, compiler.NewErrorGroupOrNil(errors)
}
// NewParametersItem creates an object of type ParametersItem if possible, returning an error if not.
func NewParametersItem(in interface{}, context *compiler.Context) (*ParametersItem, error) {
errors := make([]error, 0)
x := &ParametersItem{}
matched := false
// Parameter parameter = 1;
{
m, ok := compiler.UnpackMap(in)
if ok {
// errors might be ok here, they mean we just don't have the right subtype
t, matchingError := NewParameter(m, compiler.NewContext("parameter", context))
if matchingError == nil {
x.Oneof = &ParametersItem_Parameter{Parameter: t}
matched = true
} else {
errors = append(errors, matchingError)
}
}
}
// JsonReference json_reference = 2;
{
m, ok := compiler.UnpackMap(in)
if ok {
// errors might be ok here, they mean we just don't have the right subtype
t, matchingError := NewJsonReference(m, compiler.NewContext("jsonReference", context))
if matchingError == nil {
x.Oneof = &ParametersItem_JsonReference{JsonReference: t}
matched = true
} else {
errors = append(errors, matchingError)
}
}
}
if matched {
// since the oneof matched one of its possibilities, discard any matching errors
errors = make([]error, 0)
}
return x, compiler.NewErrorGroupOrNil(errors)
}
// NewPathItem creates an object of type PathItem if possible, returning an error if not.
func NewPathItem(in interface{}, context *compiler.Context) (*PathItem, error) {
errors := make([]error, 0)
x := &PathItem{}
m, ok := compiler.UnpackMap(in)
if !ok {
message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)
errors = append(errors, compiler.NewError(context, message))
} else {
allowedKeys := []string{"$ref", "delete", "get", "head", "options", "parameters", "patch", "post", "put"}
allowedPatterns := []*regexp.Regexp{pattern0}
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
errors = append(errors, compiler.NewError(context, message))
}
// string _ref = 1;
v1 := compiler.MapValueForKey(m, "$ref")
if v1 != nil {
x.XRef, ok = v1.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for $ref: %+v (%T)", v1, v1)
errors = append(errors, compiler.NewError(context, message))
}
}
// Operation get = 2;
v2 := compiler.MapValueForKey(m, "get")
if v2 != nil {
var err error
x.Get, err = NewOperation(v2, compiler.NewContext("get", context))
if err != nil {
errors = append(errors, err)
}
}
// Operation put = 3;
v3 := compiler.MapValueForKey(m, "put")
if v3 != nil {
var err error
x.Put, err = NewOperation(v3, compiler.NewContext("put", context))
if err != nil {
errors = append(errors, err)
}
}
// Operation post = 4;
v4 := compiler.MapValueForKey(m, "post")
if v4 != nil {
var err error
x.Post, err = NewOperation(v4, compiler.NewContext("post", context))
if err != nil {
errors = append(errors, err)
}
}
// Operation delete = 5;
v5 := compiler.MapValueForKey(m, "delete")
if v5 != nil {
var err error
x.Delete, err = NewOperation(v5, compiler.NewContext("delete", context))
if err != nil {
errors = append(errors, err)
}
}
// Operation options = 6;
v6 := compiler.MapValueForKey(m, "options")
if v6 != nil {
var err error
x.Options, err = NewOperation(v6, compiler.NewContext("options", context))
if err != nil {
errors = append(errors, err)
}
}
// Operation head = 7;
v7 := compiler.MapValueForKey(m, "head")
if v7 != nil {
var err error
x.Head, err = NewOperation(v7, compiler.NewContext("head", context))
if err != nil {
errors = append(errors, err)
}
}
// Operation patch = 8;
v8 := compiler.MapValueForKey(m, "patch")
if v8 != nil {
var err error
x.Patch, err = NewOperation(v8, compiler.NewContext("patch", context))
if err != nil {
errors = append(errors, err)
}
}
// repeated ParametersItem parameters = 9;
v9 := compiler.MapValueForKey(m, "parameters")
if v9 != nil {
// repeated ParametersItem
x.Parameters = make([]*ParametersItem, 0)
a, ok := v9.([]interface{})
if ok {
for _, item := range a {
y, err := NewParametersItem(item, compiler.NewContext("parameters", context))
if err != nil {
errors = append(errors, err)
}
x.Parameters = append(x.Parameters, y)
}
}
}
// repeated NamedAny vendor_extension = 10;
// MAP: Any ^x-
x.VendorExtension = make([]*NamedAny, 0)
for _, item := range m {
k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
if strings.HasPrefix(k, "x-") {
pair := &NamedAny{}
pair.Name = k
result := &Any{}
handled, resultFromExt, err := compiler.HandleExtension(context, v, k)
if handled {
if err != nil {
errors = append(errors, err)
} else {
bytes, _ := yaml.Marshal(v)
result.Yaml = string(bytes)
result.Value = resultFromExt
pair.Value = result
}
} else {
pair.Value, err = NewAny(v, compiler.NewContext(k, context))
if err != nil {
errors = append(errors, err)
}
}
x.VendorExtension = append(x.VendorExtension, pair)
}
}
}
}
return x, compiler.NewErrorGroupOrNil(errors)
}
// NewPathParameterSubSchema creates an object of type PathParameterSubSchema if possible, returning an error if not.
func NewPathParameterSubSchema(in interface{}, context *compiler.Context) (*PathParameterSubSchema, error) {
errors := make([]error, 0)
x := &PathParameterSubSchema{}
m, ok := compiler.UnpackMap(in)
if !ok {
message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)
errors = append(errors, compiler.NewError(context, message))
} else {
requiredKeys := []string{"required"}
missingKeys := compiler.MissingKeysInMap(m, requiredKeys)
if len(missingKeys) > 0 {
message := fmt.Sprintf("is missing required %s: %+v", compiler.PluralProperties(len(missingKeys)), strings.Join(missingKeys, ", "))
errors = append(errors, compiler.NewError(context, message))
}
allowedKeys := []string{"collectionFormat", "default", "description", "enum", "exclusiveMaximum", "exclusiveMinimum", "format", "in", "items", "maxItems", "maxLength", "maximum", "minItems", "minLength", "minimum", "multipleOf", "name", "pattern", "required", "type", "uniqueItems"}
allowedPatterns := []*regexp.Regexp{pattern0}
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
errors = append(errors, compiler.NewError(context, message))
}
// bool required = 1;
v1 := compiler.MapValueForKey(m, "required")
if v1 != nil {
x.Required, ok = v1.(bool)
if !ok {
message := fmt.Sprintf("has unexpected value for required: %+v (%T)", v1, v1)
errors = append(errors, compiler.NewError(context, message))
}
}
// string in = 2;
v2 := compiler.MapValueForKey(m, "in")
if v2 != nil {
x.In, ok = v2.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for in: %+v (%T)", v2, v2)
errors = append(errors, compiler.NewError(context, message))
}
// check for valid enum values
// [path]
if ok && !compiler.StringArrayContainsValue([]string{"path"}, x.In) {
message := fmt.Sprintf("has unexpected value for in: %+v (%T)", v2, v2)
errors = append(errors, compiler.NewError(context, message))
}
}
// string description = 3;
v3 := compiler.MapValueForKey(m, "description")
if v3 != nil {
x.Description, ok = v3.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for description: %+v (%T)", v3, v3)
errors = append(errors, compiler.NewError(context, message))
}
}
// string name = 4;
v4 := compiler.MapValueForKey(m, "name")
if v4 != nil {
x.Name, ok = v4.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for name: %+v (%T)", v4, v4)
errors = append(errors, compiler.NewError(context, message))
}
}
// string type = 5;
v5 := compiler.MapValueForKey(m, "type")
if v5 != nil {
x.Type, ok = v5.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for type: %+v (%T)", v5, v5)
errors = append(errors, compiler.NewError(context, message))
}
// check for valid enum values
// [string number boolean integer array]
if ok && !compiler.StringArrayContainsValue([]string{"string", "number", "boolean", "integer", "array"}, x.Type) {
message := fmt.Sprintf("has unexpected value for type: %+v (%T)", v5, v5)
errors = append(errors, compiler.NewError(context, message))
}
}
// string format = 6;
v6 := compiler.MapValueForKey(m, "format")
if v6 != nil {
x.Format, ok = v6.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for format: %+v (%T)", v6, v6)
errors = append(errors, compiler.NewError(context, message))
}
}
// PrimitivesItems items = 7;
v7 := compiler.MapValueForKey(m, "items")
if v7 != nil {
var err error
x.Items, err = NewPrimitivesItems(v7, compiler.NewContext("items", context))
if err != nil {
errors = append(errors, err)
}
}
// string collection_format = 8;
v8 := compiler.MapValueForKey(m, "collectionFormat")
if v8 != nil {
x.CollectionFormat, ok = v8.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for collectionFormat: %+v (%T)", v8, v8)
errors = append(errors, compiler.NewError(context, message))
}
// check for valid enum values
// [csv ssv tsv pipes]
if ok && !compiler.StringArrayContainsValue([]string{"csv", "ssv", "tsv", "pipes"}, x.CollectionFormat) {
message := fmt.Sprintf("has unexpected value for collectionFormat: %+v (%T)", v8, v8)
errors = append(errors, compiler.NewError(context, message))
}
}
// Any default = 9;
v9 := compiler.MapValueForKey(m, "default")
if v9 != nil {
var err error
x.Default, err = NewAny(v9, compiler.NewContext("default", context))
if err != nil {
errors = append(errors, err)
}
}
// float maximum = 10;
v10 := compiler.MapValueForKey(m, "maximum")
if v10 != nil {
switch v10 := v10.(type) {
case float64:
x.Maximum = v10
case float32:
x.Maximum = float64(v10)
case uint64:
x.Maximum = float64(v10)
case uint32:
x.Maximum = float64(v10)
case int64:
x.Maximum = float64(v10)
case int32:
x.Maximum = float64(v10)
case int:
x.Maximum = float64(v10)
default:
message := fmt.Sprintf("has unexpected value for maximum: %+v (%T)", v10, v10)
errors = append(errors, compiler.NewError(context, message))
}
}
// bool exclusive_maximum = 11;
v11 := compiler.MapValueForKey(m, "exclusiveMaximum")
if v11 != nil {
x.ExclusiveMaximum, ok = v11.(bool)
if !ok {
message := fmt.Sprintf("has unexpected value for exclusiveMaximum: %+v (%T)", v11, v11)
errors = append(errors, compiler.NewError(context, message))
}
}
// float minimum = 12;
v12 := compiler.MapValueForKey(m, "minimum")
if v12 != nil {
switch v12 := v12.(type) {
case float64:
x.Minimum = v12
case float32:
x.Minimum = float64(v12)
case uint64:
x.Minimum = float64(v12)
case uint32:
x.Minimum = float64(v12)
case int64:
x.Minimum = float64(v12)
case int32:
x.Minimum = float64(v12)
case int:
x.Minimum = float64(v12)
default:
message := fmt.Sprintf("has unexpected value for minimum: %+v (%T)", v12, v12)
errors = append(errors, compiler.NewError(context, message))
}
}
// bool exclusive_minimum = 13;
v13 := compiler.MapValueForKey(m, "exclusiveMinimum")
if v13 != nil {
x.ExclusiveMinimum, ok = v13.(bool)
if !ok {
message := fmt.Sprintf("has unexpected value for exclusiveMinimum: %+v (%T)", v13, v13)
errors = append(errors, compiler.NewError(context, message))
}
}
// int64 max_length = 14;
v14 := compiler.MapValueForKey(m, "maxLength")
if v14 != nil {
t, ok := v14.(int)
if ok {
x.MaxLength = int64(t)
} else {
message := fmt.Sprintf("has unexpected value for maxLength: %+v (%T)", v14, v14)
errors = append(errors, compiler.NewError(context, message))
}
}
// int64 min_length = 15;
v15 := compiler.MapValueForKey(m, "minLength")
if v15 != nil {
t, ok := v15.(int)
if ok {
x.MinLength = int64(t)
} else {
message := fmt.Sprintf("has unexpected value for minLength: %+v (%T)", v15, v15)
errors = append(errors, compiler.NewError(context, message))
}
}
// string pattern = 16;
v16 := compiler.MapValueForKey(m, "pattern")
if v16 != nil {
x.Pattern, ok = v16.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for pattern: %+v (%T)", v16, v16)
errors = append(errors, compiler.NewError(context, message))
}
}
// int64 max_items = 17;
v17 := compiler.MapValueForKey(m, "maxItems")
if v17 != nil {
t, ok := v17.(int)
if ok {
x.MaxItems = int64(t)
} else {
message := fmt.Sprintf("has unexpected value for maxItems: %+v (%T)", v17, v17)
errors = append(errors, compiler.NewError(context, message))
}
}
// int64 min_items = 18;
v18 := compiler.MapValueForKey(m, "minItems")
if v18 != nil {
t, ok := v18.(int)
if ok {
x.MinItems = int64(t)
} else {
message := fmt.Sprintf("has unexpected value for minItems: %+v (%T)", v18, v18)
errors = append(errors, compiler.NewError(context, message))
}
}
// bool unique_items = 19;
v19 := compiler.MapValueForKey(m, "uniqueItems")
if v19 != nil {
x.UniqueItems, ok = v19.(bool)
if !ok {
message := fmt.Sprintf("has unexpected value for uniqueItems: %+v (%T)", v19, v19)
errors = append(errors, compiler.NewError(context, message))
}
}
// repeated Any enum = 20;
v20 := compiler.MapValueForKey(m, "enum")
if v20 != nil {
// repeated Any
x.Enum = make([]*Any, 0)
a, ok := v20.([]interface{})
if ok {
for _, item := range a {
y, err := NewAny(item, compiler.NewContext("enum", context))
if err != nil {
errors = append(errors, err)
}
x.Enum = append(x.Enum, y)
}
}
}
// float multiple_of = 21;
v21 := compiler.MapValueForKey(m, "multipleOf")
if v21 != nil {
switch v21 := v21.(type) {
case float64:
x.MultipleOf = v21
case float32:
x.MultipleOf = float64(v21)
case uint64:
x.MultipleOf = float64(v21)
case uint32:
x.MultipleOf = float64(v21)
case int64:
x.MultipleOf = float64(v21)
case int32:
x.MultipleOf = float64(v21)
case int:
x.MultipleOf = float64(v21)
default:
message := fmt.Sprintf("has unexpected value for multipleOf: %+v (%T)", v21, v21)
errors = append(errors, compiler.NewError(context, message))
}
}
// repeated NamedAny vendor_extension = 22;
// MAP: Any ^x-
x.VendorExtension = make([]*NamedAny, 0)
for _, item := range m {
k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
if strings.HasPrefix(k, "x-") {
pair := &NamedAny{}
pair.Name = k
result := &Any{}
handled, resultFromExt, err := compiler.HandleExtension(context, v, k)
if handled {
if err != nil {
errors = append(errors, err)
} else {
bytes, _ := yaml.Marshal(v)
result.Yaml = string(bytes)
result.Value = resultFromExt
pair.Value = result
}
} else {
pair.Value, err = NewAny(v, compiler.NewContext(k, context))
if err != nil {
errors = append(errors, err)
}
}
x.VendorExtension = append(x.VendorExtension, pair)
}
}
}
}
return x, compiler.NewErrorGroupOrNil(errors)
}
// NewPaths creates an object of type Paths if possible, returning an error if not.
func NewPaths(in interface{}, context *compiler.Context) (*Paths, error) {
errors := make([]error, 0)
x := &Paths{}
m, ok := compiler.UnpackMap(in)
if !ok {
message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)
errors = append(errors, compiler.NewError(context, message))
} else {
allowedKeys := []string{}
allowedPatterns := []*regexp.Regexp{pattern0, pattern1}
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
errors = append(errors, compiler.NewError(context, message))
}
// repeated NamedAny vendor_extension = 1;
// MAP: Any ^x-
x.VendorExtension = make([]*NamedAny, 0)
for _, item := range m {
k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
if strings.HasPrefix(k, "x-") {
pair := &NamedAny{}
pair.Name = k
result := &Any{}
handled, resultFromExt, err := compiler.HandleExtension(context, v, k)
if handled {
if err != nil {
errors = append(errors, err)
} else {
bytes, _ := yaml.Marshal(v)
result.Yaml = string(bytes)
result.Value = resultFromExt
pair.Value = result
}
} else {
pair.Value, err = NewAny(v, compiler.NewContext(k, context))
if err != nil {
errors = append(errors, err)
}
}
x.VendorExtension = append(x.VendorExtension, pair)
}
}
}
// repeated NamedPathItem path = 2;
// MAP: PathItem ^/
x.Path = make([]*NamedPathItem, 0)
for _, item := range m {
k, ok := compiler.StringValue(item.Key)
if ok {
v := item.Value
if strings.HasPrefix(k, "/") {
pair := &NamedPathItem{}
pair.Name = k
var err error
pair.Value, err = NewPathItem(v, compiler.NewContext(k, context))
if err != nil {
errors = append(errors, err)
}
x.Path = append(x.Path, pair)
}
}
}
}
return x, compiler.NewErrorGroupOrNil(errors)
}
// NewPrimitivesItems creates an object of type PrimitivesItems if possible, returning an error if not.
func NewPrimitivesItems(in interface{}, context *compiler.Context) (*PrimitivesItems, error) {
errors := make([]error, 0)
x := &PrimitivesItems{}
m, ok := compiler.UnpackMap(in)
if !ok {
message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)
errors = append(errors, compiler.NewError(context, message))
} else {
allowedKeys := []string{"collectionFormat", "default", "enum", "exclusiveMaximum", "exclusiveMinimum", "format", "items", "maxItems", "maxLength", "maximum", "minItems", "minLength", "minimum", "multipleOf", "pattern", "type", "uniqueItems"}
allowedPatterns := []*regexp.Regexp{pattern0}
invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
if len(invalidKeys) > 0 {
message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
errors = append(errors, compiler.NewError(context, message))
}
// string type = 1;
v1 := compiler.MapValueForKey(m, "type")
if v1 != nil {
x.Type, ok = v1.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for type: %+v (%T)", v1, v1)
errors = append(errors, compiler.NewError(context, message))
}
// check for valid enum values
// [string number integer boolean array]
if ok && !compiler.StringArrayContainsValue([]string{"string", "number", "integer", "boolean", "array"}, x.Type) {
message := fmt.Sprintf("has unexpected value for type: %+v (%T)", v1, v1)
errors = append(errors, compiler.NewError(context, message))
}
}
// string format = 2;
v2 := compiler.MapValueForKey(m, "format")
if v2 != nil {
x.Format, ok = v2.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for format: %+v (%T)", v2, v2)
errors = append(errors, compiler.NewError(context, message))
}
}
// PrimitivesItems items = 3;
v3 := compiler.MapValueForKey(m, "items")
if v3 != nil {
var err error
x.Items, err = NewPrimitivesItems(v3, compiler.NewContext("items", context))
if err != nil {
errors = append(errors, err)
}
}
// string collection_format = 4;
v4 := compiler.MapValueForKey(m, "collectionFormat")
if v4 != nil {
x.CollectionFormat, ok = v4.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for collectionFormat: %+v (%T)", v4, v4)
errors = append(errors, compiler.NewError(context, message))
}
// check for valid enum values
// [csv ssv tsv pipes]
if ok && !compiler.StringArrayContainsValue([]string{"csv", "ssv", "tsv", "pipes"}, x.CollectionFormat) {
message := fmt.Sprintf("has unexpected value for collectionFormat: %+v (%T)", v4, v4)
errors = append(errors, compiler.NewError(context, message))
}
}
// Any default = 5;
v5 := compiler.MapValueForKey(m, "default")
if v5 != nil {
var err error
x.Default, err = NewAny(v5, compiler.NewContext("default", context))
if err != nil {
errors = append(errors, err)
}
}
// float maximum = 6;
v6 := compiler.MapValueForKey(m, "maximum")
if v6 != nil {
switch v6 := v6.(type) {
case float64:
x.Maximum = v6
case float32:
x.Maximum = float64(v6)
case uint64:
x.Maximum = float64(v6)
case uint32:
x.Maximum = float64(v6)
case int64:
x.Maximum = float64(v6)
case int32:
x.Maximum = float64(v6)
case int:
x.Maximum = float64(v6)
default:
message := fmt.Sprintf("has unexpected value for maximum: %+v (%T)", v6, v6)
errors = append(errors, compiler.NewError(context, message))
}
}
// bool exclusive_maximum = 7;
v7 := compiler.MapValueForKey(m, "exclusiveMaximum")
if v7 != nil {
x.ExclusiveMaximum, ok = v7.(bool)
if !ok {
message := fmt.Sprintf("has unexpected value for exclusiveMaximum: %+v (%T)", v7, v7)
errors = append(errors, compiler.NewError(context, message))
}
}
// float minimum = 8;
v8 := compiler.MapValueForKey(m, "minimum")
if v8 != nil {
switch v8 := v8.(type) {
case float64:
x.Minimum = v8
case float32:
x.Minimum = float64(v8)
case uint64:
x.Minimum = float64(v8)
case uint32:
x.Minimum = float64(v8)
case int64:
x.Minimum = float64(v8)
case int32:
x.Minimum = float64(v8)
case int:
x.Minimum = float64(v8)
default:
message := fmt.Sprintf("has unexpected value for minimum: %+v (%T)", v8, v8)
errors = append(errors, compiler.NewError(context, message))
}
}
// bool exclusive_minimum = 9;
v9 := compiler.MapValueForKey(m, "exclusiveMinimum")
if v9 != nil {
x.ExclusiveMinimum, ok = v9.(bool)
if !ok {
message := fmt.Sprintf("has unexpected value for exclusiveMinimum: %+v (%T)", v9, v9)
errors = append(errors, compiler.NewError(context, message))
}
}
// int64 max_length = 10;
v10 := compiler.MapValueForKey(m, "maxLength")
if v10 != nil {
t, ok := v10.(int)
if ok {
x.MaxLength = int64(t)
} else {
message := fmt.Sprintf("has unexpected value for maxLength: %+v (%T)", v10, v10)
errors = append(errors, compiler.NewError(context, message))
}
}
// int64 min_length = 11;
v11 := compiler.MapValueForKey(m, "minLength")
if v11 != nil {
t, ok := v11.(int)
if ok {
x.MinLength = int64(t)
} else {
message := fmt.Sprintf("has unexpected value for minLength: %+v (%T)", v11, v11)
errors = append(errors, compiler.NewError(context, message))
}
}
// string pattern = 12;
v12 := compiler.MapValueForKey(m, "pattern")
if v12 != nil {
x.Pattern, ok = v12.(string)
if !ok {
message := fmt.Sprintf("has unexpected value for pattern: %+v (%T)", v12, v12)
errors = append(errors, compiler.NewError(context, message))
}
}
// int64 max_items = 13;
v13 := compiler.MapValueForKey(m, "maxItems")
if v13 != nil {
t, ok := v13.(int)
if ok {
x.MaxItems = int64(t)
} else {
message := fmt.Sprintf("has unexpected value for maxItems: %+v (%T)", v13, v13)
errors = append(errors, compiler.NewError(context, message))
}
}
// int64 min_items = 14;
v14 := compiler.MapValueForKey(m, "minItems")
if v14 != nil {
t, ok := v14.(int)
if ok {
x.MinItems = int64(t)
} else {
message := fmt.Sprintf("has unexpected value for minItems: %+v (%T)", v14, v14)
errors = append(errors, compiler.NewError(context, message))
}
}
// bool unique_items = 15;
v15 := compiler.MapValueForKey(m, "uniqueItems")
if v15 != nil {